<?xml version="1.0" encoding="UTF-8"?>
<toolchain saga-version="2.2.0">
	<group>imagery_classification</group>
	<identifier>lczc</identifier>
	<menu absolute="true">Imagery|Classification</menu>
	<name>Local Climate Zone Classification</name>
	<author>B. Bechtel, O. Conrad (c) 2015/16</author>
	<description>
		Updates:
		[[ul]]
		[[li]][[b]]2016/08/15[[/b]] Automated filtering of Style Place Holders[[/li]]
		[[li]][[b]]2016/09/07[[/b]] added cmd line support for kml import[[/li]]
		[[/ul]]		
	</description>
	<reference>
		<authors>Bechtel, B., Alexander, P. J., Böhner, J., Ching, J., Conrad, O., Feddema, J., Gerald, M., See, L., Stewart, I.</authors>
		<year>2015</year>
		<title>Mapping local climate zones for a worldwide database of the form and function of cities</title>
		<where>ISPRS International Journal of Geo-Information, 4(1), 199-219. doi:10.3390/ijgi4010199.</where>
	</reference>

	<!-- P A R A M E T E R S -->
	<parameters>
		<!-- Input Grids -->
		<option varname="GRID_SYSTEM" type="grid_system">
			<name>Grid System</name>
		</option>
		<input varname="FEATURES" type="grid_list" parent="GRID_SYSTEM">
			<name>Features</name>
		</input>

		<option varname="GRIDDEFILE" type="file">
			<condition type="has_gui" variable="false"></condition>
			<name>grid definition for KML2shp conversion</name>
			<description>well known text, prj file - workaround for command line</description>
			<filter>Well known text|*.prj;|All Files|*.*</filter>
		</option>

		<!-- Training Areas -->
		<option varname="FILE_TRAINING" type="file">
			<name>Training Areas</name>
			<filter>KML/KMZ Files|*.kml;*.kmz|All Files|*.*</filter>
		</option>

		<!-- Classification -->
		<option varname="CLASSIFIER" type="choice">
			<name>Classifier</name>
			<choices>Random Forest (ViGrA)|Random Forest (OpenCV)|Normal Bayes|Support Vector Machine|Artificial Neural Network</choices>
			<value>0</value>
		</option>

		<!-- Results -->
		<option varname="CLASS_DEF_SRC" type="choice">
			<name>Class Definition</name>
			<choices>built-in|from file</choices>
			<value>0</value>
		</option>
		<option varname="CLASS_DEF_FILE" type="file" parent="CLASS_DEF_SRC">
			<condition value="1" type="=">CLASS_DEF_SRC</condition>
			<name>Class Definition File</name>
			<filter>Table Files|*.txt;*.dbf;*csv|All Files|*.*</filter>
		</option>

		<output varname="LCZC" type="grid" parent="GRID_SYSTEM">
			<name>LCZC</name>
			<output_name>LCZC</output_name>
		</output>
		<option varname="LCZC_FILE" type="file" save="true" parent="LCZC">
			<name>KMZ File</name>
			<description>Export to KMZ file (Google Earth). Ignored if empty.</description>
			<filter>KMZ Files|*.kmz|All Files|*.*</filter>
		</option>

		<output varname="LCZC_FILTERED" type="grid" optional="true" parent="GRID_SYSTEM">
			<name>LCZC (Filtered)</name>
			<output_name>LCZC (Filtered)</output_name>
		</output>
		<option varname="FILE_FILTERED_LCZC" type="file" save="true" parent="LCZC_FILTERED">
			<condition type="exists">LCZC_FILTERED</condition>
			<name>KMZ File</name>
			<description>Export to KMZ file (Google Earth). Ignored if empty.</description>
			<filter>KMZ Files|*.kmz|All Files|*.*</filter>
		</option>
		<option varname="FILTER_RADIUS" type="integer" parent="LCZC_FILTERED">
			<condition type="exists">LCZC_FILTERED</condition>
			<name>Majority Filter Radius</name>
			<value min="1">3</value>
		</option>
	</parameters>
	
	<!-- T O O L S -->
	<tools>
		<!-- P R E P R O C E S S I N G -->
		<tool library="io_gdal" tool="3" name="OGR: Import Vector Data">
			<output id="SHAPES">TRAINING_SINGLE</output>
			<option id="FILES" varname="true">FILE_TRAINING</option>
			<option id="GEOM_TYPE">9</option>
		</tool>

		<tool library="shapes_tools" tool="2" name="Merge Layers">
			<input  id="INPUT">TRAINING_SINGLE</input>
			<option id="SRCINFO">TRUE</option>
			<option id="MATCH">TRUE</option>
			<output id="MERGED">TRAINING_MERGED</output>
		</tool>

		<tool library="shapes_polygons" tool="7" name="Polygon Shape Indices">
			<input id="SHAPES">TRAINING_MERGED</input>
		</tool>

		<tool library="grid_tools" tool="32" name="Select Grid from List">
			<input  id="GRIDS">FEATURES</input>
			<output id="GRID">FEATURE</output>
			<option id="INDEX">0</option>
		</tool>

		<condition type="has_gui" variable="true"><if>
			<!-- with GUI - pick definition from Grid -->
			<tool library="pj_proj4" tool="2" name="Coordinate Transformation (Shapes)">
				<input  id="CRS_PICKER.CRS_GRID">FEATURE</input>
			<!--<input	id="PICK" parms="CRS_GRID">FEATURE</input>-->
				<input	id="SOURCE">TRAINING_MERGED</input>
				<output id="TARGET">TRAINING_PROJ</output>
			</tool>
		</if><else>
			<!-- without GUI - pick definition from prj file -->
			<tool library="pj_proj4" tool="2" name="Coordinate Transformation (Shapes)">
				<option	id="CRS_METHOD">2</option>
				<option	id="CRS_FILE" varname="true">GRIDDEFILE</option>
				<input	id="SOURCE">TRAINING_MERGED</input>
				<output id="TARGET">TRAINING_PROJ</output>
			</tool>
		</else></condition>

		<!-- C L A S S I F I C A T I O N -->
		<condition variable="CLASSIFIER" type="=" value="0">
			<tool library="imagery_vigra" tool="9" name="Random Forest Classification (ViGrA)">
				<input	id="FEATURES">FEATURES</input>
				<input	id="TRAINING">TRAINING_PROJ</input>
				<option id="FIELD">Source</option>
				<option id="LABEL_AS_ID">TRUE</option>
				<option id="DO_MRMR">FALSE</option>
				<option id="RF_TREE_COUNT" varname="true">RF_TREE_COUNT</option>
				<option id="RF_TREE_SAMPLES">1</option>
				<output id="CLASSES">LCZC</output>
			</tool>
		</condition>

		<condition variable="CLASSIFIER" type="=" value="1">
			<tool library="imagery_opencv" tool="10" name="Random Forest Classification">
				<input  id="FEATURES">FEATURES</input>
				<option id="NORMALIZE">false</option>
				<output id="CLASSES">CLASSES</output>
				<output id="CLASSES_LUT">CLASSES_LUT</output>
				<option id="MODEL_TRAIN">0</option>
				<input  id="TRAIN_AREAS">TRAINING_PROJ</input>
				<option id="TRAIN_CLASS">Source</option>

				<option id="MAX_DEPTH">32</option>
				<option id="MIN_SAMPLES">2</option>
				<option id="MAX_CATEGRS">17</option>
				<option id="1SE_RULE">true</option>
				<option id="TRUNC_PRUNED">true</option>
				<option id="REG_ACCURACY">0.01</option>
				<option id="ACTIVE_VARS">0</option>
			</tool>
		</condition>

		<condition variable="CLASSIFIER" type="=" value="2">
			<tool library="imagery_opencv" tool="5" name="Normal Bayes Classification">
				<input  id="FEATURES">FEATURES</input>
				<option id="NORMALIZE">false</option>
				<output id="CLASSES">CLASSES</output>
				<output id="CLASSES_LUT">CLASSES_LUT</output>
				<option id="MODEL_TRAIN">0</option>
				<input  id="TRAIN_AREAS">TRAINING_PROJ</input>
				<option id="TRAIN_CLASS">Source</option>
			</tool>
		</condition>

		<condition variable="CLASSIFIER" type="=" value="3">
			<tool library="imagery_opencv" tool="7" name="Support Vector Machine Classification">
				<input  id="FEATURES">FEATURES</input>
				<option id="NORMALIZE">false</option>
				<output id="CLASSES">CLASSES</output>
				<output id="CLASSES_LUT">CLASSES_LUT</output>
				<option id="MODEL_TRAIN">0</option>
				<input  id="TRAIN_AREAS">TRAINING_PROJ</input>
				<option id="TRAIN_CLASS">Source</option>

				<option id="SVM_TYPE">0</option>
				<option id="C">5</option>
				<option id="NU">0.5</option>
				<option id="P">0.5</option>
				<option id="KERNEL">5</option>
				<option id="COEF0">1</option>
				<option id="DEGREE">0.5</option>
				<option id="GAMMA">5</option>
			</tool>
		</condition>

		<condition variable="CLASSIFIER" type="=" value="4">
			<tool library="imagery_opencv" tool="11" name="Artificial Neural Network Classification">
				<input  id="FEATURES">FEATURES</input>
				<option id="NORMALIZE">false</option>
				<output id="CLASSES">CLASSES</output>
				<output id="CLASSES_LUT">CLASSES_LUT</output>
				<option id="MODEL_TRAIN">0</option>
				<input  id="TRAIN_AREAS">TRAINING_PROJ</input>
				<option id="TRAIN_CLASS">Source</option>

				<option id="ANN_LAYERS">3</option>
				<option id="ANN_NEURONS">5</option>
				<option id="ANN_MAXITER">300</option>
				<option id="ANN_EPSILON">0.0000001192092896</option>
				<option id="ANN_ACTIVATION">1</option>
				<option id="ANN_ACT_ALPHA">1</option>
				<option id="ANN_ACT_BETA">1</option>
				<option id="ANN_PROPAGATION">1</option>
				<option id="ANN_RP_DW0">0</option>
				<option id="ANN_RP_DW_PLUS">1.2</option>
				<option id="ANN_RP_DW_MINUS">0.5</option>
				<option id="ANN_RP_DW_MIN">0.1</option>
				<option id="ANN_RP_DW_MAX">1.1</option>
				<option id="ANN_BP_DW">0.1</option>
				<option id="ANN_BP_MOMENT">0.1</option>
			</tool>
		</condition>

		<condition variable="CLASSIFIER" type="!" value="0">
			<tool library="grid_tools" tool="15" name="Reclassify Grid Values">
				<input  id="INPUT">CLASSES</input>
				<output id="RESULT">LCZC</output>
				<option id="METHOD">3</option>
				<option id="TOPERATOR">1</option>
				<input  id="RETAB_2">CLASSES_LUT</input>
				<option id="F_MIN">VALUE</option>
				<option id="F_MAX">VALUE</option>
				<option id="F_CODE">CLASS</option>
				<option id="NODATAOPT">false</option>
				<option id="OTHEROPT">false</option>
				<option id="RESULT_TYPE">9</option>
				<option id="RESULT_NODATA_CHOICE">0</option>
			</tool>
		</condition>

		<!-- P O S T P R O C E S S I N G -->
		<!-- create look-up table for classification -->
		<condition variable="CLASS_DEF_SRC" type="=" value="1">
			<condition variable="CLASS_DEF_FILE" type="not_equal" value="">
				<tool library="io_table" tool="1" name="Import Text Table">
					<option id="FILENAME" varname="true">CLASS_DEF_FILE</option>
					<output id="TABLE">CLASS_DEF</output>
				</tool>
			</condition>
		</condition>
		
		<condition type="not_exists" variable="CLASS_DEF">
			<tool library="grid_visualisation" tool="11" name="Create a Table from Look-up Table">
				<output id="TABLE">CLASS_DEF</output>
				<option id="LUT"><OPTION type="static_table" id="LUT" name="Lookup Table">
					<FIELDS>
						<FIELD type="COLOR" >Color</FIELD>
						<FIELD type="STRING">Name</FIELD>
						<FIELD type="STRING">Description</FIELD>
						<FIELD type="DOUBLE">Minimum</FIELD>
						<FIELD type="DOUBLE">Maximum</FIELD>
					</FIELDS><RECORDS>
						<RECORD><FIELD>     140</FIELD><FIELD >1. compHR   </FIELD><FIELD   >compHR</FIELD><FIELD>  1</FIELD><FIELD>  1</FIELD></RECORD>
						<RECORD><FIELD>     209</FIELD><FIELD >2. compMR   </FIELD><FIELD   >compMR</FIELD><FIELD>  2</FIELD><FIELD>  2</FIELD></RECORD>
						<RECORD><FIELD>     255</FIELD><FIELD >3. compLR   </FIELD><FIELD   >compLR</FIELD><FIELD>  3</FIELD><FIELD>  3</FIELD></RECORD>
						<RECORD><FIELD>   19903</FIELD><FIELD >4. openHR   </FIELD><FIELD   >openHR</FIELD><FIELD>  4</FIELD><FIELD>  4</FIELD></RECORD>
						<RECORD><FIELD>   26367</FIELD><FIELD >5. openMR   </FIELD><FIELD   >openMR</FIELD><FIELD>  5</FIELD><FIELD>  5</FIELD></RECORD>
						<RECORD><FIELD> 5609983</FIELD><FIELD >6. openLR   </FIELD><FIELD   >openLR</FIELD><FIELD>  6</FIELD><FIELD>  6</FIELD></RECORD>
						<RECORD><FIELD>  388858</FIELD><FIELD >7. light    </FIELD><FIELD    >light</FIELD><FIELD>  7</FIELD><FIELD>  7</FIELD></RECORD>
						<RECORD><FIELD>12369084</FIELD><FIELD >8. largeLow </FIELD><FIELD >largeLow</FIELD><FIELD>  8</FIELD><FIELD>  8</FIELD></RECORD>
						<RECORD><FIELD>11193599</FIELD><FIELD >9. sparse   </FIELD><FIELD   >sparse</FIELD><FIELD>  9</FIELD><FIELD>  9</FIELD></RECORD>
						<RECORD><FIELD> 5592405</FIELD><FIELD>10. industr  </FIELD><FIELD  >industr</FIELD><FIELD> 10</FIELD><FIELD> 10</FIELD></RECORD>
						<RECORD><FIELD>   27136</FIELD><FIELD >A. denseTree</FIELD><FIELD>denseTree</FIELD><FIELD>101</FIELD><FIELD>101</FIELD></RECORD>
						<RECORD><FIELD>   43520</FIELD><FIELD >B. scatTree </FIELD><FIELD >scatTree</FIELD><FIELD>102</FIELD><FIELD>102</FIELD></RECORD>
						<RECORD><FIELD> 2458980</FIELD><FIELD >C. bush     </FIELD><FIELD     >bush</FIELD><FIELD>103</FIELD><FIELD>103</FIELD></RECORD>
						<RECORD><FIELD> 7986105</FIELD><FIELD >D. lowPlant </FIELD><FIELD >lowPlant</FIELD><FIELD>104</FIELD><FIELD>104</FIELD></RECORD>
						<RECORD><FIELD>       0</FIELD><FIELD >E. paved    </FIELD><FIELD    >paved</FIELD><FIELD>105</FIELD><FIELD>105</FIELD></RECORD>
						<RECORD><FIELD>11466747</FIELD><FIELD >F. soil     </FIELD><FIELD     >soil</FIELD><FIELD>106</FIELD><FIELD>106</FIELD></RECORD>
						<RECORD><FIELD>16738922</FIELD><FIELD >G. water    </FIELD><FIELD    >water</FIELD><FIELD>107</FIELD><FIELD>107</FIELD></RECORD>
					</RECORDS>
				</OPTION></option>
			</tool>
		</condition>
			
		<!-- LCZC visualization and storing to file -->
		<condition type="has_gui" variable="true">
			<tool library="grid_visualisation" tool="10" name="Select Look-up Table for Grid Visualization">
				<input id="GRID">LCZC</input>
				<input id="LUT">CLASS_DEF</input>
			</tool>
		</condition>

		<condition variable="LCZC_FILE" type="not_equal" value="">
			<tool library="io_grid_image" tool="2" name="Export Grid to KML">
				<input	id="GRID">LCZC</input>
				<option	id="LUT"  varname="true">CLASS_DEF</option>
				<option id="FILE" varname="true">LCZC_FILE</option>
				<option id="COLOURING">3</option>
				<option id="RESAMPLING">false</option>
				<option id="OUTPUT">2</option>
			</tool>
		</condition>

		<!-- LCZC majority filtering, visualization and storing to file -->
		<condition type="exists" variable="LCZC_FILTERED">
			<tool library="grid_filter" tool="6" name="Majority Filter">
				<input	id="INPUT">LCZC</input>
				<option id="KERNEL_RADIUS" varname="true">FILTER_RADIUS</option>
				<output id="RESULT">LCZC_FILTERED</output>
			</tool>

			<condition type="has_gui" variable="true">
				<tool library="grid_visualisation" tool="10" name="Select Look-up Table for Grid Visualization">
					<input id="GRID">LCZC_FILTERED</input>
					<input id="LUT">CLASS_DEF</input>
				</tool>
			</condition>

			<condition type="not_equal" value="" variable="FILE_FILTERED_LCZC">
				<tool library="io_grid_image" tool="2" name="Export Grid to KML">
					<input	id="GRID">LCZC_FILTERED</input>
					<option	id="LUT"  varname="true">CLASS_DEF</option>
					<option id="FILE" varname="true">FILE_FILTERED_LCZC</option>
					<option id="COLOURING">3</option>
					<option id="RESAMPLING">false</option>
					<option id="OUTPUT">2</option>
				</tool>
			</condition>
		</condition>
	</tools>
</toolchain>
