r - R sf: Points of LinearRing do not form a closed linestring
问题描述
I am trying to calculate the centroids of a set of polygons.
My dataset, geodata
, contains five columns including one geometry
column of class sfc_GEOMETRY
, with 45759 rows.
When I run sf::st_centroid(geodata)
, I get the following message
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.
In addition: Warning messages:
1: In st_centroid.sf(geodata) : st_centroid assumes attributes are constant over geometries of x
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
- Should I run a loop to detect which geometry is not closed?
- Is this a problem with the class of my geometry? Should it be
sfc_MULTIPOLYGON
?
Possible solution:
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.
- 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()
函数应该告诉您哪些行有问题。
看起来您的几何图形之一可能由不正确数量的点组成。
有关在 r-spatial 查找和解决问题的更多信息:https ://www.r-spatial.org/r/2017/03/19/invalid.html
推荐阅读
- swift - UIPickerView didSelectRow 之后的空变量
- swift - 我正在尝试制作基本的随机数..swift
- python - 无法将 NumPy 数组转换为张量(不支持的对象类型 int)
- python - Discord.py 在反应中添加表情符号不起作用?
- java - itext的getUnderContent和getOverContent的区别
- android - RecyclerView、不同的 ViewTypes 和 notifyItemMoved() 导致视觉故障
- vue.js - VUE 以最简洁的方式呈现当前日期和时间
- react-native - expo:build web 后浏览器地址链接不起作用
- yii2 - Yii 2.0 覆盖 ActiveQuery - 调用未知方法:yii\db\ActiveQuery::fechadas()
- python - 在python中绘制特定的字母和数字