-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
98 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from PolygonDust import Point, Polygon | ||
|
||
class RawInput: | ||
def __init__(self, paths: list[str] | None): | ||
self.polygons: list[Polygon] = self.build(paths) | ||
|
||
def build(self, paths: list[str]): | ||
polygons: list[Polygon] = [] | ||
|
||
if paths is None: | ||
return polygons | ||
|
||
for polygon_path in paths: | ||
vertex_list = [] | ||
with open(polygon_path[0], "r") as file: | ||
print(polygon_path[0]) | ||
vertex_lines = file.read().split('\n') | ||
for vertex_line in vertex_lines: | ||
if(len(vertex_line) == 0): | ||
continue | ||
vertex_list.append(Point(float(vertex_line.split(", ")[0]), float(vertex_line.split(", ")[1]))) | ||
polygon = Polygon(vertex_list) | ||
polygons.append(polygon) | ||
return polygons | ||
|
||
def get_result(self) -> list[Polygon]: | ||
return self.polygons |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import fiona | ||
from PolygonDust import Point, Polygon | ||
|
||
class ShapefileInput: | ||
def __init__(self, paths: list[str] | None): | ||
self.polygons: list[Polygon] = self.build(paths) | ||
|
||
def build(self, paths: list[str] | None): | ||
polygons: list[Polygon] = [] | ||
|
||
if paths is None: | ||
return polygons | ||
|
||
for shapefile_path in paths: | ||
with fiona.open(shapefile_path[0], "r") as shapefile: | ||
for feature in shapefile: | ||
geometry = feature['geometry'] | ||
|
||
print(geometry) | ||
|
||
# Ensure it's a polygon | ||
if geometry['type'] == 'Polygon': | ||
coordinates = geometry['coordinates'][0] # Outer boundary | ||
print(f"Shapefile {shapefile_path} have {len(coordinates)} vertexes.") | ||
polygon = Polygon([Point(vertice[0], vertice[1]) for vertice in coordinates]) | ||
polygons.append(polygon) | ||
|
||
if geometry['type'] == "MultiPolygon": | ||
for i in range(len(geometry['coordinates'])): | ||
coordinates = geometry['coordinates'][i][0] | ||
print(f"Shapefile {shapefile_path} have {len(coordinates)} vertexes.") | ||
polygon = Polygon([Point(vertice[0], vertice[1]) for vertice in coordinates]) | ||
polygons.append(polygon) | ||
return polygons | ||
|
||
def get_result(self) -> list[Polygon]: | ||
return self.polygons |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import pywavefront | ||
from PolygonDust import Point, Polygon | ||
|
||
class WaveformInput: | ||
def __init__(self, paths: list[str] | None): | ||
self.polygons: list[Polygon] = self.build(paths) | ||
|
||
def build(self, paths: list[str]): | ||
polygons: list[Polygon] = [] | ||
|
||
if paths is None: | ||
return polygons | ||
|
||
for polygon_path in paths: | ||
scene: pywavefront.Wavefront = pywavefront.Wavefront(polygon_path[0], strict=True, encoding="utf-8", parse=False) | ||
scene.parse() | ||
|
||
polygon = Polygon([Point(vertice[0], vertice[1]) for vertice in scene.vertices]) | ||
polygons.append(polygon) | ||
return polygons | ||
|
||
def get_result(self) -> list[Polygon]: | ||
return self.polygons |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters