Problem creating shapefile from detectionMaps

13 views
Skip to first unread message

Emily Langer

unread,
Apr 3, 2024, 6:13:35 AMApr 3
to camtrapR
Hello--

This may be a simple error, but I'm having an issue with writing a shapefile after making a richness plot and cannot seem to find the solution. 

The function will run and produce a richness plot in r, but shows an error when writing the shapefile:

Unknown field name `Thmnphs_srts': updating a layer with improper field name(s)?
Error: Write error
In addition: Warning messages:
1: In abbreviate_shapefile_names(obj) :
  Field names abbreviated for ESRI Shapefile driver
2: In CPL_write_ogr(obj, dsn, layer, driver, as.character(dataset_options),  :
  GDAL Message 6: Normalized/laundered field name: 'Thmnphs_srts' to 'Thmnphs_sr'
3: In CPL_write_ogr(obj, dsn, layer, driver, as.character(dataset_options),  :
  GDAL Message 6: Normalized/laundered field name: 'Thmnphs_srtl' to 'Thmnphs__1'

I combed through my data and don't have any variables called "Thmnphs_srts".

I'm not sure what the issue might be here. 

Thanks,
Emily


Jürgen Niedballa

unread,
Apr 5, 2024, 2:02:00 AMApr 5
to Emily Langer, camtrapR
Hello Emily,
shapefiles are a problematic file format for a number of reasons, one of them being a hard limit on the length of column names (10 characters). To accommodate that limit R and other software will truncate column names when saving shapefiles. Hence "Thmnphs_srts" is an abbreviated species name. There is also "Thmnphs_srtl", but they are both 12 characters (guess it removes vowels in the first step). Since that is still too long they get truncated and end up being identical, which likely causes the error. 
That is not directly a camtrapR issue, but happens in the function that saves the shapefiles (st_write() from the sf package)

The best workaround is likely to save the spatial layer (output of detectioMaps) manually with st_write(). You can write to geopackage, which is generally a better format than shapefile and keeps the species names in the column headers intact. 

Something like this should work:

 outtable_sf <- st_as_sf(outtable, 
                         coords = c(Xcol, Ycol))

 outtable_sf <- st_set_crs(outtable_sf, shapefileProjection)

 st_write(obj = outtable_sf,
          dsn = "C:/path/to/geopackage.gpkg",
          layer = "species_detections")


Best regards,
Jürgen 


--
You received this message because you are subscribed to the Google Groups "camtrapR" group.
To unsubscribe from this group and stop receiving emails from it, send an email to camtrapr+u...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/camtrapr/22442734-d785-45cf-827c-6f55173577d5n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages