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.
- From the
Raster
menu, go toExtraction
and clickClip Raster by Extent...
- For
Input layer
, choose the layer with your elevation data. - Click the
...
button to the right ofClipping 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.
- 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
- If you want to keep the clipped layer permanently, click the
...
button to the right of theMerged
box and chooseSave to file...
- Give the file a name, and select
IMG files (*.img)
from theSave 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.)
- Give the file a name, and select
- Leave
Open output file after running algorithm
checked. - Click the
Run
button. The process will run. - Click the
Close
button to close theClip Raster by Extent
window. - In the
Layers
box (bottom left, usually), rename your new clipped layer. - 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.
- 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.
- 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. - 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.
- Click the path data layer in the
Layers
box to select it. - From the
Layer
menu, chooseToggle 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 theLayers
box.
2. Go toExport
and chooseSave Features As...
3. SelectGeoPackage
as theFormat
.
4. Click the...
button to choose a name and location.
5. Leave theAdd saved file to map
option checked.
6. ClickOK
. You will now have a new, editable layer to work with. - From the
Edit
menu, chooseAdd Line Feature... (Ctrl-.)
. The cursor will change to a targeting cursor. - 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.
- Right-click to stop drawing the line. A box will pop up allowing you to set “feature attributes” – just click
OK
. - From the
Layer
menu, chooseSave Layer Edits
. - From the
Layer
menu, chooseToggle Editing
to exit edit mode.
And now, back to our regularly scheduled clipping…
- If it is not already open (on the right side of the screen, usually), open the
Processing Toolbox
by choosingToolbox (Ctrl-Alt-T)
from theProcessing
menu. - In the
Processing Toolbox
, go intoGDAL
, then intoVector geoprocessing
, and chooseClip vector by extent
. - For
Input layer
, choose you path data’s vector layer. - Click the
...
button to the right ofClipping extent (xmin, xmax, ymin, ymax)
and chooseUse Layer Extent...
- Choose your elevation data’s raster layer in the
Select Extent
popup (not your path data’s vector layer). - If you want to keep the clipped layer permanently, click the
...
button to the right of theMerged
box and chooseSave 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.
- Leave
Open output file after running algorithm
checked. - Click the
Run
button. The process will run. - Click the
Close
button to close theClip Vector by Extent
window. - In the
Layers
box (bottom left, usually), rename your new clipped layer.