I was trying to figure out what st_read does with the FID column. From reviewing the code, I found that it comes in as the names of the geometry column, i.e., one accesses it with names(nc$geometry) rather than nc$FID. Is this considered "public" behavior that should be documented?
Good point! Anything is open for discussion as long as sf has 0.x versions, as far as I'm concerned. The FIDs in sfc names have caused some havoc in conversion to leaflet, I believe in tmap and mapview. I still feel this is more natural to do than adding an FID column, since FID is not a feature attribute. Another natural thing to do would be to ignore them, since these seem shapefile remains, not part of the simple feature access standard. However, the de facto standard, GDAL, provides them.
FID when instantiated by OGRSQL and explicitly select-ed? Or when it exists in the format?
We use https://github.com/r-spatial/sf/blob/master/src/gdal_read.cpp#L214 but if I'm not mistaken OGR would create values 0, 1, etc if the format doesn't have any.
Might it make sense to put the FID in a per-sfg attribute other than the name, and use a st_fid() access method, rather than using the name?
Since #918 is also caused by named feature geometries, I propose to go with Roger's proposal:
st_read to read feature ID's and add them as an attribute column, the name of which has to be specified to st_read (like: feature_id_column_name = "FID").Please comment on short notice, sf CRAN release will happen soon. @tim-salabim @dbaston @rsbivand @mdsumner @etiennebr
Sounds good to me.
Sure, but can't sf code just ignore names rather than making pain for everyone writing constructors?
I think that is what the proposal is: ignore FIDs unless user specifies, not put them geom list column names.
st_read and st_write now both have an argument fid_column_name that can specify the name of the column containing feature IDs. By default, FIDs are ignored - many formats seem to not have them, and they don't seem to be part of the simple feature standard.
Most helpful comment
st_readandst_writenow both have an argumentfid_column_namethat can specify the name of the column containing feature IDs. By default, FIDs are ignored - many formats seem to not have them, and they don't seem to be part of the simple feature standard.