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

Feature Request: Add "Point on Surface" Extraction Method for Polygons #24

Open
fuadyassin opened this issue Nov 27, 2024 · 3 comments
Open
Assignees
Labels
enhancement New feature or request

Comments

@fuadyassin
Copy link

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.

@kasra-keshavarz
Copy link
Collaborator

Thanks Fuad, I'll merge this into the main branch soon.

@kasra-keshavarz kasra-keshavarz self-assigned this Nov 27, 2024
@kasra-keshavarz kasra-keshavarz added the enhancement New feature or request label Nov 27, 2024
@mee067
Copy link

mee067 commented Nov 27, 2024

we need to enhance this for gauge locations as we talked before. Gauges at the outlets are not always mapped to the correct subbasin as the centroid of another subbasin maybe closer to the gauge. Can we supply polygon outlets (intersection of river and subbasin shape) instead of centroids?

@fuadyassin
Copy link
Author

fuadyassin commented Nov 27, 2024

@mee067 Thank you for pointing that out. The enhancement to flag stations or use polygon outlets (intersection of river and subbasin shape) is indeed another development we are working on. For now, this update ensures that the centroid is correctly placed within the polygon and improves the default streamflow station identification function. The additional improvement you mentioned will be implemented as an alternative option alongside the default method in future updates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants