TransWikia.com

GDAL point ordering (difference in version 2.2 and 3.0) Python

Geographic Information Systems Asked by user1502898 on April 10, 2021

I’m currently trying to update some legacy Python code from gdal version 2.2.3 to 3.0.2, (along with python 2 > python 3)

I need to generate contours and unpack the points, along the lines of:

_, output = gdal.ContourGenerate( .... )
points_list = [contour.GetGeometryRef().GetPoints() for contour in output]

Now points_list contains the same very similar points for each contour, regardless of version. However the ordering is changed between 2.2.3 and 3.0.2

Python list comprehension preserves the order provided by the object being iterated. So unless GetPoints is unordered, I don’t think this is a python issue.

Can anyone suggest a way to dictate the ordering generated by GetPoints? Or point me at the change log for this behaviour, so I can figure out what’s happened?

One Answer

Your observation may be related with the change in the order of the points in polygons that is discussed in gdal-dev mailing list thread https://lists.osgeo.org/pipermail/gdal-dev/2021-February/053534.html. You seem to deal with contour lines but maybe the process is first building polygons in some previous step. Even if your issue was not the same it could be that pushing the geometries through the geometry normalizing function in the sama way than in this pull request https://github.com/OSGeo/gdal/pull/3506 could help with keeping the order of the points uniform.

The new OGR_G_Normalize() is using GEOS and it does the same thing as ST_Normalize in PostGIS https://postgis.net/docs/ST_Normalize.html

Answered by user30184 on April 10, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP