Skip to content
This repository has been archived by the owner on Nov 17, 2022. It is now read-only.

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
gka committed May 31, 2012
0 parents commit f85124e
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 0 deletions.
31 changes: 31 additions & 0 deletions country-template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"layers": [{
"id": "context",
"src": "shp/ne_50m_admin_0_countries.shp",
"simplify": 1.5
},{
"id": "regions",
"src": "shp/ne_10m_admin_1_states_provinces_shp.shp",
"attributes": [{
"src": "ISO", "tgt": "iso3"
},"NAME_1","FIPS_1"],
"filter": ["ISO","=","DEU"],
"styles": {
"fill": "red",
"fill-opacity": 0.35
},
"simplify": 1.2
}],
"bounds": {
"mode": "polygon",
"data": {
"layer": "regions"
},
"padding": 0.06
},
"export": {
"height": 300,
"round": 1,
"ratio": 1.5
}
}
42 changes: 42 additions & 0 deletions make-maps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@


from kartograph import Kartograph as Kartograph
import shapefile
import json
import os.path

map_output_dir = 'maps/'

country_min_area = {
'JPN': .1,
'AUS': .01,
'CAN': .05,
'ALA': .1,
'FRA': .2,
'DNK': .1,
'ITA': .05,
'GBR': .165,
'ESP': .165
}

custom_country_center = {
'USA': (-98.606, 39.622)
}

# extract admin codes from shapefile, sorted by population
records = shapefile.Reader('shp/ne_50m_admin_0_countries.shp').records()
records = sorted(records, key=lambda rec: rec[23] * -1)
adm_codes = [rec[9] for rec in records]

K = Kartograph()

for adm_code in adm_codes:
map_filename = map_output_dir + adm_code + '.svg'
if not os.path.exists(map_filename):
tmpl = json.loads(open('country-template.json').read())
tmpl['layers'][1]['filter'][2] = adm_code
print adm_code
try:
K.generate(tmpl, map_filename, preview=False)
except:
print 'error!'
1 change: 1 addition & 0 deletions maps/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.svg
7 changes: 7 additions & 0 deletions shp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
*.shp
*.dbf
*.shx
*.sbx
*.sbn
*.prj
*.zip
7 changes: 7 additions & 0 deletions shp/download.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh
wget http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/50m/cultural/50m-admin-0-countries.zip
unzip -d . 50m-admin-0-countries.zip
wget http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/50m/physical/50m-lakes.zip
unzip -d . 50m-lakes.zip
wget http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/10m/cultural/10m-admin-1-states-provinces-shp.zip
unzip -d . 10m-admin-1-states-provinces-shp.zip

0 comments on commit f85124e

Please sign in to comment.