User Tools

Site Tools


C02-1: Google Earth images

About Google Earth images

The data sources of the Google Earth images are high-resolution imagery from satellites as well as in some cases aerial photographs. Google Earth images are free of charge and offer a high spatial resolution of few centimeters. The images are often used as ancillary data source to digitize training sites for e.g. land cover classifications or are used as backround images in mapping. The RGB bands, however, might also be used as direct input for classifications. This tutorial shows how Google Earth images can be downloaded via R.

Download of the images

First we load a polygon shapefile of Fogo which we use as template for the download of the images.

## Warning: package 'rgdal' was built under R version 3.1.3
## Loading required package: sp
## Warning: package 'sp' was built under R version 3.1.3
## rgdal: version: 0.9-3, (SVN revision 530)
##  Geospatial Data Abstraction Library extensions to R successfully loaded
##  Loaded GDAL runtime: GDAL 1.11.2, released 2015/02/10
##  Path to GDAL shared files: C:/Users/tnauss/Documents/R/win-library/3.1/rgdal/gdal
##  GDAL does not use iconv for recoding strings.
##  Loaded PROJ.4 runtime: Rel. 4.9.1, 04 March 2015, [PJ_VERSION: 491]
##  Path to PROJ.4 shared files: C:/Users/tnauss/Documents/R/win-library/3.1/rgdal/proj
##  Linking to sp version: 1.1-0
## Warning: package 'raster' was built under R version 3.1.3
## Warning: package 'dismo' was built under R version 3.1.3
template <- readOGR("D:/active/bis-fogo/school2015/data/remote-sensing/masks/fogo_polygon.shp",

The dismo package has the function “gmap” which allows to download Google Earth images from within R.

## starting httpd help server ... done

As decribed on the help page, gmap requires a Spatial object (“x”) as Input parameter to define the location of the Images. The resulting image is then centered to the extent of this object. The “type” parameter needs to be changed to “satellite” in order to download Google Earth satellite images. The zoom argument can be changed according to the desired level of detail. Allowed values are 0 (the whole world) to 21 (very small area). The size arguments defines the size of the image in terms of columns and rows.

Since the image is a RGB image, we can use the plotRGB function to depict the result.

google_image <- gmap(template, type='satellite', zoom=10, 
                     rgb=TRUE, size=c(400, 400), lonlat=TRUE)

Create a high resolution Mosaic

The detail decreases when a larger extent is used. If you want to create a high resolution image of the overall island you would need to download several tiles and afterwards merge them to one raster. Therefore, we can create for example 4 regular distributed points on the extent of Fogo, which we can iteratively use to download the Google tiles.

sample_points <- spsample(template, n = 9, "regular")

We can then download a highly detailes Google image using each point as a center coordinate. Setting scale=2 gives the best available resolution for the defined size and zoom level. We can save the images in a list “google_tiles”.

for (i in 1:length(sample_points)){
  google_tiles[[i]] <- gmap(sample_points[i,], type='satellite', 
                           zoom=13, rgb=TRUE, size=c(640, 640), scale=2, lonlat=TRUE)

To create a mosaic we can use the mosaic function from the raster package which merges the single tiles. The tolerance argument is important to account for different origins of the tiles.

mosaic_image <- mosaic(google_tiles[[1]], google_tiles[[2]], google_tiles[[3]], 
                       google_tiles[[4]], google_tiles[[5]], google_tiles[[6]],
                       google_tiles[[7]], google_tiles[[8]], google_tiles[[9]], 
                       fun=mean, tolerance=1)