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
st_crop and st_intersection do not cut decimal degrees assuming planar cartesian coordinates #1780
Comments
On the globe, there are no straight lines. Since sf 1.0-0, "lines" between points for ellipsoidal (geographic) coordinates are great circle distances, not straight lines in Plate Carree. You can set |
Thanks for the clarification. Flat Earth was indeed practical when trying to break things into regions but an old dog can learn new tricks. |
This is an interesting problem; I feel that there may be an issue with the plot part of the linked question. Consider this code: the red polygon is taken from the SO question, and when plotted looks square (i.e. Plate Caree). Of the two cities - Being and Hanoi, sorry for not hardcoding the coordinates - one appears inside and the other outside of the polygon. But when I run
|
library(sf)
library(dplyr)
library(spData)
red_polygon <- matrix(c(60, 0, 179.9, 0, 179.9, 30, 60, 30, 60, 0), byrow = TRUE, ncol = 2) %>%
list() %>%
st_polygon() %>%
st_sfc() %>%
st_set_crs(4326) %>%
st_segmentize(units::set_units(1, degree))
cities <- tidygeocoder::geo(c("Bejing, China", "Hanoi, Vietnam")) %>%
st_as_sf(coords = c("long", "lat"), crs = 4326)
plot(st_geometry(world), xlim = c(60,180), ylim = c(0, 60))
plot(red_polygon, add = T, border = "red")
plot(st_geometry(cities), add = T, col = "blue", pch = 4) |
Exactly, and the question kind of morphs from an unexpectedly looking intersection to "how does a polygon specified by four points on a sphere look on a map" (having the bottom section sat on the equator spoils half of the fun). |
I feel that Caption for the figure can be found from here. |
For plotting, orthographic projections seem to work better for smaller areas, but also not really for an area this size (although the red one includes the points): library(sf)
library(dplyr)
library(spData)
red_polygon <- matrix(c(60, 0, 179.9, 0, 179.9, 30, 60, 30, 60, 0), byrow = TRUE, ncol = 2) %>%
list() %>%
st_polygon() %>%
st_sfc() %>%
st_set_crs(4326)
cities <- tidygeocoder::geo(c("Bejing, China", "Hanoi, Vietnam")) %>%
st_as_sf(coords = c("long", "lat"), crs = 4326)
png("x.png")
crs = st_crs("+proj=ortho +lon_0=120 +lat_0=30")
plot(st_geometry(st_transform(world, crs)))
plot(st_transform(red_polygon, crs), add = T, border = "red")
plot(st_geometry(st_transform(cities, crs)), add = T, col = "blue", pch = 4)
plot(st_transform(st_segmentize(red_polygon, units::set_units(1, degree)), crs), add = T, border = 'green') |
Yet another reason to have a cesium port for R |
Should this issue be closed or left open? I have a few suggestions on how to address it:
|
Apologies for opening a new issue. Please close if already solved.
I thought this was a feature of
sf
and therefore made an SO question: https://stackoverflow.com/questions/69027136/how-to-crop-non-projected-epgs4326-polygons-along-straight-linesAfter studying the behavior more carefully, perhaps this is, at least, an unwanted feature?
Run using the CRAN version of
sf
1.0-2. and R version 4.1.1 (2021-08-10); Platform: x86_64-apple-darwin17.0 (64-bit); Running under: macOS Big Sur 10.16The text was updated successfully, but these errors were encountered: