You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
At least in geopackages, it is valid to have NULL/None geometries in a layer.
However, when writing a GeoDataFrame with a None geometry this throws an error. Depending if the None geometry is first in the GeoDataframe or not triggers another error.
The following code triggers the errors:
import geopandas as gpd
import pyogrio
import shapely.geometry
# This results in ValueError: geometry_type must be provided
output_path = r"C:\temp\test_none_geom.gpkg"
test_gdf = gpd.GeoDataFrame(
geometry=[
None,
shapely.geometry.Polygon(shell=[(1, 1), (1, 2), (2, 2), (2, 1), (1, 1)])],
crs="epsg:31370")
pyogrio.write_dataframe(test_gdf, output_path)
# This results in TypeError: cannot convert 'NoneType' object to bytearray
test_gdf = gpd.GeoDataFrame(
geometry=[
shapely.geometry.Polygon(shell=[(1, 1), (1, 2), (2, 2), (2, 1), (1, 1)]),
None],
crs="epsg:31370")
pyogrio.write_dataframe(test_gdf, output_path)
The text was updated successfully, but these errors were encountered:
We took a fairly strict view when building this out that geometries must always be present, and didn't add adequate handling for when they aren't. I'm assuming that GDAL/OGR can handle NULL geometries provided we construct things that way, so we should allow this - and allow GDAL/OGR to be the gatekeeper if those aren't valid for a particular data format.
theroggy
changed the title
ENH: support writing None geometries (for geopackage files)
BUG: support writing None geometries (for geopackage files)
May 2, 2022
At least in geopackages, it is valid to have NULL/None geometries in a layer.
However, when writing a
GeoDataFrame
with aNone
geometry this throws an error. Depending if theNone
geometry is first in theGeoDataframe
or not triggers another error.The following code triggers the errors:
The text was updated successfully, but these errors were encountered: