MapInfo Pro

 View Only
  • 1.  Python Raster Stamp Tool

    Posted 02-29-2024 12:25

    Is there documentation on how to use the Create Raster Stamp tool in Python? I have several location centroid point files that need to be converted to a raster and want to automate the process through a python tool, but I'm struggling to find any documentation on the Create Raster tool.


    Tom Avakian
    Knowledge Community Shared Account

  • 2.  RE: Python Raster Stamp Tool

    Posted 03-04-2024 11:28

    I was finally able to find the .NET help file and have the code below. I can get the file to convert the centroids to a raster using the Stamp tool, but not the problem I'm having is that it won't convert the Raster to the new coordinate system. 

    The line of code that should change the projection is interpolationOptions.OutputDetails.CoordSysString = "UTM Zone 11 (NAD 83)\p26911, 8, 74, 7, -117, 0, 0.9996, 500000, 0", but it doesn't change the projection. 

    Any suggestions?

    rom typing import List
    import clr
    import os
    import sys

    # Add references
    # dir clr.AddReference('System.Collections')
    from os.path import abspath, join, dirname, exists, isfile
    from System import UInt32, Double
    from System.Collections.Generic import List

    # Add references for MapInfo RasterEngine
    sys.path.insert(0, "C:\\Program Files\\MapInfo\\Professional\\Raster")

    from MapInfo.RasterEngine.IO import DriverIDExtensions, DriverID
    from MapInfo.RasterEngine.Operations import RasterInterpolation, RasterProcessing
    from MapInfo.RasterEngine.Common import (

    # Define input and output file paths
    srcPointFilePath = r"D:\\TestPOPs.TAB"
    print("read input file", os.path.isfile(r"D:\\TestPOPs.TAB"))
    dstRasterFilePath = r"D:\\test.MRR"
    print("read output file", os.path.isfile(r"D:\\test.MRR"))

    # Create interpolation options
    interpolationOptions = RasterInterpolationOptions()
    interpolationOptions.Preferences.AutoCacheSize = True
    interpolationOptions.Preferences.CacheSize = 0
    interpolationOptions.Preferences.TemporaryDirectory = ""

    # Set input details TAB FILE
    file = RasterInterpolationInputFileDetails()
    file.FilePath = srcPointFilePath
    file.FileType = RasterInterpolationInputFileType.MAPINFO_TAB
    file.HeaderRows = 1
    file.CoordSysString = "Longitude / Latitude (WGS 84)\p4326, 1, 104"
    file.XFieldIndex = -1
    file.YFieldIndex = -1
    file.SubFileName = "*.*"

    #Grouping Parameters
    # file.Grouping.Apply = True
    # file.Grouping.ColumnIndex = 0
    # file.Grouping.DataType = RasterBandDataType.CharInt8


    # Set output details
    interpolationOptions.OutputDetails.AllowMultiBand = False
    interpolationOptions.OutputDetails.FilePath = dstRasterFilePath
    interpolationOptions.OutputDetails.DriverId = DriverIDExtensions.GetString(DriverID.MRR)
    interpolationOptions.OutputDetails.AutoDataType = True
    interpolationOptions.OutputDetails.CoordSysString = "UTM Zone 11 (NAD 83)\p26911, 8, 74, 7, -117, 0, 0.9996, 500000, 0"

    # Set gemetry
    interpolationOptions.Geometry.Extent.Auto = True
    interpolationOptions.Geometry.CellSize.X = 50;
    interpolationOptions.Geometry.CellSize.Y = 50;
    interpolationOptions.Geometry.CellSize.Auto = False
    interpolationOptions.InterpolateFeatures = True

    #Stamp, Clip, and Smoothing
    StampMethod = RasterInterpolationStampStampingMethod.Maximum  

    Clip = RasterInterpolationClip()
    Clip.Method = RasterInterpolationClipMethod(0)
    Clip.Near = 0    
    Clip.Far = 0    
    Clip.KeepWithinPolygon = True
    Clip.PolygonFile= ""

    Smoothing = RasterInterpolationSmoothing()
    Smoothing.Type = RasterInterpolationSmoothingType(0)
    Smoothing.Level = 1

    stampOptions = RasterInterpolationStamp(StampMethod, Clip, Smoothing)

    apiOptions = RasterApiOptions()

    RasterInterpolation.InterpolateStamp(interpolationOptions, stampOptions, apiOptions)

    Tom Avakian
    Knowledge Community Shared Account

  • 3.  RE: Python Raster Stamp Tool

    Posted 03-04-2024 14:46
    Edited by Peter Møller 03-05-2024 01:39

    Ok, I was able to change the projection, but now I'm getting an issue where I try to write the file to a .bil file instead of an MRR file. 

    This is the code I changed: 

    interpolationOptions.OutputDetails.DriverId = DriverIDExtensions.GetString(DriverID.MRR)
    interpolationOptions.OutputDetails.DriverId = DriverIDExtensions.GetString(DriverID.BIL)
    When I run this with DriverID.BIL, I get this error: 
    Error number: 701  occurred in file: convert.cpp in function: BeginConvert at line: 648 reporting: "Directory is not writable."
    Any help would be appreciated!

    Tom Avakian
    Knowledge Community Shared Account

  • 4.  RE: Python Raster Stamp Tool

    Posted 03-05-2024 01:38

    Hi Tom

    Did you fix the projection issue by changing the projection string to something like this:

    interpolationOptions.OutputDetails.CoordSysString = "CoordSys Earth Projection 8, 74, 7, -117, 0, 0.9996, 500000, 0"

    As for your write-error, I have a couple of far-fetched ideas:

    1. Could it be an existing potentially open file that prevents you from creating the new raster?
    2. You set the KeepWithinPolygon property on the Clip object to True but you don't specify a PolygonFile. I'd think we would ignore the KeepWithinPolygon property if no PolygonFile is specified.
    3. Are you using any raster settings that are specific to MRR and not supported by BIL? I didn't see any but maybe you are aware of some.

    Peter Horsbøll Møller
    Principal Presales Consultant | Distinguished Engineer
    Precisely | Trust in Data

  • 5.  RE: Python Raster Stamp Tool

    Posted 03-05-2024 01:42

    Hi Tom

    I saw that you found the Raster API Reference Guide in the Raster\Documentation subfolder of the MapInfo Pro installation folder.

    I'm sure you also found the Sample Code subfolder with .NET samples.

    I'd also recommend looking into the Python Quick Start tool that comes with MapInfo Pro. It comes with several Python examples and includes the Python scripts too, of course.

    Peter Horsbøll Møller
    Principal Presales Consultant | Distinguished Engineer
    Precisely | Trust in Data