-
Notifications
You must be signed in to change notification settings - Fork 248
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
Changes from 9 commits
d6be42b
e727b7a
ced2bff
a52597b
8436ee7
21b445d
b930b5e
f8a5a34
6b1a853
574befe
5c79e38
089cb5c
066980b
c9a06f1
3c5b4e9
9cb1561
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,42 @@ | ||||||||||||||||
| """ | ||||||||||||||||
| Roads | ||||||||||||||||
| ----- | ||||||||||||||||
| The :meth:`pygmt.Figure.plot` method allows to plot geographical data which is | ||||||||||||||||
| stored in a :class:`geopandas.GeoDataFrame` object. | ||||||||||||||||
| """ | ||||||||||||||||
|
|
||||||||||||||||
| 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 | ||||||||||||||||
|
michaelgrund marked this conversation as resolved.
Outdated
|
||||||||||||||||
|
|
||||||||||||||||
| fig.basemap( | ||||||||||||||||
| region=region, | ||||||||||||||||
| projection="M12c", | ||||||||||||||||
| frame=["af", 'WSne+t"Main roads of Oahu (Hawaii)"'], | ||||||||||||||||
| ) | ||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've figured it out! We can use the octal code for apostrophe (') which is 047, see https://docs.generic-mapping-tools.org/6.2/cookbook/octal-codes.html.
Suggested change
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great @weiji14!
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Realizing two years later that I used the wrong symbol 😅 It should be an Okina |
||||||||||||||||
| 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() | ||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.