Refactor coordinate processing into Polygons class

We have a bunch of stuff for doing lat/long transformation in the
`BroadcastMessage` class. This is not a good separation of concerns, now
that we have a separate class for dealing with polygons and coordinates.
This commit is contained in:
Chris Hill-Scott
2020-08-26 09:17:03 +01:00
parent c49a6338af
commit 3d9d663b27
7 changed files with 52 additions and 83 deletions
+10 -10
View File
@@ -53,6 +53,9 @@ class Polygons():
def __getitem__(self, index):
return self.polygons[index]
def __len__(self):
return len(self.polygons)
@cached_property
def perimeter_length(self):
return sum(
@@ -141,25 +144,22 @@ class Polygons():
])
@cached_property
def as_coordinate_pairs(self):
def as_coordinate_pairs_long_lat(self):
return [
[
[x, y] for x, y in p.exterior.coords
]
for p in self
[[x, y] for x, y in polygon.exterior.coords]
for polygon in self
]
@cached_property
def as_unenclosed_coordinate_pairs(self):
# Some mapping tools require shapes to be unenclosed, i.e. the
# last point joins the first point implicitly
def as_coordinate_pairs_lat_long(self):
return [
coordinates[:-1] for coordinates in self.as_coordinate_pairs
[[y, x] for x, y in coordinate_pairs]
for coordinate_pairs in self.as_coordinate_pairs_long_lat
]
@cached_property
def point_count(self):
return len(list(itertools.chain(*self.as_coordinate_pairs)))
return len(list(itertools.chain(*self.as_coordinate_pairs_long_lat)))
def flatten_polygons(polygons):