Skip to content

Commit 73e895f

Browse files
Update example for geopandas line geometry using Natural Earth dataset (#4229)
1 parent ccf050d commit 73e895f

File tree

1 file changed

+13
-28
lines changed

1 file changed

+13
-28
lines changed

examples/gallery/lines/linestrings.py

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,43 +4,28 @@
44
55
The :meth:`pygmt.Figure.plot` method allows us to plot geographical data such as lines
66
with LineString or MultiLineString geometry types stored in a
7-
:class:`geopandas.GeoDataFrame` object or any object that implements the
8-
`__geo_interface__ <https://gist.github.com/sgillies/2217756>`__ property.
9-
10-
Use :func:`geopandas.read_file` to load data from any supported OGR format such as a
11-
shapefile (.shp), GeoJSON (.geojson), geopackage (.gpkg), etc. Then, pass the
12-
:class:`geopandas.GeoDataFrame` object as an argument to the ``data`` parameter of
13-
:meth:`pygmt.Figure.plot`, and style the lines using the ``pen`` parameter.
7+
:class:`geopandas.GeoDataFrame` object. Use :func:`geopandas.read_file` to load data
8+
from any supported OGR format such as a shapefile (.shp), GeoJSON (.geojson), geopackage
9+
(.gpkg), etc. Then, pass the :class:`geopandas.GeoDataFrame` object as an argument to
10+
the ``data`` parameter of :meth:`pygmt.Figure.plot`, and style the lines using the
11+
``pen`` parameter.
1412
"""
1513

1614
# %%
17-
import geodatasets
1815
import geopandas as gpd
1916
import pygmt
2017

21-
# Read a sample dataset provided by the geodatasets package.
22-
# The dataset contains large rivers in Europe, stored as LineString/MultiLineString
23-
# geometry types.
24-
gdf = gpd.read_file(geodatasets.get_path("eea large_rivers"))
25-
26-
# Convert object to EPSG 4326 coordinate system
27-
gdf = gdf.to_crs("EPSG:4326")
28-
gdf.head()
18+
# Read a sample dataset provided by Natural Earth. The dataset contains rivers stored
19+
# as LineString/MultiLineString geometry types. Here will focus on Asia.
20+
provider = "https://naciscdn.org/naturalearth"
21+
rivers = gpd.read_file(f"{provider}/50m/physical/ne_50m_rivers_lake_centerlines.zip")
22+
rivers_asia = rivers.cx[57:125, 7:47].copy()
2923

30-
# %%
3124
fig = pygmt.Figure()
32-
33-
fig.coast(
34-
projection="M10c",
35-
region=[-10, 30, 35, 57],
36-
resolution="l",
37-
land="gray95",
38-
shorelines="1/0.1p,gray50",
39-
borders="1/0.1,gray30",
40-
frame=True,
41-
)
25+
fig.basemap(region=[57, 125, 7, 47], projection="M10c", frame=True)
26+
fig.coast(land="gray95", shorelines="1/0.3p,gray50")
4227

4328
# Add rivers to map
44-
fig.plot(data=gdf, pen="1p,steelblue")
29+
fig.plot(data=rivers_asia, pen="1p,steelblue")
4530

4631
fig.show()

0 commit comments

Comments
 (0)