【问题标题】:Is there an R function to change the projection of raster?是否有 R 函数来更改栅格的投影?
【发布时间】: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


    【解决方案1】:

    这是一个最小的、独立的、可重现的示例,它会产生错误。

    我认为你应该使用“EPSG:2193”而不是“epsg:2193”

    示例数据

    library(raster)
    #Loading required package: sp
    r <- raster()
    

    这失败了

    crs(r) <- "epsg:2193"
    #Error in sp::CRS(SRS_string = x) : NA
    

    它适用于(带有警告)

    crs(r) <- "EPSG:2193"
    #Warning message:
    #In showSRID(SRS_string, format = "PROJ", multiline = "NO", prefer_proj = prefer_proj) :
    #  Discarded datum New Zealand Geodetic Datum 2000 in Proj4 definition
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-30
      • 2020-11-22
      • 2014-05-30
      • 1970-01-01
      • 1970-01-01
      • 2019-06-17
      相关资源
      最近更新 更多