From d6be42ba7b48df566f95f8a682f17470c6b1bfc2 Mon Sep 17 00:00:00 2001 From: Michael Grund <23025878+michaelgrund@users.noreply.github.com> Date: Mon, 30 Aug 2021 17:50:42 +0200 Subject: [PATCH 01/12] Add gallery example showing the usage of line objects from a geopandas.GeoDataFrame Here's the first gallery example showcasing how to plot line objects stored in a geopandas.GeoDataFrame. --- examples/gallery/maps/roads | 40 +++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 examples/gallery/maps/roads diff --git a/examples/gallery/maps/roads b/examples/gallery/maps/roads new file mode 100644 index 00000000000..023760369d9 --- /dev/null +++ b/examples/gallery/maps/roads @@ -0,0 +1,40 @@ +""" +Roads +-------------------- +The :meth:`pygmt.Figure.plot` method allows to plot geographical data which is stored in a +geopandas.GeoDataFrame object. +""" + +import pygmt +import geopandas as gpd + +# 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: +# Common name roads +roads_common = gdf[df.RTTYP == "M"] +# State recognized roads +roads_state = gdf[df.RTTYP == "S"] +# Interstates +roads_interstate = gdf[df.RTTYP == "I"] + +fig = pygmt.Figure() + +# Define target region around O'ahu (Hawai'i) +region = [-158.3, -157.6, 21.2, 21.75] + +fig.basemap(region=region, projection="M-90/15c", frame=True) +fig.coast(land="gray", water = "dodgerblue4", shorelines="1p,black") + +# Plot the individual road types with different pen settings and assgin labels 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() From e727b7a0d05bb0b30c785fd4fe1d7f0cb4f4433d Mon Sep 17 00:00:00 2001 From: Michael Grund Date: Mon, 30 Aug 2021 18:28:37 +0200 Subject: [PATCH 02/12] updates --- examples/gallery/maps/{roads => roads.py} | 24 ++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) rename examples/gallery/maps/{roads => roads.py} (54%) diff --git a/examples/gallery/maps/roads b/examples/gallery/maps/roads.py similarity index 54% rename from examples/gallery/maps/roads rename to examples/gallery/maps/roads.py index 023760369d9..6757654cec5 100644 --- a/examples/gallery/maps/roads +++ b/examples/gallery/maps/roads.py @@ -1,17 +1,19 @@ """ Roads -------------------- -The :meth:`pygmt.Figure.plot` method allows to plot geographical data which is stored in a -geopandas.GeoDataFrame object. +The :meth:`pygmt.Figure.plot` method allows to plot geographical data which is +stored in a geopandas.GeoDataFrame object. """ -import pygmt 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") +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, +# the dataset contains different road types listed in the RTTYP column, # here we select the following ones to plot: # Common name roads roads_common = gdf[df.RTTYP == "M"] @@ -22,17 +24,17 @@ fig = pygmt.Figure() -# Define target region around O'ahu (Hawai'i) +# Define target region around O'ahu (Hawai'i) region = [-158.3, -157.6, 21.2, 21.75] -fig.basemap(region=region, projection="M-90/15c", frame=True) -fig.coast(land="gray", water = "dodgerblue4", shorelines="1p,black") +fig.basemap(region=region, projection="M12c", frame=True) +fig.coast(land="gray", water="dodgerblue4", shorelines="1p,black") # Plot the individual road types with different pen settings and assgin labels 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") +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() From ced2bff72996f50695ab9c0b5a2ebf2dd81099c4 Mon Sep 17 00:00:00 2001 From: Michael Grund Date: Mon, 30 Aug 2021 18:32:30 +0200 Subject: [PATCH 03/12] updates --- examples/gallery/maps/roads.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/gallery/maps/roads.py b/examples/gallery/maps/roads.py index 6757654cec5..52936e9cc65 100644 --- a/examples/gallery/maps/roads.py +++ b/examples/gallery/maps/roads.py @@ -16,11 +16,11 @@ # the dataset contains different road types listed in the RTTYP column, # here we select the following ones to plot: # Common name roads -roads_common = gdf[df.RTTYP == "M"] +roads_common = gdf[gdf.RTTYP == "M"] # State recognized roads -roads_state = gdf[df.RTTYP == "S"] +roads_state = gdf[gdf.RTTYP == "S"] # Interstates -roads_interstate = gdf[df.RTTYP == "I"] +roads_interstate = gdf[gdf.RTTYP == "I"] fig = pygmt.Figure() From 21b445d6a91b9440a8c35b7b007939f37da0f205 Mon Sep 17 00:00:00 2001 From: Michael Grund <23025878+michaelgrund@users.noreply.github.com> Date: Fri, 3 Sep 2021 17:06:43 +0200 Subject: [PATCH 04/12] Apply suggestions from code review Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com> --- examples/gallery/maps/roads.py | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/examples/gallery/maps/roads.py b/examples/gallery/maps/roads.py index 52936e9cc65..c7348183e2d 100644 --- a/examples/gallery/maps/roads.py +++ b/examples/gallery/maps/roads.py @@ -1,33 +1,31 @@ """ -Roads --------------------- +Roads +----- The :meth:`pygmt.Figure.plot` method allows to plot geographical data which is -stored in a geopandas.GeoDataFrame object. +stored in a :class:`geopandas.GeoDataFrame` object. """ import geopandas as gpd import pygmt -# read shapefile data using geopandas +# 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, +# The dataset contains different road types listed in the RTTYP column, # here we select the following ones to plot: -# Common name roads -roads_common = gdf[gdf.RTTYP == "M"] -# State recognized roads -roads_state = gdf[gdf.RTTYP == "S"] -# Interstates -roads_interstate = gdf[gdf.RTTYP == "I"] +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] +region = [-158.3, -157.6, 21.2, 21.75] # minx, maxx, miny, maxy -fig.basemap(region=region, projection="M12c", frame=True) +fig.basemap( + region=region, projection="M12c", frame=["af", 'WSne+t"Main roads of Hawaii"'] +) fig.coast(land="gray", water="dodgerblue4", shorelines="1p,black") # Plot the individual road types with different pen settings and assgin labels which are From b930b5e52a2b04bd5a91dcabfb57db8b32bfd69a Mon Sep 17 00:00:00 2001 From: Michael Grund Date: Fri, 3 Sep 2021 17:09:31 +0200 Subject: [PATCH 05/12] some formatting --- examples/gallery/maps/roads.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/examples/gallery/maps/roads.py b/examples/gallery/maps/roads.py index c7348183e2d..9c526488a43 100644 --- a/examples/gallery/maps/roads.py +++ b/examples/gallery/maps/roads.py @@ -24,12 +24,14 @@ region = [-158.3, -157.6, 21.2, 21.75] # minx, maxx, miny, maxy fig.basemap( - region=region, projection="M12c", frame=["af", 'WSne+t"Main roads of Hawaii"'] + region=region, + projection="M12c", + frame=["af", 'WSne+t"Main roads of Oahu (Hawaii)"'], ) fig.coast(land="gray", water="dodgerblue4", shorelines="1p,black") -# Plot the individual road types with different pen settings and assgin labels which are -# displayed in the legend +# Plot the individual road types with different pen settings and assgin labels +# 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") From f8a5a348ae2386bfbef88f0246d9243e02d1117d Mon Sep 17 00:00:00 2001 From: Michael Grund Date: Sat, 4 Sep 2021 09:18:11 +0200 Subject: [PATCH 06/12] adjust title --- examples/gallery/maps/roads.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/gallery/maps/roads.py b/examples/gallery/maps/roads.py index 9c526488a43..24c244cb152 100644 --- a/examples/gallery/maps/roads.py +++ b/examples/gallery/maps/roads.py @@ -26,7 +26,7 @@ fig.basemap( region=region, projection="M12c", - frame=["af", 'WSne+t"Main roads of Oahu (Hawaii)"'], + frame=["af", 'WSne+t"Main roads of O`ahu (Hawai`i)"'], ) fig.coast(land="gray", water="dodgerblue4", shorelines="1p,black") From 6b1a85393c16ae53c2683171fa8ee3d893e24eb4 Mon Sep 17 00:00:00 2001 From: Michael Grund Date: Mon, 6 Sep 2021 17:57:57 +0200 Subject: [PATCH 07/12] adjust title --- examples/gallery/maps/roads.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/gallery/maps/roads.py b/examples/gallery/maps/roads.py index 24c244cb152..9c526488a43 100644 --- a/examples/gallery/maps/roads.py +++ b/examples/gallery/maps/roads.py @@ -26,7 +26,7 @@ fig.basemap( region=region, projection="M12c", - frame=["af", 'WSne+t"Main roads of O`ahu (Hawai`i)"'], + frame=["af", 'WSne+t"Main roads of Oahu (Hawaii)"'], ) fig.coast(land="gray", water="dodgerblue4", shorelines="1p,black") From 574befe77ad27e4ed42259dcce00dd424f01f7e9 Mon Sep 17 00:00:00 2001 From: Michael Grund <23025878+michaelgrund@users.noreply.github.com> Date: Wed, 8 Sep 2021 18:36:19 +0200 Subject: [PATCH 08/12] Apply suggestions from code review Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com> --- examples/gallery/maps/roads.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/examples/gallery/maps/roads.py b/examples/gallery/maps/roads.py index 9c526488a43..806f81a63d4 100644 --- a/examples/gallery/maps/roads.py +++ b/examples/gallery/maps/roads.py @@ -1,8 +1,12 @@ """ Roads ----- -The :meth:`pygmt.Figure.plot` method allows to plot geographical data which is -stored in a :class:`geopandas.GeoDataFrame` object. +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 @@ -23,11 +27,8 @@ # Define target region around O'ahu (Hawai'i) region = [-158.3, -157.6, 21.2, 21.75] # minx, maxx, miny, maxy -fig.basemap( - region=region, - projection="M12c", - frame=["af", 'WSne+t"Main roads of Oahu (Hawaii)"'], -) +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 From 089cb5cc9eb9f20506c3811d3a8ec8de5cbe9502 Mon Sep 17 00:00:00 2001 From: Michael Grund <23025878+michaelgrund@users.noreply.github.com> Date: Thu, 9 Sep 2021 08:32:31 +0200 Subject: [PATCH 09/12] Apply suggestions from code review Co-authored-by: Dongdong Tian --- examples/gallery/maps/roads.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/gallery/maps/roads.py b/examples/gallery/maps/roads.py index 806f81a63d4..33ec42c6242 100644 --- a/examples/gallery/maps/roads.py +++ b/examples/gallery/maps/roads.py @@ -25,13 +25,13 @@ fig = pygmt.Figure() # Define target region around O'ahu (Hawai'i) -region = [-158.3, -157.6, 21.2, 21.75] # minx, maxx, miny, maxy +region = [-158.3, -157.6, 21.2, 21.75] # xmin, xmax, ymin, ymax 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 +# Plot the individual road types with different pen settings and assign labels # 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") From 066980bab34562f03057da831cb766cd9da6af85 Mon Sep 17 00:00:00 2001 From: Michael Grund Date: Thu, 9 Sep 2021 08:38:13 +0200 Subject: [PATCH 10/12] adjust parameter formatting --- examples/gallery/maps/roads.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/gallery/maps/roads.py b/examples/gallery/maps/roads.py index 33ec42c6242..a79578a86b0 100644 --- a/examples/gallery/maps/roads.py +++ b/examples/gallery/maps/roads.py @@ -5,8 +5,8 @@ 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. +: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 From c9a06f1d3bd11a19b4e5e6a0a713a60ce2af1923 Mon Sep 17 00:00:00 2001 From: Michael Grund Date: Thu, 9 Sep 2021 17:40:17 +0200 Subject: [PATCH 11/12] moved file to lines and vectors category --- examples/gallery/lines/roads.py | 43 +++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 examples/gallery/lines/roads.py diff --git a/examples/gallery/lines/roads.py b/examples/gallery/lines/roads.py new file mode 100644 index 00000000000..a79578a86b0 --- /dev/null +++ b/examples/gallery/lines/roads.py @@ -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] # xmin, xmax, ymin, ymax + +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 assign labels +# 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() From 3c5b4e9622ed4b3021f5856efccae679eaae5c64 Mon Sep 17 00:00:00 2001 From: Michael Grund Date: Thu, 9 Sep 2021 17:41:28 +0200 Subject: [PATCH 12/12] removed file from maps category --- examples/gallery/maps/roads.py | 43 ---------------------------------- 1 file changed, 43 deletions(-) delete mode 100644 examples/gallery/maps/roads.py diff --git a/examples/gallery/maps/roads.py b/examples/gallery/maps/roads.py deleted file mode 100644 index a79578a86b0..00000000000 --- a/examples/gallery/maps/roads.py +++ /dev/null @@ -1,43 +0,0 @@ -""" -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] # xmin, xmax, ymin, ymax - -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 assign labels -# 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()