Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Gadm guide again #29

Merged
merged 1 commit into from
Jun 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions docs/gallery/maps/gadm.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
How to use political borders from GADM
---------------------------------------

GADM (https://gadm.org/) is a project that provides spatial data for all countries and their sub-divisions.
They allow you to freely use their data (see `license <https://gadm.org/license.html>`_) to make your own maps.
You can use this script to download the data from their server.
You only need to select a data set (using a three-letter code) and a level.
Not all levels are available. Check first in their website if the data set exists.
Here is a table with the number of file available for each level.

======= ============
Level # of files
======= ============
0 254
1 230
2 171
3 69
4 21
5 2
======= ============

The script will download the selected data and level in KMZ format.
Then, it will unzip that file (to KML) and convert it to a GMT format.
At the end, you will have a GMT file in the same directory.
To demostrate, we will create a level 1 map of Mexico (code MEX).

.. gmtplot::

# How to plot political borders from GADM data set
#
# GDAM data
# ------------------------------------
# Set country with three-leter code.
COUNTRY=MEX
# Set level from 0 to 5. 0 = Country outline.
LEVEL=1
# GADM data set version
VERSION=4.1
# File formats (https://gadm.org/formats.html)
FORMAT=kmz
SITE="https://geodata.ucdavis.edu/gadm/"
# Remove dot from version
VERSION_WITHOUT_DOT=$(echo ${VERSION} | tr -d '.')
# Set file name without extension
NAME="gadm${VERSION_WITHOUT_DOT}_${COUNTRY}_${LEVEL}"
# URL
URL="${SITE}gadm${VERSION}/${FORMAT}/${NAME}.${FORMAT}"
# ------------------------------------
# Download data from GADM
echo "Downloading geographic data provided by the https://gadm.org project. It may take a while."
gmt which $URL -Gc
# Unzip KMZ to KML. Set to NOT (-n) overwrite existing file.
unzip -n ${NAME}.${FORMAT}
# Convert KML file to GMT format with OGR/GDAL
ogr2ogr -f "GMT" ${NAME}.gmt ${NAME}.kml
# Test Plot data
gmt begin ${COUNTRY} png
gmt plot ${NAME}.gmt -Wred -JM15c -Bf -Re
gmt end
# Delete KMZ and KML files
rm ${NAME}.km?
10 changes: 10 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ Seismology and geodesy
Basemaps
~~~~~~~~

.. grid:: 2 3 3 4

.. grid-item-card:: :doc:`gallery/maps/gadm`
:padding: 1
:link-type: doc
:link: gallery/maps/gadm

.. image:: _images/7dd36e07258e1015a0673dea4e472db1.png


Histograms
~~~~~~~~~~

Expand Down