def threshold(layer, working_directory, forms): logger.debug("threshold {}".format(forms)) image_in = layer.get_source() temp = [] i = 1 if len(forms) == 1: output_filename = os.path.join( working_directory, os.path.basename(os.path.splitext(image_in)[0]) + "_threshold" + os.path.splitext(image_in)[1]) OTBApplications.bandmath_cli([image_in], forms[0], output_filename) else: for formula in forms: output_filename = os.path.join( working_directory, os.path.basename(os.path.splitext(image_in)[0]) + "_threshold" + str(i) + os.path.splitext(image_in)[1]) OTBApplications.bandmath_cli([image_in], formula, output_filename) i += 1 temp.append(output_filename) output_filename = os.path.join( working_directory, os.path.basename(os.path.splitext(image_in)[0]) + "_threshold" + os.path.splitext(image_in)[1]) OTBApplications.concatenateImages_cli(temp, output_filename) return output_filename
def angles(layer, working_directory, x, y): ident = layer.get_qgis_layer().dataProvider().identify( QgsPoint(x, y), QgsRaster.IdentifyFormatValue) logger.debug(ident) if ident is not None: attr = ident.results() logger.debug(attr) if len(attr) == layer.get_qgis_layer().bandCount(): image_in = layer.get_qgis_layer().source() output_filename = os.path.join( working_directory, os.path.basename(os.path.splitext(image_in)[0]) + "_angles" + str(x).replace(".", "dot") + "_" + str(y).replace(".", "dot") + os.path.splitext(image_in)[1]) if not os.path.isfile(output_filename): num = [] denom = [] fact = [] # acos((im1b1*1269+im1b2*1060+im1b3*974+im1b4*1576)/ # (sqrt((1269*1269+1060*1060+974*974+1576*1576)* # (im1b1*im1b1+im1b2*im1b2+im1b3*im1b3+im1b4*im1b4)))) for index in range(1, layer.get_qgis_layer().bandCount() + 1): current_band = "im1b{}".format(index) band_value = attr[index] num.append(current_band + "*" + str(band_value)) denom.append(str(band_value) + "*" + str(band_value)) fact.append(current_band + "*" + current_band) #compute denom for testing != 0 mult_denom = "({})*({})".format("+".join(denom), "+".join(fact)) #raw formula formula = "acos(({})/(sqrt({})))".format( "+".join(num), mult_denom) #add threshold formule_ = '"({}>0.0001?1/{}:0)"'.format(formula, formula) #add test on denom formula_with_test_denom_diff_0 = "({}!=0?{}:0)".format( mult_denom, formule_) logger.debug("num {}".format(num)) logger.debug("denom {}".format(denom)) logger.debug("fact {}".format(fact)) logger.debug( "formula {}".format(formula_with_test_denom_diff_0)) OTBApplications.bandmath_cli([image_in], formula_with_test_denom_diff_0, output_filename) # rlayer = manage_QGIS.addRasterLayerToQGIS( output_filename, os.path.basename(os.path.splitext(image_in)[0]) + "_angles" + str(x) + "_" + str(y), iface ) # manage_QGIS.histogram_stretching( rlayer, iface.mapCanvas()) return output_filename
def angles(layer, working_directory, x, y): ident = layer.get_qgis_layer().dataProvider().identify( QgsPoint(x, y), QgsRaster.IdentifyFormatValue) logger.debug(ident) if ident is not None: attr = ident.results() logger.debug(attr) if len(attr) == layer.get_qgis_layer().bandCount(): image_in = layer.get_qgis_layer().source() output_filename = os.path.join( working_directory, os.path.basename(os.path.splitext(image_in)[0]) + "_angles" + str(x).replace(".", "dot") + "_" + str(y).replace(".", "dot") + os.path.splitext(image_in)[1]) if not os.path.isfile(output_filename): num = [] denom = [] fact = [] # acos((im1b1*1269+im1b2*1060+im1b3*974+im1b4*1576)/ # (sqrt((1269*1269+1060*1060+974*974+1576*1576)* # (im1b1*im1b1+im1b2*im1b2+im1b3*im1b3+im1b4*im1b4)))) for index in range(1, layer.get_qgis_layer().bandCount() + 1): current_band = "im1b" + str(index) band_value = attr[index] num.append(current_band + "*" + str(band_value)) denom.append(str(band_value) + "*" + str(band_value)) fact.append(current_band + "*" + current_band) formula = "if(((" + "+".join(fact) + ") != 0)," formula += "acos(" formula += "(" + "+".join(num) + ")/" formula += "(sqrt(" formula += "(" + "+".join(denom) + ")*" formula += "(" + "+".join(fact) + ")" formula += "))" formula += "), 0)" formule_ = "\"if( " + formula + ">0.0001, 1/" + formula + ", 0)\"" logger.debug("num" + str(num)) logger.debug("denom" + str(denom)) logger.debug("fact" + str(fact)) logger.debug("formula" + str(formula)) OTBApplications.bandmath_cli([image_in], formule_, output_filename) # rlayer = manage_QGIS.addRasterLayerToQGIS( output_filename, os.path.basename(os.path.splitext(image_in)[0]) + "_angles" + str(x) + "_" + str(y), iface ) # manage_QGIS.histogram_stretching( rlayer, iface.mapCanvas()) return output_filename
def angles(layer, working_directory, x, y): ident = layer.get_qgis_layer().dataProvider().identify(QgsPoint(x, y), QgsRaster.IdentifyFormatValue) logger.debug(ident) if ident is not None: attr = ident.results() logger.debug(attr) if len(attr) == layer.get_qgis_layer().bandCount(): image_in = layer.get_qgis_layer().source() output_filename = os.path.join(working_directory, os.path.basename(os.path.splitext(image_in)[0]) + "_angles" + str(x).replace(".", "dot") + "_" + str(y).replace(".", "dot") + os.path.splitext(image_in)[1]) if not os.path.isfile(output_filename): num = [] denom = [] fact = [] # acos((im1b1*1269+im1b2*1060+im1b3*974+im1b4*1576)/ # (sqrt((1269*1269+1060*1060+974*974+1576*1576)* # (im1b1*im1b1+im1b2*im1b2+im1b3*im1b3+im1b4*im1b4)))) for index in range(1, layer.get_qgis_layer().bandCount() + 1): current_band = "im1b" + str(index) band_value = attr[index] num.append(current_band + "*" + str(band_value)) denom.append(str(band_value) + "*" + str(band_value)) fact.append(current_band + "*" + current_band) formula = "if(((" + "+".join(fact) + ") != 0)," formula += "acos(" formula += "(" + "+".join(num) + ")/" formula += "(sqrt(" formula += "(" + "+".join(denom) + ")*" formula += "(" + "+".join(fact) + ")" formula += "))" formula += "), 0)" formule_ = "\"if( " + formula + ">0.0001, 1/" + formula + ", 0)\"" logger.debug("num" + str(num)) logger.debug("denom" + str(denom)) logger.debug("fact" + str(fact)) logger.debug("formula" + str(formula)) OTBApplications.bandmath_cli([image_in], formule_, output_filename) # rlayer = manage_QGIS.addRasterLayerToQGIS( output_filename, os.path.basename(os.path.splitext(image_in)[0]) + "_angles" + str(x) + "_" + str(y), iface ) # manage_QGIS.histogram_stretching( rlayer, iface.mapCanvas()) return output_filename
def angles(layer, working_directory, x, y): ident = layer.get_qgis_layer().dataProvider().identify(QgsPoint(x, y), QgsRaster.IdentifyFormatValue) logger.debug(ident) if ident is not None: attr = ident.results() logger.debug(attr) if len(attr) == layer.get_qgis_layer().bandCount(): image_in = layer.get_qgis_layer().source() output_filename = os.path.join(working_directory, os.path.basename(os.path.splitext(image_in)[0]) + "_angles" + str(x).replace(".", "dot") + "_" + str(y).replace(".", "dot") + os.path.splitext(image_in)[1]) if not os.path.isfile(output_filename): num = [] denom = [] fact = [] # acos((im1b1*1269+im1b2*1060+im1b3*974+im1b4*1576)/ # (sqrt((1269*1269+1060*1060+974*974+1576*1576)* # (im1b1*im1b1+im1b2*im1b2+im1b3*im1b3+im1b4*im1b4)))) for index in range(1, layer.get_qgis_layer().bandCount() + 1): current_band = "im1b{}".format(index) band_value = attr[index] num.append(current_band + "*" + str(band_value)) denom.append(str(band_value) + "*" + str(band_value)) fact.append(current_band + "*" + current_band) #compute denom for testing != 0 mult_denom = "({})*({})".format("+".join(denom), "+".join(fact)) #raw formula formula = "acos(({})/(sqrt({})))".format("+".join(num), mult_denom) #add threshold formule_ = '"({}>0.0001?1/{}:0)"'.format(formula, formula) #add test on denom formula_with_test_denom_diff_0 = "({}!=0?{}:0)".format(mult_denom, formule_) logger.debug("num {}".format(num)) logger.debug("denom {}".format(denom)) logger.debug("fact {}".format(fact)) logger.debug("formula {}".format(formula_with_test_denom_diff_0)) OTBApplications.bandmath_cli([image_in], formula_with_test_denom_diff_0, output_filename) # rlayer = manage_QGIS.addRasterLayerToQGIS( output_filename, os.path.basename(os.path.splitext(image_in)[0]) + "_angles" + str(x) + "_" + str(y), iface ) # manage_QGIS.histogram_stretching( rlayer, iface.mapCanvas()) return output_filename
def brightness(layer, working_directory): # IB = sqrt(RxR+PIRxPIR) if not layer: logger.debug("Aucune layer selectionnée") else: if layer.pir and layer.red: image_in = layer.source_file logger.debug("image_in" + image_in) logger.debug(working_directory) output_filename = os.path.join(working_directory, os.path.basename(os.path.splitext(image_in)[0]) + "_brillance" + os.path.splitext(image_in)[1]) logger.debug(output_filename) if not os.path.isfile(output_filename): layer_pir = "im1b" + str(layer.pir) layer_red = "im1b" + str(layer.red) expression = "\"sqrt(" + layer_red + "*" + layer_red + "*" + layer_pir + "*" + layer_pir + ")\"" logger.debug(expression) logger.debug("image_in" + image_in) OTBApplications.bandmath_cli([image_in], expression, output_filename) return output_filename
def ndti(layer, working_directory): # SQRT(R+0.5) # NDTI= (R-G)/(R+G) if not layer: logger.debug("Aucune layer selectionnée") else: if layer.red: image_in = layer.source_file logger.debug("image_in" + image_in) output_filename = os.path.join(working_directory, os.path.basename(os.path.splitext(image_in)[0]) + "_ndti" + os.path.splitext(image_in)[1]) logger.debug(output_filename) if not os.path.isfile(output_filename): layer_red = "im1b" + str(layer.red) layer_green = "im1b" + str(layer.green) # expression = "\"sqrt(" + layer_red + "+0.5)\"" expression = "\"if((" + layer_red + "+" + layer_green + ")!=0,(" + layer_red + "-" + layer_green + ")/(" + layer_red + "+" + layer_green + "),0)\"" logger.debug(expression) logger.debug("image_in" + image_in) OTBApplications.bandmath_cli([image_in], expression, output_filename) return output_filename
def ndvi(layer, working_directory): # NDVI= (PIR-R)/(PIR+R) if not layer: logger.debug("Aucune layer selectionnée") else: if layer.pir and layer.red: image_in = layer.source_file logger.debug("image_in: " + image_in) logger.debug(working_directory) output_filename = os.path.join(working_directory, os.path.basename(os.path.splitext(image_in)[0]) + "_ndvi" + os.path.splitext(image_in)[1]) logger.debug(output_filename) if not os.path.isfile(output_filename): layer_pir = "im1b" + str(layer.pir) layer_red = "im1b" + str(layer.red) expression = "\"if((" + layer_pir + "+" + layer_red + ")!=0,(" + layer_pir + "-" + layer_red + ")/(" + layer_pir + "+" + layer_red + "),0)\"" logger.debug(expression) logger.debug("image_in" + image_in) OTBApplications.bandmath_cli([image_in], expression, output_filename) return output_filename return ""
def threshold(layer, working_directory, forms): logger.debug("threshold" + str(forms)) image_in = layer.get_source() temp = [] i = 1 if len(forms) == 1: output_filename = os.path.join(working_directory, os.path.basename(os.path.splitext(image_in)[0]) + "_threshold" + os.path.splitext(image_in)[1]) OTBApplications.bandmath_cli([image_in], forms[0], output_filename) else: for formula in forms: output_filename = os.path.join(working_directory, os.path.basename(os.path.splitext(image_in)[0]) + "_threshold" + str(i) + os.path.splitext(image_in)[1]) OTBApplications.bandmath_cli([image_in], formula, output_filename) i += 1 temp.append(output_filename) output_filename = os.path.join(working_directory, os.path.basename(os.path.splitext(image_in)[0]) + "_threshold" + os.path.splitext(image_in)[1]) OTBApplications.concatenateImages_cli(temp, output_filename) return output_filename
def brightness(layer, working_directory): # IB = sqrt(RxR+PIRxPIR) if not layer: logger.debug("Aucune layer selectionnée") else: if layer.pir and layer.red: image_in = layer.source_file logger.debug("image_in" + image_in) logger.debug(working_directory) output_filename = os.path.join( working_directory, os.path.basename(os.path.splitext(image_in)[0]) + "_brillance" + os.path.splitext(image_in)[1]) logger.debug(output_filename) if not os.path.isfile(output_filename): layer_pir = "im1b{}".format(layer.pir) layer_red = "im1b{}".format(layer.red) expression = "\"sqrt(" + layer_red + "*" + layer_red + "+" + layer_pir + "*" + layer_pir + ")\"" logger.debug(expression) logger.debug("image_in" + image_in) OTBApplications.bandmath_cli([image_in], expression, output_filename) return output_filename
def ndti(layer, working_directory): # SQRT(R+0.5) # NDTI= (R-G)/(R+G) if not layer: logger.debug("Aucune layer selectionnée") else: if layer.red: image_in = layer.source_file logger.debug("image_in" + image_in) output_filename = os.path.join( working_directory, os.path.basename(os.path.splitext(image_in)[0]) + "_ndti" + os.path.splitext(image_in)[1]) logger.debug(output_filename) if not os.path.isfile(output_filename): layer_red = "im1b{}".format(layer.red) layer_green = "im1b{}".format(layer.green) # expression = "\"sqrt(" + layer_red + "+0.5)\"" expression = "\"((" + layer_red + "+" + layer_green + ")!=0?(" + layer_red + "-" + layer_green + ")/(" + layer_red + "+" + layer_green + "):0)\"" logger.debug(expression) logger.debug("image_in" + image_in) OTBApplications.bandmath_cli([image_in], expression, output_filename) return output_filename
def ndvi(layer, working_directory): # NDVI= (PIR-R)/(PIR+R) if not layer: logger.debug("Aucune layer selectionnée") else: if layer.pir and layer.red: image_in = layer.source_file logger.debug("image_in: " + image_in) logger.debug(working_directory) output_filename = os.path.join( working_directory, os.path.basename(os.path.splitext(image_in)[0]) + "_ndvi" + os.path.splitext(image_in)[1]) logger.debug(output_filename) if not os.path.isfile(output_filename): layer_pir = "im1b{}".format(layer.pir) layer_red = "im1b{}".format(layer.red) expression = "\"((" + layer_pir + "+" + layer_red + ")!=0?(" + layer_pir + "-" + layer_red + ")/(" + layer_pir + "+" + layer_red + "):0)\"" logger.debug(expression) logger.debug("image_in" + image_in) OTBApplications.bandmath_cli([image_in], expression, output_filename) return output_filename return ""