Merge least feature count polygons with neighbouring polygons #58
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description:
This PR introduces a feature to merge small polygons with their neighboring larger polygons based on shared boundary lengths. The goal is to ensure that polygons below a certain area threshold or containing fewer buildings are merged with their best-suited neighbor to avoid fragmentation.
Updates:
A temporary table
leastfeaturepolygons
is created to store polygons smaller than the minimum area obtained from standard deviation or those with fewer than a dynamically calculated number of buildings which is half the number provided my user.A loop is implemented to iterate over all small polygons, finding the neighboring polygon that shares the longest boundary using
ST_Length(ST_Intersection())
.After identifying the best neighbor, the small polygon is merged into the larger one using
ST_Union()
.Controlled Deletion:
Small polygons are deleted from the
taskpolygons
table only after a successful merge, ensuring no polygon is prematurely removed and repeated or overlapped.The neighboring polygon is selected based on the maximum shared boundary, ensuring accurate merges.
Added building count in the properties of geojson
Response:
Before:
num_buildings = 100
After:
num_buildings = 100
Issue
Further splitting if the task polygons contains more features (buildings) than the threshold is yet to be done.