To vectorise a raster in QGIS, use the Polygonize tool. Here's how:
-
Open QGIS. Load your raster layer into the QGIS project if it isn't already.
-
Access the Polygonize Tool: Navigate to
Raster ► Conversion ► Polygonize (Raster to Vector)
. The tool dialog will appear. -
Configure the Tool:
- Input layer: Select the raster layer you want to convert.
- Field name: Change the default field name (which describes the values of the raster) to a more suitable name. This field will contain the raster values in the resulting vector layer. For example, if your raster represents land use, you might name it "landuse_code".
- Output layer: Specify the output vector file. Click the browse button (...) next to the "Output layer" field and choose a location and filename for the new vector layer. You can also choose the file format (e.g., Shapefile, GeoPackage).
- Create attribute index: (Optional) Check this if you plan to perform attribute-based queries on the resulting vector layer, to speed up the process.
-
Run the Tool: Click the "Run" button. The vectorisation process will begin.
-
Add the Output Layer (If Not Added Automatically): Once the process is complete, the newly created vector layer may or may not be automatically added to your QGIS project. If it isn't, locate the output file you specified in step 3, and drag and drop it into the QGIS Layers panel, or use
Layer -> Add Layer -> Add Vector Layer
.
Example:
Let's say you have a raster representing terrain types. The raster values could be categories like "forest," "residential," and "water." To vectorize this:
- You load the raster layer.
- Open the Polygonize tool.
- Set the input raster layer to your terrain raster.
- Change the "Field name" to something like "terrain_type".
- Specify an output file name, for example,
all_terrain.shp
saved in theexercise_data/residential_development
folder. - Run the tool.
- The resulting vector layer will contain polygons, each representing a contiguous area of a specific terrain type. The "terrain_type" attribute field in the vector layer will hold the raster value (e.g., "forest", "residential", "water") for each polygon.
Troubleshooting:
- No output: Ensure the raster layer is properly loaded and that the output file path is valid and accessible.
- Invalid geometry: Sometimes, vectorization can create invalid geometries. Use the "Check Validity" tool (Processing Toolbox -> Vector geometry -> Check validity) to identify and fix any invalid geometries.
- Large output file: Complex rasters can result in very large vector files. Consider simplifying the raster before vectorizing, or using a more efficient vector format like GeoPackage.