Compare commits

..

No commits in common. "3e519568dbdd369eb9c17b31ab70285fdf57e916" and "c6670fefc635399dba0be05482b558a99827e94d" have entirely different histories.

2 changed files with 12 additions and 59 deletions

View file

@ -1,64 +1,15 @@
import re
import math
import shapely
from typing import Self
def load_poly_from_file(path: str) -> shapely.Polygon:
points = list()
class PointSequence(list):
@staticmethod
def from_file(path: str) -> Self:
ret = PointSequence()
with open(path, 'r') as fh:
data = fh.read()
with open(path, 'r') as fh:
data = fh.read()
for line in data.split('\n'):
lat, lon = re.split(', ', line)
for line in data.split('\n'):
if line == '':
continue
points.append((float(lon), float(lat)))
lat, lon = re.split(r'\s*,\s*', line)
ret.add(float(lon), float(lat))
return ret
def __init__(self, points: list=None):
super().__init__()
self.poly = None
for point in points:
typeof = type(point)
if typeof is tuple:
self.add(*point)
elif typeof is shapely.Point:
self.append(point)
def add(self, lon: float, lat: float):
self.append(shapely.Point(lon, lat))
def is_closed(self) -> bool:
return self[-1] == self[0]
def close(self):
if self[-1] != self[0]:
self.append(self[0])
self.poly = shapely.Polygon(self)
def nearest_index(self, point: shapely.Point) -> int:
indices = list()
for i in range(0, len(self)):
indices.append((i, self[i].distance(point)))
indices.sort(key=lambda i: i[1])
return indices[0][0]
def line_heading(p1: shapely.Point, p2: shapely.Point) -> float:
dx = p2.x - p1.x
dy = p2.y - p1.y
return math.atan2(dy, dx)
return shapely.Polygon(points)

View file

@ -68,8 +68,10 @@ def parse_coord(coord: str) -> tuple[float, float]:
if lon <= 6100:
lon += 10000
return shapely.Point(0.01 * -lon,
0.01 * int(coord[0:4]))
return (
0.01 * -lon,
0.01 * int(coord[0:4])
)
def each_poly(parts: list[str]):
points = list()