Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
数据帧到R中的ArcGIS ASCII_R_Ascii_Arcgis - Fatal编程技术网

数据帧到R中的ArcGIS ASCII

数据帧到R中的ArcGIS ASCII,r,ascii,arcgis,R,Ascii,Arcgis,我有一个数据帧(predHB.Lv1Hard),它包含3列“y”=经度,“x”=纬度,“predLv1Hard”=模型输出的概率。所有列都是数字 > head(predHB.Lv1Hard) y x predLv1Hard 1 -21.78557 114.0319 0.00000000 2 -21.78557 114.0319 0.06315789 3 -21.78557 114.0320 0.00000000 4 -21.78557 114.03

我有一个数据帧(predHB.Lv1Hard),它包含3列“y”=经度,“x”=纬度,“predLv1Hard”=模型输出的概率。所有列都是数字

> head(predHB.Lv1Hard)
      y        x      predLv1Hard
1 -21.78557 114.0319  0.00000000
2 -21.78557 114.0319  0.06315789
3 -21.78557 114.0320  0.00000000
4 -21.78557 114.0320  0.00000000
5 -21.78557 114.0321  0.00000000
6 -21.78557 114.0321  0.00000000
我正在尝试解决如何将其导出到可以在ArcGIS中打开的ASCII(可以是.txt格式,最好是.asc格式)

我试图模拟的代码(SPlus)如下所示(R中似乎没有等效的export.data函数)


检查包装
光栅

首先需要将数据帧转换为光栅文件(重新排列列以匹配xyz):

如果点不在常规栅格中,可以尝试使用函数
光栅化
。对于该文件的头部,我无能为力,但可以举一个例子:

# Convert to SpatialPoinDataFrane
coordinates(predHB.Lv1Hard) <- ~x+y

# Calculate the extent of the observations
ext <- extent(predHB.Lv1Hard)

# Get the distance between points
table(diff(predHB.Lv1Hard@coords[,1]))
#0 0.00010000000000332 
#3                   2
# With the limited info I have I could assume that the resolution is 0.00010000000000332 degrees.
# If you know the original resolution, much better.

# Create the template
r <- raster(ext=ext,res=0.00010000000000332)
# Final raster
to_ascii <- rasterize(predHB.Lv1Hard, r, 'predLv1Hard')

# Write raster to ascii
writeRaster(to_ascii,'filename.asc', format='ascii')
#转换为SpatialPoinDataFrane

坐标(predHB.Lv1Hard)确定有
write.table
及其所有美味的参数。我曾尝试使用write.table,但它似乎混淆了列名,也无法正确导出,您能详细说明吗?谢谢恐怕你得更具体一点,到底是什么搞砸了。。。请随意将您尝试过的内容编辑到您的问题中。谢谢您的回复!不幸的是,我得到了错误“rasterFromXYZ(predHB.Lv1Hard[,c(2,1,3)]):x单元格大小不规则”数据是否需要为偶数正方形/矩形才能工作?根据错误消息,是的。第二种选择是使用
光栅化
,但要做到这一点,您需要创建光栅模板。噢,哇,太棒了!这似乎成功了!就分辨率而言,数据是5 x 5 m(但我也将在2 x 2 m处工作),这就是你在那里工作的吗?这是在-21到-22度的latWell,我计算的分辨率大约是10米,但我只使用了前6个点。如果你用所有的点来做,它会给你一个更精确的估计。
r <- rasterFromXYZ(predHB.Lv1Hard[,c(2,1,3)])
writeRaster(r,'filename.asc', format='ascii')
# Convert to SpatialPoinDataFrane
coordinates(predHB.Lv1Hard) <- ~x+y

# Calculate the extent of the observations
ext <- extent(predHB.Lv1Hard)

# Get the distance between points
table(diff(predHB.Lv1Hard@coords[,1]))
#0 0.00010000000000332 
#3                   2
# With the limited info I have I could assume that the resolution is 0.00010000000000332 degrees.
# If you know the original resolution, much better.

# Create the template
r <- raster(ext=ext,res=0.00010000000000332)
# Final raster
to_ascii <- rasterize(predHB.Lv1Hard, r, 'predLv1Hard')

# Write raster to ascii
writeRaster(to_ascii,'filename.asc', format='ascii')