-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_maps.py
executable file
·145 lines (132 loc) · 4.69 KB
/
generate_maps.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/usr/bin/python
# -*- coding: utf-8 -*-
import optparse
from continents import ContinentsGenerator
from states import StatesGenerator
from generator import MapGenerator
from regions import RegionsGenerator
COUNTRIES_MEDIUM_FILE = "src/ne_50m_admin_0_countries_lakes/ne_50m_admin_0_countries_lakes.shp"
COUNTRIES_FILE = "src/ne_110m_admin_0_countries_lakes/ne_110m_admin_0_countries_lakes.shp"
CITIES_FILE = "src/ne_110m_populated_places/ne_110m_populated_places.shp"
COAST_FILE = "src/ne_50m_land/ne_50m_land.shp"
PHYSICAL_FILE = "src/ne_10m_geography_regions_polys/ne_10m_geography_regions_polys.shp"
RIVERS_FILE = "my_src/ne_110m_rivers_lake_centerlines/ne_110m_rivers_lake_centerlines.shp"
LAKES_FILE = "src/ne_110m_lakes/ne_110m_lakes.shp"
def main():
p = optparse.OptionParser()
options, arguments = p.parse_args()
if len(arguments) < 1:
print_usage()
else:
maps = arguments.pop(0)
codes = arguments
generator = None
if maps == 'all':
StatesGenerator().generate([])
WorldGenerator().generate([])
ContinentsGenerator().generate([])
elif maps == 'states':
codes = [c.upper() for c in codes]
generator = StatesGenerator()
elif maps == 'continents':
generator = ContinentsGenerator()
elif maps == 'world':
generator = WorldGenerator()
elif maps == 'regions':
generator = RegionsGenerator()
else:
print_usage()
if generator is not None:
generator.generate(codes)
def print_usage():
print "USAGE: \n./generate_maps.py [all|states|continents|world] [<map_codes> ...]"
def cities_size_filter(record):
return record['POP_MAX'] > 10 ** 5
class WorldGenerator(MapGenerator):
default_codes = ["world"]
def generate_one(self, code):
config = {
"layers": [{
"id": "bg",
"src": COUNTRIES_FILE,
"join": {'export-ids': False},
"filter": ["iso_a2", "is not", "AQ"]
}, {
"id": "state",
"src": COUNTRIES_FILE,
"attributes": {
"code": "iso_a2",
"name": "name",
"population": "pop_est",
},
"filter": {"and": [
["iso_a2", "is not", "AQ", "GF"],
["name", "is not", "N. Cyprus"]
]}
}, {
"id": "island",
"src": PHYSICAL_FILE,
"simplify": 1,
"attributes": {
"code": "name",
"name": "name"
},
"filter": {"and": [
{"featurecla": "Island"},
lambda r: r["scalerank"] < 4,
["name", "not in", ["Great Nicobar", "N. Andaman", "Middle Andaman", "S. Andaman"]],
lambda r: r["name"].decode('cp1252').encode('utf') != "Bol’shoy Begichev I.",
]}
}, {
"id": "mountains",
"src": PHYSICAL_FILE,
"attributes": {
"code": "name",
"name": "name"
},
"filter": {"and": [
{"featurecla": "Range/mtn"},
lambda r: r["scalerank"] < 3,
]}
}, {
"id": "river",
"src": RIVERS_FILE,
"attributes": {
"code": "name",
"name": "name"
},
"filter": {"and": [
["name", "not in", ["Peace", "Yangtze"]],
]}
}, {
"id": "lake",
"src": LAKES_FILE,
"attributes": {
"code": "name",
"name": "name"
},
"filter": {"and": [
["name", "not in", [
"Lake Athabasca",
"Great Salt Lake",
"Lake Tana",
"Lake Okeechobee",
]],
]}
}, {
"id": "city",
"src": CITIES_FILE,
"attributes": {
"code": "NAMEASCII",
"name": "NAME",
"state-code": "ISO_A2",
"population": "POP_MAX"
},
"filter": {"and": [
lambda r: r["POP_MAX"] > 2 * 10 ** 6,
]}
}]
}
self.generate_map(config, "world")
if __name__ == '__main__':
main()