Skip to content

Commit

Permalink
Merge pull request #20 from ecmwf/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
awarde96 authored Sep 18, 2024
2 parents 62ca52c + 3b977d9 commit d447ea3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion polytope_mars/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"frame": Frame,
"path": Path,
"shapefile": Shapefile,
"wkt": Wkt,
"polygon": Wkt,
}


Expand Down
19 changes: 10 additions & 9 deletions polytope_mars/features/wkt.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from polytope import shapes
from shapely import wkt

from ..feature import Feature

# from shapely import wkt


# Function to convert POLYGON and MULTIPOLYGON to points
def get_coords(geom):
Expand All @@ -17,20 +18,20 @@ def get_coords(geom):

class Wkt(Feature):
def __init__(self, config):
assert config.pop("type") == "wkt"
assert config.pop("type") == "polygon"
self.shape = config.pop("shape")
self.df = wkt.loads(self.shape)
# self.df = wkt.loads(self.shape)

assert len(config) == 0, f"Unexpected keys in config: {config.keys()}"

def get_shapes(self):
coordinates = get_coords(self.df)
# coordinates = get_coords(self.df)
polygons = []
for coord in coordinates:
points = []
for point in coord:
points.append([point[0], point[1]])
polygons.append(shapes.Polygon(["latitude", "longitude"], points))
# for coord in self.shape:
points = []
for point in self.shape:
points.append([point[0], point[1]])
polygons.append(shapes.Polygon(["latitude", "longitude"], points))
return [shapes.Union(["latitude", "longitude"], *polygons)]

def incompatible_keys(self):
Expand Down

0 comments on commit d447ea3

Please sign in to comment.