Original Message:
Sent: 03-06-2023 03:42
From: Peter Møller
Subject: Python Raster Clip error
Hi Kathy
You need to look for the Extensibility Reference Help file.
From MapInfo Pro, you can find it by right-clicking in the Python Console and from the Help dropdown in the SQL Window:
And for the MapInfo Pro Raster SDK, you can find a help file in the Raster\Documentation\API folder in the MapInfo Pro installation folder:
This is also where you find a number of MapInfo Pro Raster samples (.NET not Python).
------------------------------
Peter Horsbøll Møller
Principal Presales Consultant | Distinguished Engineer
Precisely | Trust in Data
Original Message:
Sent: 03-03-2023 13:22
From: Kathy Gillis
Subject: Python Raster Clip error
Thank you, Peter, the code now works!
It would be most helpful to be able to read documentation specific to mapinfo modules and functions written in python. Are those types of docs available (my searches indicate no). I do have Python Quick Start loaded in mapinfo which helps a little. It is inefficient and quite cumbersome to try to dir() and help() my way to figuring things out.
I really appreciate your helping me - Kathy
------------------------------
Kathy Gillis
AT&T
SAN RAMON OR
Original Message:
Sent: 03-03-2023 03:27
From: Peter Møller
Subject: Python Raster Clip error
Hi Kathy
It seems your code is missing a bit in the end. It may just be a single parameter in the RasterProcessing.Clip
line.
I'd suggest that you try to change this line:
outputRasterDriverID = DriverIDExtensions.GetString(DriverID.ASC)
to
outputRasterDriverID = DriverIDExtensions.GetString(DriverID.MRR)
The line tells the processing the format is ESRI ASC but it seems both your files are in fact MRR files.
------------------------------
Peter Horsbøll Møller
Principal Presales Consultant | Distinguished Engineer
Precisely | Trust in Data
Original Message:
Sent: 03-02-2023 22:49
From: Kathy Gillis
Subject: Python Raster Clip error
Hi,
I took this code from another post (Luke Lynx; Run MapInfo Raster Clip operation through python) and updated it for my version of MI Pro (21.3) and am getting the following error and would greatly appreciate some guidance. It appears to be related to the file extension. Kathy
ERROR:
RasterException : Invalid file extension.
at MapInfo.RasterEngine.Common.MIRasterError.VerifyRetValue(Int32 iRetVal)
at MapInfo.RasterEngine.Operations.RasterProcessing.Clip(String inputRasterFilePath, String inputTabFilePath, String outputRasterFilePath, String outputRasterDriverID, Boolean retainInsideRegions, RasterApiOptions apiOptions, IRasterProgressTracker progressTracker)
CODE:
#Raster Clip Operation using Tab File Input
import string
import clr
import os
import sys
from os.path import abspath, join, dirname, exists
sys.path.insert(0,"C:\\Program Files\\MapInfo\\Professional\\Raster")
clr.AddReference("MapInfo.RasterEngine.IO")
clr.AddReference("MapInfo.RasterEngine.Common")
clr.AddReference("MapInfo.RasterEngine.Operations")
from MapInfo.RasterEngine.Operations import RasterProcessing
from MapInfo.RasterEngine.Common import RasterInputDetails, RasterApiOptions, RasterClipExtent
from MapInfo.RasterEngine.IO import DriverIDExtensions, DriverID
#Input and output file path
rasterInput = r"C:\\path_to_input\\filename.mrr"
rasterOutput = r"C:\\path_to_output\\output_filename.mrr"
outputRasterDriverID = DriverIDExtensions.GetString(DriverID.ASC)
tabInput = r"C:\\path_to_geometry_to_clip raster_to\\Vermont.tab"
retainInsideRegion = True
apiOptions = RasterApiOptions(RasterClipExtent())
RasterProcessing.Clip(rasterInput, tabInput, rasterOutput, outputRasterDriverID, retainInsideRegion,
------------------------------
Kathy Gillis
AT&T
SAN RAMON OR
------------------------------