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

fix zero vs non-zero length logic; round dist to nearest #8

Merged
merged 2 commits into from
Jan 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/build-deploy-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -37,4 +38,4 @@ jobs:
- name: deploy pull request container
run: |
docker tag ${{ env.container }} ${{ env.versioned }}
docker push ${{ env.versioned }}
docker push ${{ env.versioned }}
3 changes: 2 additions & 1 deletion .github/workflows/build-deploy-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -39,4 +40,4 @@ jobs:
run: |
docker tag ${{ env.container }} ${{ env.versioned }}
docker push ${{ env.versioned }}
docker push ${{ env.container }}
docker push ${{ env.container }}
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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]"

Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
6 changes: 3 additions & 3 deletions entrypoint.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
Expand Down
7 changes: 0 additions & 7 deletions test/my_address_file_geocoded_roads_0.2.0_1000m_buffer.csv

This file was deleted.

7 changes: 0 additions & 7 deletions test/my_address_file_geocoded_roads_0.2.0_400m_buffer.csv

This file was deleted.

7 changes: 0 additions & 7 deletions test/my_address_file_geocoded_roads_0.2.1_1000m_buffer.csv

This file was deleted.

7 changes: 0 additions & 7 deletions test/my_address_file_geocoded_roads_0.2.1_400m_buffer.csv

This file was deleted.

7 changes: 7 additions & 0 deletions test/my_address_file_geocoded_roads_0.2.2_1000m_buffer.csv
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions test/my_address_file_geocoded_roads_0.2.2_400m_buffer.csv
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions test/my_address_file_geocoded_shorter.csv
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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