Skip to content
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

read_watersurfaces(): make fix_geom handling a bit more efficient #185

Merged
merged 2 commits into from
Aug 8, 2024

Conversation

florisvdh
Copy link
Member

@cecileherr pointed out in #184 that applying the optional count of invalid polygons in read_habitatmap(fix_geom = TRUE) is very slow. It was copied from read_watersurfaces(), where timing was still acceptable.

It seems that I calculated the polygon validity twice. Reducing this to a single calculation already gives some speedup, even though this will not be acceptable yet in case of read_habitatmap().

> # using n2khab 0.10.1
>
> system.time(n2khab::read_watersurfaces(fix_geom = TRUE) |> invisible())
Fixed 9 invalid or corrupt geometries.
   user  system elapsed 
 21.675   1.443   7.712 
> system.time(n2khab::read_watersurfaces(fix_geom = TRUE) |> invisible())
Fixed 9 invalid or corrupt geometries.
   user  system elapsed 
  6.377   0.031   6.408 
>
> # using n2khab@876df05
>
> devtools::load_all(".")
ℹ Loading n2khab
Attaching n2khab 0.10.1.9000.
Will use sf 1.0-16.
Will use terra 1.7-78.
> system.time(read_watersurfaces(fix_geom = TRUE) |> invisible())
Fixed 9 invalid or corrupt geometries.
   user  system elapsed 
  5.454   0.034   5.488 
> system.time(read_watersurfaces(fix_geom = TRUE) |> invisible())
Fixed 9 invalid or corrupt geometries.
   user  system elapsed 
  5.147   0.010   5.157 
> system.time(read_watersurfaces(fix_geom = TRUE) |> invisible())
Fixed 9 invalid or corrupt geometries.
   user  system elapsed 
  5.143   0.051   5.193 
> system.time(read_watersurfaces() |> invisible())
   user  system elapsed 
  1.188   0.012   1.203 

Restarting R session...

> # using n2khab 0.10.1
>
> system.time(n2khab::read_watersurfaces(fix_geom = TRUE) |> invisible())
Fixed 9 invalid or corrupt geometries.
   user  system elapsed 
  8.179   0.135   8.298 

@florisvdh florisvdh merged commit 1f843ea into dev_nextrelease Aug 8, 2024
3 checks passed
@florisvdh florisvdh deleted the ws_fix_geom_speedup branch August 8, 2024 13:06
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.

1 participant