-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlocation.py
More file actions
60 lines (46 loc) · 1.21 KB
/
Copy pathlocation.py
File metadata and controls
60 lines (46 loc) · 1.21 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
# ---
# jupyter:
# jupytext:
# text_representation:
# extension: .py
# format_name: percent
# format_version: '1.3'
# jupytext_version: 1.15.2
# kernelspec:
# display_name: Python 3 (ipykernel)
# language: python
# name: python3
# ---
# %%
from typing import NamedTuple
from util import DefaultReprMixin
class Location(NamedTuple):
name: str
lat: float
lon: float
def _repr_html_(self):
import folium
my_map = folium.Map(location=self.latlon, zoom_start=14)
folium.Marker(self.latlon, popup=self.name).add_to(my_map)
return my_map._repr_html_()
@property
def latlon(self):
# TODO we don't really need this, can deprecate
return self.lat, self.lon
@property
def lonlat(self):
return self.lon, self.lat
def __iter__(self):
yield self.lat
yield self.lon
def __getitem__(self, idx):
return [self.lat, self.lon][idx]
def __len__(self):
return 2
def __str__(self):
return self.name
class Polygon(DefaultReprMixin):
def __init__(self, locs):
self.locs = locs
def __eq__(self, other):
return self.locs == other.locs