MapInfo Pro

 View Only
  • 1.  Raster SDK merge method in Python

    Posted 08-18-2020 10:01
    Edited by Seydou DiopMena 08-18-2020 10:03
    Hi everyone,

    I am testing the python integration in MapInfo and I was trying to use the method merge (MapInfo.RasterEngine.Operations ) but I get this error :

    "TypeError : No method matches given arguments for Merge: (<class 'list'>, <class 'int'>, <class 'str'>, <class 'str'>, <class 'int'>, <class 'int'>, <class 'int'>)"

    It seems my input parameters are at fault, however since there is no python documentation I don't kow which one of the parameters is not correct.
    I was trying to replicate the same parameters as the one that are on the .NET documentation :
    This is my code :
    RasterProcessing.Merge(gridList,0, strOutFilePath, DriverIDExtensions.GetString(DriverID.MRR),2, 0, 2)
    variable gridList is a list of strings and the variable strOutFilePath is a string
    My questions are :

    -Does somebody have an example of the merge method used in python ? 
    -Does anybody knows the exact python data type that need ot be put in parameters for the merge method ?

    Thanks in advance !


    Seydou DiopMena
    Quebec QC

  • 2.  RE: Raster SDK merge method in Python

    Posted 08-19-2020 00:18
    Edited by Anshul Goel 08-19-2020 02:50
    Hi Seydou,

    Try the below sample code for raster Merge operation.
    ### Category: Raster Operation Merge
    import clr
    import sys
    from os.path import abspath, join, dirname, exists
    from System import UInt32
    from MapInfo.RasterEngine.IO import DriverIDExtensions, DriverID
    from MapInfo.RasterEngine.Operations import RasterProcessing
    from MapInfo.RasterEngine.Common import MergeType, RasterResampleMethod, MergeOperator, RasterCreationOptions, MergeMultiResolutionMode
    from MapInfo.RasterEngine.Common import RasterApiOptions, RasterCompressionType, RasterCompressionOptions, RasterEnvelope
    cwd = dirname(__file__)
    inputFile1 = abspath(join(cwd, "..\\Data\\SeattleElevation.grd"))
    inputFile2 = abspath(join(cwd, "..\\Data\\seattleelevation_shifted_reprojected.grd"))
    outputFile = abspath(join(cwd, "..\\Data\\SeattleMerge.mrr"))
    outputFileTab = abspath(join(cwd, "..\\Data\\"))
    inputFiles = [inputFile1, inputFile2]
    mergeOffset = [0.0, 0.0]
    primaryRasterIndex = UInt32(0)
    outputRasterDriverID = DriverIDExtensions.GetString(DriverID.MRR)
    mergeOperator = MergeOperator.Stamp
    mergeType = MergeType.Union
    rasterResampleMethod = RasterResampleMethod.Nearest
    creationOptions = RasterCreationOptions(RasterCompressionOptions(RasterCompressionType.LZMA, 5), -1)
    apiOptions = RasterApiOptions()
    apiOptions.CreationOptions = creationOptions
    rasterEnvelope = RasterEnvelope(501971.54, 5233455.52, 584719.71, 5304829.39)
    RasterProcessing.Merge(inputFiles, primaryRasterIndex, outputFile, outputRasterDriverID, 
    mergeOperator, mergeType, rasterResampleMethod, False, MergeMultiResolutionMode.OptimumMinimum , 
    rasterEnvelope, apiOptions, None)
    if exists(outputFile) and exists(outputFileTab):
            table = pro.Catalog.OpenTable(outputFileTab)
            if table:
                do('map from {}'.format(table.Alias))


    Anshul Goel
    Knowledge Community Shared Account
    Shelton CT

  • 3.  RE: Raster SDK merge method in Python

    Posted 08-19-2020 09:20
    Hi Anshul,

    Thank you for the code example, it worked . It was my primaryIndex parameter that had to be forced with Uint32() 

    Thanks again


    Seydou DiopMena
    Quebec QC