|
4 | 4 |
|
5 | 5 | The :meth:`pygmt.Figure.plot` method allows us to plot geographical data such as lines |
6 | 6 | 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. |
14 | 12 | """ |
15 | 13 |
|
16 | 14 | # %% |
17 | | -import geodatasets |
18 | 15 | import geopandas as gpd |
19 | 16 | import pygmt |
20 | 17 |
|
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() |
29 | 23 |
|
30 | | -# %% |
31 | 24 | 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") |
42 | 27 |
|
43 | 28 | # Add rivers to map |
44 | | -fig.plot(data=gdf, pen="1p,steelblue") |
| 29 | +fig.plot(data=rivers_asia, pen="1p,steelblue") |
45 | 30 |
|
46 | 31 | fig.show() |
0 commit comments