【问题标题】:Plot lat/lon points on OpenStreetMap Using R使用 R 在 OpenStreetMap 上绘制纬度/经度点
【发布时间】:2018-10-12 09:47:34
【问题描述】:

我很难把头绕在投影上。我在北欧的一个地方的积分最终在中非。

我的代码如下。

#Loading packages

library(OpenStreetMap)
library(rgdal)
library(ggplot2)

#defining world map
map <- openmap(c(70,-179), c(-70,179))
plot(map)

#Finding my work place in Northern Europe (Ørbækvej 100, Odense, Denmark from here: https://www.latlong.net/convert-address-to-lat-long.html)
subscr<-data.frame(lat=c(55.381640),
                   lon=c(10.433600))

#I am not sure what this does, but found on the web for a map in Germany: (https://gis.stackexchange.com/questions/209166/plotting-bubbles-on-top-of-openstreetmap-in-r) 
coordinates(subscr)<-~lat+lon
proj4string(subscr)<-CRS("+init=epsg:4326")
points(spTransform(subscr,osm()))
#as can be seen using this method the dot turns up in Eastern Africa


symbols(y = subscr$lon, x = subscr$lat, circles = 1, add = TRUE,
        inches = 0.0001, bg = "darkgreen")
#as can be seen using the method the dot turns up in Western/Mid Africa

谁能解释甚至帮助我把点放在丹麦、北欧?

【问题讨论】:

  • 关于您的代码中的“我不确定这是做什么的”:地图具有一定的projection。如果您配置了错误的投影,您的坐标最终会出现在错误的位置。

标签: r ggplot2 gis openstreetmap


【解决方案1】:

我不知道你想要什么样的地图,但为了绘制经纬度点,leaflet 是我的默认武器选择..

library( leaflet )
library( magrittr )

subscr<-data.frame(lat=c(55.381640),
                   lon=c(10.433600))

leaflet() %>% addTiles() %>% 
  addCircleMarkers(data = subscr,
                   lat = ~lat, lng = ~lon,
                   color = "blue")

【讨论】:

  • 感谢您的尝试。它可以工作,但我需要调整点大小的可能性。那可能吗?我可以更改该传单包中的地图布局吗?
  • @SanderEhmsen 当然...您可以更改标记的radius,颜色,等等。请参阅传单帮助文件?addControl,或阅读cran.r-project.org/web/packages/leaflet/leaflet.pdfaddControl-部分
【解决方案2】:

您一定要使用开放的街道地图吗?您可能会考虑使用与ggplot2 很好交互的ggmap 包。但是,有时我在下载带有ggmap 的开放街道地图时会遇到麻烦,但 google-maps 应该可以工作。

考虑以下示例。请注意,我在下载命令中删除了地图中不必要的文本。

# download
map <- get_googlemap(center = "Europe", zoom = 3, 
                     style = paste0("feature:administrative.country|",
                                    "element:labels|visibility:off"),
                     filename = "Map",
                     language = "en-EN") # you might want to adjust the language settings

# see what you've got
ggmap(map)

# edit map
ggmap(map)+

  # do some scaling (make it smaller)
  scale_x_continuous(limits = c(-12, 42), expand = c(0, 0)) +
  scale_y_continuous(limits = c(35, 70), expand = c(0, 0))+

  # remove unwanted information
  theme(axis.title.x    = element_blank(),
        axis.title.y    = element_blank(),
        axis.line       = element_blank(),
        axis.ticks      = element_blank(),
        axis.text       = element_blank(),
        plot.title      = element_blank(),
        plot.background = element_blank())+

  # add whatever you like based on your coordinates using annotate()
  annotate("text", x = 10.433600, y = 55.381640, 
           label = "You are here",
           size = 2.4, color = "black", fontface = "bold",
           na.rm = TRUE, hjust = 0.5)

这能解决您的问题吗?

【讨论】:

  • 感谢您的努力。我曾经使用 ggmap(或 RgoogleMaps)。但我不断收到错误,因此放弃了它:download.file 中的错误(url,destfile = tmp,quiet = !messaging,mode =“wb”):无法打开 URL(被 Sander 缩短)另外:警告消息:在 download.file(url, destfile = tmp, quiet = !messaging, mode = "wb") : cannot open URL 'maps.googleapis.com/maps/api/…': HTTP status was '403 Forbidden'
  • 以下是关于此问题的对话:stackoverflow.com/questions/19827598/…。有趣的是,我最近从 Windows 8 升级到了 Windows 10,现在我遇到了同样的错误。
猜你喜欢
  • 2012-04-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-01-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多