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

geoContains function doesn't seem to handle MultiPolygons #277

Closed
secondl1ght opened this issue Jan 19, 2023 · 9 comments
Closed

geoContains function doesn't seem to handle MultiPolygons #277

secondl1ght opened this issue Jan 19, 2023 · 9 comments

Comments

@secondl1ght
Copy link

I am using the geoContains function to determine if a point is inside a polygon. It works fine for simple polygons, but it does not seem to work for multi polys. Is this expected behavior? Thanks

@Fil
Copy link
Member

Fil commented Jan 19, 2023

It should work. Please make sure the polygon has the expected winding order. https://observablehq.com/@fil/rewind
I'm going to close the issue, but if you think this is a bug, please share the data which triggers it, and I'll reopen.

@Fil Fil closed this as completed Jan 19, 2023
@secondl1ght
Copy link
Author

Thanks for the quick response @Fil, I have tested to make sure the polygon is in the expected winding order by using this GeoJSON linter at https://geojsonlint.com/. It will notify you if you need to rewind the data and also the polygon is displaying correctly on my map and I am not seeing this behavior you described:

Alas when it happens, it’s painful: a shape that represents a tiny speck of land becomes inflated to represent the whole globe minus that tiny speck of land, the map fills with a uniform color, the local projection explodes.

Here is an example of one of the GeoJSON files that does not seem to be working correctly for me: https://gist.github.com/secondl1ght/a902b36dac2379fead3452af49a77973

The same code I wrote is working for other polygons so your theory does make sense that it would be certain GeoJSONs that I am using causing issues. I thought I had it narrowed down to a multipoly issue because those seemed to be the problem ones from when I looked. Maybe you can see if something is wrong with this Dublin file I shared?

Thanks for the help!

@Fil
Copy link
Member

Fil commented Jan 19, 2023

If you rewind it it works
https://observablehq.com/@recifs/dublin-geojson--support

@secondl1ght
Copy link
Author

Wow ok thanks! I guess I should have tested that the polygon drew correctly using D3. I am trying to find your package to use but I don't see it on NPM when I search for @fil/rewind, do you mind sharing a link to it please?

@Fil
Copy link
Member

Fil commented Jan 19, 2023

For now it's just a function in a notebook. https://observablehq.com/@fil/rewind

More discussion at #138

@secondl1ght
Copy link
Author

Thanks, I had a look and it's not super clear to me which part of the code I need to copy over into my app. There is a lot of code there, do I need all of it to complete the rewind that I require?

@Fil
Copy link
Member

Fil commented Jan 20, 2023

Consider fixing the geojson outside your application. If that's not possible, then you should copy 3 cells: geoRewindFeature and its dependencies geoRewindStream and geoProjectSimple. Also make sure you agree with the license (which I had not set yet, now ISC).

@secondl1ght
Copy link
Author

Thanks, is there also a way to check which polygons need to be rewound? I don't want to rewind ones that are already following the required spec.

@secondl1ght
Copy link
Author

I tried fixing the geojsons outside the application using https://geojsonlint.com/ to check for the 'right-hand rule'. But for some reason the problem GeoJSONs are not being picked up with errors on the lint website but they are still not working with D3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants