Terrain Relief Models, Unabridged

QGIS – Clipping Your Data

Clipping your elevation data (raster) layer

For simplicity’s sake, the Heightmap Export plugin works on full layers. To select a particular area of interest, you simply clip the relevant area out of your large dataset and then use the Heightmap Export plugin on your new clipped layer.

  1. From the Raster menu, go to Extraction and click Clip Raster by Extent...
  2. For Input layer, choose the layer with your elevation data.
  3. Click the ... button to the right of Clipping extent (xmin, xmax, ymin, ymax) and choose an option:
    • If you have a layer with bounds that match your area of interest (e.g. an import from a Google Earth .kml with waypoints on the edges), choose Use Layer Extent... and select the appropriate layer from the popup.
    • If you just want to draw a rectangle, choose Select Extent on Canvas and draw your selection rectangle. Note, however, that due coordinate reference systems and map projections, the aspect ratio on screen does not necessarily correlate to the aspect ratio when carved.
  4. If you want to keep the clipped layer permanently, click the ... button to the right of the Merged box and choose Save to file...
    • Give the file a name, and select IMG files (*.img) from the Save as type: drop-down menu. (You could alternately choose another type, but IMG files, i.e. Erdas Imagine Image files, are self-contained and convenient.)
  5. Leave Open output file after running algorithm checked.
  6. Click the Run button. The process will run.
  7. Click the Close button to close the Clip Raster by Extent window.
  8. In the Layers box (bottom left, usually), rename your new clipped layer.
  9. Optionally, right-click the source layer(s) and remove (so you won’t have a jumble to look through later).

Clipping your path data (vector) layer

For trail engraving and the like, we want to take the clipped raster layer (containing the elevation data of our area of interest) and use that as a cookie cutter to clip the path data’s vector layer. When we continue into the CAM portion of the workflow, we’ll then be able to scale the exported path data to match the size and aspect ratio of the exported heighmap data, making alignment trivial.

  1. In the Layers box, uncheck all layers except your clipped raster layer of elevation data and your layer of path data.

    This isn’t strictly necessary, but it makes it a lot easier to see what’s going on.

  2. If the path data’s vector layer is not on top of the elevation data raster layer in the map window, drag it up the list in the Layers box so it will be on top in the map window.
  3. Look at your paths. Does at least one line cross all four sides of your raster layer (i.e. top, bottom, left, and right)?
    • Yes. Great, continue from step 11.
    • No. To allow for scaling and alignment later, we need at least one line to touch each edge, so let’s just add some temporary lines.
  4. Click the path data layer in the Layers box to select it.
  5. From the Layer menu, choose Toggle Editing to enter edit mode.

    If Toggle Editing is disabled, all you need to do is save the layer in an editable format:
    1. Right-click the layer in the Layers box.
    2. Go to Export and choose Save Features As...
    3. Select GeoPackage as the Format.
    4. Click the ... button to choose a name and location.
    5. Leave the Add saved file to map option checked.
    6. Click OK. You will now have a new, editable layer to work with.

  6. From the Edit menu, choose Add Line Feature... (Ctrl-.). The cursor will change to a targeting cursor.
  7. Click to start a line, click again to set the next point, and so on, making a line that crosses any edges that weren’t crossed by your paths.
  8. Right-click to stop drawing the line. A box will pop up allowing you to set “feature attributes” – just click OK.
  9. From the Layer menu, choose Save Layer Edits.
  10. From the Layer menu, choose Toggle Editing to exit edit mode.

And now, back to our regularly scheduled clipping…

  1. If it is not already open (on the right side of the screen, usually), open the Processing Toolbox by choosing Toolbox (Ctrl-Alt-T) from the Processing menu.
  2. In the Processing Toolbox, go into GDAL, then into Vector geoprocessing, and choose Clip vector by extent.
  3. For Input layer, choose you path data’s vector layer.
  4. Click the ... button to the right of Clipping extent (xmin, xmax, ymin, ymax) and choose Use Layer Extent...
  5. Choose your elevation data’s raster layer in the Select Extent popup (not your path data’s vector layer).
  6. If you want to keep the clipped layer permanently, click the ... button to the right of the Merged box and choose Save to file...
    • Give your new file a name, and feel free to leave the type as GeoPackage (*.gpkg) unless you have reason to choose otherwise.
  7. Leave Open output file after running algorithm checked.
  8. Click the Run button. The process will run.
  9. Click the Close button to close the Clip Vector by Extent window.
  10. In the Layers box (bottom left, usually), rename your new clipped layer.
3 Likes