Empty geometries not all created the same way
See original GitHub issueCurrently 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:
- Created 4 years ago
- Reactions:1
- Comments:9 (7 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
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