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.

Empty geometries not all created the same way

See original GitHub issue

Currently there are two ways to create an empty geometry (e.g. Polygon):

from shapely import wkt
from shapely.geometry import mapping, Polygon

# Method 1: using an empty constructor
g1 = Polygon()
print('{}, {}, {}'.format(mapping(g1), g1.geom_type, g1.wkt))
# {'type': 'Polygon', 'coordinates': ()}, GeometryCollection, GEOMETRYCOLLECTION EMPTY

# Method 2: loading empty WKT
g2 = wkt.loads('POLYGON EMPTY')
print('{}, {}, {}'.format(mapping(g2), g2.geom_type, g2.wkt))
# {'type': 'Polygon', 'coordinates': ()}, Polygon, POLYGON EMPTY

(all other geometry types behave the same way).

In both cases, the Python objects know they are Polygons based on the Python object type. However the GEOS objects (referenced by ._geom) are either GeometryCollection or Polygon, based on how the geometries were constructed. This seems inconsistent to me, as I’d expect the two methods to be identical.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:1
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
jorisvandenbosschecommented, Aug 12, 2022

Small update on one of the mentioned issues here: the WKB serialization for POINT EMPTY now works and uses the format of PONIT (NaN NaN) (as was already done before by eg PostGIS as well). GEOS itself now does this since version 3.9.0, and with shapely 2.0 we also ensure consistent behaviour for this across all GEOS versions.

1reaction
jorisvandenbosschecommented, Apr 4, 2022

Also, empty geometries have has_z always as False:

Yes, that’s a known limitation. GEOS doesn’t really properly support empty 3D geometries. See also https://github.com/shapely/shapely/issues/1345#issuecomment-1069701607

In the documentation on the main branch we have a note about this in has_z:

https://github.com/shapely/shapely/blob/fc55006ecac8ad7835fe1618d6d391bfe076403c/shapely/predicates.py#L39-L43

Read more comments on GitHub >

github_iconTop Results From Across the Web

Empty geometries not all created the same way #742 - GitHub
Currently there are two ways to create an empty geometry (e.g. Polygon): from shapely import wkt from shapely.geometry import mapping, ...
Read more >
Missing and empty geometries - GeoPandas
Empty geometries are actual geometry objects but that have no coordinates (and thus also no area, for example). They can for example originate...
Read more >
Remove empty geometries from geodataframe
The GeoDataFrame and GeoSeries have an is_empty attribute, similar to shapely geometry objects. You can use this to filter out the empty ...
Read more >
Geodatabase error: The operation was attempted on an empty ...
I found this as I was getting the same exact error in Desktop. I use backend STIsEmpty(), STIsValid(), STIsSimple() as mentioned in previous ......
Read more >
Finding invalid geometry—ArcMap | Documentation
Empty geometries can be introduced when data is created or edited programmatically and when bad data is imported into your geographic information system....
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