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

Multi- empty geometries loose Z/M dimensions #888

Open
mwtoews opened this issue May 2, 2023 · 4 comments
Open

Multi- empty geometries loose Z/M dimensions #888

mwtoews opened this issue May 2, 2023 · 4 comments
Milestone

Comments

@mwtoews
Copy link
Contributor

mwtoews commented May 2, 2023

Investigating further into HasZ shows some inconsistencies between types. These are expected:

for geom_type in POINT LINESTRING LINEARRING POLYGON; do
  geom="$geom_type Z EMPTY"
  echo "$geom"
  echo -n "  copy: "
  ./bin/geosop -a "$geom" -f wkt
  echo -n "  hasZ: "
  ./bin/geosop -a "$geom" -f txt hasZ
done

outputs

POINT Z EMPTY
  copy: POINT Z EMPTY
  hasZ: true
LINESTRING Z EMPTY
  copy: LINESTRING Z EMPTY
  hasZ: true
LINEARRING Z EMPTY
  copy: LINEARRING Z EMPTY
  hasZ: true
POLYGON Z EMPTY
  copy: POLYGON Z EMPTY
  hasZ: true

and similar expected behaviour with M/ZM coordinate types.

However, these are not expected:

for geom_type in GEOMETRYCOLLECTION MULTIPOINT MULTILINESTRING MULTIPOLYGON; do
  geom="$geom_type Z EMPTY"
  echo "$geom"
  echo -n "  copy: "
  ./bin/geosop -a "$geom" -f wkt
  echo -n "  hasZ: "
  ./bin/geosop -a "$geom" -f txt hasZ
done

outputs

GEOMETRYCOLLECTION Z EMPTY
  copy: GEOMETRYCOLLECTION EMPTY
  hasZ: false
MULTIPOINT Z EMPTY
  copy: MULTIPOINT EMPTY
  hasZ: false
MULTILINESTRING Z EMPTY
  copy: MULTILINESTRING EMPTY
  hasZ: false
MULTIPOLYGON Z EMPTY
  copy: MULTIPOLYGON EMPTY
  hasZ: false

and similar behaviour with M/ZM coordinate types. The expected behaviour should mimic the non-multi empty geometries, similar to PostGIS:

postgis=# select st_astext('POINT Z EMPTY');
   st_astext   
---------------
 POINT Z EMPTY
(1 row)

postgis=# select st_astext('MULTIPOINT Z EMPTY');
     st_astext      
--------------------
 MULTIPOINT Z EMPTY
(1 row)

postgis=# select st_astext('GEOMETRYCOLLECTION Z EMPTY');
         st_astext          
----------------------------
 GEOMETRYCOLLECTION Z EMPTY
(1 row)

@mwtoews
Copy link
Contributor Author

mwtoews commented May 9, 2023

Unfortunately, this one is beyond my C++ abilities to fix. Any help/pointers would be appreciated!

@dbaston
Copy link
Member

dbaston commented May 9, 2023

The issue is that collections don't actually store their own dimensions, they just check their sub-geometries on request:

https://github.com/libgeos/geos/blob/main/src/geom/GeometryCollection.cpp#L168

To store MULTIPOLYGON Z EMPTY you would need to modify GeometryCollection to store this directly.

@pramsey pramsey added this to the 3.13.0 milestone Jun 7, 2023
@pramsey
Copy link
Member

pramsey commented Jun 27, 2023

And then the basic geometries go and check their coordinate sequence...

https://github.com/libgeos/geos/blob/main/src/geom/Polygon.cpp#L149

@pramsey
Copy link
Member

pramsey commented Jul 14, 2023

Doesn't feel like there's anything more elegant solution-wise than an isEmpty member on Geometry, am I missing anything?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants