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

Add geos_inner_join_keys() #76

Merged
merged 4 commits into from
Aug 24, 2022
Merged

Add geos_inner_join_keys() #76

merged 4 commits into from
Aug 24, 2022

Conversation

paleolimbot
Copy link
Owner

@paleolimbot paleolimbot commented Aug 22, 2022

library(geos)
library(sf)
#> Linking to GEOS 3.11.0, GDAL 3.5.1, PROJ 9.0.1; sf_use_s2() is TRUE
library(readr)

tempdir <- tempfile()
dir.create(tempdir)

if (!file.exists("~/Desktop/phl_parking.csv")) {
  curl::curl_download(
    "https://phl.carto.com/api/v2/sql?filename=parking_violations&format=csv&skipfields=cartodb_id,the_geom,the_geom_webmercator&q=SELECT%20*%20FROM%20parking_violations%20WHERE%20issue_datetime%20%3E=%20%272012-01-01%27%20AND%20issue_datetime%20%3C%20%272017-12-31%27",
    "~/Desktop/phl_parking.csv"
  )
}

curl::curl_download(
  "https://github.com/azavea/geo-data/raw/master/Neighborhoods_Philadelphia/Neighborhoods_Philadelphia.zip",
  file.path(tempdir, "Neighborhoods_Philadelphia.zip")
)

unzip(file.path(tempdir, "Neighborhoods_Philadelphia.zip"), exdir = tempdir)

violations <-  read_csv(
  "~/Desktop/phl_parking.csv",
  col_types = cols(
    anon_ticket_number = col_double(),
    lon = col_double(),
    lat = col_double(),
    .default = col_skip()
  )
) |> 
  dplyr::filter(is.finite(lon), is.finite(lat)) |> 
  st_as_sf(coords = c("lon", "lat"), crs = "OGC:CRS84")

neighbourhoods <- read_sf(file.path(tempdir, "Neighborhoods_Philadelphia.shp")) %>% 
  dplyr::select(NAME) %>% 
  st_transform("OGC:CRS84")

system.time(keys <- geos::geos_inner_join_keys(neighbourhoods$geometry, violations$geometry))
#>    user  system elapsed 
#>  21.251   0.901  22.239

system.time({
  n_geos <- as_geos_geometry(neighbourhoods$geometry)
  viol_geos <- as_geos_geometry(violations$geometry)
})
#>    user  system elapsed 
#>   3.631   0.207   3.897

system.time(keys <- geos::geos_inner_join_keys(n_geos, viol_geos))
#>    user  system elapsed 
#>   9.293   0.524   9.880

Created on 2022-08-21 by the reprex package (v2.0.1)

@codecov-commenter
Copy link

codecov-commenter commented Aug 22, 2022

Codecov Report

Merging #76 (e3c1eec) into master (b48bc56) will increase coverage by 0.04%.
The diff coverage is 98.27%.

@@            Coverage Diff             @@
##           master      #76      +/-   ##
==========================================
+ Coverage   95.69%   95.73%   +0.04%     
==========================================
  Files          34       35       +1     
  Lines        3111     3168      +57     
==========================================
+ Hits         2977     3033      +56     
- Misses        134      135       +1     
Impacted Files Coverage Δ
R/geos-join.R 98.24% <98.24%> (ø)
R/geos-basic-strtree.R 97.87% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@paleolimbot paleolimbot merged commit 3203a60 into master Aug 24, 2022
@paleolimbot paleolimbot deleted the joins branch August 25, 2022 00:49
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