【问题标题】:Converting Raster to Point Shapefile将栅格转换为点形状文件
【发布时间】:2020-01-15 12:20:39
【问题描述】:

我正在尝试将光栅转换为点形状文件

> library (raster)
> ras <- raster("dem.tif")
> pts = rasterToPoints(ras)
> pts
               x         y       Z
   [1,] 70.87500 38.375007  5.035302e+14
   [2,] 71.12500 38.375007  4.563356e+14
   [3,] 70.62500 38.125007  4.987732e+14
   [4,] 70.87500 38.125007  4.108542e+14
   [5,] 71.12500 38.125007  4.114788e+14
   [6,] 70.37500 37.875006  6.538783e+14
   [7,] 70.62500 37.875006  5.798219e+14
   [8,] 70.87500 37.875006  5.045395e+14
   [9,] 71.12500 37.875006  4.315951e+14
> writeOGR(p, ".", "output_name, driver="ESRI Shapefile")
Error in writeOGR(p, ".", "filename", driver = "ESRI Shapefile") : 
  inherits(obj, "Spatial") is not TRUE
> raster::shapefile(pts, "output_name.shp")
Error in (function (classes, fdef, mtable)  : 
  unable to find an inherited method for function ‘shapefile’ for signature ‘"matrix"’
> shapefile(p, outfile, overwrite=TRUE)
Error in (function (classes, fdef, mtable)  : 
  unable to find an inherited method for function ‘shapefile’ for signature ‘"matrix"’
>plot(pts)

将这些文件转换为 shapefile 我在哪里错了?

【问题讨论】:

    标签: r raster shapefile points


    【解决方案1】:

    您需要使用pts = rasterToPoints(ras, spatial = TRUE) 来确保pts 是SpatialPointsDataFrame。照原样,它只是一个matrix(如错误消息中所述),因此无法导出为 shapefile。

    【讨论】:

    • 所有编写代码现在都可以工作了。谢谢@caldwelist ..你能建议如何将光栅转换为nlayers的点shapefile吗?我尝试了pts = rasterToPoints(ras_stck, spatial = TRUE, bylayer=TRUE),但它给出了错误消息:(函数(类,fdef,mtable)中的错误:无法找到签名“字符”的函数“nlayers”的继承方法
    • bylayer 似乎不是rasterToPoints 的可接受参数,因此您可能需要找到另一个处理矢量数据的包,并为每个属性创建pts 的版本(假设rasterToPoints 为每一层创建了一个带有属性的点文件)。
    猜你喜欢
    • 2016-06-07
    • 2011-03-25
    • 2011-03-08
    • 1970-01-01
    • 2019-03-21
    • 1970-01-01
    • 2019-05-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多