无法在 R 中绘制 sf 线串:CPL_geos_is_empty(st_geometry(x)) 中的错误

2023-12-26

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

https://i.stack.imgur.com/Gtt61.png https://i.stack.imgur.com/Gtt61.png

https://i.stack.imgur.com/6z8MO.png https://i.stack.imgur.com/6z8MO.png

我都保存为 shapefile 并使用以下命令将它们加载到 R 中sf包裹。这些点将使用标准绘制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...

And 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()不返回任何错误消息,但它在绘图窗格中返回一个空白屏幕,因此这也是不行的。

但 ggplot2 很棒,并且返回图形,没问题:

> ggplot() + 
+   geom_sf(data = hurricane_paths)

Mapview 也很好:> mapview::mapview(hurricane_paths)

但基本的plot()功能依然顽固。 问题可能是什么?


我遇到了和你一样的问题,问题似乎出在从点到线串的转换上。按照线程中找到的解决方案从点创建多线,使用 sf 包按 ID 分组 https://stackoverflow.com/questions/50908771/create-multilines-from-points-grouped-by-id-with-sf-package,你可能需要使用

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

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

我希望它有帮助。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

无法在 R 中绘制 sf 线串:CPL_geos_is_empty(st_geometry(x)) 中的错误 的相关文章

随机推荐