-
Notifications
You must be signed in to change notification settings - Fork 245
Handle geopandas and shapely geometries via geo_interface link #1000
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
Merged
Merged
Changes from 13 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
28b6994
Add intersphinx mapping to geopandas docs
weiji14 7d0a3a7
Create tempfile_from_geojson function to handle __geo_interface__
weiji14 e7012d4
Add geopandas.GeoDataFrame to list of allow table inputs to info
weiji14 21b3160
Merge branch 'master' into geopandas_integration
weiji14 2acb0ab
Handle generic __geo_interface__ objects via fiona and geopandas
weiji14 9ec8feb
Merge branch 'master' into geopandas_integration
weiji14 337f7a6
Merge branch 'master' into geopandas_integration
329e480
Install geopandas on the Python 3.9/NumPy 1.20 test build only
weiji14 a662f7d
Mention optional geopandas dependency in install and maintenance docs
weiji14 1f9dfc4
Merge branch 'master' into geopandas_integration
weiji14 c8eedb2
Future proof wording to allow other optional packages besides geopandas
weiji14 bd94abc
Merge branch 'master' into geopandas_integration
weiji14 34de789
Tweak tempfile_from_geojson docstring and remove unused fiona code
weiji14 1ab67f3
Merge branch 'master' into geopandas_integration
weiji14 bf72a62
Add geopandas.GeoDataFrame to standardized table-classes filler text
weiji14 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| """ | ||
| Tests on integration with geopandas. | ||
| """ | ||
| import numpy.testing as npt | ||
| import pytest | ||
| from pygmt import info | ||
|
|
||
| gpd = pytest.importorskip("geopandas") | ||
| shapely = pytest.importorskip("shapely") | ||
|
|
||
|
|
||
| @pytest.fixture(scope="module", name="gdf") | ||
| def fixture_gdf(): | ||
| """ | ||
| Create a sample geopandas GeoDataFrame object with shapely geometries of | ||
| different types. | ||
| """ | ||
| linestring = shapely.geometry.LineString([(20, 15), (30, 15)]) | ||
| polygon = shapely.geometry.Polygon([(20, 10), (23, 10), (23, 14), (20, 14)]) | ||
| multipolygon = shapely.geometry.shape( | ||
| { | ||
| "type": "MultiPolygon", | ||
| "coordinates": [ | ||
| [ | ||
| [[0, 0], [20, 0], [10, 20], [0, 0]], # Counter-clockwise | ||
| [[3, 2], [10, 16], [17, 2], [3, 2]], # Clockwise | ||
| ], | ||
| [[[6, 4], [14, 4], [10, 12], [6, 4]]], # Counter-clockwise | ||
| [[[25, 5], [30, 10], [35, 5], [25, 5]]], | ||
| ], | ||
| } | ||
| ) | ||
| # Multipolygon first so the OGR_GMT file has @GMULTIPOLYGON in the header | ||
| gdf = gpd.GeoDataFrame( | ||
| index=["multipolygon", "polygon", "linestring"], | ||
| geometry=[multipolygon, polygon, linestring], | ||
| ) | ||
|
|
||
| return gdf | ||
|
|
||
|
|
||
| def test_geopandas_info_geodataframe(gdf): | ||
| """ | ||
| Check that info can return the bounding box region from a | ||
| geopandas.GeoDataFrame. | ||
| """ | ||
| output = info(table=gdf, per_column=True) | ||
| npt.assert_allclose(actual=output, desired=[0.0, 35.0, 0.0, 20.0]) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "geomtype,desired", | ||
| [ | ||
| ("multipolygon", [0.0, 35.0, 0.0, 20.0]), | ||
| ("polygon", [20.0, 23.0, 10.0, 14.0]), | ||
| ("linestring", [20.0, 30.0, 15.0, 15.0]), | ||
| ], | ||
| ) | ||
| def test_geopandas_info_shapely(gdf, geomtype, desired): | ||
| """ | ||
| Check that info can return the bounding box region from a shapely.geometry | ||
| object that has a __geo_interface__ property. | ||
| """ | ||
| geom = gdf.loc[geomtype].geometry | ||
| output = info(table=geom, per_column=True) | ||
| npt.assert_allclose(actual=output, desired=desired) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.