question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

POINT M parsed as POINT Z

See original GitHub issue

I’m writing a service that is an interface to pyproj, currently using Shapely to handle WKT de/serialisation. I need to support Z, M and ZM geometry types, e.g. POINT Z, POINT M and POINT ZM, because the service is expected to handle vertical datum transformations, and time-dependent datum shifts, so both Z (verical) and M (time) are important pieces of information.

I understand that Shapely does not support M and in fact will silently drop it and therefore does not produce M output; this is fine for my use-case. What I find particularly difficult to handle is that POINT M gets re-interpreted as POINT Z, so it’s not just a matter of the measure being dropped, but actually re-interpreted as a vertical coordinate that is not present in the input.

Expected behavior and actual behavior

Expected

My ideal result is that M values are retained:

from shapely import wkt
g = wkt.loads('POINT M (0 0 5)')
g.wkt
# 'POINT M (0 0 5)'

Failing that, anticipating that’s a lot of work to implement, I’d be happy with the following, since it’s merely lossy rather than inventing new information.

from shapely import wkt
g = wkt.loads('POINT M (0 0 5)')
g.wkt
# 'POINT (0 0)'

Actual

from shapely import wkt
g = wkt.loads('POINT M (0 0 5)')
g.wkt
# 'POINT Z (0 0 5)'

Steps to reproduce the problem.

See above. These examples are for POINT, but the problem is present for other geometry types too.

Operating system

Docker (Debian bullseye-slim)

Shapely version and provenance

1.7.0 installed from PyPI using pip

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
jorisvandenbosschecommented, Apr 9, 2021

I wouldn’t expect anything for a number of years, as GEOS development seems to move at glacial pace.

Unrelated to the actual issue, but just want to counter-balance this statement a bit 😉 It’s not because they didn’t fix the WKT parsing issue, that GEOS is moving only slowly. There have been many exciting new features and improvements in the last releases (eg robust overlays with big speed-ups and fixed precision).

(but, it’s probably correct to say that there isn’t much development around geometries with “M” coordinates, and which is generally not well supported by GEOS. So if you need those features, looking at GDAL might be the better option)

1reaction
jorisvandenbosschecommented, Dec 3, 2022

This is fixed on GEOS main branch:

>>> from shapely import wkt 
>>> g = wkt.loads('POINT M (0 0 5)') 
>>> g.wkt                                                                                                                                                                                                      
'POINT M (0 0 5)'

(we don’t yet have the APIs to access that M value (-> https://github.com/shapely/shapely/issues/1648), but at least the parsing works correctly)

Read more comments on GitHub >

github_iconTop Results From Across the Web

POINT M parsed as POINT Z · Issue #882 · shapely/shapely
I'm writing a service that is an interface to pyproj, currently using Shapely to handle WKT de/serialisation. I need to support Z, M...
Read more >
WKTReader (org.locationtech.jts:jts-core 1.19.0 API)
As of version 1.15, JTS can read (but not write) WKT syntax which specifies coordinate dimension Z, M or ZM as modifiers (e.g....
Read more >
CS143 Midterm Exam Solutions
Z → aMa | bMb | aRb | bRa. M → c. R → c. (i) LR(1) Parsing. (14 Points). Draw the states...
Read more >
Reading M-Values from shapefiles using GeoPandas/Fiona
Geopandas can't properly read geometries with M-values. ... Shapely/POINT M parsed as POINT Z · Fiona/M Values in Shapefile aren't shown.
Read more >
Fastest Way to Parse Points in Polygon Feature Class?
get_Point(m))); } } } } private static string PointToString(IPoint point) { return (point.X + ", " + point.Y + ", " + point.Z);...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found