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

POC: Handle __geo_interface__ objects using pyogrio instead of fiona #3237

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ jobs:
numpy-version: '1.26'
pandas-version: ''
xarray-version: ''
optional-packages: ' contextily geopandas ipython pyarrow rioxarray sphinx-gallery'
optional-packages: ' contextily geopandas ipython pyarrow pyogrio rioxarray sphinx-gallery'

timeout-minutes: 30
defaults:
Expand Down
14 changes: 6 additions & 8 deletions pygmt/helpers/tempfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,12 @@
# Other 'geo' formats which implement __geo_interface__
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pyogrio package doesn't support the schema parameter. With geopandas 1.0 released, pyogrio will be the default engine, and then the code at lines 136-150 will break.

We need to find a way to support both geopandas 0.x and 1.x.

import json

import fiona

with fiona.Env():
jsontext = json.dumps(geojson.__geo_interface__)
# Do Input/Output via Fiona virtual memory
with fiona.io.MemoryFile(file_or_bytes=jsontext.encode()) as memfile:
geoseries = gpd.GeoSeries.from_file(filename=memfile)
geoseries.to_file(**ogrgmt_kwargs)
import pyogrio

Check warning on line 157 in pygmt/helpers/tempfile.py

View check run for this annotation

Codecov / codecov/patch

pygmt/helpers/tempfile.py#L157

Added line #L157 was not covered by tests

jsontext = json.dumps(geojson.__geo_interface__)

Check warning on line 159 in pygmt/helpers/tempfile.py

View check run for this annotation

Codecov / codecov/patch

pygmt/helpers/tempfile.py#L159

Added line #L159 was not covered by tests
# Do Input/Output via Pyogrio (GDAL) virtual memory
geodataframe = pyogrio.read_dataframe(jsontext)
geodataframe.to_file(**ogrgmt_kwargs)

Check warning on line 162 in pygmt/helpers/tempfile.py

View check run for this annotation

Codecov / codecov/patch

pygmt/helpers/tempfile.py#L161-L162

Added lines #L161 - L162 were not covered by tests

yield tmpfile.name

Expand Down