r - 将栅格转换为点形状文件
问题描述
我正在尝试将栅格转换为点 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, fdef, mtable) :
unable to find an inherited method for function ‘shapefile’ for signature ‘"matrix"’
>plot(pts)
解决方案
您需要使用pts = rasterToPoints(ras, spatial = TRUE)
以确保它pts
是一个SpatialPointsDataFrame
. 照原样,它只是一个matrix
(如错误消息中所述),因此无法导出为 shapefile。
推荐阅读
- flutter - AppLifecycleState.paused 上的执行保证?
- anylogic - 有没有办法(轻松)使用文本编辑器而不是图形来进行交通逻辑?
- python - Seaborn jointplot kde 在 Jupyter 上不起作用
- r - 将字符日期更改为数字日期,然后在数据框中提取年份
- bash - 无法找到实时磁盘性能数据 [UBUNTU 18.04]
- node.js - GCP Gitlab CI Cloud Function NodeJs 部署失败:RESOURCE_ERROR 400
- python - 将 django 模型导入 python 文件
- r - 在 ggplot2 轴标签中使用下标和斜体
- reactjs - 在 React 应用旁边访问 Plotly dash 应用
- flutter - Flutter:CocoaPods 找不到 pod“Firebase/Messaging”的兼容版本