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

Merge least feature count polygons with neighbouring polygons #58

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Sujanadh
Copy link
Contributor

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:

{
      "type": "Feature",
      "geometry": {
        "type": "Polygon",
        "coordinates": [
          [
            [
              85.329736,
              27.798211563
            ],
            [
              85.330273109,
              27.798061799
            ],
            [
              85.331683065,
              27.797746463
            ],
            [
              85.331811757,
              27.797866055
            ],
            [
              85.33221594,
              27.79781169
            ],
            [
              85.332281149,
              27.797402154
            ],
            .
            .
            .
            [
              85.335539882,
              27.794265868
            ]
          ]
        ]
      },
      "properties": {
        "building_count": 130
      }
    }

Before:

num_buildings = 100
image

After:

num_buildings = 100
image

Issue

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

Successfully merging this pull request may close these issues.

1 participant