R object class representing a QGIS layer.
qgislayer(layerinfo)
layerinfo | a list of layer members as parsed from a Network API JSON response |
---|
A list of class qgislayer
. Although the exact member fields might
depend on the layer type, a qgislayer
can be expected to contain at
least the following fields:
id
QGIS-internal id string for the layer
crs
an rgdal::CRS object
extent
a numeric vector of class bbox
(as would be returned
by a call to sf::st_bbox()
), giving the layer extents in coordinates
of the projection (order xMin, yMin, xMax, yMax
)
A qgislayer
is simply a list, containing all members as parsed from the
Network API's JSON response.
While the parsed JSON response only contains string and numeric primitives,
the qgislayer()
constructor automatically parses some fields to
appropriate R types.
Several functions that normally take a layer id (such as
mapLayers.removeMapLayer()
) also accept a qgislayer
object for their
id
argument (see examples).
mapLayer()
, mapLayers()
, mapCanvas.layers()
# make sure to use double braces to get the actual layer *element*, not its # list position (which is a list of length 1 containing the layer element..) layer <- iface.addTileLayer('http://c.tile.openstreetmap.org/{z}/{x}/{y}.png') print(layer)#> 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] "c.tile.openstreetmap.org tiles" #> extent: [1] -20037508 -20037508 20037508 20037508 #> publicSource: [1] "type=xyz&url=http%3A%2F%2Fc.tile.openstreetmap.org%2F%7Bz%7D%2F%7Bx%7D%2F%7By%7D.png" #> type: [1] 1 #> id: [1] "c_tile_openstreetmap_org_tiles20170830121005759" #> isEditable: [1] FALSE#> [1] "c_tile_openstreetmap_org_tiles20170830121005759"## mapLayers.removeMapLayer(layer$id) # the qgislayer object is *not* synced up with QGIS -- while the object is still unchanged: print(layer)#> 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] "c.tile.openstreetmap.org tiles" #> extent: [1] -20037508 -20037508 20037508 20037508 #> publicSource: [1] "type=xyz&url=http%3A%2F%2Fc.tile.openstreetmap.org%2F%7Bz%7D%2F%7Bx%7D%2F%7By%7D.png" #> type: [1] 1 #> id: [1] "c_tile_openstreetmap_org_tiles20170830121005759" #> isEditable: [1] FALSE#> Error in qgisremote("/qgis/mapLayer", c(id = checkqgislayer(id)), ...): 500: 'No layer with id: c_tile_openstreetmap_org_tiles20170830121005759'