Skip to content

Commit ae1b23f

Browse files
authoredDec 9, 2024··
update xx_address data (#120)
1 parent 395a872 commit ae1b23f

File tree

2 files changed

+39
-16
lines changed

2 files changed

+39
-16
lines changed
 

‎inst/codec_data/xx_address/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
[![latest github release for xx_address dpkg](https://img.shields.io/github/v/release/geomarker-io/codec?sort=date&filter=xx_address-*&display_name=tag&label=%5B%E2%98%B0%5D&labelColor=%238CB4C3&color=%23396175)](https://github.com/geomarker-io/codec/releases?q=xx_address&expanded=false)
44

5-
Census tract-level measures of crime incidents (including property crimes, violent crimes, other crimes, and gunshots) in Hamilton County, Ohio. Tract-level measures are derived from the data packages stored in the [`xx_address` repository](https://github.com/geomarker-io/xx_address). Version 1.0.1 of the `xx_address` CoDEC data resource harmonizes [`crime_incidents-v0.1.1`](https://github.com/geomarker-io/xx_address/releases/tag/crime_incidents-v0.1.1) and [`shotspotter-v0.1.1`](https://github.com/geomarker-io/xx_address/releases/tag/shotspotter-v0.1.1). View the metadata for each of these data packages for more information about their sources.
5+
Census tract-level measures of crime incidents (including property crimes, violent crimes, other crimes, gunshots, and reported shootings) in Hamilton County, Ohio. Tract-level measures are derived from the data packages stored in the [`xx_address` repository](https://github.com/geomarker-io/xx_address), including [`crime_incidents-v0.1.2`](https://github.com/geomarker-io/xx_address/releases/tag/crime_incidents-v0.1.2), [`shotspotter-v0.1.2`](https://github.com/geomarker-io/xx_address/releases/tag/shotspotter-v0.1.2), and [`reported_shootings-v0.1.0`](https://github.com/geomarker-io/xx_address/releases/tag/reported_shootings-v0.1.0). View the metadata for each of these data packages for more information about their sources.
66

7-
Crime measures were geocoded to the street range, then aggregated to the tract level by summing the number of crimes for all streets that intersect the tract. If a street range overlaps more than one tract, the crimes are counted for the tract in which the majority of the street lies.
7+
Jittered (within the same block) latitude and longitude corresponding to the location of each reported crime are available from each data source. Crimes aggregated to the tract level by summing the number of crimes for each tract. For higher resolution crime data, see the [`xx_address` repository](https://github.com/geomarker-io/xx_address).

‎inst/codec_data/xx_address/xx_address.R

+37-14
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,23 @@ library(dplyr)
88
library(sf)
99
library(dpkg)
1010
library(geoarrow)
11+
library(addr)
1112
options(arrow.unsafe_metadata = TRUE)
1213

1314
crime_incidents <-
14-
dpkg::stow("gh://geomarker-io/xx_address/crime_incidents-v0.1.1") |>
15+
dpkg::stow("gh://geomarker-io/xx_address/crime_incidents-v0.1.2") |>
1516
arrow::read_parquet() |>
16-
mutate(geometry = sf::st_as_sfc(geometry)) |>
17-
st_as_sf(crs = 4326) |>
17+
select(date_time, lon_jittered, lat_jittered, category) |>
18+
filter(!is.na(lon_jittered), !is.na(lat_jittered)) |>
19+
st_as_sf(coords = c("lon_jittered", "lat_jittered"), crs = 4326) |>
1820
st_transform(st_crs(cincy::tract_tigris_2010)) |>
1921
st_join(cincy::tract_tigris_2010, largest = TRUE) |>
2022
st_drop_geometry() |>
2123
mutate(
2224
year = lubridate::year(date_time),
2325
month = lubridate::month(date_time)
24-
) |>
25-
select(-tlid, -address_x, -date_time) |>
26+
) |>
27+
select(-date_time) |>
2628
group_by(census_tract_id_2010, year, month, category) |>
2729
tally()|>
2830
tidyr::pivot_wider(
@@ -31,29 +33,48 @@ crime_incidents <-
3133
)
3234

3335
shotspotter <-
34-
dpkg::stow("gh://geomarker-io/xx_address/shotspotter-v0.1.1") |>
36+
dpkg::stow("gh://geomarker-io/xx_address/shotspotter-v0.1.2") |>
3537
arrow::read_parquet() |>
36-
mutate(geometry = sf::st_as_sfc(geometry)) |>
37-
st_as_sf(crs = 4326) |>
38+
select(date_time, lon_jittered, lat_jittered) |>
39+
filter(!is.na(lon_jittered), !is.na(lat_jittered)) |>
40+
st_as_sf(coords = c("lon_jittered", "lat_jittered"), crs = 4326) |>
3841
st_transform(st_crs(cincy::tract_tigris_2010)) |>
3942
st_join(cincy::tract_tigris_2010, largest = TRUE) |>
4043
st_drop_geometry() |>
4144
mutate(
4245
year = lubridate::year(date_time),
4346
month = lubridate::month(date_time)
4447
) |>
45-
select(-tlid, -address_x, -date_time) |>
48+
select(-date_time) |>
4649
group_by(census_tract_id_2010, year, month) |>
4750
tally() |>
4851
rename(gunshots = n)
4952

53+
reported_shootings <-
54+
dpkg::stow("gh://geomarker-io/xx_address/reported_shootings-v0.1.0") |>
55+
arrow::read_parquet() |>
56+
select(date, lon_jittered, lat_jittered) |>
57+
filter(!is.na(lon_jittered), !is.na(lat_jittered)) |>
58+
st_as_sf(coords = c("lon_jittered", "lat_jittered"), crs = 4326) |>
59+
st_transform(st_crs(cincy::tract_tigris_2010)) |>
60+
st_join(cincy::tract_tigris_2010, largest = TRUE) |>
61+
st_drop_geometry() |>
62+
mutate(
63+
year = lubridate::year(date),
64+
month = lubridate::month(date)
65+
) |>
66+
select(-date) |>
67+
group_by(census_tract_id_2010, year, month) |>
68+
tally() |>
69+
rename(reported_shootings = n)
70+
5071
all_tracts <-
5172
cincy::tract_tigris_2010 |>
5273
st_drop_geometry() |>
5374
as_tibble() |>
5475
mutate(date = list(seq.Date(
5576
from = as.Date("2011-01-01"),
56-
to = as.Date("2024-06-01"),
77+
to = as.Date("2024-11-01"),
5778
by = "month"
5879
))) |>
5980
tidyr::unnest(cols = c(date)) |>
@@ -64,18 +85,20 @@ all_tracts <-
6485
select(-date)
6586

6687
d_out <-
67-
left_join(all_tracts, crime_incidents, by = c("census_tract_id_2010", "year", "month")) |>
68-
left_join(shotspotter, by = c("census_tract_id_2010", "year", "month")) |>
88+
purrr::reduce(
89+
.x = list(all_tracts, crime_incidents, shotspotter, reported_shootings),
90+
.f = \(x, y) left_join(x, y, by = c("census_tract_id_2010", "year", "month"))
91+
) |>
6992
mutate(
70-
across(c(property, violent, other, gunshots),
93+
across(c(property:reported_shootings),
7194
\(x) ifelse(is.na(x), 0, x))) |>
7295
filter(!is.na(census_tract_id_2010))
7396

7497
out_dpkg <-
7598
d_out |>
7699
as_codec_dpkg(
77100
name = "xx_address",
78-
version = "0.1.0",
101+
version = "0.2.0",
79102
title = "Crime",
80103
homepage = "https://geomarker.io/codec",
81104
description = paste(readLines(fs::path_package("codec", "codec_data", "xx_address", "README.md")), collapse = "\n")

0 commit comments

Comments
 (0)
Please sign in to comment.