R sf:LinearRing 的点不形成闭合线串 [英] R sf: Points of LinearRing do not form a closed linestring

查看:289
本文介绍了R sf:LinearRing 的点不形成闭合线串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试计算一组多边形的质心.

I am trying to calculate the centroids of a set of polygons.

我的数据集geodata 包含五列,其中包括一列sfc_GEOMETRYgeometry 列,有45759 行.

My dataset, geodata, contains five columns including one geometry column of class sfc_GEOMETRY, with 45759 rows.

当我运行 sf::st_centroid(geodata) 时,我收到以下消息

When I run sf::st_centroid(geodata), I get the following message

CPL_geos_op("centroid", x, numeric(0), integer(0), numeric(0), Error in CPL_geos_op("centroid", x, numeric(0), integer(0), numeric(0), : Evaluation error: IllegalArgumentException: Points of LinearRing do not form a closed linestring.

Error in CPL_geos_op("centroid", x, numeric(0), integer(0), numeric(0), : Evaluation error: IllegalArgumentException: Points of LinearRing do not form a closed linestring.

此外:警告消息:

1:在 st_centroid.sf(geodata) 中:st_centroid 假设属性在 x 的几何上是恒定的

1: In st_centroid.sf(geodata) : st_centroid assumes attributes are constant over geometries of x

2: 在 st_centroid.sfc(st_geometry(x), of_largest_polygon = of_largest_polygon) 中:st_centroid 没有为经度/纬度数据提供正确的质心

2: In st_centroid.sfc(st_geometry(x), of_largest_polygon = of_largest_polygon) : st_centroid does not give correct centroids for longitude/latitude data

  • 我应该运行一个循环来检测哪个几何图形没有闭合吗?
  • 这是我的几何类的问题吗?应该是sfc_MULTIPOLYGON吗?
  • 我在通过循环读入文件列表时遇到了这个问题.循环会读入文件,然后将它们rbind 一起放入geodata,然后然后计算质心:

    I was encountering this problem when reading in a list of files through a loop. The loop would read in the files and then rbind them together into geodata, and then calculate the centroid:

    for(i in 1:length(list)){
      file <- st_read(list[i])
      geodata <- rbind(geodata, file) #geodata is here a void sf object
    }
    geocent <- st_centroid(geodata)
    

    当我计算循环中的质心(对于列表中的每个文件)时,错误消失了.

    When I calculated the centroids within the loop (for each file in the list), the error disappeared.

    for(i in 1:length(list)){
      file <- st_read(list[i])
      file <- st_centroid(file)
      geocent <- rbind(geodata, file) #geodata is here a void sf object
    }
    

    因此,我认为问题在于绑定操作.

    Hence, I think the problem lay in the binding operation.

    • 也许我没有以正确的方式定义我的 void sf 对象.
    • 也许 rbind 不是合适的函数,或者我应该指定它的参数.
    • Perhaps I had not defined my void sf object in the right manner.
    • Perhaps rbind was not the appropriate function, or I should have specified its parameters.

    推荐答案

    无需运行循环来查找哪个几何体不好.st_is_valid() 函数应该会告诉您哪些行有问题.

    There's no need to run a loop to find which geometry is bad. The st_is_valid() function should tell you which row(s) have the problem.

    您的几何图形之一可能由错误数量的点组成.

    It looks like one of your geometries might be made up of an incorrect number of points.

    有关在 r-spatial 中查找和解决问题的更多信息:https://www.r-spatial.org/r/2017/03/19/invalid.html

    More info about finding and fixing the problem at r-spatial: https://www.r-spatial.org/r/2017/03/19/invalid.html

    这篇关于R sf:LinearRing 的点不形成闭合线串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆