Spatial join longitude and latitude points to multipolygon shapefile
I have a spatial data frame of the longitude and latitude of wildfire origins that I am trying to perform a spatial join on to a US Census TIGER/Line shapefile (places) to see if/where there is spatial intersection of fire origins and places.
I am converting the longitude and latitude to coordinate geometry using
st_as_sf then attempting to
st_join this to the places file, but am encountering an error as the CRS are different. The shapefile is in NAD83 projection, so I am attempting to match that.
library(tidyverse) library(sf) > head(fires) # Longitude Latitude FireName #1 -106.46667 34.66000 TRIGO #2 -81.92972 35.87111 SUNRISE #3 -103.76944 37.52694 BRIDGER #4 -122.97556 39.37500 BACK #5 -121.15611 39.62778 FREY #6 -106.38306 34.77056 BIG SPRING #convert df to sf fires_sf <- st_as_sf(fires, coords = c("Longitude", "Latitude"), crs = 4269, agr = "constant") head(fires_sf$geometry) #Geometry set for 6 features #Geometry type: POINT #Dimension: XY #Bounding box: xmin: -122.9756 ymin: 34.66 xmax: -81.92972 ymax: 39.62778 #Geodetic CRS: NAD83 #POINT (-106.4667 34.66) #POINT (-81.92972 35.87111) #POINT (-103.7694 37.52694) #POINT (-122.9756 39.375) #POINT (-121.1561 39.62778) head(places$geometry) #Geometry set for 6 features #Geometry type: MULTIPOLYGON #Dimension: XY #Bounding box: xmin: -1746916 ymin: -395761.6 xmax: -1655669 ymax: -212934.8 #Projected CRS: USA_Contiguous_Albers_Equal_Area_Conic #First 5 geometries: #MULTIPOLYGON (((-1657066 -233757.7, -1657192 -2... #MULTIPOLYGON (((-1668181 -273428.5, -1669420 -2... #MULTIPOLYGON (((-1735046 -389578.2, -1735146 -3... #MULTIPOLYGON (((-1732841 -376703.9, -1732642 -3... #MULTIPOLYGON (((-1693749 -377716, -1693286 -377.. joined <- st_join(places, fires_sf)
Error in st_geos_binop("intersects", x, y, sparse = sparse, prepared = prepared, : st_crs(x) == st_crs(y) is not TRUE
To work around this, I have tried
st_transform to change the projection to longitude and latitude coordinates, as the places shapefile may be using UTM coordinates, and the datum to NAD83 in both spatial frames. I am getting an error for this as well.
#transform CRS projections places_transform <- st_transform(places, "+proj=longlat +datum=NAD83") fires_sf_transform <- st_transform(fires_sf, "+proj=longlat +datum=NAD83") joined_new <- st_join(places_transform, fires_sf_transform)
Error in s2_geography_from_wkb(x, oriented = oriented, check = check) : Evaluation error: Found 1045 features with invalid spherical geometry.  Loop 0 is not valid: Edge 280 has duplicate vertex with edge 306
I have attempted to convert the geometry from longitude and latitude coordinates in the fires dataset to UTM coordinates to match the places shapefile, but this was also unsuccessful.
Any advice on how I can properly perform the spatial join of these points and multipolygons would be greatly appreciated.