-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Add RFC99 text: Geometry coordinate precision #9300
Conversation
19aaf96
to
b95ed37
Compare
doc/source/development/rfc/rfc99_geometry_coordinate_precision.rst
Outdated
Show resolved
Hide resolved
|
||
It will *not* be able to store it in its metadata. The possibility of storing | ||
the coordinate metadata in the .csvt side-car file has been considered, but it | ||
would not be backwards-compatible. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can/should precision be detected in the way that column types are?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Obviously it could, but I'm not sure I want to do that implementation effort :-). It could be relatively easy when constructing point geometries from X,Y columns, but it becomes trickier when importing them from WKT, because our WKT import code should take note of that.
WKB export methods will be modified in a similar way as in the prototype | ||
https://github.com/OSGeo/gdal/pull/6974 to nullify least significant bits from | ||
the precision specifications. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I understand correctly (which might not be the case!), the coordinates will be rounded as such...
However, simply rounding coordinates can/will lead to invalid polygons (e.g. self-intersections, polygon rings touching,...).
So, I wonder, why not use GEOS set_precision to round the coordinates in the export methods?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the coordinates will be rounded as such...
yes
However, simply rounding coordinates can/will lead to invalid polygons (e.g. self-intersections, polygon rings touching,...).
This may indeed be possible if users indicate a precision not consistent of the actual point spacing of their geometries
So, I wonder, why not use GEOS set_precision to round the coordinates in the export methods?
Good suggestion. However there would be a cost in doing so systematically. But I'm inclined to add a GEOSGeom_setPrecision_r() step in a ogr2ogr workflow when the user explicitly specifies -xyRes, which can indeed causes generation of invalid geometries. For other workflows, the assumption is that the coordinate precision of the source is correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RFC text and implementation updated with the above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe a configuration option could be introduced to give the user the option to apply set_precision systematically when writing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe a configuration option could be introduced to give the user the option to apply set_precision systematically when writing?
It is not obvious to me that this is needed at that point, because either people use ogr2ogr and it takes care of that, or they use individual steps of the OGR API (CreateLayer(), CreateFeature()) and can explicitly invoke OGRGeometry::SetPrecision() if needed. A config option to do that systematically (not clear at that point if that would be in each driver that honours coordinate precision, or in in the generic CreateFeature() code) could potentially be added as a further enhancement
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking about the drivers that honour the coordinate precision: if the precision is set and the configuration option is enabled, the validity of the geometries are guaranteed by gdal but a performance penalty can occur. If the the precision is set and configuration option is not enabled... it is the user's responsibility to make sure the geometries are rounded in a way they are valid as otherwise they can end up becoming invalid when saved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh well, I might consider doing this, but for GeoPackage (or formats that would use the same strategy), the value that is written will not be "exactly" the one after rounding to the precision, due to zeroing out least significant bits. It will be compatible with the requested precision however. That is if you ask for a precision of let's say 0.1 and you encode 0.1, the value you get when reading back will be 0.125 for example. Would that be a problem? My intuition would be that if the geometries are valid with respect to the 0.1 precision, those small changes of coordinate values < 0.1 shouldn't induce new in-validities, but I might be wrong...
If so, I was thinking about potentially also applying the precision when reading back so that 0.125 gets seen as 0.1, but that cost might be undesirable, and would only be done by the GDAL reader, so likely not a good option.
Or perhaps we should apply the zeroing out of LSBs in GeoPackage WKB only if a specific creation option is specified like DISCARD_COORD_LSB=YES ? (not sure which default should be used)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good questions. I follow the same intuition regarding the probable limited impact of zeroing LSBs, but I'm not at all a specialist in floating point representations, so not sure at all.
Applying precision when reading indeed sounds as not ideal... hopefully it can be avoided.
Maybe it is worth a test to see if zeroing out the LSB's after using GEOS set_precision is still having a significant impact?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it is worth a test to see if zeroing out the LSB's after using GEOS set_precision is still having a significant impact?
on a quick check, as expected, the zeroing out of the LSB's can be reversed to the initial "decimal" precision, since we are conservative on the number of zeroed LSB's, and the geometry is still valid. However I've revered the default behaviour of the GPKG driver to not do that zeroing out by default. See the last commit (4fb6233) of this PR for the updates, as well as the new OGR_APPLY_GEOM_SET_PRECISION configuration option that is taken into account by the generic code path of CreateFeature() to run OGRGeometry::SetPrecision().
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great.
f9093e0
to
0dfef9a
Compare
If so, the precision can be determined from the source without specifically adding meta data or modifying the driver(s)? |
I'm not super keen on that. This could be done outside of GDAL if needed
It would require to read ahead the entire source file. Could potentially be done as a further enhancement of the CSV driver if desired (cf #9300 (review))
Wouldn't fit at all with the spirit of this RFC where the coordinate precision is, once determined, a constant value at the geometry-column level. In ogr2ogr type of scenarios, you need to declare the coordinate precision of the output layer at the time it is created |
- a few drivers (GeoJSON, JSONFG, OpenFileGDB) have layer creation options to | ||
specify coordinate precision, but there is currently no driver agnostic way | ||
of specifying it. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this is relevant, but just for information.
The motivation why I'm interested in applying precisions in general... is to avoid slivers. And I like that this feature offers a way to standardise/specify the precision at the layer/dataset level in a clear and transparent way. When calculating several overlays between different layers after each other, or if calculating overlays between layers where features have been snapped on line segments of the other layer, slivers or dangling nodes of typically ~1e-8 (m) or narrower will appear in the result due to rounding issues. Using a GEOS set_precision of >=1e-8 will remove such dangling nodes from larger polygons and will change sliver polygons to EMPTY geometries or NULL, making it easy to identify and remove them.
Can we work towards unifying on just one of British or American English? I suggest we aim for American English based on that dominating the current code base. A partial look at the code base for just meter versus metre that shows that the code base is very inconsistent for this particular word.
|
done |
Motion adopted. Will wait before merging (after updating voting history & status) that the PR with the candidate implementation is also merged |
Partially rendered view at https://github.com/rouault/gdal/blob/rfc99_text/doc/source/development/rfc/rfc99_geometry_coordinate_precision.rst