I would like to make a KDE out of a Shapefile. For this, I made a grid as rectangle, but R does not take it. Instead of taking it, it is using the centroid of the Points.
This is what I got in the console:
> library(sf)
> library(ggplot2)
> library(SpatialKDE)
> library(rnaturalearth)
> library(rnaturalearthdata)
> d_trees <- sf::st_read("digitised_trees.shp")
Reading layer `digitised_trees' from data source
`C:UsersreginDocumentsUNIGIS_SalzburgModul_8aufgabe_2digitised_trees.shp' using driver `ESRI Shapefile'
Simple feature collection with 4145 features and 2 fields
Geometry type: POINT
Dimension: XY
Bounding box: xmin: 672578 ymin: 5188850 xmax: 673748.4 ymax: 5189592
Projected CRS: WGS 84 / UTM zone 32N
> s_trees <- sf::st_read("simulated_trees.shp")
Reading layer `simulated_trees' from data source
`C:UsersreginDocumentsUNIGIS_SalzburgModul_8aufgabe_2simulated_trees.shp' using driver `ESRI Shapefile'
Simple feature collection with 3879 features and 2 fields
Geometry type: POINT
Dimension: XY
Bounding box: xmin: 672633.5 ymin: 5188850 xmax: 673749.2 ymax: 5189561
Projected CRS: WGS 84 / UTM zone 32N
> # Visualising data
> ggplot(data = d_trees) +
+ geom_sf() +
+ coord_sf(xlim = c(672578, 673748.4), ylim = c(5188850, 5189592)) +
+ ggtitle("Digitised Trees")
> ggplot(data = s_trees) +
+ geom_sf() +
+ coord_sf(xlim = c(672633.5, 673749.2), ylim = c(5188850, 5189561)) +
+ ggtitle("Simulated Trees")
> band_width <- 50000
> cell_size <- 20000
> # create grid for KDE
> grid_trees <- SpatialKDE::create_grid_rectangular(s_trees, cell_size = cell_size, side_offset = 0)
> # calculate KDE
> kde <- SpatialKDE::kde(s_trees, band_width = band_width, kernel = "quartic", grid = grid_trees)
Using centroids instead of provided `grid` geometries to calculate KDE estimates.
> # load world map
> world <- rnaturalearth::ne_countries(scale = 'medium', type = 'map_units', returnclass = 'sf')
> # visualising KDE
> ggplot(data = world) +
+ geom_sf() +
+ geom_sf(data = kde, aes(fill = kde_value), colour = NA) +
+ scale_fill_viridis_c(trans = "sqrt", alpha = .6, name = "KDE Value") +
+ coord_sf(xlim = c(672578, 673748.4), ylim = c(5188850, 5189592), expand = FALSE) +
+ theme(panel.grid.major = element_line(colour = "transparent"))
Fehler: Invalid index: field name 'x_start' not found
Zusätzlich: Warnmeldung:
In st_is_longlat(x) :
bounding box has potentially an invalid value range for longlat data
Can somebody help with the mistakes :
Using centroids instead of provided grid
geometries to calculate KDE estimates.
Fehler: Invalid index: field name ‘x_start’ not found
Zusätzlich: Warnmeldung:
In st_is_longlat(x) :
bounding box has potentially an invalid value range for longlat data
Thank you in advance!
I did try to change band_width and cell_size a lot, but this did not help at all.
Regggina is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1