Skip to content

Commit 7f7e8f5

Browse files
Determining bounds of polygon
1 parent 38a70b9 commit 7f7e8f5

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

scripts/gpd_helper.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,28 @@
77

88
class GpdHelper:
99
def __init__(self) -> None:
10-
pass
10+
self.input_epsg = input_epsg
11+
self.output_epsg = output_epsg
12+
13+
14+
def get_bound_from_polygon(self, polygon: Polygon) -> tuple:
15+
""" Computes bounds value for the given polygon
16+
17+
Args:
18+
polygon (Polygon): Shapely geometry object describing the polygon.
19+
20+
Returns:
21+
tuple: A tuple of Bounds object and a string of a given polygon in a form accepted by the pdal pipeline.
22+
"""
23+
polygon_df = gpd.GeoDataFrame([polygon], columns=['geometry'])
24+
polygon_df.set_crs(epsg=self.output_epsg, inplace=True)
25+
polygon_df['geometry'] = polygon_df['geometry'].to_crs(epsg=self.input_epsg)
26+
xmin, ymin, xmax, ymax = polygon_df['geometry'][0].bounds
27+
bound = Bounds(xmin, xmax, ymin, ymax)
28+
x_cord, y_cord = polygon_df['geometry'][0].exterior.coords.xy
29+
polygon_str = self.get_polygon_str(x_cord, y_cord)
30+
31+
return bound, polygon_str
32+
33+
34+

0 commit comments

Comments
 (0)