MapInfo Pro Developers User Group

Expand all | Collapse all

Automating Contour Creation

  • 1.  Automating Contour Creation

    Posted 05-17-2021 10:59
    Hello,

    I am looking for a way to automate contour creation with MapInfo, MapBasic, or Python. It's common practice for us to create contour tables of different intervals at certain depths, such as 1' for 0-50, 5' for 55-100, 10' for 110-500 and so on. The current Raster contour tool only allows us to create one interval set at a time. The result is we need to then append the tables and delete the extra files. Over the course of a project we need to repeat the process hundreds of times. I attempted to use the custom intervals option in the contours tool, but it proved very tedious for designating hundreds of contours

    I've created a few MapBasic tools and added them into the ribbon, but I am yet to grasp even the basics of Python integration and accessing the Raster toolbox. Any help getting started will be appreciated.

    Thank you,


    Brandon

    ------------------------------
    Brandon Shepherd
    Knowledge Community Shared Account
    Shelton CT
    ------------------------------


  • 2.  RE: Automating Contour Creation

    Posted 05-23-2021 19:38
    Edited by Duri Bradshaw 05-23-2021 19:38
    Hi Brandon,

    Have a look at this post, there is some sample code and links to more info
    https://community.precisely.com/communities/community-home/digestviewer/viewthread?MessageKey=d713632a-a019-4e9d-87b3-299de9b47446

    ------------------------------
    Duri Bradshaw
    Spatial IT Consultant
    Insight GIS
    ------------------------------



  • 3.  RE: Automating Contour Creation

    Posted 05-24-2021 10:34
    We have some python examples that use the Raster SDK in our "Python Quick Start" which you can get from the MapInfo Marketplace.
    If you have 2019.3 you can simply type "python" in the Pro QuickSearch box on the title bar and it will list the app from the Marketplace.

    ------------------------------
    Bob Fortin
    Software Architect and Distinguished Engineer
    MapInfo Pro Development Team
    ------------------------------



  • 4.  RE: Automating Contour Creation

    Posted 05-25-2021 03:46
    Edited by Anshul Goel 05-26-2021 06:25
    Hey Brandon,

    Please refer the below sample code for running contour operation using Python. This should give you some idea on getting started.

    Manual Intervals:
    #Polyline contours
    #Create Manual spaced contours, with a natural range (defined by grid)
    #Contour styles will be defined in the manual levels
    
    
    from typing import List
    import clr
    import sys
     
    from os.path import abspath, join, dirname, exists
    from System import UInt32
    from System.Drawing import Color
    from System.Collections.Generic import List
    sys.path.insert(0,"C:\\Program Files\\MapInfo\\Professional19\\Raster")
    clr.AddReference("MapInfo.RasterEngine.IO")
    clr.AddReference("MapInfo.RasterEngine.Common")
    clr.AddReference("MapInfo.RasterEngine.Operations")
    
    from MapInfo.RasterEngine.IO import DriverIDExtensions, DriverID
    from MapInfo.RasterEngine.Operations import RasterAnalysis
    from MapInfo.RasterEngine.Common import ManualLevel, ContourOptions, InterpolationMethod, ContourLevels, FieldBandFilter,ContourStyle
     
    cwd = dirname(__file__)
     
    inputFile = abspath(join(cwd, "..\\RasterData\\GRD\\Elevation.grd"))
    outputFile = abspath(join(cwd, "..\\RasterData\\GRD\\Elevation_contour.tab"))
    
    polygonContouring=False;
    
    manualLevels= List[ManualLevel]()
    
    manualLevels.Add(ManualLevel(100.0,ContourStyle(2,1,Color.Red)))
    manualLevels.Add(ManualLevel(200.0,ContourStyle(2,1,Color.Green)))
    manualLevels.Add(ManualLevel(300.0,ContourStyle(2,1,Color.Blue)))
    
    options=ContourOptions()
    options.InterpolationMethod=InterpolationMethod.Default
    options.Levels=ContourLevels(manualLevels)
    
    fieldBandFilter=FieldBandFilter(UInt32(0),UInt32(0))
    
     
    RasterAnalysis.Contour(inputFile, outputFile, 0, options, polygonContouring, fieldBandFilter)
    
    if exists(outputFile):
            print('Contour Successful!')
            table = pro.Catalog.OpenTable(outputFile)
            if table:
                do('map from {}'.format(table.Alias))​


    Fixed Intervals:

    #Polyline contours
    #Create ConstantMinMax spaced (80 unit increments) contours starting from the data min, with a natural range (defined by grid)
    #A major line will be created every 10th line increment and have the MajorStyle applied
    #All minor lines have MinorStyle applied
    
    from typing import List
    import clr
    import sys
     
    from os.path import abspath, join, dirname, exists
    from System import UInt32
    from System.Drawing import Color
    sys.path.insert(0,"C:\\Program Files\\MapInfo\\Professional19\\Raster")
    clr.AddReference("MapInfo.RasterEngine.IO")
    clr.AddReference("MapInfo.RasterEngine.Common")
    clr.AddReference("MapInfo.RasterEngine.Operations")
    
    from MapInfo.RasterEngine.IO import DriverIDExtensions, DriverID
    from MapInfo.RasterEngine.Operations import RasterAnalysis
    from MapInfo.RasterEngine.Common import ManualLevel, ContourOptions, InterpolationMethod, ContourLevels, FieldBandFilter,ContourStyle,ContourLevelType
     
    cwd = dirname(__file__)
     
    inputFile = abspath(join(cwd, "..\\RasterData\\GRD\\SeattleElevation.grd"))
    outputFile = abspath(join(cwd, "..\\RasterData\\GRD\\Elevation_contour.tab"))
    
    polygonContouring=False;
    
    contourStyles=[
        10,
    ContourStyle(3,2,Color.Red),
    ContourStyle(1,1,Color.Blue)
    ]
    
    options=ContourOptions(InterpolationMethod.Default,ContourLevels(ContourLevelType.ConstantMinMax,UInt32(80)),contourStyles)
    
    fieldBandFilter=FieldBandFilter(UInt32(0),UInt32(0))
    
    RasterAnalysis.Contour(inputFile, outputFile, 0, options, polygonContouring, fieldBandFilter)
    
    if exists(outputFile):
            print('Contour Successful!')
            table = pro.Catalog.OpenTable(outputFile)
            if table:
                do('map from {}'.format(table.Alias))


    Hope it helps.

    Thanks
    Anshul



    ------------------------------
    Anshul Goel
    Pitney Bowes Software Inc.
    Shelton CT
    ------------------------------



  • 5.  RE: Automating Contour Creation

    Posted 05-26-2021 10:20
    Thank you very much. I don't think there is a better way to get started than with this. I appreciate it.

    ------------------------------
    Brandon Shepherd
    Knowledge Community Shared Account
    Shelton CT
    ------------------------------



  • 6.  RE: Automating Contour Creation

    Posted 7 days ago
    We undertook a similar task to this last year, transforming 1500 - 1km DEM tiles into 0.25m contours. We had a few attempts at doing it in MapInfo but ultimately went down the FME route. Contours were produced at 0.25m across all the elevation range -2m - 1300m but there was an option we didn't take advantage of to provide a contours translation table that would have allowed altering the contour interval for different elevation ranges. TAB output was fully styled to match our existing colour schemes and a labelling process was also run that produced 'acceptable' labels for 1:250/500 scale.

    If FME is an option for you I think we should be able to provide the FME workspace that was created for this. Processing took quite awhile, week or more, so if your area is a similar size (1500sq km) or larger you may want to rejig the FME workspace to take advantage of parallel processing.

    ------------------------------
    William Dean
    Cairns Regional Council
    Cairns QLD
    ------------------------------