Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change wkt to take list of points instead of wkt string #19

Merged
merged 3 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading