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

Enhance shape to domain Conversion to Retain All Subpolygons #133

Open
Jinnkunn opened this issue Feb 19, 2025 · 1 comment
Open

Enhance shape to domain Conversion to Retain All Subpolygons #133

Jinnkunn opened this issue Feb 19, 2025 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@Jinnkunn
Copy link
Collaborator

Currently, when converting a shapefile containing multiple subpolygons into a domain, only one subpolygon is retained, instead of the full set of polygons. It would be beneficial to further encapsulate shape and domain to support complete multi-polygon information.

@Jinnkunn Jinnkunn added the enhancement New feature or request label Feb 19, 2025
@Jinnkunn Jinnkunn self-assigned this Feb 19, 2025
@Jinnkunn
Copy link
Collaborator Author

Jinnkunn commented Feb 19, 2025

This issue can be reproduced when exporting data for Alex's data request. The problem arises because an additional step is required: creating a convex_hull before instantiating a domain. For example:

gdf = gpd.read_file('./shape/')
gdf = gdf.explode(index_parts=True)  # index_parts=True to handle the index correctly
print(gdf.crs)

minx, miny, maxx, maxy =  gdf.iloc[0]['geometry'].bounds

domain_list = []
for idx in range(gdf.shape[0]):
    polygon_utm = gdf.iloc[idx]['geometry']
    domain_list.append(polygon_utm)
    minx, miny, maxx, maxy = min(minx, polygon_utm.bounds[0]), min(miny, polygon_utm.bounds[1]), max(maxx, polygon_utm.bounds[2]), max(maxy, polygon_utm.bounds[3])

new_geo_series = gpd.GeoSeries(shapely.ops.unary_union(domain_list))
new_geo_series = new_geo_series.convex_hull
mask = new_geo_series

domain = aisdb.gis.Domain(name=f'domain', zones=[{
        'name': f'domain',
        'geometry': mask.geometry.iloc[0]
    }  ])

Users unfamiliar with the Shapely library may find this process confusing. To improve usability, we could implement a function where users simply pass in the Shapely instance, and the function handles the creation of required geometry instances. Additionally, it could automatically convert the Coordinate Reference System (CRS) if the original CRS is not EPSG:4326.

This would eliminate the need for users to manually manipulate Shapely instances, making the workflow more intuitive and efficient.

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

1 participant