R 在传单贴图中渲染无投影的shapefile
我想渲染传单贴图内部的形状文件 没有投影,所以我试着给它一个R 在传单贴图中渲染无投影的shapefile,r,leaflet,shapefile,map-projections,R,Leaflet,Shapefile,Map Projections,我想渲染传单贴图内部的形状文件 没有投影,所以我试着给它一个 directions <- readOGR("./directions/", "directions") proj4string(directions) <- CRS("+proj=longlat +datum=WGS84 +no_defs") 方向% setView(液化天然气=-3.8196207, lat=40.4678698, 缩放=10) 问题是我得到一个错误,说: 不符合数据的地理CRS:45078
directions <- readOGR("./directions/", "directions")
proj4string(directions) <- CRS("+proj=longlat +datum=WGS84 +no_defs")
方向%
setView(液化天然气=-3.8196207,
lat=40.4678698,
缩放=10)
问题是我得到一个错误,说:
不符合数据的地理CRS:450781.167295 4485221.863980
我试着像CRS一样使用其他投影
proj4string(directions) <- CRS("+proj=utm +zone=30 +ellps=GRS80 +units=m +no_defs")
proj4string(方向)你非常接近。您需要做的是将UTM区域17N的投影转换为经纬度投影
library(sp)
library(rgdal)
library(leaflet)
# Read the shapefile
directions <- readOGR("directions", "directions")
# Set the projection to be UTM zone 30N
proj4string(directions) <- CRS("+proj=utm +zone=30 +ellps=GRS80 +units=m +no_defs")
# Conduct project transformation from UTM zone 30N to long-lat
directions_longlat <- spTransform(directions, CRS("+proj=longlat +datum=WGS84 +no_defs"))
map <- leaflet() %>%
addProviderTiles("CartoDB.Positron") %>%
addPolygons(data = directions_longlat, weight=1, col = 'black') %>%
setView(lng = -3.8196207,
lat = 40.4678698,
zoom = 10)
map
库(sp)
图书馆(rgdal)
图书馆(单张)
#阅读shapefile
方向可能是问题的根源?谢谢你的回复@user6617454,但我的问题是我不再出现错误,仍然无法在地图上看到形状文件,我不知道为什么。我还查看了坐标坐标(方向)
,似乎没有错误。它们看起来和我渲染的一个工作形状文件一样好。看起来传单需要WGS 84投影来显示。
library(sp)
library(rgdal)
library(leaflet)
# Read the shapefile
directions <- readOGR("directions", "directions")
# Set the projection to be UTM zone 30N
proj4string(directions) <- CRS("+proj=utm +zone=30 +ellps=GRS80 +units=m +no_defs")
# Conduct project transformation from UTM zone 30N to long-lat
directions_longlat <- spTransform(directions, CRS("+proj=longlat +datum=WGS84 +no_defs"))
map <- leaflet() %>%
addProviderTiles("CartoDB.Positron") %>%
addPolygons(data = directions_longlat, weight=1, col = 'black') %>%
setView(lng = -3.8196207,
lat = 40.4678698,
zoom = 10)
map