Skip to content

Instantly share code, notes, and snippets.

@hugolpz
Last active September 30, 2019 23:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hugolpz/358d785b6ae94c34dd29 to your computer and use it in GitHub Desktop.
Save hugolpz/358d785b6ae94c34dd29 to your computer and use it in GitHub Desktop.
Wikiatlas — administrative layer
# Folder
**/test/
# Files (globes)
*.zip
*.rar
*.tiff
*.tif
*.shp
*.shx
*.dbf
*.prj
#*.geo.json
*.sql
*.pdf
*.sbn
*.sbx
*.tsv
*.csv
#*.png
#*.jpg
*.svg
* *_.html
# Root
*.README.html
*.VERSION.txt

Makefile

Action: When run, this administrative.makefile download administrative L0 (countries), L1 (subunits), and cities (places) GIS sources, process them (unzip, crop, filter), to output an elegant composite stack of your target L1 district upon L0 backgrounds, as topojson and WP styled SVG files.

Output:

  • administrative.topo.json, containing:
  • countries
  • subdivisions (of the target country)
  • places (with population above a given number):

Direct command:

make -f administrative.makefile ITEM=India WEST=67.0 NORTH=37.5  EAST=99.0 SOUTH=05.0 SELECTOR_L1="admin IN ('INDIA')"

Parameters:

  • SELECTOR_L1=... (SQL selector, default value "admin IN ('France')") selects and keeps L1 administrative areas respecting SQL query.
  • SELECTOR_PLACES=... (SQL selector, default value ADM0NAME = '$(ITEM)' AND POP_MAX > '$(POP_MIN)') selects and keeps places administrative areas respecting SQL query.
  • SELECTOR_POP_MIN=... (integer > 0, default value 200000) selects and keeps places (towns and cities) with populations above (>) value. Easier than SELECTOR_PLACES=.
  • QUANTIZATION=... (default 1e4, from 1e3 to 1e6) : maximum number of differentiable points along either dimension

Derivated from ogr2ogr and topojson.js.

[1]: If not there, the download task will automatically download the NaturalEarth countries, subunits, and places archive files totaling about 30MB. This may take from few minutes.

See also:

Suggestions? Drop me a suggestion/command line @hugo_lz

#DEFAULT VALUES (customizable):
# inherit ITEM, WEST, NORTH, EAST, SOUTH from master.makefile.
SELECTOR_POP_MIN=200000
SELECTOR_L1=admin IN ('$(ITEM)')
SELECTOR_PLACES=ADM0NAME = '$(ITEM)' AND POP_MAX > '$(SELECTOR_POP_MIN)'
QUANTIZATION=1e4
#MAKEFILE
topojson: geojson_filters
topojson \
-q $(QUANTIZATION) \
-o $(ITEM).administrative.topo.json \
-- admin_0=countries.geo.json admin_1=subunits.geo.json places=places.geo.json
geojson_filters: crop unzip
ogr2ogr -f GeoJSON \
countries.geo.json \
crop_L0.shp
ogr2ogr -f GeoJSON -where "$(SELECTOR_L1)" \
subunits.geo.json \
ne_10m_admin_1_states_provinces.shp
ogr2ogr -f GeoJSON -where "$(SELECTOR_PLACES)" \
places.geo.json \
ne_10m_populated_places.shp
#or "iso_a2 = 'AT' AND SCALERANK < 20" , see also sr_adm0_a3
#ADM0NAME = 'Egypt' OR ADM0NAME = 'Iran' OR SOV0NAME = 'Saudi Arabia' OR SOV0NAME = 'Lebanon' OR SOV0NAME = 'Turkey' OR SOV0NAME = 'Syria' OR SOV0NAME = 'Iraq' OR ISO_A2 = 'noFR'
crop: unzip touch
ogr2ogr -clipsrc $(WEST) $(NORTH) $(EAST) $(SOUTH) crop_L0.shp ne_10m_admin_0_countries.shp
# WNES coordinates
#unzip -n : no overwrite
unzip: downloads
unzip -n ../data/NE/countries.zip
unzip -n ../data/NE/subunits.zip
unzip -n ../data/NE/places.zip
touch: unzip
touch ne_10m_admin_0_countries.shp
touch ne_10m_admin_1_states_provinces.shp
touch ne_10m_populated_places.shp
downloads: clean d0 d1 d2 d3
# downloads done.
d0:
mkdir -p ../data/NE/
d1:
curl \
-o ../data/NE/countries.zip \
-L -C - 'http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/10m/cultural/ne_10m_admin_0_countries.zip'
## http://www.nacis.org/naturalearth/10m/cultural/NE_10m_admin_0_map_subunits.zip
d2:
curl \
-L -C - 'http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/10m/cultural/ne_10m_admin_1_states_provinces.zip' \
-o ../data/NE/subunits.zip
d3:
curl \
-L -C - 'http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/10m/cultural/ne_10m_populated_places.zip' \
-o ../data/NE/places.zip
clean:
rm -f *.json
rm -f *.dbf
rm -f *.prj
rm -f *.shp
rm -f *.shx
rm -f *.html
rm -f *.txt
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment