从“预先网格化”的表面创建表面。点 [英] creating a surface from "pre-gridded" points
问题描述
我有一个大的 data.frame
,它有3个变量经度
,纬度
和 Temp
。
数据的排列方式是:网格的1/4度 - 这样 dput(head(dat))
给出:
结构(列表(经度= c(0.125,0.375,0.625,0.875,1.1125,
1.375),纬度= c(0.125,0.125,0.125,0.125,0.125,0.1125
),Temp = c(25.2163,25.1917,25.1593,25.125,25.0908,25.0612
)),.Names = c(Longitude,Latitude,Temp),row.names = c(NA,
6L),class =data.frame)。
我有问题将其重新安排到所需的格式。
我想创建一个常规曲面对象(通常是一个列表),其中x和y是网格值,z是相应的表面的矩阵。这是 使用这个表面对象,我可以很容易地使用 任何建议都会很棒。 假设您的数据类似于 我们创建一个 I have a large The data is arranged so that it is regularly spaced on a "grid" of 1/4 degree - so that I am having problems re-arranging it to the required format. I would like to create a regular surface object (typically a list), where x and y are the grid values and z is a corresponding matrix of the surface. This is the usual format used by Using this surface object I will could then be able to easily interpolate to a matrix of locations using Any suggestions would be great. Suppose your data is like We create a Also see Change Lat & Lon vectors to matrix in R. 这篇关于从“预先网格化”的表面创建表面。点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! persp ,
contour ,
图像
等。
interp.surf
插入位置矩阵。从字段
包。
set.seed(123)
d <= data.frame(lon = rep(seq(0,1,0.25),times = 5),
lat = rep(seq(0,1,0.25),each = 5),
temp = sample(1:25,25,replace = TRUE))
head(d,8)
#lon lat temp
#1 0.00 0.00 8
#2 0.25 0.00 20
#3 0.50 0.00 11
#4 0.75 0.00 23
#5 1.00 0.00 24
#6 0.00 0.25 2
#7 0.25 0.25 14
#8 0.50 0.25 23
z
矩阵,它们表示网格中每个点的值。然后,我们将网格线的位置( x
和 y
)放入一个列表中,以及 z
。
library(reshape2)
z< - acast(d, (独特的(d $ lat)),
y = sort(唯一的(d $ lat)),
b(b,b,b,b,b,b,b)
<另请参阅更改Lat& Lon矢量矩阵在R 。data.frame
which has 3 variables Longitude
, Latitude
and Temp
.dput(head(dat))
gives:structure(list(Longitude = c(0.125, 0.375, 0.625, 0.875, 1.125,
1.375), Latitude = c(0.125, 0.125, 0.125, 0.125, 0.125, 0.125
), Temp = c(25.2163, 25.1917, 25.1593, 25.125, 25.0908, 25.0612
)), .Names = c("Longitude", "Latitude", "Temp"), row.names = c(NA,
6L), class = "data.frame").
persp
, contour
, image
etc. interp.surf
from the fields
package.set.seed(123)
d <- data.frame(lon=rep(seq(0,1,0.25), times=5),
lat=rep(seq(0,1,0.25), each=5),
temp=sample(1:25, 25, replace=TRUE))
head(d, 8)
# lon lat temp
# 1 0.00 0.00 8
# 2 0.25 0.00 20
# 3 0.50 0.00 11
# 4 0.75 0.00 23
# 5 1.00 0.00 24
# 6 0.00 0.25 2
# 7 0.25 0.25 14
# 8 0.50 0.25 23
z
matrix that represent the values for each point in the grid. We then put the locations of the grid lines (x
and y
) into a list, together with z
.library(reshape2)
z <- acast(d, lat~lon, value.var="temp")
X <- list(x=sort(unique(d$lon)),
y=sort(unique(d$lat)),
z=z)
image(X, col=gray.colors(25))
with(d, text(lon, lat, labels=temp))