【发布时间】:2020-02-12 11:25:18
【问题描述】:
我有飓风轨迹点,我在 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() 不返回任何错误消息,但它会在绘图窗格中返回一个空白屏幕,所以这也是不行的。
但是ggplot2很棒,而且返回一个图形,没问题:
> ggplot() +
+ geom_sf(data = hurricane_paths)
Mapview 也可以:> mapview::mapview(hurricane_paths)
但是基本的plot() 功能仍然很顽固。
可能是什么问题?
【问题讨论】: