I have created a map in R using mapview. I am trying to convert it to a shapefile so I can view it on ArcGIS. I don't believe I should be using Raster for the data I am using. What other function should I use. If someone could also tell me how to draw a line between points in sf.siteBeg and sf.siteEnd that would be great! I have tried the following below:
- Convert to sf using the BEGIN/END Lat/Lon columns and create a Point geometry
- Using the points, create also a line geometry
df.site <- drop_na(df.join, c("DECDEG_BEGLAT","DECDEG_BEGLON","DECDEG_ENDLAT","DECDEG_ENDLON"))
# sf.site <- df.site %>%
# st_as_sf(coords = c("DECDEG_BEGLON", "DECDEG_BEGLAT","DECDEG_ENDLON","DECDEG_ENDLAT"))
#Error in points_rcpp(as.matrix(cc), dim) : dim(pts)[2] == nchar(gdim) is not TRUE
sf.siteBeg <- df.site |>
st_as_sf(coords = c("DECDEG_BEGLON", "DECDEG_BEGLAT"),
crs = 4326,
agr = "constant")
sf.siteEnd <- df.site |>
st_as_sf(coords = c("DECDEG_ENDLON","DECDEG_ENDLAT"),
crs = 4326,
agr = "constant")
mapview::mapview(sf.siteBeg, color = "green") + #plot the map
mapview(sf.siteEnd, color = "red") #+
- Save to shpfile (or geopackage)
library(shapefiles)
write.shp(shp = df.join, "scallop.shp")