Last active
July 19, 2021 22:50
-
-
Save bohdanszymanik/f23912fb6b162bd4803b4fe6354036d8 to your computer and use it in GitHub Desktop.
R sample to count locations in areas
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################################################################################## | |
# Import school locations | |
# Import some areas | |
# Join counts | |
# write out | |
library(readxl) | |
library(writexl) | |
library(sf) | |
HOME <- Sys.getenv("HOME") | |
setwd(paste(HOME, "\\Documents\\LocalProjects\\SchoolsInAreas", sep="")) | |
getwd() | |
# first get the column names | |
cNames <- read_excel(path="Schools.xlsx", sheet="Analysis of directory", skip=1, n_max=1) %>% names() | |
# then the raw data | |
schs <- read_excel(path="Schools.xlsx", sheet="Analysis of directory", skip=3, col_names=cNames[1:42]) | |
schsSF <- st_as_sf(schs, coords = c("Longitude", "Latitude"), crs=4326) | |
pAreas = st_read("layers\\area.gdb") | |
pAreas_wgs84 <- st_transform(pAreas, 4326) | |
schoolsInAreas <- st_join(schsSF, pAreas_wgs84, join=st_intersects) | |
write_xlsx(schoolsInAreas, "schoolsInAreas.xlsx") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment