Пример #1
0
def concatenateImages_cli(listImagesIn, outputname, options=None):
    """
    Runs the ConcatenateImages OTB application.

    Keyword arguments:
        listImagesIn     --    list of images to concatenates
        outputname     --    output image
    """

    if listImagesIn and outputname:
        command = os.path.join(prefix, "otbcli ")
        command += " ConcatenateImages "
        args = " -il " + " ".join(["\"" + f + "\"" for f in listImagesIn])
        args += " -out " + "\"" + outputname + "\""
        if options:
            args += " uint16 "

        logger.info("command: " + command)
        # os.system( command )
        # terre_image_utils.run_process(command)
        if os.name == "posix":
            # os.system( command )
            command += args
            terre_image_run_process.run_process(command)
        else:
            terre_image_run_process.run_otb_app("ConcatenateImages", args)
Пример #2
0
def kmeans_cli(image, nbClass, outputDirectory):
    """
    pass
    """
    filenameWithoutExtension = os.path.basename(os.path.splitext(image)[0])
    output = os.path.join(outputDirectory, filenameWithoutExtension +
                          "_kmeans_" + str(nbClass) + ".tif")  # + temp[index:]
    if not os.path.isfile(output):
        if image and nbClass and outputDirectory:
            command = os.path.join(prefix, "otbcli")
            command += " KMeansClassification "
            args = " -in " + "\"" + image + "\""
            args += " -out " + "\"" + output + "\""
            args += " -nc " + str(nbClass)
            args += " -rand " + str(42)

            logger.info("command: " + command)

            if os.name == "posix":
                command += args
                terre_image_run_process.run_process(command)
            else:
                terre_image_run_process.run_otb_app("KMeansClassification",
                                                    args)
    return output
Пример #3
0
def bandmath_cli(images, expression, output_filename):
    """
    This function applies otbcli_BandMath to image with the given expression

    Keyword arguments:
        image               --    raster layer to process
        expression          --    expression to apply
        outputDirectory     --    working directory
        keyword             --    keyword for output file name
    """

    command = os.path.join(prefix, "otbcli ")
    command += " BandMath "

    args = " -il "
    for image in images:
        args += "\"" + image + "\"" + " "

    args += " -exp " + str(expression)
    args += " -out " + "\"" + output_filename + "\""

    logger.info("command: " + command)
    if os.name == "posix":
        command += args
        terre_image_run_process.run_process(command)
    else:
        terre_image_run_process.run_otb_app("BandMath", args)
Пример #4
0
def gdal_translate_get_one_band(image_in, band_number, working_dir):
    """
    Runs gdal translate to get the band_number of the image_in
    TODO: working dir
    """
    output_image_one_band = os.path.join(working_dir, os.path.splitext(os.path.basename(image_in))[0] + "-b" + str(band_number) + os.path.splitext(image_in)[1])
    if not os.path.isfile(output_image_one_band):
        command_gdal = "gdal_translate -b " + str(band_number) + " " + "\"" + image_in + "\"" + " " + "\"" + output_image_one_band + "\""
        logger.info("command_gdal" + command_gdal)
        # os.system( command_gdal )
        terre_image_run_process.run_process(command_gdal)
    return output_image_one_band
Пример #5
0
def compute_overviews(filename):
    """
    Runs gdaladdo on the given filename
    """
    if not os.path.isfile(filename + ".ovr"):
        command = "gdaladdo "
        command += " -ro "
        command += "\"" + filename + "\""
        command += " 2 4 8 16"
        logger.debug("command to run" + command)
        # os.system(command)
        terre_image_run_process.run_process(command)
Пример #6
0
def get_sensor_id(image):
    currentOs = os.name

#     if currentOs == "posix":
    command = "otbcli ReadImageInfo "  # -in " + image  # + " | grep \"sensor:\""
#     else:
#         command = "otbcli ReadImageInfo -in " + image #+ " | findstr \"sensor:\""
    args = " -in " + image

    if currentOs == "posix":
        command += args
        result_sensor = terre_image_run_process.run_process(command)
    else:
        result_sensor = terre_image_run_process.run_otb_app("ReadImageInfo", args)
    if result_sensor:
        # type(result_sensor) = PyQt4.QtCore.QByteArray
        for line in str(result_sensor).splitlines():
            if "sensor" in line:
                # sensor_line = result_sensor[0]
                sensor = re.search('sensor: ([a-zA-Z \d]+)$', line)

                if sensor:
                    # group 1 parce qu'on a demande qqchose de particulier a la regexpr a cause des ()
                    sensor = sensor.group(1)
                return sensor
Пример #7
0
def get_sensor_id(image):
    currentOs = os.name

    #     if currentOs == "posix":
    command = "otbcli ReadImageInfo "  # -in " + image  # + " | grep \"sensor:\""
    #     else:
    #         command = "otbcli ReadImageInfo -in " + image #+ " | findstr \"sensor:\""
    args = " -in " + image

    if currentOs == "posix":
        command += args
        result_sensor = terre_image_run_process.run_process(command)
    else:
        result_sensor = terre_image_run_process.run_otb_app(
            "ReadImageInfo", args)
    if result_sensor:
        # type(result_sensor) = PyQt4.QtCore.QByteArray
        for line in str(result_sensor).splitlines():
            if "sensor" in line:
                # sensor_line = result_sensor[0]
                sensor = re.search('sensor: ([a-zA-Z \d]+)$', line)

                if sensor:
                    # group 1 parce qu'on a demande qqchose de particulier a la regexpr a cause des ()
                    sensor = sensor.group(1)
                return sensor
Пример #8
0
def gdal_translate_get_one_band(image_in, band_number, working_dir):
    """
    Runs gdal translate to get the band_number of the image_in
    TODO: working dir
    """
    output_image_one_band = os.path.join(
        working_dir,
        os.path.splitext(os.path.basename(image_in))[0] + "-b" +
        str(band_number) + os.path.splitext(image_in)[1])
    if not os.path.isfile(output_image_one_band):
        command_gdal = "gdal_translate -b " + str(
            band_number
        ) + " " + "\"" + image_in + "\"" + " " + "\"" + output_image_one_band + "\""
        logger.info("command_gdal" + command_gdal)
        # os.system( command_gdal )
        terre_image_run_process.run_process(command_gdal)
    return output_image_one_band
Пример #9
0
def otbcli_export_kmz(filename, working_directory):
    output_kmz = os.path.join(
        working_directory,
        os.path.basename(os.path.splitext(filename)[0]) + ".kmz")
    if not os.path.isfile(output_kmz):
        command = os.path.join(prefix, "otbcli ")
        command += "KmzExport "
        args = " -in " + "\"" + filename + "\""
        args += " -out " + "\"" + output_kmz + "\""

        logger.info("command: " + command)
        terre_image_run_process.run_process(command)
        if os.name == "posix":
            command += args
            terre_image_run_process.run_process(command)
        else:
            terre_image_run_process.run_otb_app("KmzExport", args)

    output_kmz = os.path.join(
        working_directory,
        os.path.basename(os.path.splitext(filename)[0]) + "xt.kmz")
    return output_kmz
Пример #10
0
def color_mapping_cli_ref_image(image_to_color, reference_image, working_dir):
    output_filename = os.path.join(
        working_dir,
        os.path.splitext(os.path.basename(image_to_color))
        [0]) + "colored.tif"  # + os.path.splitext(image_to_color)[0]

    if not os.path.isfile(output_filename):
        logger.info(output_filename)
        command = os.path.join(prefix, "otbcli")
        command += " ColorMapping "
        args = " -in " + "\"" + image_to_color + "\""
        args += " -out " + "\"" + output_filename + "\" uint8"
        args += " -method \"image\""
        args += " -method.image.in " + "\"" + reference_image + "\""
        logger.info("command: " + command)

        if os.name == "posix":
            command += args
            terre_image_run_process.run_process(command)
        else:
            terre_image_run_process.run_otb_app("ColorMapping", args)

    return output_filename