Skip to content
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

Change default WKT output to honor a space between geometry type and Z, M or ZM #58010

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

jgrocha
Copy link
Member

@jgrocha jgrocha commented Jul 7, 2024

Previous discussion

The discussion started on the developers mailing list.

https://lists.osgeo.org/pipermail/qgis-developer/2024-July/066901.html

Description

This PR changes the default WKT output to honor a space between the geometry type and the modifier Z, M, or ZM (when applied).

Example: 'PointZ (0 0 0)' will be written as 'Point Z (0 0 0)'.

Nothing was changed related to WKT parsing. Parsing is already quite flexible.
Different notations are allowed:

print( QgsGeometry.fromWkt( 'Point (0 0 0)' ).asWkt() )
print( QgsGeometry.fromWkt( 'PointZ (0 0 0)' ).asWkt() )
print( QgsGeometry.fromWkt( 'Point Z(0 0 0)' ).asWkt() )
print( QgsGeometry.fromWkt( 'Point Z (0 0 0)' ).asWkt() )

Output based on this PR:

Point Z (0 0 0)
Point Z (0 0 0)
Point Z (0 0 0)
Point Z (0 0 0)

Output based on current master:

PointZ (0 0 0)
PointZ (0 0 0)
PointZ (0 0 0)
PointZ (0 0 0)

Interoperability ensured by a new GDAL PR

The tools tested and discussed on the mailing list, namely, GDAL, GEOS, and QGIS support both forms for reading.

The new OSGeo/gdal#10370 enhances GDAL parsing to support also reading PointZ and Point Z.

With such enhancement, all three tools can interoperate based on WKT representations.

Proposal

Since the interoperability is already ensured, we can decide the best way to write WKT representations.

The WKT specification is defined in the OGC document https://portal.ogc.org/files/?artifact_id=25355

According to the BNF Productions for Three-Dimension Geometry WKT (pages 55, 56), the WKT should be written as point z <point z text>, linestring z <linestring z text>, etc.

Tests

Many tests use the WKT notation to compare generated and expected geometries. All tests were improved to support the new WKT writing.

OS tools side by side

QGIS GDAL shapely Postgis OpenLayers GEOS
Point Z (1 2 3) POINT Z (1 2 3) POINT Z (1 2 3) POINT Z (1 2 3) POINT Z(1 2 3) POINT Z (1 2 3)

QGIS

a = QgsGeometry.fromWkt( 'Point Z (1 2 3)' )
print(a.asWkt())

GDAL

from osgeo import ogr
a = ogr.CreateGeometryFromWkt("POINT Z (1 2 3)")
print(a.ExportToIsoWkt())

Shapely

import shapely
a = shapely.from_wkt('POINT Z (1 2 3)')
print(shapely.to_wkt(a))

PostGIS

select st_astext(st_pointfromtext('POINT Z (1 2 3)'));

OpenLayers

import WKT from 'ol/format/WKT';
var format = new WKT();
let a = format.readFeature('POINT Z (1 2 3)');
console.log(format.writeFeature(a));

GEOS

echo 'POINT Z (1 2 3)' | geosop -a stdin -f wkt

@github-actions github-actions bot added this to the 3.40.0 milestone Jul 7, 2024
@nyalldawson
Copy link
Collaborator

@mhugent do you have any insights as to why the current form was originally chosen?

Copy link

github-actions bot commented Jul 7, 2024

🪟 Windows builds ready!

Windows builds of this PR are available for testing here. Debug symbols for this build are available here.

(Built from commit 7026430)

@lbartoletti
Copy link
Member

@jgrocha this is a very good idea! I made several tests, not yet released, some months ago. QGIS WKT is not readable by some other software. So +1. Let me just a couple of times to retrieve/finish my comparison/test and to review your PR. Thanks!

@lbartoletti lbartoletti self-assigned this Jul 8, 2024
jgrocha and others added 2 commits July 8, 2024 08:53
Co-authored-by: Nyall Dawson <nyall.dawson@gmail.com>
Copy link

The QGIS project highly values your contribution and would love to see this work merged! Unfortunately this PR has not had any activity in the last 14 days and is being automatically marked as "stale". If you think this pull request should be merged, please check

  • that all unit tests are passing

  • that all comments by reviewers have been addressed

  • that there is enough information for reviewers, in particular

    • link to any issues which this pull request fixes

    • add a description of workflows which this pull request fixes

    • add screenshots if applicable

  • that you have written unit tests where possible
    In case you should have any uncertainty, please leave a comment and we will be happy to help you proceed with this pull request.
    If there is no further activity on this pull request, it will be closed in a week.

@github-actions github-actions bot added the stale Uh oh! Seems this work is abandoned, and the PR is about to close. label Jul 23, 2024
@lbartoletti lbartoletti removed the stale Uh oh! Seems this work is abandoned, and the PR is about to close. label Jul 23, 2024
Copy link

github-actions bot commented Aug 7, 2024

The QGIS project highly values your contribution and would love to see this work merged! Unfortunately this PR has not had any activity in the last 14 days and is being automatically marked as "stale". If you think this pull request should be merged, please check

  • that all unit tests are passing

  • that all comments by reviewers have been addressed

  • that there is enough information for reviewers, in particular

    • link to any issues which this pull request fixes

    • add a description of workflows which this pull request fixes

    • add screenshots if applicable

  • that you have written unit tests where possible
    In case you should have any uncertainty, please leave a comment and we will be happy to help you proceed with this pull request.
    If there is no further activity on this pull request, it will be closed in a week.

@github-actions github-actions bot added the stale Uh oh! Seems this work is abandoned, and the PR is about to close. label Aug 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale Uh oh! Seems this work is abandoned, and the PR is about to close.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants