Put together this code to filter an sf object by geometry type as suggested by @Spacedman here
Posting here for others and for myself in case there are better ways to do this.
types <- st_geometry_type(my_sf_object) types_df <- data.frame(types) my_labelled_sf_object <- merge(my_sf_object, types_df,by.x=0, by.y=0, all.x=TRUE) feature_type <- "LINESTRING" # value here can be any of # GEOMETRY,POINT, LINESTRING, POLYGON, MULTIPOINT, MULTILINESTRING, MULTIPOLYGON # GEOMETRYCOLLECTION, CIRCULARSTRING, COMPOUNDCURVE, CURVEPOLYGON, MULTICURVE, # MULTISURFACE, CURVE, SURFACE, POLYHEDRALSURFACE, TIN, TRIANGLE my_filtered_sf_object <- labelled_layers[labelled_layers$types %in% feature_type,]
this use of
%in% seems correct but strikes me as very weird syntactically since really I'm selecting only rows with
feature_type in that column rather than the other way around.