Opened 4 years ago

Closed 3 years ago

#1040 closed defect (fixed)

GeometryCollection with all empty parts does not accurately serialize to WKT or WKB

Reported by: Mike Taves Owned by: strk
Priority: major Milestone: 3.10.0
Component: Core Version: 3.8.0
Severity: Unassigned Keywords:
Cc:

Description

This is discovered via Shapely version <2 via ctypes. Take a GeometryCollectgion with all empty parts:

from shapely import geos, wkt
print(geos.geos_version_string)  # 3.8.0-CAPI-1.13.1

g = wkt.loads("GEOMETRYCOLLECTION(LINESTRING EMPTY, POLYGON EMPTY)")

# correct behavior
for n in range(geos.lgeos.GEOSGetNumGeometries(g._geom)):
    gn = geos.lgeos.GEOSGetGeometryN(g._geom, n)
    print('{}: {}'.format(n, geos.lgeos.GEOSGeomToWKT(gn)))
# 0: LINESTRING EMPTY
# 1: POLYGON EMPTY

# incorrect WKT
print(g.wkt)  # GEOMETRYCOLLECTION EMPTY

# incorrect hex-encoded WKB
print(g.wkb_hex) # 010700008002000000010200008000000000010300008000000000
#    should be 2D: 010700000002000000010200000000000000010300000000000000

The expected WKT should be the same as the input. JTS appears to have this issue too.

The WKB output is a slightly different issue, as it correctly returns a multi-part empty GeometryCollection, but they are surprisingly 3D geometries! PostGIS says it is "GEOMETRYCOLLECTION Z (LINESTRING Z EMPTY,POLYGON Z EMPTY)".

Change History (3)

comment:1 by pramsey, 3 years ago

Milestone: 3.10.0

comment:2 by pramsey, 3 years ago

I get worried changing things down so low... https://github.com/libgeos/geos/pull/451

comment:3 by Paul Ramsey <pramsey@…>, 3 years ago

Resolution: fixed
Status: newclosed

In c15609d/git:

Correctly round-trip collections of EMPTY (closes #1040)

Note: See TracTickets for help on using tickets.