Provides functionality for opening and examining different types of datasources.
More...
|
bool | BuildGdalOverviews (string Filename) |
| Builds overviews for a raster datasource managed by GDAL. More...
|
|
bool | ClearGdalOverviews (string Filename) |
| Clears overviews for a raster datasource managed by GDAL. More...
|
|
bool | get_CanOpenAs (string Filename, tkFileOpenStrategy OpenStrategy) |
| Checks whether specific open strategy is applicable for a given datasource. More...
|
|
string | get_ErrorMsg (int ErrorCode) |
| Gets the description of the specific error code. More...
|
|
bool | get_HasGdalOverviews (string Filename) |
| Returns true if specified raster datasource managed by GDAL has overviews. More...
|
|
bool | get_HasValidProxyForGrid (string Filename) |
| Returns true if specified grid datasource has proxy images for its rendering. More...
|
|
bool | get_IsGrid (string Filename) |
| Checks whether specified datasource is grid, i.e. non-RGB raster datasource which require synthetic colour scheme for rendering. More...
|
|
bool | get_IsRgbImage (string Filename) |
| Checks whether datasource is RGB image. More...
|
|
bool | get_IsSupported (string Filename) |
| Checks whether the datasource is supported (can be opened) by MapWinGis. More...
|
|
bool | get_IsSupportedBy (string Filename, tkSupportType supportType) |
| Checks whether datasource is supported by specified subsystem of MapWinGIS. More...
|
|
bool | get_IsVectorLayer (string Filename) |
| Checks whether specified datasource is vector layer that can be opened by MapWinGIS. More...
|
|
tkFileOpenStrategy | get_OpenStrategy (string Filename) |
| Determines optimal open strategy for datasource. More...
|
|
object | Open (string Filename, tkFileOpenStrategy OpenStrategy=tkFileOpenStrategy.fosAutoDetect, ICallback cBack=null) |
| Tries to open datasource with specified name. More...
|
|
OgrLayer | OpenFromDatabase (string connectionString, string layerNameOrQuery) |
| Opens a layer or runs a query against OGR spatial database. More...
|
|
Image | OpenRaster (string Filename, tkFileOpenStrategy OpenStrategy, ICallback cBack=null) |
| Tries to open raster datasource (either RGB image or grid) with specified name. More...
|
|
Shapefile | OpenShapefile (string Filename, ICallback cBack=null) |
| Tries to open shapefile with specified name. More...
|
|
OgrDatasource | OpenVectorDatasource (string Filename) |
| Tries to open specified file as OGR datasource. More...
|
|
OgrLayer | OpenVectorLayer (string Filename, ShpfileType preferedShapeType=ShpfileType.SHP_NULLSHAPE, bool forUpdate=false) |
| Tries to open specified file as OGR layer. More...
|
|
bool | RemoveProxyForGrid (string Filename) |
| Remove proxy images generated for grid rendering. More...
|
|
Provides functionality for opening and examining different types of datasources.
Traditionally MapWinGIS uses at least 3 classes to open different types of datasources: Shapefile, Image and Grid. There are different ways to open GDAL-based raster datasources: they can be opened for editing by Grid class or for rendering by Image class. Also rendering of grids can be performed directly or by creating temporary proxy image. FileManager was designed to hide all these details from user providing a mechanism to open and display any type of datasource with least amount of code.
A. Opening datasources.
To open any supported datasource the following code can be used:
tkFileOpenStrategy
Possible open strategies for datasources.
Definition: Enumerations.cs:1799
Provides functionality for opening and examining different types of datasources.
Definition: FileManager.cs:158
Perhaps receiving an object of unknown type isn't very impressive, here is more practical example which adds open datasource to the map:
if (obj != null && fm.LastOpenIsSuccess)
{
int handle = axMap1.AddLayer(obj, true);
if (handle != -1)
{
MessageBox.Show("Layer was added to the map. Open strategy: " + fm.LastOpenStrategy.ToString());
}
else
{
MessageBox.Show("Failed to add layer to the map: " + axMap1.get_ErrorMsg(axMap1.LastErrorCode));
}
}
else
{
MessageBox.Show("Failed to open datasource: " + fm.get_ErrorMsg(fm.LastErrorCode));
}
FileManager.Open returns instance of Shapefile class for shapefile datasources and instance of Image class for any raster datasources both RGB images and grids. In case of grids it may temporarily open a Grid object to create proxy image for it but then closes it. To exclude casting of opened object to known type use: FileManager.OpenRaster and FileManager.OpenShapefile. The code below shows how to cast opened object to appropriate type.
string filename = "some_filename.ext";
if (!fm.get_IsSupported(filename))
{
MessageBox.Show("Datasource isn't supported by MapWinGIS");
}
else
{
if (fm.LastOpenIsSuccess)
{
{
if (shapefile != null)
MessageBox.Show("Shapefile was opened.");
}
else
{
var image = obj as
Image;
if (image != null)
MessageBox.Show("Image was opened.");
}
}
else
{
MessageBox.Show("Failed to open datasource: " + fm.get_ErrorMsg(fm.LastErrorCode));
}
}
Represents an raster image of particular format which may be added to the map.
Definition: Image.cs:66
Provides a functionality for accessing and editing ESRI shapefiles.
Definition: Shapefile.cs:72
- Note
- Look for additional examples on opening raster datasources in description of Grid class.
B. Open strategies.
The following strategies are available through tkFileOpenStrategy enumeration:
See details on distinction between available open strategies for grids in description of Grid class.
The default tkFileOpenStrategy.fosAutoDetect strategy works like this:
1) Shapefiles are checked by (.shp) extension and fosVectorLayer is chosen.
2) It is analyzed whether datasource can be opened with GDAL:
- if so and it is RGB image, fosRgbImage is chosen;
- otherwise it is checked whether a proxy image exists for rendering this datasource, and whether its size exceeds GlobalSettings.MaxNoProxyGridSizeMb property; if either is true fosProxyForGrid will be chosen;
- otherwise fosDirectGrid will be returned.
3) A check is made whether it can be handled by MapWinGIS own grid drivers - if so fosProxyForGrid will be returned.
4) If all previous methods have failed fosNotSupported will be returned.
In most cases fosAutoDetect strategy is the best choice. However as grids have 2 strategies it may be needed to choose on of them explicitly:
string filename = "some_filename.ext";
object Open(string Filename, tkFileOpenStrategy OpenStrategy=tkFileOpenStrategy.fosAutoDetect, ICallback cBack=null)
Tries to open datasource with specified name.
Definition: FileManager.cs:219
C. Built-in file manager for map control.
An instance of FileManager class is also used by AxMap.AddLayerFromFilename method, which require only filename and open strategy to add layer to the map. Here is example of its usage:
int handle = axMap1.AddLayerFromFilename(filename,
tkFileOpenStrategy.fosAutoDetect,
true);
if (handle != -1 && axMap1.FileManager.LastOpenIsSuccess)
{
MessageBox.Show("Layer was added to the map. Open strategy: " + axMap1.FileManager.LastOpenStrategy.ToString());
}
else
{
MessageBox.Show("Failed to open grid: " + axMap1.FileManager.ErrorMsgFromObject(axMap1.FileManager.LastErrorCode));
}
- New API 4.9.1:
- Added in version 4.9.1