Add a new raster layer to QGIS.

iface.addRasterLayer(x, layerName = NULL, ...)

# S3 method for RasterBrick
iface.addRasterLayer(x, layerName = NULL,
  format = "GTiff", ...)

# S3 method for RasterLayer
iface.addRasterLayer(x, layerName = NULL,
  format = "GTiff", ...)

# S3 method for RasterStack
iface.addRasterLayer(x, layerName = NULL,
  format = "GTiff", ...)

# S3 method for list
iface.addRasterLayer(x = list(url = NULL, layers = NULL, styles
  = NULL, format = "image/svg", crs = "EPSG:4326"), layerName = NULL,
  providerKey = "wms", ...)

# S3 method for default
iface.addRasterLayer(x, layerName = NULL,
  providerKey = NULL, ...)

Arguments

x

a QGIS provider string, named list, or an instance of one of the raster package classes

layerName

name for the new layer to be displayed in the QGIS layers panel (will be filled by an appropriate default if missing)

...

low-level parameters (such as host and auth) to be passed on to qgisremote()

format

the format (only applicable when x is a raster object, see raster::writeFormats())

providerKey

QGIS provider key (only applicable when x is a list or provider string)

Value

A representation of the layer just added (a list of class qgislayer()).

Details

If x is an instance of one of the raster object classes, transfers that data to QGIS via a HTTP POST request. If the raster data is not currently stored on disk, it first needs to (temporarily) write it to disk in the specified format (default GeoTiff).

Methods (by class)

  • list: When passed a named list, compiles a WMS service provider string based on the named options found in the list, and tries to add this as a raster layer. This function provides an easy way to add a specific WMS layer without having to select it manually through the QGIS user interface. Which named options are necessary will depend on the WMS service, but in most cases the list will at the very least require entries for the url, crs, as well as layers and corresponding styles (see examples below).

  • default: When passed a simple character string, it is assumed to be a QGIS provider string, such as one pointing to a WMS url, or also a local file if you are connecting to an instance of QGIS on the same machine. A new layer with this provider string is added to QGIS without any transfer of data through the Network API plugin.

See also

iface.addTileLayer(), iface.addVectorLayer(), qgislayer(), mapLayer(), mapLayers()

Examples

# add OSM tile raster layer iface.addRasterLayer('type=xyz&url=http://c.tile.openstreetmap.org/{z}/{x}/{y}.png', providerKey = 'wms')
#> QGIS map layer with the following properties: #> crs: CRS arguments: #> +proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 #> +k=1.0 +units=m +nadgrids=@null +no_defs #> valid: [1] TRUE #> name: [1] "" #> extent: [1] -20037508 -20037508 20037508 20037508 #> publicSource: [1] "type=xyz&url=http://c.tile.openstreetmap.org/{z}/{x}/{y}.png" #> type: [1] 1 #> id: [1] "20170830121432272" #> isEditable: [1] FALSE
# named lists are treated as WMS service specifications iface.addRasterLayer(list(url = 'http://apps.ecmwf.int/wms/?token=public&version=1.3.1', layers = 'composition_co_300hpa', styles = 'sh_all_o3_300hpa', format = 'image/svg+xml', crs = 'EPSG:4326'), 'Ozone layer (no pun intended)')
#> QGIS map layer with the following properties: #> crs: CRS arguments: #> +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 #> valid: [1] TRUE #> name: [1] "Ozone layer (no pun intended)" #> extent: [1] -180 -90 180 90 #> publicSource: [1] "url=http%3A%2F%2Fapps.ecmwf.int%2Fwms%2F%3Ftoken%3Dpublic%26version%3D1.3.1&layers=composition_co_300hpa&styles=sh_all_o3_300hpa&format=image%2Fsvg%2Bxml&crs=EPSG%3A4326" #> type: [1] 1 #> id: [1] "Ozone_layer__no_pun_intended_20170830121432440" #> isEditable: [1] FALSE