sf
sf copied to clipboard
st_crop does not handle infinite values in clipping rectangle
For example, when attempting to pull out all areas east of a certain longitude:
> st_crop(nc, xmin = -79, xmax = Inf, ymin = -Inf, ymax = Inf)
although coordinates are longitude/latitude, st_intersection assumes that they are planar
Simple feature collection with 0 features and 14 fields
Bounding box: xmin: NA ymin: NA xmax: NA ymax: NA
Geodetic CRS: NAD27
[1] AREA PERIMETER CNTY_ CNTY_ID NAME FIPS FIPSNO CRESS_ID BIR74 SID74
[11] NWBIR74 BIR79 SID79 NWBIR79 geometry
<0 rows> (or 0-length row.names)
an empty sf
is returned.
Nice one! I think that for ellipsoidal coordinates, as in your example, +/- Inf
values are meaningless, but for projected coordinates, sf
creates the invalid polygon around the crop bounding box with the Inf values, passes it down to GEOS to intersect ... so a question is - if wanted - where should this be fixed?
That's a good question. It seems like GEOSClipByRect
(which I don't think sf
is using) ought to handle infinite coordinates even if the general overlay does not. I can look into it.
But per your comment on Inf
values being meaningless - would a better solution in this case be to call st_crop(nc, xmin = -79)
and have sf
do the right thing for the coordinate system in question?
Or is this feature creep?