Skip to content

Commit

Permalink
Update the gallery example for plotting lines with LineString/MultiLi…
Browse files Browse the repository at this point in the history
…neString geometry (#3711)

Co-authored-by: Dongdong Tian <[email protected]>
Co-authored-by: actions-bot <[email protected]>
Co-authored-by: Yvonne Fröhlich <[email protected]>
  • Loading branch information
4 people authored Dec 31, 2024
1 parent 3134188 commit 32cc7a2
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 46 deletions.
46 changes: 46 additions & 0 deletions examples/gallery/lines/linestrings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
"""
GeoPandas: Plotting lines with LineString or MultiLineString geometry
=====================================================================
The :meth:`pygmt.Figure.plot` method allows us to plot geographical data such as lines
with LineString or MultiLineString geometry types stored in a
:class:`geopandas.GeoDataFrame` object or any object that implements the
`__geo_interface__ <https://gist.github.com/sgillies/2217756>`__ property.
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` object as an argument to the ``data`` parameter of
:meth:`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")
print(gdf.head())

# %%
fig = pygmt.Figure()

fig.coast(
projection="M10c",
region=[-10, 30, 35, 57],
resolution="l",
land="gray95",
shorelines="1/0.1p,gray50",
borders="1/0.1,gray30",
frame=True,
)

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

fig.show()
46 changes: 0 additions & 46 deletions examples/gallery/lines/roads.py

This file was deleted.

0 comments on commit 32cc7a2

Please sign in to comment.