-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathregions.py
More file actions
71 lines (53 loc) · 11.3 KB
/
Copy pathregions.py
File metadata and controls
71 lines (53 loc) · 11.3 KB
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
'''Defines supported regions and their corresponding polygons.'''
from typing import Dict
import attr
from shapely.geometry import box
from shapely.geometry.point import Point
from shapely.geometry.polygon import Polygon
from shapely import wkt
@attr.s
class Region:
"""A polygon defining a region on the earth's surface and a name for it.
`name`: An identifier used to select this region.
`polygon`: A shapely Polygon defining the bounds of the region.
`corner_sw`: A shapely Point corresponding to the south-west corner of the
region's bounding box. This is computed from the given polygon.
`corner_ne`: A shapely Point corresponding to the north-east corner of the
region's bounding box. This is computed from the given polygon.
"""
name: str = attr.ib()
polygon: Polygon = attr.ib()
corner_sw: Point = attr.ib(init=False)
corner_ne: Point = attr.ib(init=False)
def __attrs_post_init__(self):
(minx, miny, maxx, maxy) = self.polygon.bounds
self.corner_sw = Point(minx, miny)
self.corner_ne = Point(maxx, maxy)
SUPPORTED_REGIONS = [
Region(
name="Haifa",
polygon=wkt.loads(
'POLYGON ((35.0130711 32.751651, 35.010244 32.7517819, 35.0102430198286 32.75178194815273, 35.01024204909678 32.7517820921472, 35.00702874909678 32.7523639921472, 35.00662644909678 32.7524406921472, 35.00662549715322 32.75244093059664, 35.00662457316567 32.75244126120468, 35.00662368603263 32.75244168078736, 34.95721818603263 32.78163278078735, 34.95721734429767 32.78163328530388, 34.95721655606716 32.78163386989547, 34.95715165606716 32.78168366989546, 34.95715092893219 32.78168432893219, 34.95715026989546 32.78168505606716, 34.95714968530388 32.78168584429767, 34.95690758530387 32.78203134429767, 34.95690708078735 32.78203218603263, 34.95690666120468 32.78203307316568, 34.95690633059664 32.78203399715323, 34.95690609214719 32.78203494909678, 34.95690594815273 32.7820359198286, 34.95492154815273 32.7966224198286, 34.9549215 32.7966234, 34.95492154815273 32.7966243801714, 34.95493334815273 32.7967151801714, 34.95493349214719 32.79671615090322, 34.9563888921472 32.80531335090322, 34.95638913059664 32.80531430284677, 34.95638946120468 32.80531522683432, 34.96825136120468 32.83161352683432, 34.96825178078736 32.83161441396737, 34.96845268078735 32.83200861396737, 34.96845318530387 32.83200945570233, 34.96845376989546 32.83201024393284, 34.96845442893218 32.83201097106781, 34.96845515606716 32.83201163010453, 34.96845594429767 32.83201221469612, 34.96845678603263 32.83201271921264, 34.96845767316567 32.83201313879532, 34.97791497316567 32.83632683879532, 34.97796247316568 32.83634743879532, 34.97796339715322 32.83634776940336, 34.97796434909678 32.83634800785281, 34.97990324909678 32.8367388078528, 34.9799042198286 32.83673895184727, 34.9799052 32.836739, 34.9800297 32.836744, 34.9800306801714 32.83674395184727, 34.9828419801714 32.83652965184726, 34.98284295090322 32.8365295078528, 34.98355015090322 32.83638720785281, 35.03850305090322 32.82284750785281, 35.03850400284677 32.82284726940336, 35.03850492683432 32.82284693879532, 35.03850581396737 32.82284651921265, 35.03850665570233 32.82284601469613, 35.04992065570233 32.81483011469612, 35.04992144393284 32.81482953010453, 35.04992217106781 32.81482887106781, 35.04992283010453 32.81482814393284, 35.04992341469612 32.81482735570233, 35.04992391921265 32.81482651396737, 35.04992433879532 32.81482562683432, 35.04992466940336 32.81482470284677, 35.04992490785281 32.81482375090322, 35.04992505184727 32.8148227801714, 35.05275245184727 32.7933641801714, 35.0527525 32.7933632, 35.05275245184727 32.7933622198286, 35.05275230785281 32.79336124909678, 35.0527308078528 32.79326234909678, 35.05273056940336 32.79326139715322, 35.05273023879532 32.79326047316567, 35.05272981921264 32.79325958603263, 35.03164761921265 32.75403908603263, 35.03164711469613 32.75403824429767, 35.03164653010454 32.75403745606716, 35.03154673010454 32.75390555606716, 35.03154607106782 32.75390482893219, 35.03154534393284 32.75390416989546, 35.03154455570233 32.75390358530387, 35.03154371396737 32.75390308078735, 35.03154282683433 32.75390266120468, 35.03154190284678 32.75390233059664, 35.03154095090322 32.75390209214719, 35.03086775090322 32.7537612921472, 35.0308667801714 32.75376114815273, 35.0130720801714 32.75165104815273, 35.0130711 32.751651))'),
),
Region(
name="Tel_Aviv",
polygon=wkt.loads(
'POLYGON ((34.806731 32.0345568, 34.8067300198286 32.03455684815273, 34.80672904909678 32.03455699214719, 34.74771904909678 32.0478491921472, 34.74771809715322 32.04784943059664, 34.74771717316568 32.04784976120468, 34.74711517316567 32.04808576120468, 34.74711428603263 32.04808618078736, 34.74711344429767 32.04808668530388, 34.74711265606716 32.04808726989547, 34.74711192893218 32.04808792893219, 34.74698492893219 32.04821992893218, 34.74698426989546 32.04822065606716, 34.74698368530387 32.04822144429767, 34.74698318078735 32.04822228603263, 34.74698276120468 32.04822317316567, 34.74698243059664 32.04822409715322, 34.74698219214719 32.04822504909678, 34.74698204815273 32.0482260198286, 34.746982 32.048227, 34.74698204815273 32.0482279801714, 34.74699504815273 32.0484069801714, 34.7469951921472 32.04840795090322, 34.74699543059664 32.04840890284677, 34.74818443059664 32.05237490284677, 34.74818476120468 32.05237582683432, 34.74818518078735 32.05237671396737, 34.78102368078736 32.12102581396737, 34.78152848078735 32.12190581396737, 34.78152898530387 32.12190665570233, 34.78152956989546 32.12190744393284, 34.78153022893218 32.12190817106782, 34.78368292893219 32.12411777106782, 34.78368365606716 32.12411843010454, 34.78368444429767 32.12411901469613, 34.78368528603263 32.12411951921265, 34.78368617316568 32.12411993879532, 34.78368709715323 32.12412026940336, 34.78368804909678 32.12412050785281, 34.7836890198286 32.12412065184727, 34.78369 32.12412070000001, 34.836516 32.12588, 34.839946 32.125775, 34.8399469801714 32.12577495184727, 34.83994795090322 32.12577480785281, 34.83994890284677 32.12577456940336, 34.83994982683432 32.12577423879532, 34.83995071396737 32.12577381921265, 34.83995155570233 32.12577331469613, 34.83995234393284 32.12577273010454, 34.83995307106781 32.12577207106781, 34.83995373010453 32.12577134393284, 34.83995431469612 32.12577055570233, 34.83995481921264 32.12576971396737, 34.83995523879532 32.12576882683432, 34.84081723879532 32.12339082683432, 34.84081756940336 32.12338990284677, 34.84091656940336 32.12299790284678, 34.84091680785281 32.12299695090322, 34.84095680785281 32.12283595090322, 34.84095695184727 32.1228349801714, 34.840957 32.122834, 34.840976 32.122368, 34.84097595184727 32.1223670198286, 34.84092995184727 32.1220340198286, 34.84090095184727 32.1218280198286, 34.8409008078528 32.12182704909678, 34.84078180785281 32.12117904909678, 34.84078156940336 32.12117809715323, 34.84078123879532 32.12117717316568, 34.80716193879532 32.03509807316568, 34.80716151921265 32.03509718603263, 34.80697631921264 32.03471928603263, 34.80697581469612 32.03471844429767, 34.80697523010453 32.03471765606716, 34.80697457106781 32.03471692893218, 34.80697384393284 32.03471626989546, 34.80697305570233 32.03471568530387, 34.80673655570233 32.03455848530388, 34.80673571396737 32.03455798078735, 34.80673482683432 32.03455756120468, 34.80673390284677 32.03455723059664, 34.80673295090322 32.03455699214719, 34.8067319801714 32.03455684815273, 34.806731 32.0345568))'),
),
Region(
name="Jerusalem",
polygon=wkt.loads(
'POLYGON ((35.2190939 31.7362243, 35.2190929198286 31.73622434815273, 35.21909194909678 31.73622449214719, 35.16932044909678 31.7437011921472, 35.16931949715323 31.74370143059664, 35.16892349715322 31.74383143059664, 35.16420509715323 31.74545733059664, 35.16420417316568 31.74545766120468, 35.16420328603263 31.74545808078736, 35.16420244429767 31.74545858530388, 35.16420165606716 31.74545916989547, 35.16263775606716 31.74685156989547, 35.16263702893219 31.74685222893219, 35.14452762893219 31.76404402893219, 35.14452696989547 31.76404475606716, 35.14452638530388 31.76404554429767, 35.14446068530388 31.76413494429767, 35.14438608530388 31.76425804429767, 35.14438558078736 31.76425888603263, 35.14438516120468 31.76425977316568, 35.14438483059664 31.76426069715323, 35.1443845921472 31.76426164909678, 35.14438444815273 31.7642626198286, 35.14436704815273 31.7645224198286, 35.144367 31.7645234, 35.14436704815273 31.76452438017141, 35.14436719214719 31.76452535090322, 35.14436743059664 31.76452630284678, 35.14436776120468 31.76452722683432, 35.14436818078735 31.76452811396737, 35.14444298078735 31.76466491396737, 35.14444348530387 31.76466575570233, 35.14444406989546 31.76466654393284, 35.17057436989546 31.79660224393284, 35.17057502893218 31.79660297106781, 35.17358122893219 31.79967687106781, 35.17358195606716 31.79967753010454, 35.17396285606716 31.80002183010453, 35.17420155606716 31.80021103010453, 35.17420234429767 31.80021161469612, 35.17420318603263 31.80021211921264, 35.17462698603263 31.80045831921264, 35.17462787316568 31.80045873879532, 35.17510797316568 31.80066383879533, 35.17510889715323 31.80066416940336, 35.17538249715323 31.80074626940336, 35.17538344909678 31.80074650785281, 35.17578044909678 31.80083540785281, 35.1757814198286 31.80083555184727, 35.1761864198286 31.80089255184727, 35.1825069198286 31.80164695184727, 35.1825079 31.801647, 35.1828512 31.8016584, 35.2097023 31.8016629, 35.2097032801714 31.80166285184727, 35.20970425090321 31.80166270785281, 35.24836305090322 31.79482420785281, 35.24851915090322 31.79479410785281, 35.24852010284678 31.79479386940336, 35.24852102683433 31.79479353879533, 35.24869782683432 31.79472533879532, 35.24869871396737 31.79472491921264, 35.24869955570233 31.79472441469612, 35.24882235570233 31.79464741469613, 35.24882314393284 31.79464683010454, 35.24882387106781 31.79464617106781, 35.24895557106781 31.79452297106781, 35.24895623010453 31.79452224393284, 35.24910133010454 31.79433444393284, 35.24910191469613 31.79433365570233, 35.24910241921265 31.79433281396737, 35.24910283879532 31.79433192683432, 35.24916593879532 31.79416802683432, 35.24916626940336 31.79416710284677, 35.24922336940336 31.79399380284677, 35.24922360785281 31.79399285090322, 35.24922375184727 31.7939918801714, 35.24924925184727 31.7937784801714, 35.2492493 31.7937775, 35.24924925184727 31.7937765198286, 35.2492491078528 31.79377554909678, 35.24924886940336 31.79377459715323, 35.23731196940336 31.75419149715323, 35.23731163879532 31.75419057316568, 35.23731121921264 31.75418968603263, 35.23731071469612 31.75418884429767, 35.23731013010453 31.75418805606716, 35.23730947106781 31.75418732893219, 35.22065977106782 31.73628592893219, 35.22065904393284 31.73628526989546, 35.22065825570233 31.73628468530388, 35.22065741396737 31.73628418078736, 35.22056731396737 31.73623328078736, 35.22056642683432 31.73623286120467, 35.22056550284677 31.73623253059664, 35.22056455090322 31.73623229214719, 35.2205635801714 31.73623214815273, 35.2205626 31.7362321, 35.2190939 31.7362243))'),
),
]
REGION_LOOKUP = dict(map(lambda r: (r.name, r), SUPPORTED_REGIONS))
SUPPORTED_REGION_NAMES = sorted(list(REGION_LOOKUP.keys()))
REGION_SUPPORT_MESSAGE = (
'Supported regions: ' + ', '.join(SUPPORTED_REGION_NAMES))
def get_region(region_name: str) -> Region:
try:
return REGION_LOOKUP[region_name]
except:
raise ValueError(
f'Unsupported region {region_name}. '
'Please choose one of ', SUPPORTED_REGION_NAMES)