The objective is to create heatmap polygons from a points shapefile named "df_sf" for an attribute "V1" in the shapefile and then export these polygons as another shapefile in R.
What I have tried?
I have implemented the script here to generate density plots for the points using Lat and Long data not the variable "V1" value: Create density polygons from spatial points in R
tmaps cannot be exported as shapefile and the code below does not create polygons
p1 <- st_read("spatialdata.shp")
df_sf <- sf::st_as_sf(p1)
# Install and load required packages
install.packages(c("sf", "dplyr", "tmap", "sfheaders"))
library(sf)
library(dplyr)
library(tmap)
library(sfheaders)
# Create heatmap polygons
heatmap_polygons <- df_sf %>%
st_transform(st_crs(4326)) %>%
tm_shape() +
tm_dots(col = "V1", palette = "Reds", size = 0.1, alpha = 0.5) +
tm_layout()
tm_view(legend.position = c("right", "bottom"))
tmap_leaflet(heatmap_polygons)
st_write(heatmap_sf, "heatmap_polygons.shp")
Error: Error in UseMethod("st_write") :
no applicable method for 'st_write' applied to an object of class "tmap"