Created
April 25, 2020 19:23
-
-
Save flare9x/685479db8884ad8c6e65e039100e3e88 to your computer and use it in GitHub Desktop.
Harris County Tax List - Use address to find longitude and latitude - plot on map
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
library(ggmap) | |
google_map_api_key = ## | |
data = read.csv("C:/Users/Andrew.Bannerman/Desktop/Real Estate/County Tax Lists/harris_county_tax_list/Real_acct_owner/filtered_list.csv", stringsAsFactors = F,header=T, sep=",") | |
real_acct_names = c("account","tax_year","mailto","mail_addr_one","mail_addr_two","mail_city","mail_state","mail_zip","mail_country","undeliverable","str_pfx","str_num","str_num_sfx","str_name","str_sfx","str_sfx_dir","str_unit","site_addr_one","site_addr_two","site_addr_three","state_class","school_dist","map_facet","key_map", | |
"neighborhood_code","neighborhood_group","market_area_one","market_area_one_dscr","market_area_two","market_area_two_dscr","econ_area","econ_bld_class","center_code","yr_impr","yr_annexed","splt_dt","dsc_cd","nxt_building","total_building_area","total_land_area","acerage","cap_account","shared_cap_code","land_value","improvement_value","extra_feartures_value","ag_value","assessed_value","total_appraised_value", | |
"total_market_value","prior_lnd_value","prior_impr_value","prior_x_features_value","prior_ag_value","prior_total_appraised_value","prior_total_market_value","new_construction_value","total_rcn_value","value_status","noticed","notice_date","protested","certified_date","last_inspected_date","last_inspected_by","new_owner_date","legal_dscr_one","legal_dscr_two","legal_dscr_three","legal_dscr_four","jur") | |
colnames(data) = real_acct_names | |
# Subset total units | |
data$str_unit = as.numeric(data$str_unit) | |
data = subset(data , str_unit <=4) | |
str(data) | |
address = data[,1] | |
for (i in 1:nrow(data)){ | |
address[i] = paste(paste(data[i,12],data[i,11],data[i,14],data[i,15],sep=" "),"TX",data[i,20], sep=",") | |
} | |
data$pasted_address = address | |
# register | |
register_google(key = "AIzaSyA2SrfifdBbjF45pw-qsRVhpKy2zMIG6cM", write = TRUE) | |
lon = paste0(data[1]) | |
length(lon) | |
lat = paste0(data[2]) | |
add = paste0(data[1]) | |
i=1 | |
for (i in 1:nrow(data)){ | |
temp = geocode(address[i], output = "latlona", source = "google") | |
#Sys.sleep() | |
lon[i] = temp[1] | |
lat[i] = temp[2] | |
add[i] = temp[3] | |
cat("this is iteration",i) | |
} | |
lon_out = do.call(rbind,lon) | |
lon_out = as.numeric(lon_out) | |
lat_out = do.call(rbind,lat) | |
lat_out = as.numeric(lat_out) | |
addy_out = do.call(rbind,add) | |
long_lat_addy_out = data.frame(lon_out,lat_out,addy_out) | |
nrow(long_lat_addy_out) | |
lat_upper_max_exclude = 29.808438 | |
lat_lower_min_exclude = 29.70783 | |
lon_west_exclude = -95.340112 | |
lon_east_exclude = -94.861129 | |
exclude_region = list() | |
i = 1 | |
for (i in 1:nrow(long_lat_addy_out)) { | |
if ((long_lat_addy_out[i,2] <= lat_upper_max_exclude) & (long_lat_addy_out[i,2] >= lat_lower_min_exclude) & (long_lat_addy_out[i,1] <= lon_east_exclude) & (long_lat_addy_out[i,1] >= lon_west_exclude)) { | |
exclude_region[[i]] = 0 | |
cat("within exclude zone") | |
} else { | |
exclude_region[[i]] = long_lat_addy_out[i,] | |
} | |
} | |
out = do.call(rbind,exclude_region) | |
nrow(data) | |
names = c("lon","lat","address") | |
colnames(out) = names | |
out = cbind(data,out) | |
nrow(out) | |
out = out[(out$lon != 0), ] | |
# find out of state owners | |
unique_list = unique(out$mail_state) | |
for (i in 1:nrow(out)) { | |
if (out$mail_state[i] != "TX") { | |
out$out_of_state_owners[i] = 1 | |
} else { | |
out$out_of_state_owners[i] = 0 | |
} | |
} | |
# Owner name / mailing address | |
out$mailing_address = paste(out$mailto, out$mail_addr_one, out$mail_city, out$mail_state,out$mail_zip, sep=",") | |
out$mailing_address_no_name = paste(out$mail_addr_one, out$mail_city, out$mail_state,out$mail_zip, sep=",") | |
write.csv(out,"C:/Users/Andrew.Bannerman/Desktop/Real Estate/County Tax Lists/harris_county_tax_list/Real_acct_owner/duplex_triplex_fourplex_exclude_EAST_buffalo_bayou.csv") | |
ggmap(get_googlemap(center = c(lon = -95.3698, lat = 29.7604), # houston | |
zoom = 10, scale = 2, | |
maptype ='terrain', | |
color = 'color')) + | |
geom_point(aes(x = lon, y = lat,colour="red"),data= out,size = 1)+ | |
theme(legend.position="bottom")+ | |
ggtitle("duplex, triplex and fourplex - Houston *exclude around buffalo bayou to EAST") | |
colnames(out) | |
# Loop to export letter | |
## Loop | |
library(knitr) | |
library(rmarkdown) | |
for (i in 1164:nrow(out)){ | |
cat("this is iteration",i) | |
rmarkdown::render(input = "C:/Users/Andrew.Bannerman/Desktop/Real Estate/County Tax Lists/harris_county_tax_list/harris_county_multi_family_letter.Rmd", | |
output_format = "word_document", | |
output_file = paste("letter_", i, ".doc", sep=''), | |
output_dir = "C:/Users/Andrew.Bannerman/Desktop/Real Estate/County Tax Lists/final_letters/") | |
} | |
#==================== | |
library(googleway) | |
google_map_api_key = "AIzaSyA2SrfifdBbjF45pw-qsRVhpKy2zMIG6cM" | |
key <- "AIzaSyA2SrfifdBbjF45pw-qsRVhpKy2zMIG6cM" | |
df <- data.frame(lat = -95.4066154, | |
lon = 29.7521873, | |
info = "st") | |
google_map(key = key, height = 600, search_box = T) %>% | |
add_markers(data = df, info_window = "info") | |
google_streetview(location = c(29.7475364, -95.40232), | |
size = c(400,400), | |
panorama_id = NULL, | |
output = "plot", | |
heading = 360, | |
fov = 120, | |
pitch = -10, | |
response_check = FALSE, | |
key = key) | |
nchar("0031750000008") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment