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
------------------------------