- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 Efficient way to plot data on an irregular grid 中提出了这个问题问题,但一般的反馈是将原始问题分成更易于管理的块。因此,这个新问题。
我使用组织在不规则二维网格上的卫星数据,其维度是扫描线(沿轨道维度,即 Y 轴)和地面像素(跨轨道维度,即 X 轴)。每个中心像素的经纬度信息存储在辅助坐标变量中,以及四个角坐标对(经纬度坐标在 WGS84 引用椭球上给出)。
让我们构建一个玩具数据集,其中包含一个 12x10 的潜在不规则网格和相关的表面温度测量值。
library(pracma) # for the meshgrid function
library(ggplot2)
num_sl <- 12 # number of scanlines
num_gp <- 10 # number of ground pixels
l <- meshgrid(seq(from=-20, to=20, length.out = num_gp),
seq(from=30, to=60, length.out = num_sl))
lon <- l[[1]] + l[[2]]/10
lat <- l[[2]] + l[[1]]/10
data <- matrix(seq(from = 30, to = 0, length.out = num_sl*num_gp),
byrow = TRUE, nrow = num_sl, ncol = num_gp) +
matrix(runif(num_gp*num_sl)*6, nrow = num_sl, ncol = num_gp)
df <- data.frame(lat=as.vector(lat), lon=as.vector(lon), temp=as.vector(data))
lon
和
lat
数据包含我正在使用的原始产品中提供的中心像素坐标,存储为二维矩阵,其轴是ground_pixel(X 轴)和扫描线(Y 轴)。
data
矩阵——相同的维度——包含我的测量值。然后我将三个矩阵展平并将它们存储在一个数据框中。
ggplot(df, aes(y=lat, x=lon, fill=temp)) +
geom_tile(width=2, height=2) +
geom_point(size=.1) +
borders('world', colour='gray50', size=.2) +
coord_quickmap(xlim=range(lon), ylim=range(lat)) +
scale_fill_distiller(palette='Spectral') +
theme_minimal()
width
和
height
使瓷砖彼此“接触”,但当然这甚至不会接近我想要的目标,即在 map 上绘制实际投影的地面像素。
sf
包裹?
sf
对我来说有点不清楚,因为它处理不同的投影和潜在的常规网格,而在我的情况下,我想我不必重新投影我的数据,而且,我的数据不在常规网格上。
最佳答案
这是执行此操作的一种方法。可能有更简单的东西,但这是有效的。
首先,我将使用 raster 包来操作坐标。我在这里创建的栅格是“非常规的”,因为它们包含的值是位置数据。但是为此使用栅格而不是矩阵可以访问一些有用的功能,例如 extend
最有用的是 resample
,我将使用它的双线性插值函数来查找顶点
library(raster)
latr = raster(lat)
lonr = raster(lon)
find.vertices = function(m){
r = raster(m)
vertices = raster(matrix(nrow = dim(r)[1]+1, ncol = dim(r)[2]+1))
x = extend(r, c(1,1))
x[1,] = 2*x[2,] - x[3,]
x[dim(x)[1],] = 2*x[dim(x)[1]-1,] - x[dim(x)[1]-2,]
x[,1] = 2*x[,2] - x[,3]
x[,dim(x)[2]] = 2*x[,dim(x)[2]-1] - x[,dim(x)[2]-2,]
extent(vertices) = extent(r) + res(r)
vertices = resample(x, vertices)
}
latv = find.vertices(lat)
lonv = find.vertices(lon)
df2 = data.frame(xc = lonv[], yc = latv[])
ggplot(df, aes(y=lat, x=lon, fill=temp)) +
geom_tile(width=2, height=2) +
geom_point(size=.1) +
geom_point(aes(xc, yc), data=df2, inherit.aes =F) +
borders('world', colour='gray50', size=.2) +
coord_quickmap(xlim=range(lon), ylim=range(lat)) +
scale_fill_distiller(palette='Spectral') +
theme_minimal()
Polygon
从这些顶点
nx = NCOL(latv)
ny = NROW(lonv)
polys = list()
for (i in 1:length(data)) {
x = col(data)[i]
y = row(data)[i]
polys[[i]] = Polygon(cbind(
lonv[c((x-1)*ny + y, (x-1)*ny + y + 1, x*ny + y + 1, x*ny + y, (x-1)*ny + y)],
latv[c((x-1)*ny + y, (x-1)*ny + y + 1, x*ny + y + 1, x*ny + y, (x-1)*ny + y)]
))
}
Polygon
成
SpatialPolygonsDataFrame
Polys = sapply(1:length(polys), function(i) Polygons(polys[i], i))
SPolys = sapply(1:length(polys), function(i) SpatialPolygons(Polys[i], i))
SPolys = do.call(bind, SPolys)
SPolysdf = SpatialPolygonsDataFrame(SPolys, data.frame(data=as.vector(data)))
data.frame
.传统上大多数人都使用过
fortify
为了这。但是 ggplot 文档警告说这可能会被弃用,并建议改用 broom 包。我对扫帚不太熟悉,但我决定遵循以下建议:
library(broom)
ggSPolysdf = tidy(SPolysdf)
ggSPolysdf = cbind(ggSPolysdf, data = rep(as.vector(data), each=5))
ggplot(df, aes(y=lat, x=lon, fill=temp)) +
geom_polygon(aes(long,lat,fill=data, group = id), data=ggSPolysdf) +
borders('world', colour='gray50', size=.2) +
coord_quickmap(xlim=range(lon), ylim=range(lat)) +
scale_fill_distiller(palette='Spectral') +
theme_minimal()
关于r - 在不规则网格上绘制气候数据的正确方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49047327/
negExpression : (NOT^)* primitiveElement ; 是我的规矩。我现在有这个代码: !!(1==1) 我希望我最终会得到这棵树: NOT | NOT
我遇到以下问题,我正在创建一个作为预算副本的表单,但这种类型的预算不包含增值税%,并且商品不会通过会计。 问题如下我创建了一个名为budget.table的模型如下: class TableEleme
我对 Java 相当陌生,但对一般编程不太熟悉。我在 Windows Vista 上使用 Java 1.7.0_07。我正在尝试弄清楚如何使 Swing Timer 定期计时。 我注意到,即使我设置了
我有一个静态站点,它突然显示不规则的标题。这是一个包含大量 JavaScript 的单一页面,包括页面顶部的表格选择。该网站六个月前运行良好。现在,我在 12 个不同的导航选项卡中的一半上看到无法解释
在我参加的 CS 类(class)中,有一个不规则语言的例子: {a^nb^n | n >= 0} 我可以理解它是不规则的,因为没有有限状态自动机/机器可以编写来验证和接受此输入,因为它缺少内存组件。
给定以下高频但稀疏的时间序列: #Sparse Timeseries dti1 = pd.date_range(start=datetime(2015,8,1,9,0,0),periods=10,fr
我有 X、Y、Z 格式的数据,其中所有数据都是一维数组,Z 是坐标 (X,Y) 处的测量幅度。我想将此数据显示为等高线或“imshow”图,其中等高线/颜色代表 Z 值(幅度)。 用于测量和 X 和
这是 Stackoverflow 上的一个递归问题,但给出的解决方案 here仍然不完美。对我来说,屈服仍然是 python 中最复杂的东西之一,所以我不知道如何自己修复它。 当给定函数的任何列表中的
我使用 PHP 5.3.3 在 RHEL 6 服务器上部署了一个 symfony 1.4 项目。我不定期地在 php 错误日志中收到条目,提示找不到 sfProjectConfiguration 并且
我是一名优秀的程序员,十分优秀!