How to use the command gdal_contour (with examples)
The gdal_contour command is part of the GDAL (Geospatial Data Abstraction Library) package and is used to create contour lines and polygons from a digital elevation model (DEM). Contour lines are lines that connect points of equal elevation, while polygons represent areas of equal elevation.
Use case 1: Create a vector dataset with contour lines spread over a 100-meter interval, attributing the elevation property as “ele”
Code:
gdal_contour -a ele -i 100.0 path/to/input.tif path/to/output.gpkg
Motivation: This use case is useful when you want to create a vector dataset with contour lines that represent a specific interval of elevation. By attributing the elevation property as “ele”, you can easily retrieve the elevation information of each contour line.
Explanation:
gdal_contour
: This is the name of the command.-a ele
: This option specifies that the “ele” attribute will be created to store the elevation information.-i 100.0
: This option sets the contour interval to 100 meters, meaning that contour lines will be generated every 100 meters of elevation.path/to/input.tif
: This is the path to the input digital elevation model (DEM) file.path/to/output.gpkg
: This is the path to the output vector dataset file in GeoPackage format.
Example output: The gdal_contour command will generate a vector dataset in the specified GeoPackage format. Each contour line will be represented as a separate feature in the dataset, with the elevation property “ele” storing the elevation information.
Use case 2: Create a vector dataset with polygons spread over a 100-meter interval
Code:
gdal_contour -i 100.0 -p path/to/input.tif path/to/output.gpkg
Motivation: This use case is useful when you want to create a vector dataset with polygons that represent areas of equal elevation. This can be particularly helpful for visualizing and analyzing elevation patterns over a specific interval.
Explanation:
gdal_contour
: This is the name of the command.-i 100.0
: This option sets the contour interval to 100 meters, meaning that polygons will be generated every 100 meters of elevation.-p
: This option specifies that polygons should be created instead of contour lines.path/to/input.tif
: This is the path to the input digital elevation model (DEM) file.path/to/output.gpkg
: This is the path to the output vector dataset file in GeoPackage format.
Example output: The gdal_contour command will generate a vector dataset in the specified GeoPackage format. Each polygon will represent an area of equal elevation within the defined interval.
Conclusion:
The gdal_contour command is a powerful tool for creating contour lines and polygons from digital elevation models. With the ability to customize the contour interval and attribute properties, it enables users to effectively analyze and visualize elevation data. By utilizing the examples provided, users can easily generate their desired vector datasets with contour lines or polygons.