sf icon indicating copy to clipboard operation
sf copied to clipboard

st_crop does not handle infinite values in clipping rectangle

Open dbaston opened this issue 3 years ago • 3 comments

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.

dbaston avatar Apr 17 '21 10:04 dbaston

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?

edzer avatar Apr 17 '21 11:04 edzer

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?

dbaston avatar Apr 18 '21 17:04 dbaston

Or is this feature creep?

edzer avatar May 31 '21 13:05 edzer