[英]Merge spatial point dataset with Spatial grid dataset using R. (Master dataset is in SP Points format)
I am working on spatial datasets using R. 我正在使用R处理空间数据集。
Data Description 资料说明
My master dataset is in SpatialPointsDataFrame
format and has surface temperature data (column names - "ruralLSTday", "ruralLSTnight") for every month. 我的主数据集为SpatialPointsDataFrame
格式, SpatialPointsDataFrame
都有表面温度数据(列名称-“ ruralLSTday”,“ ruralLSTnight”)。 Data snippet is shown below: 数据片段如下所示:
Master Data - (in SpatialPointsDataFrame format) 主数据-(SpatialPointsDataFrame格式)
TOWN_ID ruralLSTday ruralLSTnight year month
2920006.11 2920006 303.6800 289.6400 2001 0
2920019.11 2920019 302.6071 289.0357 2001 0
2920015.11 2920015 303.4167 290.2083 2001 0
3214002.11 3214002 274.9762 293.5325 2001 0
3214003.11 3214003 216.0267 293.8704 2001 0
3207010.11 3207010 232.6923 295.5429 2001 0
Coordinates: 座标:
longitude latitude
2802003.11 78.10401 18.66295
2802001.11 77.89019 18.66485
2803003.11 79.14883 18.42483
2809002.11 79.55173 18.00016
2820004.11 78.86179 14.47118
I want to add columns in the above data about rainfall and air temperature - This data is present in SpatialGridDataFrame
in the table "secondary_data" for every month. 我想在上面的数据中添加有关降雨和气温的列- SpatialGridDataFrame
,此数据在表“ secondary_data”中的SpatialGridDataFrame
中存在。 Snippet of "secondary_data" is shown below: “ secondary_data”的代码段显示如下:
Secondary Data - (in SpatialGridDataFrame format) 辅助数据-(采用SpatialGridDataFrame格式)
month meant.69_73 rainfall.69_73
1 1 25.40968 0.6283871
2 2 26.19570 0.4580542
3 3 27.48942 1.0800000
4 4 28.21407 4.9440000
5 5 27.98987 9.3780645
Coordinates: 座标:
longitude latitude
[1,] 76.5 8.5
[2,] 76.5 8.5
[3,] 76.5 8.5
[4,] 76.5 8.5
[5,] 76.5 8.5
Question 题
How do I add the columns from secondary data to my master data by matching over latitude longitude and month? 如何通过匹配纬度经度和月份来将辅助数据中的列添加到我的主数据中? Currently the latitude/longitude information in the two table above will not match exactly as master data is a set of points and secondary data is grid. 当前,上面的两个表中的纬度/经度信息将不完全匹配,因为主数据是一组点,辅助数据是网格。
Is there a way to find the square of the grid on the "Secondary Data" that the lat/long of my master data falls into, and interpolate? 有没有办法在我的主数据的经度/纬度落入并进行插值的“二次数据”上找到网格的平方?
If your SpatialPointsDataFrame
object is called x
, and your SpatialGridDataFrame
is called y
, then 如果您的SpatialPointsDataFrame
对象称为x
,而您的SpatialGridDataFrame
对象称为y
,则
x <- cbind(x, over(x, y))
will add the attributes (grid cell values) of y
matching to the locations of x
, to the attributes of x
. 将的属性(网格单元值)添加y
匹配的位置x
,到的属性x
。 Match is done by point-in-grid cell. 匹配由点网格单元完成。
Interpolation is a different question; 插值是一个不同的问题。 a simple way would be inverse distance with the four nearest neighbours, eg by 一个简单的方法是与四个最近的邻居成反距离,例如
library(gstat)
x = idw(meant.69_73~1, y, x, nmax = 4)
whether you want one, or the other really depends on what your grid cells mean: do they refer to (i) the point value at the grid cell center, (ii) a value that is constant throughout the grid cell, or (iii) an average value over the whole grid cell. 您是否想要一个,还是真的要取决于您的网格单元格的含义:它们是指(i)网格单元格中心的点值,(ii)在整个网格单元格中恒定的值,还是(iii)整个网格单元的平均值。 First case: interpolate, second: use over
, third: use area-to-point interpolation (not explained here). 第一种情况:插值,第二种:使用over
,第三种:使用区域到点的插值(此处未说明)。
R package raster
will offer similar functionality, but use different names. R包raster
将提供类似的功能,但使用不同的名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.