[OTB Courses] [Feature] Add command to compute compactness using OGR tools
An alternative to QGIS to compute compactness on polygons in the segmentation exercise is the OGR tools (ogr2ogr and ogrinfo). Note that the current method in the exercise does not seem to work with qgis 3.
Below the script that could be elaborate by the students in the exercise(and provided in the solutions)
# convert segments to spatialite
ogr2ogr -f SQLite segments.sqlite segments.shp -nln segments -dsco
SPATIALITE=YES
# add a compactness column
ogrinfo -dialect SQLite -sql 'ALTER TABLE segments ADD COLUMN
compactness DECIMAL(10,5)' segments.sqlite
# update the compactness with the calculation
ogrinfo -dialect SQLite -sql 'UPDATE segments SET compactness =
sqrt(ST_Area(Geometry))/ST_Perimeter(Geometry)' segments.sqlite
Edited by Manuel Grizonnet