创建具有四个角坐标的矩形多边形shapefile

问题描述

我有很多观测值,每个观测值都有四个角坐标来确定矩形区域,例如x_min,x_max,y_min和y_max。我想使用四个角坐标创建矩形多边形,然后将它们导出为shapefile,以在ArcGIS中使用。

这是一些观察结果。

ID     xmax        xmin         ymax       ymin
1   -6987035.01 -8831307.63  6160489.27  4818866.55
2   -7457581.36 -7918649.51  5705536.08  5370130.4
3   -7527291.93 -7988360.08  5623289.83  5287884.15
4   -7632927.9  -7863461.98  5533399.89  5365697.05

基于坐标,矩形的左下点应为(xmin,ymin),矩形的左上点应为(xmin,ymax),矩形的右下点应为(xmax,ymin),矩形的右上点应为(xmax,ymax)。

如何基于这四个坐标制作多边形文件并将其导出为shapefile,以便在ArcGIS中使用?

解决方法

尝试以下操作。

假设每一行代表一个多边形的边界,我将数据重新格式化为坐标矩阵。

bounds <- matrix(
  c(
    -6987035.01,-8831307.63,6160489.27,4818866.55,-7457581.36,-7918649.51,5705536.08,5370130.4,-7527291.93,-7988360.08,5623289.83,5287884.15,-7632927.9,-7863461.98,5533399.89,5365697.05
  ),nrow = 4,byrow = TRUE,dimnames = list(1:4,c('xmax','xmin','ymax','ymin'))
)

library(rgdal)
library(raster)

polygons_list = apply(bounds,1,function(x){
  ## Loop throught rows to create extent objects
  out = extent(x[c(2,4,3)]) ## x[c(2,3)] to reoder the row to match the order required by raster::extent function. The order should xmin,xmax,ymin,ymax
  ## convert the extent objects to spatial polygons
  out = as(out,'SpatialPolygons')
  ## convert the spatial polygons to spatial polygons dataframe
  out = as(out,'SpatialPolygonsDataFrame')
  ## set CRS 
  crs(out) <- '+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs'
  out
})

## conbining the list of spatial polygons dataframes into one spatial polygons dataframe
polygons_list = do.call(rbind,polygons_list)
plot(polygons_list)

## export as shapefiles for future use in ArcGIS
writeOGR(polygons_list,getwd(),"polygons_list",driver="ESRI Shapefile",overwrite_layer=FALSE)

,

我不确定这是否对您有用

result = 5.0
result = -1.0
unknown operator "L"
result = 0.6666666666666666
result = 6.0

给予 enter image description here

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...