Initial commit

This commit is contained in:
2025-03-15 05:56:50 -04:00
commit 623754358b
29 changed files with 1070 additions and 0 deletions

22
R/geocode.R Normal file
View File

@@ -0,0 +1,22 @@
library(dplyr, warn.conflicts = FALSE)
library(tidygeocoder)
# create a dataframe with addresses
some_addresses <- tibble::tribble(
~name, ~addr,
"White House", "1600 Pennsylvania Ave NW, Washington, DC",
"Transamerica Pyramid", "600 Montgomery St, San Francisco, CA 94111",
"Willis Tower", "233 S Wacker Dr, Chicago, IL 60606",
"Rob", "863 Tartan Dr, Venice, FL 34293"
)
# geocode the addresses
lat_longs <- some_addresses %>%
geocode(
addr,
method = 'google',
lat = latitude ,
long = longitude
)
#
#

145
R/main.R Normal file
View File

@@ -0,0 +1,145 @@
#libraries ----
library("leaflet")
library("readxl")
library("janitor")
library("dplyr")
library("tidyr")
library("tidygeotag")
library("sf")
# choose columns ---
cols <- c(
"account_number",
"owner_1",
"owner_2",
"subdivision",
"situs_address_property_address",
"situs_city",
"situs_state",
"situs_zip_code",
"homestead_exemption_yes_or_no"
)
# filter to St. Andrews (388) ----
df <-
readxl::read_xlsx(
path = "./data-raw/property/SCPA Public.xlsx",
n_max = Inf,
.name_repair = ~janitor::make_clean_names(.x)
) %>%
filter(
subdivision %in% c("8120", "8113", "8171", "8195", "8221",
"8163", "8240", "8159", "8149", "8110", "8254", "8215", "8143")
) %>%
#select(cols) %>%
rename(
situs_address = situs_address_property_address,
homestead = homestead_exemption_yes_or_no
) %>%
filter(!grepl("^0", situs_address)) %>%
drop_na(situs_address)
# create location ----
df1 <-
df %>%
separate(
situs_address,
into = c("street_no", "street", "suffix", "unit", "bldg", "no"),
sep = "\\s+"
) %>%
mutate(unit = ifelse(is.na(bldg), NA, unit)) %>%
mutate(location = paste(
street_no, street, suffix, ",",
situs_city, situs_state, situs_zip_code,
sep = " ")) %>%
mutate(location = gsub(" ,", ",", location)) %>%
mutate(label = paste(street_no, street, suffix, sep = " ")) %>%
arrange(account_number)
# geotag unique location (205) ----
if(!file.exists("./data-raw/geotagged_street_addresses.rds")) {
addresses <- df1 %>% select(location) %>% distinct()
lat_longs <- addresses %>%
geocode(
location,
method = 'google',
lat = lat,
long = lng
)
saveRDS(lat_longs, "./data-raw/geotagged_street_addresses.rds")
} else {
lat_longs <- readRDS("./data-raw/geotagged_street_addresses.rds")
}
# append coords ----
df2 <-
df1 %>%
left_join(lat_longs[, !names(lat_longs) %in% "account_number"],
by = c("location" = "location"),
relationship = "many-to-many") %>%
distinct() %>%
st_as_sf(coords = c("lng", "lat"), crs = 4326)
# write as esri shp file for qgis ----
sf::st_write(
df2,
"./data-raw/addresses/owners_raw.gpkg",
driver = "GPKG",
delete_dsn = TRUE
)
#####
# adjust points in QGIS
####
# after QGIS, shp --> rds ----
owners_moved <- sf::st_read(
"./data-raw/addresses/owners_moved.gpkg",
layer = "owners_raw")
owners_moved %>%
leaflet() %>%
addTiles() %>%
addMarkers()
saveRDS(owners_moved, "./data/owners.rds")
# add plats ----
plats <- sf::st_read("./data/plats/plats.shp")
owners <- readRDS("./data/owners.rds")
# display ----
library("leafpop")
m <-
leaflet() %>%
addTiles() %>%
addPolygons(
data = plats,
color = "red",
weight = 2,
opacity = 0.5,
fillOpacity = 0.2,
label = ~sub_name,
group = "Subdivisions"
) %>%
addMarkers(
data = owners,
lat = ~lat,
lng = ~lng,
popup = popupTable(
owners,
zcol = c(
"account_number",
"location",
"owner_1",
"owner_2"
)
),
group = "Owners"
) %>%
addLayersControl(
overlayGroups = c("Subdivisions", "Owners"), # Specify overlay groups
options = layersControlOptions(collapsed = FALSE) # Control options
)
m
# add condo layer