GeoPandas: Plotting lines with LineString or MultiLineString geometry

The pygmt.Figure.plot method allows us to plot geographical data such as lines with LineString or MultiLineString geometry types stored in a geopandas.GeoDataFrame object. Use geopandas.read_file to load data from any supported OGR format such as a shapefile (.shp), GeoJSON (.geojson), geopackage (.gpkg), etc. Then, pass the geopandas.GeoDataFrame object as an argument to the data parameter of pygmt.Figure.plot, and style the lines using the pen parameter.

import geopandas as gpd
import pygmt

# Read a sample dataset provided by Natural Earth. The dataset contains rivers stored
# as LineString/MultiLineString geometry types. Here will focus on Asia.
provider = "https://naciscdn.org/naturalearth"
rivers = gpd.read_file(f"{provider}/50m/physical/ne_50m_rivers_lake_centerlines.zip")
rivers_asia = rivers.cx[57:125, 7:47].copy()

fig = pygmt.Figure()
fig.basemap(region=[57, 125, 7, 47], projection="M10c", frame=True)
fig.coast(land="gray95", shorelines="1/0.3p,gray50", borders="1/0.2p,black")

# Add rivers to map
fig.plot(data=rivers_asia, pen="1p,steelblue")

fig.show()
linestrings
rivers_australia = rivers.cx[111:155, -40:-9].copy()

fig = pygmt.Figure()
fig.basemap(region=[111, 155, -40, -9], projection="M10c", frame=True)
fig.coast(land="gray95", shorelines="1/0.3p,gray50", borders="1/0.2p,black")

# Add rivers to map
fig.plot(data=rivers_australia, pen="1p,steelblue")

fig.show()
linestrings
rivers_sa = rivers.cx[-84.5:-33, -56.5:13].copy()

fig = pygmt.Figure()
fig.basemap(region=[-84.5, -33, -56.5, 13], projection="M10c", frame=True)
fig.coast(land="gray95", shorelines="1/0.3p,gray50", borders="1/0.2p,black")

# Add rivers to map
fig.plot(data=rivers_sa, pen="1p,steelblue")

fig.show()
linestrings

Total running time of the script: (0 minutes 0.696 seconds)

Gallery generated by Sphinx-Gallery