diff --git a/misc/deg.py b/misc/deg.py index 76f6e1f..5e56ce0 100644 --- a/misc/deg.py +++ b/misc/deg.py @@ -1,18 +1,22 @@ from collections import namedtuple + from decimal import Decimal as Dec + class Deg(namedtuple('Deg', ['deg', 'mm', 'ss'])): def __str__(self): return "%03d-%02d-%.1f" % (self.deg, self.mm, self.ss) + def guess(inp): if isinstance(inp, str) and '-' in inp: deg, mm, ss = inp.split('-') ddeg, dmm, dss = Dec(deg), Dec(mm), Dec(ss) return ddeg + dmm/60 + dss/3600 else: - return Dec(instr) + return Dec(inp) + def hms(deg): assert isinstance(deg, Dec) diff --git a/misc/greedy-points-to-multiline.py b/misc/greedy-points-to-multiline.py index 4442e58..e42d62a 100755 --- a/misc/greedy-points-to-multiline.py +++ b/misc/greedy-points-to-multiline.py @@ -5,6 +5,7 @@ import rtree import os from osgeo import ogr + def main(): driver = ogr.GetDriverByName('gpkg') @@ -13,7 +14,11 @@ def main(): srs = inLayer.GetSpatialRef() outDataSource = driver.CreateDataSource(sys.argv[2]) outLayerName, _ = os.path.splitext(os.path.basename(sys.argv[2])) - outLayer = outDataSource.CreateLayer(outLayerName, srs, geom_type=ogr.wkbLineString) + outLayer = outDataSource.CreateLayer( + outLayerName, + srs, + geom_type=ogr.wkbLineString + ) points = extract_layer_points(inLayer) path = greedy_path(points) @@ -36,13 +41,14 @@ def extract_layer_points(layer): points[i] = (p[0], p[1]) return points + def greedy_path(points): """Given a dict of points, return a "greedy" path between them. It will start with a random point, and keep navigating to the closest one, until all the points have been visited. """ - idx = rtree.index.Index(interleaved = False) + idx = rtree.index.Index(interleaved=False) for (i, pt) in points.items(): idx.insert(i, pt)