-
Notifications
You must be signed in to change notification settings - Fork 246
Add gallery example showing usage of line objects from a geopandas.GeoDataFrame #1474
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 11 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
d6be42b
Add gallery example showing the usage of line objects from a geopanda…
michaelgrund e727b7a
updates
michaelgrund ced2bff
updates
michaelgrund a52597b
Merge branch 'main' into gallery-gpd-lines
michaelgrund 8436ee7
Merge branch 'main' into gallery-gpd-lines
michaelgrund 21b445d
Apply suggestions from code review
michaelgrund b930b5e
some formatting
michaelgrund f8a5a34
adjust title
michaelgrund 6b1a853
adjust title
michaelgrund 574befe
Apply suggestions from code review
michaelgrund 5c79e38
Merge branch 'main' into gallery-gpd-lines
michaelgrund 089cb5c
Apply suggestions from code review
michaelgrund 066980b
adjust parameter formatting
michaelgrund c9a06f1
moved file to lines and vectors category
michaelgrund 3c5b4e9
removed file from maps category
michaelgrund 9cb1561
Merge branch 'main' into gallery-gpd-lines
seisman 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| """ | ||
| Roads | ||
| ----- | ||
| The :meth:`pygmt.Figure.plot` method allows us to plot geographical data such | ||
| as lines which are stored in a :class:`geopandas.GeoDataFrame` object. Use | ||
| :func:`geopandas.read_file` to load data from any supported OGR format such as | ||
| a shapefile (.shp), GeoJSON (.geojson), geopackage (.gpkg), etc. Then, pass the | ||
| :class:`geopandas.GeoDataFrame` as an argument to the `data` parameter in | ||
| :meth:`pygmt.Figure.plot`, and style the geometry using the `pen` parameter. | ||
| """ | ||
|
|
||
| import geopandas as gpd | ||
| import pygmt | ||
|
|
||
| # Read shapefile data using geopandas | ||
| gdf = gpd.read_file( | ||
| "http://www2.census.gov/geo/tiger/TIGER2015/PRISECROADS/tl_2015_15_prisecroads.zip" | ||
| ) | ||
| # The dataset contains different road types listed in the RTTYP column, | ||
| # here we select the following ones to plot: | ||
| roads_common = gdf[gdf.RTTYP == "M"] # Common name roads | ||
| roads_state = gdf[gdf.RTTYP == "S"] # State recognized roads | ||
| roads_interstate = gdf[gdf.RTTYP == "I"] # Interstate roads | ||
|
|
||
| fig = pygmt.Figure() | ||
|
|
||
| # Define target region around O'ahu (Hawai'i) | ||
| region = [-158.3, -157.6, 21.2, 21.75] # minx, maxx, miny, maxy | ||
|
|
||
| title = r"Main roads of O\047ahu (Hawai\047i)" # \047 is octal code for ' | ||
| fig.basemap(region=region, projection="M12c", frame=["af", f'WSne+t"{title}"']) | ||
| fig.coast(land="gray", water="dodgerblue4", shorelines="1p,black") | ||
|
|
||
| # Plot the individual road types with different pen settings and assgin labels | ||
|
michaelgrund marked this conversation as resolved.
Outdated
|
||
| # which are displayed in the legend | ||
| fig.plot(data=roads_common, pen="5p,dodgerblue", label="CommonName") | ||
| fig.plot(data=roads_state, pen="2p,gold", label="StateRecognized") | ||
| fig.plot(data=roads_interstate, pen="2p,red", label="Interstate") | ||
|
|
||
| # Add legend | ||
| fig.legend() | ||
|
|
||
| fig.show() | ||
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.