diff --git a/.github/workflows/build-deploy-pr.yaml b/.github/workflows/build-deploy-pr.yaml index 6add189..bb64a4d 100644 --- a/.github/workflows/build-deploy-pr.yaml +++ b/.github/workflows/build-deploy-pr.yaml @@ -28,6 +28,7 @@ jobs: - name: test run container run: | docker run --rm -v "${PWD}/test":/tmp ${{ env.container }} my_address_file_geocoded.csv + docker run --rm -v "${PWD}/test":/tmp ${{ env.container }} my_address_file_geocoded_shorter.csv 1000 - name: login to ghcr uses: docker/login-action@v1 with: @@ -37,4 +38,4 @@ jobs: - name: deploy pull request container run: | docker tag ${{ env.container }} ${{ env.versioned }} - docker push ${{ env.versioned }} \ No newline at end of file + docker push ${{ env.versioned }} diff --git a/.github/workflows/build-deploy-release.yaml b/.github/workflows/build-deploy-release.yaml index e325090..22309cf 100644 --- a/.github/workflows/build-deploy-release.yaml +++ b/.github/workflows/build-deploy-release.yaml @@ -29,6 +29,7 @@ jobs: - name: test container run: | docker run --rm -v "${PWD}/test":/tmp ${{ env.container }} my_address_file_geocoded.csv + docker run --rm -v "${PWD}/test":/tmp ${{ env.container }} my_address_file_geocoded_shorter.csv 1000 - name: login to ghcr uses: docker/login-action@v1 with: @@ -39,4 +40,4 @@ jobs: run: | docker tag ${{ env.container }} ${{ env.versioned }} docker push ${{ env.versioned }} - docker push ${{ env.container }} \ No newline at end of file + docker push ${{ env.container }} diff --git a/Dockerfile b/Dockerfile index a352d52..5a996ad 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,7 @@ FROM rocker/r-ver:4.0.5 # DeGAUSS container metadata ENV degauss_name="roads" -ENV degauss_version="0.2.1" +ENV degauss_version="0.2.2" ENV degauss_description="proximity and length of major roads" ENV degauss_argument="buffer radius in meters [default: 400]" diff --git a/Makefile b/Makefile index 3a57769..931734b 100644 --- a/Makefile +++ b/Makefile @@ -6,6 +6,7 @@ build: test: docker run --rm -v "${PWD}/test":/tmp roads my_address_file_geocoded.csv docker run --rm -v "${PWD}/test":/tmp roads my_address_file_geocoded.csv 1000 + docker run --rm -v "${PWD}/test":/tmp roads my_address_file_geocoded_shorter.csv 1000 shell: docker run --rm -it --entrypoint=/bin/bash -v "${PWD}/test":/tmp roads diff --git a/README.md b/README.md index 2d19bbf..bd6c142 100644 --- a/README.md +++ b/README.md @@ -8,10 +8,10 @@ If `my_address_file_geocoded.csv` is a file in the current working directory with coordinate columns named `lat` and `lon`, then the [DeGAUSS command](https://degauss.org/using_degauss.html#DeGAUSS_Commands): ```sh -docker run --rm -v $PWD:/tmp ghcr.io/degauss-org/roads:0.2.1 my_address_file_geocoded.csv +docker run --rm -v $PWD:/tmp ghcr.io/degauss-org/roads:0.2.2 my_address_file_geocoded.csv ``` -will produce `my_address_file_geocoded_roads_0.2.1_400m_buffer.csv` with added columns: +will produce `my_address_file_geocoded_roads_0.2.2_400m_buffer.csv` with added columns: - **`dist_to_1100`**: distance (meters) to the nearest S1100 road - **`dist_to_1200`**: distance (meters) to the nearest S1200 road @@ -23,10 +23,10 @@ will produce `my_address_file_geocoded_roads_0.2.1_400m_buffer.csv` with added c The default buffer radius for length of roads is 400 meters, but can be changed by supplying an optional argument to the degauss command. For example, ```sh -docker run --rm -v $PWD:/tmp ghcr.io/degauss-org/roads:0.2.1 my_address_file_geocoded.csv 800 +docker run --rm -v $PWD:/tmp ghcr.io/degauss-org/roads:0.2.2 my_address_file_geocoded.csv 800 ``` -will produce `my_address_file_geocoded_roads_0.2.1_800m_buffer.csv`, and `length_1100` and `length_1200` will be the lengths within an 800 m buffer. +will produce `my_address_file_geocoded_roads_0.2.2_800m_buffer.csv`, and `length_1100` and `length_1200` will be the lengths within an 800 m buffer. ## Geomarker Methods diff --git a/entrypoint.R b/entrypoint.R index 0a62587..4bcc7b2 100755 --- a/entrypoint.R +++ b/entrypoint.R @@ -43,13 +43,13 @@ message('finding distance to nearest S1100 road...') nearest_index_1100 <- st_nearest_feature(d_sf, roads1100) d_sf$dist_to_1100 <- purrr::map2_dbl(1:nrow(d_sf), nearest_index_1100, - ~sf::st_distance(d_sf[.x,], roads1100[.y,])) + ~round(sf::st_distance(d_sf[.x,], roads1100[.y,]), 1)) message('finding distance to nearest S1200 road...') nearest_index_1200 <- st_nearest_feature(d_sf, roads1200) d_sf$dist_to_1200 <- purrr::map2_dbl(1:nrow(d_sf), nearest_index_1200, - ~sf::st_distance(d_sf[.x,], roads1200[.y,])) + ~round(sf::st_distance(d_sf[.x,], roads1200[.y,]), 1)) message("creating buffers...") buffers <- st_buffer(d_sf, dist = as.numeric(opt$buffer_radius), nQuadSegs = 1000) @@ -66,7 +66,7 @@ get_line_length <- function(roads) { b_split <- split(b, b$road_length) # for buffers with any length, find that length - if(length(b_split) > 1) { + if(!is.null(b_split$`1`)) { roads_intersects <- purrr::map(b_split$`1`$road_index, ~roads[.x,]) roads_intersection <- purrr::map2(1:nrow(b_split$`1`), roads_intersects, diff --git a/test/my_address_file_geocoded_roads_0.2.0_1000m_buffer.csv b/test/my_address_file_geocoded_roads_0.2.0_1000m_buffer.csv deleted file mode 100644 index 06f4412..0000000 --- a/test/my_address_file_geocoded_roads_0.2.0_1000m_buffer.csv +++ /dev/null @@ -1,7 +0,0 @@ -id,lat,lon,start_date,end_date,dist_to_1100,dist_to_1200,length_1100,length_1200 -55001310120,NA,NA,6/11/20,6/18/20,NA,NA,NA,NA -55000100280,39.19674,-84.582601,3/1/17,3/8/17,12938,165416,0,1722 -55000100281,39.28765,-84.510173,1/30/12,2/6/12,15442,165383,0,2003 -55000100282,39.158521,-84.417572,12/1/20,12/8/20,7545,165425,0,0 -55000100283,39.158521,-84.417572,4/8/19,4/15/19,7545,165425,0,0 -55000100284,39.1639469,-84.5483588,4/8/19,4/15/19,12938,165456,3104,4032 diff --git a/test/my_address_file_geocoded_roads_0.2.0_400m_buffer.csv b/test/my_address_file_geocoded_roads_0.2.0_400m_buffer.csv deleted file mode 100644 index 093106e..0000000 --- a/test/my_address_file_geocoded_roads_0.2.0_400m_buffer.csv +++ /dev/null @@ -1,7 +0,0 @@ -id,lat,lon,start_date,end_date,dist_to_1100,dist_to_1200,length_1100,length_1200 -55001310120,NA,NA,6/11/20,6/18/20,NA,NA,NA,NA -55000100280,39.19674,-84.582601,3/1/17,3/8/17,12938,165416,0,0 -55000100281,39.28765,-84.510173,1/30/12,2/6/12,15442,165383,0,509 -55000100282,39.158521,-84.417572,12/1/20,12/8/20,7545,165425,0,0 -55000100283,39.158521,-84.417572,4/8/19,4/15/19,7545,165425,0,0 -55000100284,39.1639469,-84.5483588,4/8/19,4/15/19,12938,165456,0,1128 diff --git a/test/my_address_file_geocoded_roads_0.2.1_1000m_buffer.csv b/test/my_address_file_geocoded_roads_0.2.1_1000m_buffer.csv deleted file mode 100644 index 33bfe7a..0000000 --- a/test/my_address_file_geocoded_roads_0.2.1_1000m_buffer.csv +++ /dev/null @@ -1,7 +0,0 @@ -id,lat,lon,start_date,end_date,dist_to_1100,dist_to_1200,length_1100,length_1200 -55001310120,NA,NA,6/11/20,6/18/20,NA,NA,NA,NA -55000100280,39.19674,-84.582601,3/1/17,3/8/17,1982.8050582156613,427.10935508951405,0,1722 -55000100281,39.28765,-84.510173,1/30/12,2/6/12,1273.6600157735268,308.69451092255537,0,2003 -55000100282,39.158521,-84.417572,12/1/20,12/8/20,1059.8881801585765,1217.1614761035928,0,0 -55000100283,39.158521,-84.417572,4/8/19,4/15/19,1059.8881801585765,1217.1614761035928,0,0 -55000100284,39.1639469,-84.5483588,4/8/19,4/15/19,481.91589496349593,159.15864652403476,3104,4032 diff --git a/test/my_address_file_geocoded_roads_0.2.1_400m_buffer.csv b/test/my_address_file_geocoded_roads_0.2.1_400m_buffer.csv deleted file mode 100644 index f7f7ae3..0000000 --- a/test/my_address_file_geocoded_roads_0.2.1_400m_buffer.csv +++ /dev/null @@ -1,7 +0,0 @@ -id,lat,lon,start_date,end_date,dist_to_1100,dist_to_1200,length_1100,length_1200 -55001310120,NA,NA,6/11/20,6/18/20,NA,NA,NA,NA -55000100280,39.19674,-84.582601,3/1/17,3/8/17,1982.8050582156613,427.10935508951405,0,0 -55000100281,39.28765,-84.510173,1/30/12,2/6/12,1273.6600157735268,308.69451092255537,0,509 -55000100282,39.158521,-84.417572,12/1/20,12/8/20,1059.8881801585765,1217.1614761035928,0,0 -55000100283,39.158521,-84.417572,4/8/19,4/15/19,1059.8881801585765,1217.1614761035928,0,0 -55000100284,39.1639469,-84.5483588,4/8/19,4/15/19,481.91589496349593,159.15864652403476,0,1128 diff --git a/test/my_address_file_geocoded_roads_0.2.2_1000m_buffer.csv b/test/my_address_file_geocoded_roads_0.2.2_1000m_buffer.csv new file mode 100644 index 0000000..3dac0c8 --- /dev/null +++ b/test/my_address_file_geocoded_roads_0.2.2_1000m_buffer.csv @@ -0,0 +1,7 @@ +id,lat,lon,start_date,end_date,dist_to_1100,dist_to_1200,length_1100,length_1200 +55001310120,NA,NA,6/11/20,6/18/20,NA,NA,NA,NA +55000100280,39.19674,-84.582601,3/1/17,3/8/17,1982.8,427.1,0,1722 +55000100281,39.28765,-84.510173,1/30/12,2/6/12,1273.7,308.7,0,2003 +55000100282,39.158521,-84.417572,12/1/20,12/8/20,1059.9,1217.2,0,0 +55000100283,39.158521,-84.417572,4/8/19,4/15/19,1059.9,1217.2,0,0 +55000100284,39.1639469,-84.5483588,4/8/19,4/15/19,481.9,159.2,3104,4032 diff --git a/test/my_address_file_geocoded_roads_0.2.2_400m_buffer.csv b/test/my_address_file_geocoded_roads_0.2.2_400m_buffer.csv new file mode 100644 index 0000000..5df1d85 --- /dev/null +++ b/test/my_address_file_geocoded_roads_0.2.2_400m_buffer.csv @@ -0,0 +1,7 @@ +id,lat,lon,start_date,end_date,dist_to_1100,dist_to_1200,length_1100,length_1200 +55001310120,NA,NA,6/11/20,6/18/20,NA,NA,NA,NA +55000100280,39.19674,-84.582601,3/1/17,3/8/17,1982.8,427.1,0,0 +55000100281,39.28765,-84.510173,1/30/12,2/6/12,1273.7,308.7,0,509 +55000100282,39.158521,-84.417572,12/1/20,12/8/20,1059.9,1217.2,0,0 +55000100283,39.158521,-84.417572,4/8/19,4/15/19,1059.9,1217.2,0,0 +55000100284,39.1639469,-84.5483588,4/8/19,4/15/19,481.9,159.2,0,1128 diff --git a/test/my_address_file_geocoded_shorter.csv b/test/my_address_file_geocoded_shorter.csv new file mode 100644 index 0000000..57a8aff --- /dev/null +++ b/test/my_address_file_geocoded_shorter.csv @@ -0,0 +1,4 @@ +id,lat,lon,start_date,end_date +55001310120,NA,NA,6/11/20,6/18/20 +55000100280,39.19674,-84.582601,3/1/17,3/8/17 +55000100281,39.28765,-84.510173,1/30/12,2/6/12 \ No newline at end of file diff --git a/test/my_address_file_geocoded_shorter_roads_0.2.2_1000m_buffer.csv b/test/my_address_file_geocoded_shorter_roads_0.2.2_1000m_buffer.csv new file mode 100644 index 0000000..78d04aa --- /dev/null +++ b/test/my_address_file_geocoded_shorter_roads_0.2.2_1000m_buffer.csv @@ -0,0 +1,4 @@ +id,lat,lon,start_date,end_date,dist_to_1100,dist_to_1200,length_1100,length_1200 +55001310120,NA,NA,6/11/20,6/18/20,NA,NA,NA,NA +55000100280,39.19674,-84.582601,3/1/17,3/8/17,1982.8,427.1,0,1722 +55000100281,39.28765,-84.510173,1/30/12,2/6/12,1273.7,308.7,0,2003