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

[Bug]: Unable to add polygons with holes #425

Open
jashanbhullar opened this issue Jan 19, 2025 · 3 comments
Open

[Bug]: Unable to add polygons with holes #425

jashanbhullar opened this issue Jan 19, 2025 · 3 comments
Labels
bug Something isn't working

Comments

@jashanbhullar
Copy link

Describe the bug
Not able to add feature from using .addFearture function. The error is Not a valid polygon even though it passed all the checks (I manually checked the polygons with the repo code). Since it doesn't why it's invalid, I am not able to fix it also.

Terra Draw npm version
1.0.0

To Reproduce
https://stackblitz.com/edit/vitejs-vite-si8orurb?file=src%2FApp.tsx

You can copy the polygons from files and paste them on geojson.io and they work;

Expected behavior
Either add the polygon or give a better error explanation so I can fix the shape.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: macOS 14.6
  • Browser : Firefox (althoug same error appeared on chrome and safar)
  • Version: 134.0.1

Additional context
Add any other context about the problem here.

@jashanbhullar jashanbhullar added the bug Something isn't working label Jan 19, 2025
@jashanbhullar jashanbhullar changed the title [Bug] [Bug]: Unable to add polygons. Shows invalid but not sure what is wrong with the polygons Jan 19, 2025
@JamesLMilner
Copy link
Owner

Hey @jashanbhullar - thanks for the issue 👍🏻 I can see the issue here, and it is due to lacking documentation/unclear failure message:

  1. Geometries can't be Multi types - they must be of the type Point, LineString or Polygon. You can break up MultiPolygons fairly easily in plain JavaScript by iterating through each Polygon in the MultiPolygon coordinates array and splitting it out into it's own Feature object.
  2. You'll need a valid mode property in the properties for each Feature object. This is most likely polygon in your scenario.

As a first step to making this clearer I'll update the docs but I think it probably needs an explicit failure case when Multi features as passed. Sorry for the inconvenience and hope this helps!

@jashanbhullar
Copy link
Author

hello @JamesLMilner , I was flattening them using turf.flatten anyway but that seems to be the issue. The issue seems to be polygon with interior rings which represents the holes in a polygon. I updated the example with Polygon with holes and it's throwing error as well.

Not sure how one can handle this error but this is it. Maybe the first step is to add a error message that it can't handle polygon with holes and then work towards a solution. 🤔 🤔 🤔

@jashanbhullar jashanbhullar changed the title [Bug]: Unable to add polygons. Shows invalid but not sure what is wrong with the polygons [Bug]: Unable to add polygons with holes Jan 19, 2025
@jashanbhullar
Copy link
Author

Maybe it can now be considered a feature request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants