【发布时间】:2016-11-05 05:19:57
【问题描述】:
我想在栅格图层上显示一组点,并让它们以与栅格相同的比例着色。我已经查看了其他问题,但还没有解决。点值代表 30 个站点的浓度。栅格图层显示使用浓度生成的插值网格。在下面的代码中,我得到了插值的输出,它覆盖了比我需要映射的更广的区域。我将它剪辑到我用作底图的 shp 层。然后我映射剪辑的插值,并添加点。
我有显示点和栅格的地图,我不清楚如何使点的比例与栅格相同。我想我需要以某种方式从插值中提取颜色渐变,并将它们与我的 XYZ 文件中的值匹配,但我不确定这是否是正确的道路......
到目前为止我生成地图的代码:
# test data for 4 stations
XYZData<- data.frame(
X = c(577422.4, 579220.9, 580996.0, 584633.1),
Y = c(4210598, 4211570, 4212198, 4213455),Z = c(7.1,10.2,12,3))
library(raster)
rasterDF <- raster(idw_out) # idw_out is the output interpolation grid
newproj<-'my projection' # setting projection
a<-projectRaster(rasterDF, crs=newproj)
nfullName="./shpdata/this is my base map.shp"
nlayerName="name of my base map"
border_rev<-readOGR(dsn=nfullName,layer=nlayerName, verbose=F) # map extent
x1<-mask(a, border_rev) # clip interpolation to basemap
h<- colors(); h1<-h[10:100] # attempting to standardize colors used
p <- plot(x1, col=h1); points(XYZdata, type='p', col=h1)
谢谢!
编辑: 这是栅格的摘要:
class : RasterLayer
dimensions : 317, 425, 134725 (nrow, ncol, ncell)
resolution : 250, 250 (x, y)
extent : 540425, 646675, 4199125, 4278375 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=utm +zone=10 +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0
data source : in memory
names : var1.pred
values : 0.1547871, 27.05386 (min, max)
这是栅格链接:dataset
xyz数据是这样的:
mydata <- data.frame(Longitude = c(577422.442467061, 579220.875124347,
+ 580995.982508038, 584633.125414608, 585696.32284728, 589533.313960728,
+ 587475.548155474, 582963.372460121, 578940.888532248, 582075.111557177
+ ), Latitude = c(4210598.27557511,
+ 4211569.85438234, 4212197.61081488, 4213455.20812117, 4213299.86256043,
+ 4213030.38550458, 4214284.20259049, 4215457.67119233, 4213298.22263535,
+ 4217435.01191314
+ ), Result = c(7.19, 10.88, 6.59, 5.92, 4.85, 3.83, 4.57, 4.71,
+ 5.22, 2.07))
任何建议表示赞赏。
【问题讨论】:
-
请提供一个可重现的例子
标签: r colors geospatial r-raster