Marmap库网格文件到xyz

时间:2014-08-26 16:37:18

标签: grid

我有一个高质量的测深数据的.grd文件,我想在marmap中使用,但我的原始文件是网格。正如我从插图中所理解的那样,我必须将数据放在该库的.xyz文件中。有人可以告诉我如何使用这个库直接从ori«ginal文件中读取和打开这个文件? 数据在这里:http://w3.ualg.pt/~jluis/mirone/data-links.html(Bat do Algarve 50米) ?

2 个答案:

答案 0 :(得分:0)

您的.grd文件实际上是一个netCDF文件。要创建要与marmap一起使用的类bathy的对象,请执行以下操作:

library(ncdf)
dat <- open.ncdf("algarve50.grd")

x <- get.var.ncdf(dat,varid="x")
y <- get.var.ncdf(dat,varid="y")
z <- get.var.ncdf(dat,varid="z")

mat <- matrix(z, byrow=FALSE, nrow=length(x), dimnames=list(x,y))
class(mat) <- "bathy"

然后,要绘图,请使用:

library(marmap)
library(RColorBrewer)  # For nice color palettes

plot(mat, land = TRUE, n = 1, lwd = 0.3, image = TRUE, 
     bpal = list(c(min(mat), 0, rev(brewer.pal(9,"Blues"))),
             c(0, max(mat), grey(seq(.7,.1,-.05)))))

警告:你的浴室对象非常大(差不多有500万个细胞!)所以密谋可能需要一些时间。无论如何,结果如下:enter image description here

答案 1 :(得分:0)

您需要做的就是在创建第一个bathy对象(在上面的答案中称为subsetBathy())后使用mat函数。您可以通过直接单击地图在交互模式下使用该功能(两次定义矩形区域,或两次以上以获得任何形状的多边形),或者通过手动输入边界的坐标以非交互模式所需区域的框。例如,放大Ria Formosa:

ria.formosa <- subsetBathy(mat, x=c(-8,-7.7), y=c(36.9,37.1), locator=F)
plot(ria.formosa)
summary(ria.formosa)

Bathymetric data of class 'bathy', with 601 rows and 401 columns
Latitudinal range: 36.9 to 37.1 (36.9 N to 37.1 N)
Longitudinal range: -8 to -7.7 (8 W to 7.7 W)
Cell size: 0 minute(s)

Depth statistics:
    Min.  1st Qu.   Median     Mean  3rd Qu.     Max. 
-768.800  -73.820   -2.332  -36.330   17.140  363.600 

First 5 columns and rows of the bathymetric matrix:
             36.9   36.9005    36.901   36.9015    36.902
-8      -89.86719 -89.46094 -89.03516 -88.62500 -88.19922
-7.9995 -89.89062 -89.47266 -89.03516 -88.60938 -88.19531
-7.999  -89.89453 -89.46094 -89.03906 -88.59375 -88.18750
-7.9985 -89.90625 -89.47656 -89.03906 -88.58984 -88.15625
-7.998  -89.89844 -89.45703 -89.02734 -88.58594 -88.15625