-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposal: Create a geometry iterator #319
Comments
One common use-case we have for iterating geometries is to populate an So in that case we might want the return value to be something like |
Other possibilities to include if we have enough use cases:
sounds like a thumbs up and no design doc needed, just a PR. |
@emlys do you have any thoughts or objections that you would like to add to this? |
this sounds good to me! just a couple thoughts -
|
Also related, we have a similar issue over in InVEST: natcap/invest#1619. Would the Fiona API address/clarify/simplify the above proposal? We should look into how feature iteration is handled in Fiona, for sure. |
In many different InVEST models, we have a similar pattern of iterating through all features in a layer and then doing something with that feature's geometry. But there is a great deal of variety with how we handle these geometries. One item previously described in natcap/invest#64 is that we don't consistently handle the case where a feature may not have a defined geometry, but there are other common manipulations done as well:
geometry.buffer(0)
if not validshapely
geometryMultiPoint
-->Point
.I propose that we create a geometry iterator that handles the above common cases, and to provide a common entry point to more easily and consistently handle future cases. This is intended to resolve issues with geometries specifically, not to provide a consistent feature iterator. There are plenty of examples in InVEST where we iterate over features solely to create new geometries in a new layer or to only access field values. This proposal is not intended to change that pattern.
I was thinking of an interface that looked something like this:
Where:
skip_missing
indicates how to handle missing geometries. IfTrue
, alogging.WARNING
message is logged, but iteration continues. IfFalse
, anException
is raised.expand_multipart
indicates whether multipart geometries should be expanded into their component geometries. IfTrue
,MultiPolygon
geometry (for example), would yield multiplePolygon
geometries. IfFalse
, aMultiPolygon
geometry would yield aMultiPolygon
geometry.repair_invalid
, ifTrue
, would cause some basic geometry repair (likebuffer(0)
) on any geometries that GEOS thinks are invalid.returns
indicates the target type, which would be eitherogr
orshapely
.Questions
pygeoprocessing
?The text was updated successfully, but these errors were encountered: