首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >from How to apply read.topo or as.topo to .xyz file from ETOPO1

from How to apply read.topo or as.topo to .xyz file from ETOPO1
EN

Stack Overflow用户
提问于 2014-07-04 03:13:55
回答 1查看 285关注 0票数 0

我真的很喜欢oce软件包,我想用plot.topo来绘制加拿大东部和美国东北部的海岸线和水深地图。我正在尝试创建一个像"topoMaritimes“这样的数据集,它是可用的,并且覆盖了我的大部分研究区域,但我需要将美国的纽芬兰/拉布拉多和新英格兰也包括在内。

我尝试使用worldCoastline数据集,但分辨率太低。

我从我的研究区域从ETOPO1获得了一个.xyz数据集(使用与oce创建者相同的源:http://www.ngdc.noaa.gov/mgg/gdas/gd_designagrid.html),这对我来说应该是有效的。我现在正尝试使用read.topo()或as.topo()将其读入R,但遇到了问题。

考虑到这里指定的信息:http://www.inside-r.org/packages/cran/oce/docs/read.topo,我假设read.topo()可以工作。但是当我使用read.topo时:

代码语言:javascript
复制
geo<-read.topo("ETOPO1data.xyz")
Error in if (is.character(file) && grep(".nc$", file)) { : 
missing value where TRUE/FALSE needed

显然,此错误表明缺少值/NAs?

当我尝试将其作为通用文本文件导入时,它可以工作:

代码语言:javascript
复制
geo<-read.table(file="ETOPO1data.xyz", sep="")

head(geo)
           V1         V2  V3
1 -73.000000, 56.000000, 331
2 -72.983333, 56.000000, 328
3 -72.966667, 56.000000, 327
4 -72.950000, 56.000000, 327
5 -72.933333, 56.000000, 325
6 -72.916667, 56.000000, 324

然而,当我试图将其转换为"topo“类型的对象时,我得到了一个错误:

代码语言:javascript
复制
geo<-as.topo(geo$V1, geo$V2, geo$V3)
Error in Summary.factor(c(1261L, 1260L, 1259L, 1258L, 1257L, 1256L, 1255L,  : 
min not meaningful for factors

事实证明,经度和纬度字段是因子:

代码语言:javascript
复制
str(geo)
'data.frame':   1211821 obs. of  3 variables:
$ V1: Factor w/ 1261 levels "-52.000000,",..: 1261 1260 1259 1258 1257 1256 1255 1254         1253 1252 ...
$ V2: Factor w/ 961 levels "40.000000,","40.016667,",..: 961 961 961 961 961 961 961 961 961 961 ...
$ V3: int  331 328 327 327 325 324 325 329 336 351 ...

但是,将经纬度/纬度转换为数字类型会完全更改它们的值:

代码语言:javascript
复制
geo$V1<-as.numeric(geo$V1)
geo$V2<-as.numeric(geo$V2)
head(geo)
V1  V2  V3
1 1261 961 331
2 1260 961 328
3 1259 961 327
4 1258 961 327
5 1257 961 325
6 1256 961 324

有人知道如何将x/y/z (即经度/纬度/深度)文件转换为"topo“对象吗?这会不会是我使用ETOPO1而不是ETOPO2造成的问题?

提前感谢!

EN

回答 1

Stack Overflow用户

发布于 2014-07-04 13:22:16

尝试使用marmap包。

library(marmap) papoue <- getNOAA.bathy(lon1 = 140, lon2 = 155, lat1 = -13, lat2 = 0, resolution = 10) summary(papoue) blues <- colorRampPalette(c("red","purple","blue","cadetblue1", "white"))

可以使用as.xyzas.bathy在数据类型之间进行转换

plot(papoue, image = TRUE, bpal = blues(100))

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24561642

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档