如何获取地图以仅显示所需部分 [英] How to get map to show only desired portion

查看:46
本文介绍了如何获取地图以仅显示所需部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有这个代码(从

此外,这些警告消息是什么意思?他们有什么需要担心的吗?

 警告消息:1:在showSRID(uprojargs,格式="PROJ",多行="NO",prefer_proj = preferred_proj)中:Proj4定义中丢弃的ellps WGS 84:+ proj = merc + a = 6378137 + b = 6378137 + lat_ts = 0 + lon_0 = 0 + x_0 = 0 + y_0 = 0 + k = 1 + units = m + nadgrids = @ null +wktext + no_defs + type = crs2:在showSRID(uprojargs,格式="PROJ",多行=否",prefer_proj = preferred_proj)中:Proj4定义中的废弃基准面世界大地测量系统1984 

解决方案

我从mp对象获得了bbox信息,如下所示:

 >mp [["bbox"]] [["p1"]][1] -10575352 5311972>mp [["bbox"]] [["p2"]][1] -8126323 3895304 

然后按如下所示修改ggplot的限制:

  OpenStreetMap :: autoplot.OpenStreetMap(mp,expand = FALSE)+geom_polygon(data = states_map_merc,aes(x = x,y = y,group = group),fill ="black",colour ="white",alpha = 0,size = .5)+geom_polygon(data = counties_map_merc,aes(x = x,y = y,group = group),fill ="black",colour ="white",alpha = 0,size = .1)+scale_x_continuous(expand = c(0,0),极限= c(-10575352,-8126323))+scale_y_continuous(expand = c(0,0),极限= c(3895304,5311972)) 

最后两行定义了轴的扩展和极限.有关更多信息,请

Say that I have this code (which is modified from OpenStreetMaps autoplot error in RStudio Server and Shiny Server in R4.0.0):

library(maps)
library(OpenStreetMap)
library(ggplot2)
library(tidyverse)
mp <- openmap(c(33,-95), c(43,-73),4,'stamen-watercolor')
states_map <- map_data("state")
states_map_merc <- as.data.frame(projectMercator(states_map$lat,states_map$long))
states_map_merc$group <- states_map$group
counties_map <- map_data("county")
counties_map_merc <- as.data.frame(projectMercator(counties_map$lat,counties_map$long))
counties_map_merc$group <- counties_map$group
OpenStreetMap::autoplot.OpenStreetMap(mp,expand=FALSE) + 
    geom_polygon(data=states_map_merc, aes(x=x,y=y,group=group), fill="black",colour="white",alpha=0, size=.5) + 
    geom_polygon(data=counties_map_merc, aes(x=x,y=y,group=group), fill="black",colour="white",alpha=0, size=.1)

How can I only get it to make the colored portion of the graph? In other words, only the portion as defined in the openmap command.

It currently looks like:

Also, what do these warning messages mean? Are they anything to worry about?

Warning messages:
1: In showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj = prefer_proj) :
  Discarded ellps WGS 84 in Proj4 definition: +proj=merc +a=6378137 +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null +wktext +no_defs +type=crs
2: In showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj = prefer_proj) :
  Discarded datum World Geodetic System 1984 in Proj4 definition

解决方案

I obtained the bbox information from the mp object as follows:

> mp[["bbox"]][["p1"]]
[1] -10575352   5311972
> mp[["bbox"]][["p2"]]
[1] -8126323  3895304 

And then modified the limits of the ggplot as follows:

OpenStreetMap::autoplot.OpenStreetMap(mp,expand=FALSE) + 
  geom_polygon(data=states_map_merc, aes(x=x,y=y,group=group), fill="black",colour="white",alpha=0, size=.5) + 
  geom_polygon(data=counties_map_merc, aes(x=x,y=y,group=group), fill="black",colour="white",alpha=0, size=.1)+
  
  scale_x_continuous(expand = c(0,0), limits = c(-10575352 ,-8126323))+
  
  scale_y_continuous(expand = c(0,0), limits = c(3895304, 5311972))

The last two lines define the expansion and limits of axes. More information are here

EDIT:

这篇关于如何获取地图以仅显示所需部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆