Ejemplo n.º 1
0
def otbcli_export_kmz(filename, working_directory, warning_size=0):
    """
    Returns the output of KmzExport
    Args:
        filename:
        working_directory:
        warning_size:

    Returns:

    """
    output_kmz = os.path.join(working_directory, os.path.basename(os.path.splitext(filename)[0]) + ".kmz")
    if not os.path.isfile(output_kmz):
        # args = u' -in "{}" -out "{}"'.format(filename, output_kmz)
        # if warning_size != 0:
        #     args += " -tilesize {}".format(warning_size)

        list_args = ["-in", filename, "-out", output_kmz] + (["-tilesize", str(warning_size)] if warning_size != 0 else [])

        args = get_osgeo_command("", list_args)


        command = get_otb_command("KmzExport", args)
        logger.info("command: " + command)
        TerreImageProcess().run_process(command)
        output_kmz = os.path.join(working_directory, os.path.basename(os.path.splitext(filename)[0]) + "xt.kmz")
        return output_kmz
Ejemplo n.º 2
0
def ComputeLabelImagePopulation_cli(im1, im2, out):
    """

    Args:
        im1:
        im2:

    Returns:

    """
    args = u'-in1 "{}" -in2 "{}" -out "{}"'.format(im1, im2, out)
    command = get_otb_command("ComputeLabelImagePopulation", args)
    result = TerreImageProcess().run_process(command)
    return result
Ejemplo n.º 3
0
def classification_map_regularization_cli(out, outregul):
    """
    Returns the output of OTB Application ClassificationMapRegularization
    Args:
        image_in:

    Returns:

    """

    args = u'-io.in "{}" -io.out "{}" -ip.radius 1 -ip.suvbool false'.format(out, outregul)
    command = get_otb_command("ClassificationMapRegularization", args)
    result = TerreImageProcess().run_process(command)
    return result
Ejemplo n.º 4
0
def image_classifier_cli(vrtfile, outstatfile, outsvmfile, out):
    """
    Returns the output of OTB Application ImageClassifier
    Args:
        image_in:

    Returns:

    """

    args = u'-in "{}" -imstat "{}" -model "{}" -out "{}"'.format(vrtfile, outstatfile, outsvmfile, out)
    command = get_otb_command("ImageClassifier", args)
    result = TerreImageProcess().run_process(command)
    return result
Ejemplo n.º 5
0
def compute_statistics_cli(image_in, xml_output):
    """
    Returns the output of OTB Application ComputeImagesStatistics
    Args:
        image_in:

    Returns:

    """

    args = u' -il "{}" -out "{}"'.format(image_in, xml_output)
    command = get_otb_command("ComputeImagesStatistics", args)
    result = TerreImageProcess().run_process(command)
    return result
Ejemplo n.º 6
0
def read_image_info_cli(image_in):
    """
    Returns the output of OTB Application ReadImageInfo
    Args:
        image_in:

    Returns:

    """

    args = u' -in "%s"'%(unicode(image_in))
    command = get_otb_command("ReadImageInfo", args)
    result = TerreImageProcess().run_process(command)
    return result
Ejemplo n.º 7
0
def ImageEnvelope_cli(image_in, vector_out, epsg_code=""):
    """

    Args:
        im1:
        im2:

    Returns:

    """
    args = u'-in "{}" -out "{}"'.format(image_in, vector_out)
    if epsg_code:
        args += u' -proj "{}"'.format(epsg_code)
    command = get_otb_command("ImageEnvelope", args)
    result = TerreImageProcess().run_process(command)
    return result
Ejemplo n.º 8
0
def color_mapping_cli_ref_image(image_to_color, reference_image, working_dir):
    terre_image_logging.display_parameters(locals(), "color_mapping_cli_ref_image", logger)
    output_filename = os.path.join(working_dir, os.path.splitext(os.path.basename(image_to_color))[0] + "colored.tif")

    if not os.path.isfile(output_filename):
        logger.info(output_filename)
        command = os.path.join(prefix, "otbcli")
        command += " ColorMapping "
        # args = u' -in "{}" -out "{}" uint8 -method "image" -method.image.in "{}" '.format(image_to_color,
        #                                                                             output_filename,
        #                                                                             reference_image)
        args = get_osgeo_command("", ["-in", image_to_color, "-out", output_filename, "uint8",
                                      "-method", "image", "-method.image.in", reference_image])
        command = get_otb_command("ColorMapping", args)
        logger.info("command: " + command)
        TerreImageProcess().run_process(command)
    return output_filename
Ejemplo n.º 9
0
def kmeans_cli(image, nbClass, outputDirectory):
    """
    pass
    """
    terre_image_logging.display_parameters(locals(), "kmeans_cli", logger)
    filenameWithoutExtension = os.path.basename(os.path.splitext(image)[0])
    output = os.path.join(outputDirectory, u"{}_kmeans_{}.tif".format(filenameWithoutExtension, nbClass))  # + temp[index:]
    if not os.path.isfile(output):
        if image and nbClass and outputDirectory:
            # args = u' -in "{}" -out "{}" -nc {} -rand {} '.format(image,
            #                                                       output,
            #                                                       nbClass,
            #                                                       42)
            args = get_osgeo_command("", ["-in", image, "-out", output, "-nc", str(nbClass), "-rand", "42"])
            command = get_otb_command("KMeansClassification", args)
            logger.info("command: " + command)
            TerreImageProcess().run_process(command)
    return output
Ejemplo n.º 10
0
def train_image_classifier_cli(vrtfile, vd, outstatfile, outsvmfile, confmat):
    """
    Returns the output of OTB Application TrainImagesClassifier
    Args:
        image_in:

    Returns:

    """
    args = u' -io.il "{}" -io.vd "{}" -io.imstat "{}" -io.out "{}"' \
           u' -io.confmatout "{}" -classifier libsvm -sample.vtr 0.1'.format(vrtfile,
                                                                            vd,
                                                                            outstatfile,
                                                                            outsvmfile,
                                                                            confmat)
    command = get_otb_command("TrainImagesClassifier", args)
    result = TerreImageProcess().run_process(command)
    return result
Ejemplo n.º 11
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:
        # args = u' -il {}'.format(" ".join(["\"" + f + "\"" for f in listImagesIn]))
        # args += u' -out "{}"'.format(outputname)

        args = get_osgeo_command("", ["-il"] + listImagesIn + ["-out", outputname, "uint16" if options else ""])
        # if options:
            # args += u" uint16 "

        command = get_otb_command("ConcatenateImages", args)
        logger.info("command: " + command)
        TerreImageProcess().run_process(command)
Ejemplo n.º 12
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
    """

    # args = " -il "
    # for image in images:
    #     args += u'"{}" '.format(image)

    # args += u'-exp {} -out "{}"' .format(expression, output_filename)
    args = get_osgeo_command("", ["-il"] + images + ["-exp", expression, "-out", output_filename])

    command = get_otb_command("BandMath", args)
    logger.info("command: " + command)
    TerreImageProcess().run_process(command)