【发布时间】:2021-08-10 18:53:21
【问题描述】:
我是 geo spatial 数据的新手,正在尝试使用 leaflet 和 shapefile 创建 choropleth map。
我试图在 传单地图 上绘制数据,但出现错误:错误:必须提供 x/y 属性,这似乎是由于一些投影问题 & 不确定如何根据 leaflet() 更正投影。
我的 shapefile 投影
ind_global$geometry %>%
st_crs()
输出:
User input: WGS 84
wkt:
GEOGCRS["WGS 84",
DATUM["World Geodetic System 1984",
ELLIPSOID["WGS 84",6378137,298.257223563,
LENGTHUNIT["metre",1]]],
PRIMEM["Greenwich",0,
ANGLEUNIT["degree",0.0174532925199433]],
CS[ellipsoidal,2],
AXIS["latitude",north,
ORDER[1],
ANGLEUNIT["degree",0.0174532925199433]],
AXIS["longitude",east,
ORDER[2],
ANGLEUNIT["degree",0.0174532925199433]],
ID["EPSG",4326]]
library(raster)
crs(ind_global$geometry)
CRS arguments: +proj=longlat +datum=WGS84 +no_defs
(更新:
链接到几何数据集ind_global: https://github.com/johnsnow09/covid19-df_stack-code/blob/main/ind_global_rds.rds
)
我试过的代码:
library(tidyverse)
library(sf)
libraary(leaflet)
library(htmlwidgets)
pal <- colorBin(palette = "OrRd", 9, domain = ind_global$total_vaccinations)
ind_global %>%
st_as_sf() %>%
st_transform(crs = "+init=epsg:4326") %>%
leaflet() %>%
addProviderTiles(provider = "CartoDB.Positron") %>%
add_polygons(label = Country.Region,
stroke = FALSE,
smoothFactor = .5,
opacity = 1,
fillOpacity = 0.7,
fillColor = ~ pal(total_vaccinations),
highlightOptions = highlightOptions(weight = 5,
fillOpacity = 1,
bringToFront = TRUE)) %>%
addLegend("bottomright",
pal = pal,
values = ~ total_vaccinations,
title = "total Vaaccinations",
opacity = 0.7)
也尝试了以下预测,但出现错误:
st_transform(crs = "+proj=longlat +datum=WGS84 +no_defs")
st_transform(crs = "+proj=longlat +ellps=GRS80")
使用 ggplot 和 geom_sf()
绘制时的 Shape 文件【问题讨论】:
标签: r leaflet geospatial projection sf