diff --git a/examples/gallery/lines/linestrings.py b/examples/gallery/lines/linestrings.py index 18f94502f16..af1c07b80be 100644 --- a/examples/gallery/lines/linestrings.py +++ b/examples/gallery/lines/linestrings.py @@ -4,43 +4,54 @@ 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__ `__ 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. +: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` 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")) +# 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() -# Convert object to EPSG 4326 coordinate system -gdf = gdf.to_crs("EPSG:4326") -gdf.head() # %% +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") -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=rivers_australia, pen="1p,steelblue") + +fig.show() + + +# %% +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=gdf, pen="1p,steelblue") +fig.plot(data=rivers_sa, pen="1p,steelblue") fig.show()