【问题标题】:Intersection between spatial lines and spatial polygon to identify空间线与空间多边形的交点以识别
【发布时间】:2019-04-16 23:42:25
【问题描述】:

我正在尝试识别与多边形相交的空间线以消除它们

我尝试了各种软件包来完成这项工作,但它们都给出了相同的错误“RGEOSBinPredFunc(spgeom1, spgeom2, byid, func) 中的错误: IllegalArgumentException:点数组必须包含 0 或 >1 个元素”

空间线和多边形可以从此链接https://drive.google.com/drive/folders/1CWzZzZucBjhfAthApnOGgSEL7dLXlPt5下载

库(rgeos)

lines_onland1 个元素”

lines_onland1 个元素”

库(光栅)

lines_onland1 个元素

穿越陆地的线

【问题讨论】:

    标签: spatial intersection


    【解决方案1】:

    数据

    library(raster)
    my.lines <- shapefile("my.lines.shp")
    polygons <- shapefile("polygons.shp")
    

    先找出错误发生在哪里

    err <- NULL
    for (i in 1:length(my.lines)) {
        x <- try(raster::intersect(my.lines[i,], polygons))
        if (class(x) == "try-error") {
            err <- c(err, i)
        }
    }
    
    err
    #[1]  48  59 191 294
    

    错误发生在由单个位置组成的四行,这使它们无效

    geom(my.lines[err,])
    #     object part cump         x        y
    #[1,]      1    1    1 -28.53502 38.53658
    #[2,]      2    1    2 -28.53413 38.53638
    #[3,]      3    1    3 -28.54550 38.53687
    #[4,]      4    1    4 -28.53340 38.53602
    

    删除无效行,一切正常

    x <- raster::intersect(my.lines[-err,], polygons) 
    

    【讨论】:

      猜你喜欢
      • 2010-11-21
      • 1970-01-01
      • 1970-01-01
      • 2019-05-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-30
      • 2011-09-26
      相关资源
      最近更新 更多