简体   繁体   English

用坐标栅格图转换表

[英]Converting table with coordinates raster plot

I'm a total beginner and have what I believe is a rather simple problem, but I am kind of stuck... 我是一个初学者,我相信这是一个非常简单的问题,但是我有点困惑……

I have a data table with three columns: x , y and height values. 我有一个包含三列的数据表: xyheight值。 I've imported the csv file and extracted the values: 我已经导入了csv文件并提取了值:

data <- read.csv("C:/Data/heights.csv")
mydata <- data[, c("x", "y", "height")]

I then need to put the height values into a grid with these coordinates, which I created as a raster: 然后,我需要将height值放入具有这些坐标的网格中,这些坐标是作为栅格创建的:

grid <- raster(ncol=2001, nrow=2001, xmn=479975, xmx=500025, ymn=119975, ymx=140025)

I think you are very close. 我觉得你很亲密。 I'd suggest you reading the raster package material, the vignette and description . 我建议您阅读光栅包装材料, 小插图说明

You'll have to pay attention to your data and how it is organized. 您必须注意自己的数据及其组织方式。 By row? 按排? Column? 柱? raster cells values will be populated by row. 栅格像元值将按行填充。

Using something simmilar to the example provided in the help ?raster 使用的东西simmilar在帮助中提供的例子?raster

library(raster)
vals <- 1:100
r1 <- raster(nrows=10, ncols=10, xmn=479975, xmx=500025, ymn=119975, ymx=140025)
r1[] <- vals
plot(r1)

在此处输入图片说明

But the procedure may be different approaching with a spatial object 但是,处理空间物体的过程可能有所不同

library(sp)
x <- 1:10
y <- 1:10
df <- data.frame(expand.grid(x=x,y=y), v=1:100)
coordinates(df)=~x+y
gridded(df) = TRUE
r2 <- raster(df)
plot(r2)

来自空间物体的栅格

I think this may be the best approach but it would be better to have an idea about your data and how it is organized. 我认为这可能是最好的方法,但是最好对您的数据及其组织方式有所了解。

You could try this: 您可以尝试以下方法:

library(raster)
x <- rasterFromXYZ(mydata)
extent(x) <- c(479975, 500025, 119975, 140025)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM