OpenDroneMap-WebODM/plugins/contours/calc_contours.grass

38 wiersze
1.2 KiB
Plaintext
Executable File

# dem_file: GeoTIFF DEM containing the surface to calculate contours
# interval: Contours interval
# format: OGR output format
# simplify: Simplify value
# epsg: target EPSG code
# destination: destination folder. If it does not exist, it will be created.
#
# ------
# output: If successful, prints the full path to the contours file. Otherwise it prints "error"
ext=""
if [ "${format}" = "GeoJSON" ]; then
ext="geojson"
elif [ "${format}" = "GPKG" ]; then
ext="gpkg"
elif [ "${format}" = "DXF" ]; then
ext="dxf"
elif [ "${format}" = "ESRI Shapefile" ]; then
ext="shp"
fi
gdal_contour -a elevation -i ${interval} -f GPKG "${dem_file}" contours.gpkg > /dev/null
ogr2ogr -dialect SQLite -where "ST_Length(geom) > 4" -simplify ${simplify} -t_srs EPSG:${epsg} -overwrite -f "${format}" output.$$ext contours.gpkg > /dev/null
if [ -e "output.$$ext" ]; then
# ESRI ShapeFile extra steps to compress into a zip archive
# we leverage Python's shutil in this case
if [ "${format}" = "ESRI Shapefile" ]; then
ext="zip"
mkdir contours/
mv output* contours/
echo "import shutil;shutil.make_archive('output', 'zip', 'contours/')" | python
fi
echo "$$(pwd)/output.$$ext"
else
echo "error"
fi