【发布时间】:2021-10-21 08:30:25
【问题描述】:
我正在尝试使用密度交互式地图绘制崩溃数据,但是栅格不添加投影。
我的数据框看起来像:
| TA_name | crashes |
|---|---|
| chch | 13223 |
| grey | 2322 |
| buller | 123 |
这是我迄今为止尝试过的方法:
library(devtools)
install_github("mtennekes/oldtmaptools")
library(oldtmaptools)
# creates a smooth map
# bandwidth is a size of the kernel, default to 1/50th of the shortest side
crash_density <- smooth_map(crashes_TA, bandwidth = 0.5, smooth.raster = T)
tmap_mode("view")
library(viridis) # colour schemes
library(rasterVis) # raster analysis and plotting
plot3D(crash_density$raster, zfac = 0.5, col=viridis_pal(option = "B",direction = -1, alpha = 0.5))
library(spatstat)
# data to ppp class
crashes_pp <- crashes_TA %>% as.ppp()
# just filtering Christchurch City TA
chch <- TA %>%
filter(TA_name == "chch")
# defining shape of observation window (owin)
# setting it to Christchurch
Window(crashes_pp) <- as.owin(chch)
crashes_pp
# heat map - sigma is a bandwidth, eps - final raster resolution
crashes.kd1 <- density(crashes_pp, sigma = 500, eps = 200)
# airbnb.kd1 <- density(airbnb_pp, sigma = bw.diggle, eps = 200)
image(crashes.kd1)
# multiplying
crashes.kd1 <- crashes.kd1*1000^2
# converting to raster
crashes.kd1 <- raster(crashes.kd1)
# adding crs
crs(crashes.kd1) <- "epsg:2193"
但是我得到一个错误:
Error in CRS(SRS_string = x) : NA
由于未执行投影,我的绘图运行在错误的位置。
【问题讨论】:
标签: r raster projection