有人可以告诉我如何进行以下操作:我有一个来自荷兰(Urk)小镇的ESRI shapefile,以及用标记在地图上绘制每个家庭用户的情节。 Leaflet提供错误,指出文件具有NULL值,但我似乎无法找到它们。
# what does this file look like
> ogrInfo("WGS1984_Urk/nummer.shp", "nummer")
Source: "WGS1984_Urk/nummer.shp", layer: "nummer"
Driver: ESRI Shapefile; number of rows: 7792
Feature type: wkbPoint with 2 dimensions
Extent: (5.591987 52.64994) - (170059.4 518956.2)
LDID: 87
Number of fields: 18
name type length typeName
1 NUMMER_ID 4 16 String
2 STRAATNAAM 4 80 String
3 HUISNUMMER 0 8 Integer
......
# Read ESRI shapefiles into R
> huisnummers_Urk <-readOGR(dsn="WGS1984_Urk/nummer.shp",
layer="nummer", verbose = TRUE,
dropNULLGeometries= TRUE,
p4s = "+proj=longlat +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +no_defs")
# Info from spdplyr package
> huisnummers_Urk
class : SpatialPointsDataFrame
features : 7792
extent : 5.591987, 170059.4, 52.64994, 518956.2 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +no_defs
variables : 18
# A tibble: 7,792 × 18
# Plot house in Leaflet
> leaflet(huisnummers_Urk) %>%
addTiles() %>%
addMarkers(lng = huisnummers_Urk$x1, lat = huisnummers_Urk$x2)
Error in validateCoords(lng, lat, funcName) :
addMarkers requires non-NULL longitude/latitude values
# Where are the missing values?
> huisnummers_Urk@coords[!complete.cases(huisnummers_Urk@coords),]
coords.x1 coords.x2
我应该从哪里开始看到我在做错了什么?我把所有的坐标放在一个矩阵中进行检查,看不到NA的/ NULL。
答案 0 :(得分:0)
我发现了两个错误:一个在代码中,另一个在数据集中。
1)lng和lat的Leaflet命令应该指向&#34; huisnummers_Urk $ coords.x1&#34;。坐标 slot 的名称也是&#34; coords&#34;这在de列中重复。所以我犯了将这部分遗漏掉的错误。
2)图表有lng / lat值,您可以使用spdplyr包过滤它们:
huisnummer_urk <- huisnummer_urk %>%
filter(huisnummer_urk$coords.x1 >= -90,
huisnummer_urk$coords.x1 <= 90, huisnummer_urk$coords.x2 >= -180, huisnummer_urk$coords.x2 <= 180)