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

Merged
merged 2 commits into from
Oct 30, 2024

Conversation

Sujanadh
Copy link
Contributor

@Sujanadh Sujanadh commented Oct 22, 2024

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

Copy link
Member

@spwoodcock spwoodcock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Going to approve this, as we can make the param configurable by the user in a future modular approach 👍

'properties', JSONB_BUILD_OBJECT()
'geometry', ST_ASGEOJSON(t.geom)::jsonb,
'properties', JSONB_BUILD_OBJECT(
'building_count', (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💫

small_polygon RECORD; -- set small_polygon and nearest_neighbor as record
nearest_neighbor RECORD; -- in order to use them in the loop
BEGIN
min_buildings := num_buildings * 0.5;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tried modifying this number a bit to see the result?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0.5 is ok, but as a user I would imagine if they requested 15 buildings per task, but only got 8 they might be a bit disappointed 😅

Does 0.7 change things by a lot?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This discrepancy will obviously scale linearly: say they request 50 buildings average and get 25 minimum.

But personally, I think if users are requesting 50 geoms per area there is something wrong with their methodology! I would imagine 10 buildings per task is more realistic for an individual or team 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh crap i didn't see these comments , yeah i had tried with params such as 0.7 but got so big tasks in result. Yeah we can change this in future based on the practical use case scenarios

@spwoodcock spwoodcock merged commit b76e10c into main Oct 30, 2024
3 of 5 checks passed
@spwoodcock spwoodcock deleted the refactor/split-algorithm branch October 30, 2024 09:01
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.

Filter out split geometries with too few buildings
2 participants