r - 无法在 R : Error in CPL_geos_is_empty(st_geometry(x)) 中绘制 SF 线串

标签 r geometry gis qgis sf

我有飓风轨迹点,我在 QGIS 中将其转换为线:

https://i.imgur.com/PUOTpsi.png

https://i.imgur.com/5cbCdX2.png

我都保存为 shapefile 并使用 sf 将它们加载到 R 中包裹。这些点将使用标准 plot() 绘制。功能,但线条不会。

我遇到错误:

plot(hurricane_paths)
Error in CPL_geos_is_empty(st_geometry(x)) : 
     Evaluation error: IllegalArgumentException: point array must contain 0 or >1 elements.

我在使用 plot(st_geometry(hurricane_paths)) 时遇到了同样的错误

不过,R 肯定会加载到几何图形中:
> hurricane_paths
Simple feature collection with 1410 features and 5 fields
geometry type:  LINESTRING
dimension:      XY
bbox:           xmin: -179.9 ymin: -4.9 xmax: 8 ymax: 70.7
epsg (SRID):    4269
proj4string:    +proj=longlat +datum=NAD83 +no_defs
First 10 features:
             N.A begin  end Year           N.A_1                       geometry
1  1976143N24271  <NA> <NA> 1976 SUBTROP:UNNAMED LINESTRING (-89 24, -89.6 2...
2  1976155N11265  <NA> <NA> 1976         ANNETTE LINESTRING (-95 11.4, -95.2...
3  1976159N27281  <NA> <NA> 1976         UNNAMED LINESTRING (-79 26.8, -78.5...

st_geometry(hurricane_paths)返回
Geometry set for 1410 features 
geometry type:  LINESTRING
dimension:      XY
bbox:           xmin: -179.9 ymin: -4.9 xmax: 8 ymax: 70.7
epsg (SRID):    4269
proj4string:    +proj=longlat +datum=NAD83 +no_defs
First 5 geometries:
LINESTRING (-89 24, -89.6 24.8, -90 25.4, -90.5...
LINESTRING (-95 11.4, -95.2 11.7, -95.3 12.1, -...
LINESTRING (-79 26.8, -78.5 28, -78.1 29.2, -77...
LINESTRING (-81 26.5, -78.5 28.2, -76.2 30, -73...
LINESTRING (-103 16, -104.1 15.8, -105.1 15.8, ...

我已经在我的几何列中检查了 NA:
> which(is.na(hurricane_paths$geometry)==T)
integer(0)
plot_sf()不会返回任何错误消息,但它会在绘图 Pane 中返回一个空白屏幕,因此这也是不行的。

但是 ggplot2 很棒,并且返回图形,没问题:
> ggplot() + 
+   geom_sf(data = hurricane_paths)

Mapview也很好:> mapview::mapview(hurricane_paths)
但基本plot()功能依然顽固。
可能是什么问题?

最佳答案

我遇到了和你一样的问题,似乎问题出在从点到线串的转换中。遵循在线程 Create Multilines from Points, grouped by ID with sf package 中找到的解决方案,您可能必须使用

summarise(do_union = FALSE) %>%
st_cast("LINESTRING")

在将点数据集转换为线串之前。

我希望它有帮助。

关于r - 无法在 R : Error in CPL_geos_is_empty(st_geometry(x)) 中绘制 SF 线串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58400453/

相关文章:

r - 如何在 R 中为每个其他变量创建等级变量?

r stargazer - 将线添加到回归输出并定制它们的顺序

performance - MATLAB/ Octave : cut a lot of circles from a image

r - 确定 R 中向量的最小值

r - 自定义分区统计图,其中各州按领土分组

javascript - 如何在 JavaScript 中将鼠标点对齐到一个 Angular

algorithm - 包含不超过 11 个点的最大圆

gis - 如何将经度和纬度数据转换为 NetLogo 的 shapefile

algorithm - 是否有生成二维凹包的有效算法?

mysql - 多边形中的点 : Invalid GIS data provided to function st_within