Add a fallback to `geometry` for FeatureCollections
Fixes #151
What do people think of this?
This enables:
tab = Shapefile.Table(...)
shapes = GI.geometry(tab)
# or, and more importantly,
tab = GeoJSON.read(...)
shapes = GI.geometry(tab)
This can always be customized for individual tables for efficiency's sake, but from a UI perspective I think this is a solid improvement over what we have now.
Seems sensible to me. Maybe a little confusing that its not getgeom and also allows getgeom(fc, i) ?
getgeom doesn't work for Features by definition though, we may want to change the API spec in some theoretical 2.0 to make that work? I guess the idea back then was probably a separation of interests between Features and Geometries (see e.g trait vs geomtrait)...
I could definitely allow geometry(fc, i) as well though.
I'm not sure what you mean "by definition"... we are talking about FeatureCollection not Feature and its currently just undefined.
We could equally say geometry doesn't work for FeatureCollection "by definition".
The reason to use getgeom is that it always works on a list of geometries, and can choose an indexed geometry, while geometry currently just returns a single geometry
(best not to read to much "I guess the idea back then..." with features, they just were not given much thought, we nearly didn't include them at all)
Just hit some code needing this pretty badly...
But I do think getgeom is a more suitable method for getting an iterable of geometries or a single geometry by index from from a feature collection - as it matches the same behavior and return values as for a geometry collection.
@evetion any thoughts on this?
So we shot ourselves in the foot with the geometry name for Features (to be compatible with pre v1 of GeoInterface). The Feature(Collection) part of the spec has always a been underdeveloped.
Current
properties(::Feature)
geometry(::Feature)
getfeature(::FeatureCollection) and getfeature(::FeatureCollection, i)
geometrycolumns(::FeatureCollection) = (:geometry,) can be multiple!
Suggestion
- deprecate
geometryin favor ofgetgeom(just rename) and think aboutgetprop? The naming seems more consistent (getprefix is used for geometries and for featurecollections). getgeomon fc is just agetgeom(getfeature)iterator- think well about handling multiple geometries using
geometrycolumns. I think the spec forbids a feature from having multiple geometries, but given we equate a row in a table with a feature, we implicitly allow it.