GdalUtils Class Reference

Implementation of the GDAL v2 librified functions. Not all functions are implemented yet. More...

Collaboration diagram for GdalUtils:
Collaboration graph

Public Member Functions

bool ClipVectorWithVector (string bstrSubjectFilename, string bstrOverlayFilename, string bstrDstFilename, bool useSharedConnection=true)
 Clips the vector with another vector. More...
 
bool GdalVectorTranslate (string bstrSrcFilename, string bstrDstFilename, Array Options, bool useSharedConnection=false)
 Converts simple features data between file formats. Implementing the librified function of GDAL's ogr2ogr.exe tool More...
 
bool GDALWarp (string bstrSrcFilename, string bstrDstFilename, Array Options)
 Image reprojection and warping utility. Implementing the librified function of GDAL's gdalwarp.exe tool More...
 
string get_ErrorMsg (int ErrorCode)
 Retrieves the error message associated with the specified error code. More...
 

Properties

string DetailedErrorMsg [get]
 Gets the detailed error message. More...
 
ICallback GlobalCallback [get, set]
 The global callback is the interface used by MapWinGIS to pass progress and error events to interested applications. More...
 
string Key [get, set]
 The key may be used by the programmer to store any string data associated with the object. More...
 
int LastErrorCode [get]
 Retrieves the last error generated in the object. More...
 

Detailed Description

Implementation of the GDAL v2 librified functions. Not all functions are implemented yet.

New API 4.9.5:
Added in version 4.9.5

Member Function Documentation

◆ ClipVectorWithVector()

bool GdalUtils.ClipVectorWithVector ( string  bstrSubjectFilename,
string  bstrOverlayFilename,
string  bstrDstFilename,
bool  useSharedConnection = true 
)

Clips the vector with another vector.

Parameters
bstrSubjectFilenameThe subject filename.
bstrOverlayFilenameThe overlay filename.
bstrDstFilenameThe destination filename.
useSharedConnectionIf set to true improves performance but also might make it instable.

Uses GdalUtils.GdalVectorTranslate under the hood.

New API 4.9.5:
Added in version 4.9.5
// Clipping large shapefile with border file
const string subjectFilename = @"D:\dev\GIS-Data\Issues\MWGIS-78 Clipper\Fishnet.shp";
const string borderFilename = @"D:\dev\GIS-Data\Issues\MWGIS-78 Clipper\border.shp";
var outputFilename = Path.Combine(tempFolder, "GdalVectorTranslate.shp");
var gdalUtils = new GdalUtils();
if (!gdalUtils.ClipVectorWithVector("LargeFile.shp", "Border.shp", outputFilename))
{
Debug.WriteLine("GdalVectorTranslate failed: " + gdalUtils.ErrorMsg[gdalUtils.LastErrorCode] + " Detailed error: " + gdalUtils.DetailedErrorMsg);
}

◆ GdalVectorTranslate()

bool GdalUtils.GdalVectorTranslate ( string  bstrSrcFilename,
string  bstrDstFilename,
Array  Options,
bool  useSharedConnection = false 
)

Converts simple features data between file formats. Implementing the librified function of GDAL's ogr2ogr.exe tool

Parameters
bstrSrcFilenameThe source filename.
bstrDstFilenameThe destination filename.
OptionsThe options, as a string array
useSharedConnectionIf set to true improves performance but also might make it instable.

See GDAL's documentation here: http://www.gdal.org/ogr2ogr.html

New API 4.9.5:
Added in version 4.9.5
// Converting shapefile to gml:
var outputFilename = Path.Combine(Path.GetTempPath(), "translated.gml");
var options = new[]
{
"-f", "GML"
};
var gdalUtils = new GdalUtils();
if (!gdalUtils.GdalVectorTranslate(inputFilename, outputFilename, options, true))
{
Debug.WriteLine("GdalVectorTranslate failed: " + gdalUtils.ErrorMsg[gdalUtils.LastErrorCode] + " Detailed error: " + gdalUtils.DetailedErrorMsg);
}

◆ GDALWarp()

bool GdalUtils.GDALWarp ( string  bstrSrcFilename,
string  bstrDstFilename,
Array  Options 
)

Image reprojection and warping utility. Implementing the librified function of GDAL's gdalwarp.exe tool

Parameters
bstrSrcFilenameThe source filename.
bstrDstFilenameThe destination filename.
OptionsThe options, as a string array

See GDAL's documentation here: http://www.gdal.org/gdalwarp.html

New API 4.9.5:
Added in version 4.9.5
// Example of creating VRT file from TIFF file. More options are possible:
var output = Path.GetTempPath() + "GdalWarp.vrt";
var options = new[]
{
"-of", "vrt",
"-overwrite"
};
var gdalUtils = new GdalUtils();
if (!gdalUtils.GDALWarp("test.tif", output, options))
{
Debug.WriteLine("GdalWarp failed: " + gdalUtils.ErrorMsg[gdalUtils.LastErrorCode] + " Detailed error: " + gdalUtils.DetailedErrorMsg);
}
// Example of cutting a TIFF file with a border file:
var output = Path.GetTempPath() + "GdalWarpCutline.vrt";
const string border = @"test.shp";
var options = new[]
{
"-of", "vrt",
"-overwrite",
"-crop_to_cutline",
"-cutline", border
};
var gdalUtils = new GdalUtils();
if (!gdalUtils.GDALWarp("test.tif", output, options))
{
Debug.WriteLine("GdalWarp failed: " + gdalUtils.ErrorMsg[gdalUtils.LastErrorCode] + " Detailed error: " + gdalUtils.DetailedErrorMsg);
}

◆ get_ErrorMsg()

string GdalUtils.get_ErrorMsg ( int  ErrorCode)

Retrieves the error message associated with the specified error code.

Parameters
ErrorCodeThe error code for which the error message is required.
Returns
The error message description for the specified error code.
New API 4.9.5:
Added in version 4.9.5

Property Documentation

◆ DetailedErrorMsg

string GdalUtils.DetailedErrorMsg
get

Gets the detailed error message.

New API 4.9.5:
Added in version 4.9.5

◆ GlobalCallback

ICallback GdalUtils.GlobalCallback
getset

The global callback is the interface used by MapWinGIS to pass progress and error events to interested applications.

New API 4.9.5:
Added in version 4.9.5

◆ Key

string GdalUtils.Key
getset

The key may be used by the programmer to store any string data associated with the object.

New API 4.9.5:
Added in version 4.9.5

◆ LastErrorCode

int GdalUtils.LastErrorCode
get

Retrieves the last error generated in the object.

New API 4.9.5:
Added in version 4.9.5