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

Trouble searching points @turf/within when latitudes invert #1210

Closed
stenvdb opened this issue Jan 2, 2018 · 2 comments
Closed

Trouble searching points @turf/within when latitudes invert #1210

stenvdb opened this issue Jan 2, 2018 · 2 comments
Labels

Comments

@stenvdb
Copy link

stenvdb commented Jan 2, 2018

I'm looking for points that fall within a rectangle on my map. But when I'm zooming out enough the search rectangle can overlap the border where longitude 179.86250559999996 for example inverts and becomes -179.78593190000004 (between Asia and North America, don't know what the name is for this "border"). Having trouble understanding what goes wrong here..

Hopefully the following screenshot explains it. It shows the rectangle I'm using to search within, the longitudes invert when dragging just over the border, and in the top log I'm getting the wrong results, the bottom log is displaying correct results.

screen shot 2018-01-02 at 11 07 15

Edit: I think a better way of explaining what I'm trying to do, is searching within a rectangle that is both in the eastern and western hemisphere. Is this possible?

@rowanwins
Copy link
Member

Hi @stenvdb

Welcome to the joys of working with the 180 Meridian, this blog post sets out some of the issues around it.

I think what I'd be tempted to do in your case is split your rectangle into two when it crosses the 180, and then run the operation twice, and then combine the results.

Im going to close this issue and it's a not a problem with turf as such, just a challenge with working with geographic data, but hopefully that helps get you on your way.

@stebogit
Copy link
Collaborator

stebogit commented Jan 4, 2018

@stenvdb I'm not sure I get your case without an actual example.
The 180 meridian issue, well illustrated in @tmcw's article, is actually related to points beyond the -180/+180 degree range; so for instance if you had points and rectangle going from 179 to 190 or from -179 to -190 degrees.
You are saying your points though switch from round -179 longitude to around +179 (which is inside the above mentioned range)? That seems weird to me. 🤔

Anyway, if @rowanwins' suggestion (useful when dealing with 180 crossing features) is not working for you, would you please add an actual case we could test?

Anyway, what version of Turf are you using? Please note that since v5.0 @turf/within has been replaced by @turf/boolean-within: while the first returned the points, of a collection, within a polygon, the latter returns just true or false whether the input point is inside a polygon or not.

Note: for the records, I just tested @turf/boolean-within and it seems to deal OK with points and polygons crossing the -180/+180 degree range. 👍

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

No branches or pull requests

4 participants