ropensci / rnaturalearth

An R package to hold and facilitate interaction with natural earth map data :earth_africa:
http://ropensci.github.io/rnaturalearth/
Other
214 stars 24 forks source link

Country polygons with longitudinal coordinates outside (-180, 180) #108

Closed stephanie-stewart closed 2 weeks ago

stephanie-stewart commented 2 months ago

I am trying to use the country polygons as an input to another function that checks to make sure that all the coordinates are in the appropriate range. Using ne_countries() is currently getting flagged as being outside of that range. I'm not totally sure why this would be happening, but I am also struggling to identify an easy fix. The issue is illustrated in the following:

library(rnaturalearth) country_poly <- ne_countries() poly_xmax <- raster::extent(country_poly)@xmax poly_xmax > 180 # Evaluates to True poly_xmax > 180.00000000000001 # Evaluates to True poly_xmax > 180.0000000000001 # Evaluates to False

I don't know if this is something that would make sense/be possible to fix upstream to avoid any similar issues in the future.

PMassicotte commented 2 months ago

I do not have the same results as you do, probably related to how floats are represented on your computer (https://en.wikipedia.org/wiki/IEEE_754).

However, at that many level of decimals, you are around the nanometer precision:

decimal places degrees distance


9 0.000000001 111 μm 10 0.0000000001 11.1 μm 11 0.00000000001 1.11 μm 12 0.000000000001 111 nm 13 0.0000000000001 11.1 nm

https://gis.stackexchange.com/questions/8650/measuring-accuracy-of-latitude-and-longitude

stephanie-stewart commented 2 months ago

Thanks for the clarification. That makes sense, and the concern I have is not so much about the accuracy of the measurement, it is just that the function I am trying to use won't run so long as poly_xmax is greater than 180 by any amount. I am guessing the easiest way around this would be to use a very small inward buffer?

PMassicotte commented 2 months ago

Which function are you trying to use? Maybe you could try to round the coords to the xx decimals?

PMassicotte commented 2 weeks ago

@stephanie-stewart Please re-open the issue if you need.