Skip to content

Faster cc_sea(): switched terra:extract to terra:relate#108

Merged
azizka merged 3 commits intoropensci:masterfrom
plantarum:tws_cc_sea
May 27, 2025
Merged

Faster cc_sea(): switched terra:extract to terra:relate#108
azizka merged 3 commits intoropensci:masterfrom
plantarum:tws_cc_sea

Conversation

@plantarum
Copy link
Copy Markdown
Contributor

@plantarum plantarum commented May 26, 2025

In my tests this decreased the processing time for 10K records from 94 seconds to < 1 second. I didn't look too carefully at the logic in that function, after determining that it was the call to terra:extract that was taking up all the time, and terra:relate could be made to accomplish the same thing in a tiny fraction of the time.

I ran your tests and everything came back fine (except for an unrelated issue with cc_outl and Taiwan?).

data(buffland)
buffland <- unwrap(buffland)
crs(buffland) <- '+proj=longlat +datum=WGS84 +no_defs'

x <- data.frame(decimalLongitude = runif(10000, -180, 180), 
                decimalLatitude = runif(10000, -90, 90))

cleaned <- cc_sea(x, ref = buffland)

plantarum added 3 commits May 26, 2025 12:25
In my tests this decreased the processing time for 10K records from 94
seconds to < 1 second.
Errors in tests due to naturalearth using CN-TW for Taiwan, GBIF using TW.
Also -99 wasn't handled as a missing data value.
`relate` isn't availbe in the package Namespace, needs to be located in
`terra::`.
@azizka azizka merged commit 9195fb6 into ropensci:master May 27, 2025
5 checks passed
@azizka
Copy link
Copy Markdown
Collaborator

azizka commented May 27, 2025

Looks good. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants