I am trying to geocode a dataset using the given latitude and longitude. I am then going to use these points and join polygon features to them. However, the projection I am using for the points is incorrect. How do I go about this in a better more efficient way?
I begin by uploading the files and setting the projection. The polygon file I have already has a projection so I used that projection for the points.
fema <- readOGR(paste(fema.path, "/2010_DFIRM.shp", sep=""))
fema@proj4string
#CRS arguments:
#+proj=lcc +lat_1=30.28333333333333 +lat_2=28.38333333333333
#+lat_0=27.83333333333333
#+lon_0=-99 +x_0=600000 +y_0=3999999.9998984 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0
#+units=us-ft +no_defs
data <- read.table(paste(inf.path, "/samp_HT_ANALYSIS", sep = ""), sep=",", fill=T)
coords <- data[,c(22:23)]
data.sp <- SpatialPointsDataFrame(data = data, coords = coords, proj4string =
CRS("+proj=lcc +lat_1=30.28333333333333 +lat_2=28.38333333333333 +lat_0=27.83333333333333 +lon_0=-99 +x_0=600000 +y_0=3999999.9998984 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=us-ft +no_defs"))
However, when I do the spatial join using the following code...
test <- over(data.sp, fema, returnList = T)
No attributes overlap with my points.
I went on to map the points in ArcMap with a base layer map and they aren't mapped at all on the plane. Can someone please explain how I can solve this? Also, general information on projections in R would be great. I thought I could just set the CRS equal of one file equal to the other but I may have to reproject all of my files.
UPDATE: I have rerun my code using suggestions below. However, they are still not plotting correctly. I checked some of the indivudal lat long coordinates in my data and they are within my study region. Here is the updated code.
# Data temp for map
data.use <- read.csv(paste(inf.path, "/Houston_sample_subset.csv", sep = ""))
coords <- as.data.frame(matrix(0,nrow=nrow(data.use),2))
coords[,1] <- data.use$PROP_LATITUDE
coords[,2] <- data.use$PROP_LONGITUDE
data.sp <- SpatialPointsDataFrame(data = data.use, coords = coords, proj4string =
CRS("+proj=longlat +datum=WGS84 +no_defs"))
# Study area
study.area <- readOGR("./FEMA_FLOOD/tl_2017_us_county/tl_2017_us_county.shp")
study.area@proj4string
study.area <- spTransform(study.area, crs(data.sp))
study.area <- subset(study.area, study.area$CBSAFP == 26420)
tiff("./PLOTS/test.tiff", width = 5, height = 5, units = "in", res = 800)
plot(study.area)
plot(data.sp, add =T)
dev.off()
Only the study region is plotted. I switched to plotting study region vs. fema maps because the fema maps take too long to generate.