joining of sf objects as dataframe fails: OGR: not enough data / GDAL: WKB is too small

Any idea what GDAL Error 1: Length of input WKB is too small is trying to tell me?

I get this on sf::st_transform() and sf::st_write() operations.
The cause is likely I mistreated my data.
However, I can't interpret the error to avoid it.

My workflow so somewhat like this (non-reproducible pseudocode, sorry):

sf1 <- st_read("shape1.shp")
sf2 <- st_read("shape2.shp")
selectedcols <- names(sf1)[which(names(sf1) %in% names(sf2))]

sf1 %<>% sf1 %>% select(selectedcols)
sf2 %<>% sf2 %>% select(selectedcols)

df1 <- as.data.frame(sf1)
df2 <- as.data.frame(sf2)

allshapes <- rbind(sf1, sf2)
allshapes <- st_sf(allshapes, sf_column_name = "geometry")

identical(st_crs(sf1), st_crs(allshapes)) # should be true!
allshapes <- st_transform(allshapes, crs=25832) # fails

#> OGR: Not enough data 
#> Error in CPL_transform(x, crs$proj4string) : OGR error
#> In addition: Warning message:
#> In CPL_transform(x, crs$proj4string) :
#>   GDAL Error 1: Length of input WKB is too small

st_write(allshapes, "filename.shp") # fails

# > OGR: Not enough data 
# > Error in CPL_write_ogr(obj, dsn, layer, driver, as.character(dataset_options),  : 
# >  OGR error
# > In addition: Warning message:
# >  In CPL_write_ogr(obj, dsn, layer, driver, as.character(dataset_options),  :
# >  GDAL Error 1: Length of input WKB is too small

st_write(allshapes, "filename.gpkg") # fails also

# > OGR: Not enough data 
# > Error in CPL_write_ogr(obj, dsn, layer, driver, as.character(dataset_options),  : 
# >  OGR error
# > In addition: Warning message:
# >  In CPL_write_ogr(obj, dsn, layer, driver, as.character(dataset_options),  :
# >  GDAL Error 1: Length of input WKB is too small


plot(allshapes) # works, i.e. geometry is there, attributes are there.

Note: I can't st_join(). I am fairly new to working with spatial data in R, but I am puzzled that all columns (i.e. with suffix .x and .y) are present, while the spatial part of joining throws away a large portion of my data (like: 2/3rds). This is why I opted for the rbind(as.data.frame()) way.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.