Note
Go to the end to download the full example code.
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 or any object that implements the
__geo_interface__ property.
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 geodatasets
import geopandas as gpd
import pygmt
# Read a sample dataset provided by the geodatasets package.
# The dataset contains large rivers in Europe, stored as LineString/MultiLineString
# geometry types.
gdf = gpd.read_file(geodatasets.get_path("eea large_rivers"))
# Convert object to EPSG 4326 coordinate system
gdf = gdf.to_crs("EPSG:4326")
gdf.head()
Total running time of the script: (0 minutes 2.749 seconds)