Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: support writing None geometries (for geopackage files) #59

Closed
theroggy opened this issue Mar 17, 2022 · 2 comments · Fixed by #135
Closed

BUG: support writing None geometries (for geopackage files) #59

theroggy opened this issue Mar 17, 2022 · 2 comments · Fixed by #135
Labels
bug Something isn't working

Comments

@theroggy
Copy link
Member

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)
@brendan-ward brendan-ward added the bug Something isn't working label Mar 17, 2022
@brendan-ward
Copy link
Member

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 theroggy changed the title ENH: support writing None geometries (for geopackage files) BUG: support writing None geometries (for geopackage files) May 2, 2022
@theroggy
Copy link
Member Author

theroggy commented May 8, 2023

reference #105

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants