25 lines
541 B
Python
25 lines
541 B
Python
import re
|
|
import math
|
|
import shapely
|
|
|
|
def load_poly_from_file(path: str) -> shapely.Polygon:
|
|
points = list()
|
|
|
|
with open(path, 'r') as fh:
|
|
data = fh.read()
|
|
|
|
for line in data.split('\n'):
|
|
if line == '':
|
|
continue
|
|
|
|
lat, lon = re.split(r'\s*,\s*', line)
|
|
|
|
points.append((float(lon), float(lat)))
|
|
|
|
return shapely.Polygon(points)
|
|
|
|
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)
|