R语言tif转shp
时间: 2023-11-30 08:03:12 浏览: 414
你可以使用 `raster` 包和 `rgdal` 包来将 Raster 栅格数据(如 tif 文件)转换为矢量数据(如 shp 文件)。首先,你需要安装这些包并加载它们。
以下是一个示例代码,用于将 tif 文件转换为 shp 文件:
```R
library(raster)
library(rgdal)
# 读取 tif 文件
raster_data <- raster("path_to_your_tif_file.tif")
# 将 tif 转换为矢量数据
vector_data <- rasterToPolygons(raster_data, dissolve = TRUE)
# 保存为 shp 文件
writeOGR(vector_data, "path_to_save_shp_file", "output_layer_name", driver = "ESRI Shapefile")
```
请确保将 "path_to_your_tif_file.tif" 替换为你的 tif 文件的实际路径,并将 "path_to_save_shp_file" 替换为你想要保存 shp 文件的路径和名称。另外,你可以自定义输出图层的名称。
阅读全文
相关推荐











