Open mwtoews opened 6 days ago
Shapefile cannot make the distinction between NULL/None values versus POINT EMPTY, and the choice was made to return NULL/None when reading.
E.g. Geopackage does support the distinction between both, so there you will get the proper round-tripping...
import tempfile
from pyogrio.geopandas import read_dataframe, write_dataframe
import geopandas as gp
import shapely
for geom in [shapely.from_wkt("POINT EMPTY"), None]:
for suffix in [".shp", ".gpkg"]:
gdf = gp.GeoDataFrame({"x": [0]}, geometry=[geom], crs=4326)
filename = f"{tempfile.gettempdir()}/test{suffix}"
write_dataframe(gdf, filename)
df = read_dataframe(filename)
print(f"{suffix=}, {geom=}: {df.geometry.iloc[0]}")
# suffix='.shp', geom=<POINT EMPTY>: None
# suffix='.gpkg', geom=<POINT EMPTY>: POINT EMPTY
# suffix='.shp', geom=None: None
# suffix='.gpkg', geom=None: None
While preparing #435 it seems that
write_dataframe()
is happy to write a dataframe with (e.g.) a "POINT EMPTY" geometry. However,read_dataframe()
will read this geometry as None, so the two geodataframes don't round-trip. E.g.:Note this is the same as fiona, e.g.:
returns the same. And raw fiona doesn't do much better except identify the geometry type in the schema: