-
Notifications
You must be signed in to change notification settings - Fork 0
/
ABlccscript.txt
158 lines (98 loc) · 6.9 KB
/
ABlccscript.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#################
## Classification for Abisko
###############
# Author Matthias Siewert
# March 2016
########################################
# This script generates a Land cover classification using an object based approach.
# The classification result is of very high resolution at 1m with a minimum patch size of 130m2
########################
##############
### START ###
##############
cd Abisko/GIS_RS_data/DSM/
##### Step 1: merge The Illuminationcorrected OrthoPhoto with the Dem at 1m scale
gdal_merge.py -separate Raster/ABsdDEM2m.tif Raster/ABorthoIlluCor.tif -o temp/ABlccCompo.tif -v -ps 1 1
###########################################################good
#Segmentation workflow
# make it smooth
otbcli_MeanShiftSmoothing -in temp/ABlccCompo.tif -fout temp/LCC/ABorthoSDsegfil.tif -foutpos temp/LCC/ABorthoSDsegfilspat.tif -spatialr 5 -ranger 13 -thres 0.1 -maxiter 100 -modesearch 0
#devide into segments
otbcli_LSMSSegmentation -in temp/LCC/ABorthoSDsegfil.tif -inpos tempSegTemp//ABorthoSDsegfilspat.tif -out temp/LCC/Segmentation.tif uint32 -spatialr 5 -ranger 13 -minsize 0
#merge too small segments
otbcli_LSMSSmallRegionsMerging -in temp/LCC/ABorthoSDsegfil.tif -inseg temp/LCC/Segmentation.tif -out temp/LCC/Segmentation_merged.tif uint32 -minsize 130
#make a segemented vector file use original image
#otbcli_LSMSVectorization -in temp/ABlccCompo.tif -inseg temp/LCC/Segmentation_merged.tif -out temp/LCC/ABdem_orthoIlluCor_seg.shp
######################################################################
#make a new composite with the tagret input layers for the classifcation; make sure to have same pixelsize as above:
#gdal_merge.py -separate temp/ABlccCompo.tif temp/ABspot5IlluCorr.tiff -o temp/LCC/ABlccCompo_inputlayers.tif
gdal_merge.py -separate temp/ABlccCompo.tif temp/ABspot5IlluCorr.tiff temp/ABspotndvi.tif temp/ABspotsavi.tif temp/AB_NIRSWIR.tif temp/DEMderivs/ABslope2m.tif -o temp/LCC/ABlccCompo_inputlayers.tif
#now segment this image instead
otbcli_LSMSVectorization -in temp/LCC/ABlccCompo_inputlayers.tif -inseg temp/LCC/Segmentation_merged.tif -out temp/LCC/ABsegmnAlllayers130.shp
#copy the file to avaoid overwrite
ogr2ogr -a_srs EPSG:3006 temp/LCC/ABsegm.shp temp/LCC/ABsegmnAlllayers130.shp
#######################################
#Classification workflow
#Use QGIS Join attributes by location tool to koin the segments with the training files.
#Call the resulting file:
temp/LCC/ABsegm_trained.shp
# Calculate statistics for both the training set and for the segmentation results
otbcli_ComputeOGRLayersFeaturesStatistics -inshp temp/LCC/ABsegm_trained.shp -outstats temp/LCC/segmentation_merged_train.xml -feat meanB0 meanB1 meanB2 meanB3 meanB4 meanB5 meanB6 meanB7 meanB8 meanB9 meanB10 meanB11
otbcli_ComputeOGRLayersFeaturesStatistics -inshp temp/LCC/ABsegm.shp -outstats temp/LCC/segmentation_merged.xml -feat meanB0 meanB1 meanB2 meanB3 meanB4 meanB5 meanB6 meanB7 meanB8 meanB9 meanB10 meanB11
# now train the classifier
otbcli_TrainOGRLayersClassifier -inshp temp/LCC/ABsegm_trained.shp -instats temp/LCC/segmentation_merged_train.xml -outsvm temp/LCC/svmModel.svm -feat meanB0 meanB1 meanB2 meanB3 meanB4 meanB5 meanB6 meanB7 meanB8 meanB9 meanB10 meanB11 -cfield TrainInt
otbcli_OGRLayerClassifier -inshp temp/LCC/ABsegm.shp -instats temp/LCC/segmentation_merged_train.xml -insvm temp/LCC/svmModel.svm -feat meanB0 meanB1 meanB2 meanB3 meanB4 meanB5 meanB6 meanB7 meanB8 meanB9 meanB10 meanB11 -cfield predicted9
###############################
###### Water mask ####
###############################
#copy the file to avaoid overwrite
ogr2ogr temp/LCC/ABwater.shp temp/LCC/ABsegmnAlllayers130.shp
#######################################
#Classification workflow
#Use QGIS Join attributes by location tool to koin the segments with the training files.
#Call the resulting file:
temp/LCC/ABwater_trained.shp
# Calculate statistics for both the training set and for the segmentation results
otbcli_ComputeOGRLayersFeaturesStatistics -inshp temp/LCC/ABwater_trained.shp -outstats temp/LCC/segmentation_merged_train.xml -feat meanB1 meanB11
otbcli_ComputeOGRLayersFeaturesStatistics -inshp temp/LCC/ABwater.shp -outstats temp/LCC/segmentation_merged.xml -feat meanB1 meanB11
# now train the classifier
otbcli_TrainOGRLayersClassifier -inshp temp/LCC/ABwater_trained.shp -instats temp/LCC/segmentation_merged_train.xml -outsvm temp/LCC/svmModel.svm -feat meanB1 meanB11 -cfield TrainInt
otbcli_OGRLayerClassifier -inshp temp/LCC/ABwater.shp -instats temp/LCC/segmentation_merged_train.xml -insvm temp/LCC/svmModel.svm -feat meanB1 meanB11 -cfield predicted
#########
# Dissolve:
### doesn*t work for some reason! # use Saga instead
ogr2ogr Water/ABwatermaskDis.shp Water/ABwatermaskAdj.shp -dialect sqlite -sql "SELECT ST_Union(Geometry), predicted FROM ABwatermaskAdj GROUP BY predicted"
gdal_rasterize -a predicted -tr 1.0 1.0 -l ABwatermaskAdj Water/ABwatermaskAdj.shp Water/ABwatermaskDis.tif
gdal_polygonize.py Water/ABwatermaskDis.tif -f "ESRI Shapefile" Water/ABwatermaskDisTif.shp WaterMask
###############################
###### Water mask END ####
###############################
###############################
###### Final processing ####
###############################
# Rasterize the the final lcc result and do all merging and clipping with the raster.
# If you need the LCC as a vector, then vectorize it in the end.
gdalwarp out/M2m.tif DSM/temp/DEMderivs/ABDEM2mb.tif -tr 2 2 -s_srs EPSG:3006
### Dissolve :
### Use SagaGIS for dissolve, goes much much faster!
v.db.update map=ABlccAnthOR@ABlss layer=1 column=Class query_column=b_cat+a_Class where="CASE WHEN b_cat > 0 THEN 15 ELSE a_Class end"
# the following did not work in cmd but worked in qgis directly
saga_cmd shapes_polygons 5 -POLYGONS temp/LCC/ABLCCfinal.shp -FIELD_1 Class -DISSOLVED temp/LCC/ABlcc.shp
###############################
###### Done ####
###############################
transfer to multipart first
#Union of the anthor layer#
# seems to have worked
saga_cmd shapes_polygons 17 -A temp/LCC/ABfinallccsagadis.shp -B Vector/ABanthro.shp -RESULT temp/LCC/ABlccSagaDisAnthSPLIT 1.shp -SPLIT 1
#Union of the anthor layer#
saga_cmd shapes_polygons 17 -A temp/LCC/ABfinallccsagadis.shp -B Vector/ABanthro.shp -RESULT temp/LCC/ABlccSagaDisAnthSplit0.shp -SPLIT 0
# Dissolve again
saga_cmd shapes_polygons 5 -POLYGONS temp/LCC/ABlccSagaDisAnth.shp -FIELD_1 ClassFinal -DISSOLVED temp/LCC/ABlccSagaDisAnthDis.shp
#Module Polygon multi Parts to Separate Polygons
saga_cmd shapes_polygons 10 -POLYGONS temp/LCC/ABlccSagaDisAnth.shp -PARTS temp/LCC/ABlccSagaDisAnthMP.shp
Copied label by hand from ABLCCfinal.shp
# clean the file using self-intersect
saga_cmd shapes_polygons 12 -POLYGONS temp/LCC/ABfinallccsagadis.shp -ID Class -INTERSECT temp/LCC/ABfinallccsagadisClean.shp
# Then dissolve
saga_cmd shapes_polygons 5 -POLYGONS temp/LCC/ABlccSagaDisAnthDisInter.shp -FIELD_1 ClassFinal -DISSOLVED temp/LCC/ABlccSagaDisAnthInterDis.shp