【问题标题】:Can I clip an area around a shapefile in R by specifying the coordinates?我可以通过指定坐标来裁剪 R 中 shapefile 周围的区域吗?
【发布时间】:2016-10-10 00:36:11
【问题描述】:

我在 R 中有一张土地覆盖数据地图,想要裁剪一个特定区域的圆圈,比如 20 公里,然后提取生成的圆形 shapefile。

# read in the shape file, assign the CRS and plot it
area <- readShapePoly("Corrine Land Use ITM Projection - Copy.shp", proj4string = CRS("+init=epsg:2157"))
plot(area, xlim = c(560000,600000), ylim = c(530000,580000), axes=TRUE)

# create a dataframe of the location where the buffer should be made and plot it
locations<-data.frame(latitude=584503.3,longitude = 560164.5)
points(locations, bg='tomato2', pch=21, cex=3)

在执行此操作之前,我是否需要先将我的点更改为坐标系? 形状文件是 Corine Landcover 2012 - National http://gis.epa.ie/GetData/Download

谢谢

【问题讨论】:

标签: r coordinates gis spatial shapefile


【解决方案1】:

你的多边形

area <- shapefile("Corrine Land Use ITM Projection - Copy.shp")

您可以像这样创建一个(或多个)圈子:

library(dismo)
p <- polygons(circles(cbind(0,0), sqrt(20000 / pi), lonlat=FALSE, dissolve=FALSE))
crs(p) <- crs(area) 

相交

int <- crop(area, p)

shapefile(int, 'landcover_circle.shp')

【讨论】:

    【解决方案2】:

    @Manassa:我相信你需要在剪辑之前确保 shapefile 和光栅在同一个投影中,然后你可以使用光栅库中的裁剪功能。请注意,输出将是一个裁剪的栅格,而不是原始问题中所述的 shapefile。

    # Reproject shapefile to same projection as the raster
    #shp = shapefile
    #r = raster
    library(rdgal)
    shp.reproject <- spTransform(shp, crs(r))
    
    #crop raster with polygon
    library(raster)
    r.crop <- crop(r, shp.reproject)
    

    【讨论】:

    • 我的错;我以为您正在处理土地覆盖数据的栅格版本。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-30
    • 2015-09-26
    • 1970-01-01
    相关资源
    最近更新 更多