在R中的Google地图背景上重叠图像图 [英] Overlap image plot on a Google Map background in R

查看:553
本文介绍了在R中的Google地图背景上重叠图像图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在威尼托(意大利地区)

通过图像轮廓

c>:

  image(X,Y,evalmati,col = heat.colors(100),xlab =,ylab =,asp = 1,zlim = zlimits,main = title)
contour(X,Y,evalmati,add = T)

(在这里您可以找到对象:

 库(marmap)

#从NOAA或GEBCO服务器获取高温测量和测深数据
#bath < - getNOAA.bathy(lon1 = 10,lon2 = 14,lat1 = 44,lat2 = 47,res = 1,keep = TRUE)
bath < - readGEBCO.bathy(GEBCO_2014_2D_10.0_44.0_14.0_47.0.nc)

#为海洋和陆地创建调色板
blues< - c( lightteelblue4,lightsteelblue3,lightsteelblue2,lightsteelblue1)
灰色<-c(灰色(0.6),灰色(0.93),灰色(0.99))

#绘制高度/深度图b b = b(浴,land = T,im = T,lwd = .03,bpal = list(c(0,max(浴),灰色),c(min(浴), 0,blues)))
plot(bath,n = 1,add = T,lwd = .5)#添加海岸线

#将你的数据转换成一个有水的物体
rownames(evalmati)< - X
colnames(evalm ati)< - y
class(evalmati)< - bathy

#在地图
上绘制覆盖evalmati(evalmati,land = T,im = T, lwd = .1,bpal = col2alpha(heat.colors(100),。7),add = T,drawlabels = TRUE)#use deep = shallow = step =调整轮廓线
plot(outline.buffer( evalmati),add = TRUE,n = 1)#数据大纲

#添加城市位置和名称
库(地图)
map.cities(country =Italy ,label = T,minpop = 50000)

由于您的 evalmati data现在是 bathy 对象,您可以像调整地图背景一样调整其在地图上的外观(调整等高线的数量和宽度,调整颜色渐变等)。 plot.bath()同时使用 image() contour(),所以你应该可以得到和 image()一样的结果。请查看 plot.bathy()的帮助以及更多示例的包装短片。



< img src =https://i.stack.imgur.com/Es0Vj.jpgalt =在这里输入图片描述>


I'm trying to add this plot of a function defined on Veneto (italian region)

obtained by an image and contour:

image(X,Y,evalmati,col=heat.colors(100), xlab="", ylab="", asp=1,zlim=zlimits,main=title)
contour(X,Y,evalmati,add=T)

(here you can find objects: https://dl.dropboxusercontent.com/u/47720440/bounty.RData)

on a Google Map background.

I tried two ways:

PACKAGE RGoogleMaps

I downloaded the map mbackground

MapVeneto<-GetMap.bbox(lonR=c(10.53,13.18),latR=c(44.7,46.76),size = c(640,640),MINIMUMSIZE=TRUE)
PlotOnStaticMap(MapVeneto)

but i don't know the commands useful to add the plot defined by image and contour to the map

PACKAGE loa

I tried this way:

lat.loa<-NULL
lon.loa<-NULL
z.loa<-NULL
nx=dim(evalmati)[1]
ny=dim(evalmati)[2]
for (i in 1:nx)
{
    for (j in 1:ny)
    {
        if(!is.na(evalmati[i,j]))
        {
            lon.loa<-c(lon.loa,X[i])
            lat.loa<-c(lat.loa,Y[j])
            z.loa<-c(z.loa,evalmati[i,j])
        }
    }
}

GoogleMap(z.loa ~ lat.loa*lon.loa,col.regions=c("red","yellow"),labels=TRUE,contour=TRUE,alpha.regions=list(alpha=.5, alpha=.5),panel=panel.contourplot)

but the plot wasn't like the first one:

in the legend of this plot I have 7 colors, and the plot use only these values. image plot is more accurate.

How can I add image plot to GoogleMaps background?

解决方案

If the use of a GoogleMap map is not mandatory (e.g. if you only need to visualize the coastline + some depth/altitude information on the map), you could use the package marmap to do what you want. Please note that you will need to install the latest development version of marmap available on github to use readGEBCO.bathy() since the format of the files generated when downloading GEBCO files has been altered recently. The data from the NOAA servers is fine but not very accurate in your region of interest (only one minute resolution vs half a minute for GEBCO). Here is the data from GEBCO I used to produce the map : GEBCO file

library(marmap)

# Get hypsometric and bathymetric data from either NOAA or GEBCO servers
# bath <- getNOAA.bathy(lon1=10, lon2=14, lat1=44, lat2=47, res=1, keep=TRUE)
bath <- readGEBCO.bathy("GEBCO_2014_2D_10.0_44.0_14.0_47.0.nc")

# Create color palettes for sea and land
blues <- c("lightsteelblue4", "lightsteelblue3", "lightsteelblue2", "lightsteelblue1")
greys <- c(grey(0.6), grey(0.93), grey(0.99))

# Plot the hypsometric/bathymetric map
plot(bath, land=T, im=T, lwd=.03, bpal = list(c(0, max(bath), greys), c(min(bath), 0, blues)))
plot(bath, n=1, add=T, lwd=.5)  # Add coastline

# Transform your data into a bathy object
rownames(evalmati) <- X
colnames(evalmati) <- Y
class(evalmati) <- "bathy"

# Overlay evalmati on the map
plot(evalmati, land=T, im=T, lwd=.1, bpal=col2alpha(heat.colors(100),.7), add=T, drawlabels=TRUE) # use deep= shallow= step= to adjust contour lines
plot(outline.buffer(evalmati),add=TRUE, n=1) # Outline of the data

# Add cities locations and names
library(maps)
map.cities(country="Italy", label=T, minpop=50000)

Since your evalmati data is now a bathy object, you can adjust its appearance on the map like you would for the map background (adjust the number and width of contour lines, adjust the color gradient, etc). plot.bath() uses both image() and contour() so you should be able to get the same results as when you plot with image(). Please take a look at the help for plot.bathy() and the package vignettes for more examples.

这篇关于在R中的Google地图背景上重叠图像图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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