The current extract_centroid method works well for most polygons but may return points outside the boundary. Adding a method to extract the point on surface using GeoPandas' representative_point() would make sure the point lies within the polygon.
Proposed Functionality to be added in the utility and for drainage database lat long coordinates:
def extract_point_on_surface(gdf, obj_id, epsg=4326):
if not gdf.crs:
gdf.set_crs(epsg=4326)
point_on_surface = gdf.geometry.representative_point()
if gdf.crs.to_epsg() != epsg:
point_on_surface = gdf.to_crs(epsg=epsg).geometry.representative_point()
coords_df = pd.DataFrame({
obj_id: gdf[obj_id],
'lat': point_on_surface.y,
'lon': point_on_surface.x
})
return coords_df
This will make sures extracted points always lie within the polygon boundary.
Provides users an alternative to centroid-based coordinates.
This would be a great addition to complement the existing functionality.
The current extract_centroid method works well for most polygons but may return points outside the boundary. Adding a method to extract the point on surface using GeoPandas' representative_point() would make sure the point lies within the polygon.
Proposed Functionality to be added in the utility and for drainage database lat long coordinates:
This will make sures extracted points always lie within the polygon boundary.
Provides users an alternative to centroid-based coordinates.
This would be a great addition to complement the existing functionality.