将栅格转换为Point Shapefile

我正在尝试将栅格转换为点shapefile

> 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,mtable)  : 
  unable to find an inherited method for function ‘shapefile’ for signature ‘"matrix"’
>plot(pts)

将栅格转换为Point Shapefile

将这些文件转换为shapefile时,我在哪里出错?

YUEYOUJING 回答:将栅格转换为Point Shapefile

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

本文链接:https://www.f2er.com/2765336.html

大家都在问