官术网_书友最值得收藏!

  • QGIS 2 Cookbook
  • Alex Mandel Víctor Olaya Ferrero Anita Graser Alexander Bruy
  • 502字
  • 2021-07-16 11:12:43

Building virtual rasters (catalogs)

When you have a lot of rasters (instead of one big raster) that are all part of the same dataset (typically adjacent to each other), you don't want to load each file individually and then style it. It's much easier to load one file and treat it as one layer. This recipe lets you do this without actually creating a single monstrous raster, which can be difficult to work with.

Getting ready

You will need two or more raster files that have adjacent extents or only overlap partially around the edges and are in the same projection. Ideally, the files should be of the same type, such as all elevations, all air photos, and so on. For this recipe, the elevation rasters from the OSGeo EDU (North Carolina) dataset will work.

How to do it…

  1. (Optional) Load the elevation rasters to your current map.
  2. Go to Raster Menu | Miscellanous | Build Virtual Raster (Catalog).
  3. Check the Use visible raster layers checkbox or choose SELECT, browse to the example data, and select all four.
  4. SELECT and name an output file using the .vrt extension.
  5. (Optional) Check the Load into canvas when finished checkbox if you want to see the results immediately:
    How to do it…

    Tip

    GDAL command line equivalent: <command> <output.vrt> <list of inputs... space between each...>

    For example, gdalbuildvrt elevlid.vrt elevlid_D782_6.tif elevlid_D783_6m.tif elevlid_D792_6m.tif elevlid_D793_6m.tif.

How it works…

GDAL VRT format is an XML file that defines the location of each raster file relative to an anchor file. It uses the existing spatial extent information of the rasters to figure out their positions relative to each other and then anchors the set in the given coordinate system.

There's more…

Using a VRT is all about saving time. When you have hundreds of raster files for one particular dataset, you can combine them into a single file. However, this file could be gigantic in size and somewhat impossible to work with. This is a quick way to be able use the files as a seamless background layer. If you need to perform analysis, you'll likely need to either combine the layers or loop over them individually.

You could also generate Tile Index (also in the Miscellaneous menu), which makes a shapefile of the outlines of the rasters and puts the ID and path of the raster in the attribute table. This would allow you to figure out which image you want to load for a given map without having to load them all.

Finally, if you really want to make all of the files a single large file, use the context menu (right-click on the loaded VRT layer and choose Save As). If you have overlaps, more complicated situations, or want to merge without loading the files, first use the Merge tool (also in the Miscellaneous menu). This can be tricky if your files overlap, you'll need to decide how to handle the double data.

See also

主站蜘蛛池模板: 吉安市| 新余市| 梧州市| 买车| 阜康市| 拉萨市| 吉首市| 永春县| 平乡县| 延吉市| 凉山| 德州市| 水富县| 洞头县| 纳雍县| 呼和浩特市| 岳池县| 那曲县| 西昌市| 旬阳县| 达拉特旗| 博爱县| 定安县| 蒙山县| 两当县| 平邑县| 沈丘县| 凤阳县| 都昌县| 商都县| 视频| 双牌县| 桑植县| 莲花县| 延庆县| 稻城县| 上饶市| 井冈山市| 杭锦后旗| 莲花县| 白河县|