Layer management

Functions

int AxMap.AddLayer (object Object, bool visible)
 Adds a layer to the map. More...
 
int AxMap.AddLayerFromDatabase (string connectionString, string layerNameOrQuery, bool visible)
 Adds a layer from spatial database accessed via GDAL/OGR drivers. More...
 
int AxMap.AddLayerFromFilename (string filename, tkFileOpenStrategy openStrategy, bool visible)
 Adds layer from the specified datasource. More...
 
void AxMap.Clear ()
 Removes all data from the map and sets its properties to the default state. More...
 
object AxMap.get_GetObject (int layerHandle)
 Returns the layer object with the given handle. The object could be a Shapefile, Grid, or Image object. More...
 
Image AxMap.get_Image (int layerHandle)
 Gets image object associated with the layer. More...
 
Extents AxMap.get_layerExtents (int layerHandle)
 Gets the layer extents More...
 
int AxMap.get_LayerHandle (int layerPosition)
 Gets the handle of the layer at the given position in the map. Returns -1 if there is no layer at the specified position More...
 
int AxMap.get_LayerPosition (int layerHandle)
 Gets the position of the specified layer in the map. More...
 
bool AxMap.get_LayerVisibleAtCurrentScale (int layerHandle)
 Gets a value which indicates whether a layer is visible at current map scale. More...
 
OgrLayer AxMap.get_OgrLayer (int layerHandle)
 Gets instance of OGR layer object associated with the specified layer. More...
 
Shapefile AxMap.get_Shapefile (int layerHandle)
 Gets shapefile object associated with the layer. More...
 
WmsLayer AxMap.get_WmsLayer (int layerHandle)
 Gets the WmsLayer More...
 
bool AxMap.MoveLayer (int initialPosition, int targetPosition)
 Moves a layer in the map from the initial position to a target position. More...
 
bool AxMap.MoveLayerBottom (int initialPosition)
 Moves the specified layer below all other layers. More...
 
bool AxMap.MoveLayerDown (int initialPosition)
 Moves the specified layer down one layer in the map. More...
 
bool AxMap.MoveLayerTop (int initialPosition)
 Moves the specified layer to the top of all other layers. More...
 
bool AxMap.MoveLayerUp (int initialPosition)
 Moves the specified layer up one layer in the map. More...
 
bool AxMap.ReloadOgrLayerFromSource (int ogrLayerHandle)
 Performs the same operation as OgrLayer.ReloadFromSource, then compares projections with the Map, and if the settings allow, will reproject on-the-fly. More...
 
void AxMap.RemoveAllLayers ()
 Removes all layers from the map. More...
 
void AxMap.RemoveLayer (int layerHandle)
 Removes the specified layer from the map More...
 
void AxMap.RemoveLayerWithoutClosing (int layerHandle)
 Removes layer from the map without its closing. More...
 
void AxMap.ReSourceLayer (int layerHandle, string newSrcPath)
 Changes the data source for the specified layer without its closing. More...
 
void AxMap.RestartBackgroundLoading (int ogrLayerHandle)
 Restarts the background loading thread of dynamically loaded layers More...
 
void AxMap.set_Image (int layerHandle, Image newValue)
 Replaces the image object associated with the layer. More...
 
void AxMap.set_Shapefile (int layerHandle, Shapefile newValue)
 Replaces the shapefile object associated with the layer. More...
 
bool AxMap.StartNewBoundShape (double x, double y)
 Allow to initiate digitizing a new shape with a starting point More...
 
bool AxMap.StartNewBoundShapeEx (int layerHandle)
 Allow to initiate digitizing a new shape with a starting point More...
 

Properties

int AxMap.NumLayers [get]
 Gets the number of layers loaded in the map. More...
 

Detailed Description

Here is a list of properties and methods which allow to work with layers of the map. This module is a part of the documentation of AxMap class.

dot_inline_dotgraph_17.png

Graph description

Function Documentation

◆ AddLayer()

int AxMap.AddLayer ( object  Object,
bool  visible 
)

Adds a layer to the map.

In case of OgrDatasource all layers will be added to the map. For grid datasources an instance of Image class created with Grid.OpenAsImage will be used for rendering.

Parameters
ObjectThe object to add to the map. The following types are supported: Shapefile, Image, Grid, OgrLayer, OgrDatasource.
visibleSets whether the layer is visible after being added to the map.
Returns
Returns the integer handle for the layer added to the map.
Examples
AddCategoryRange.cs, AddLayers.cs, CalculateArea.cs, CreateBuffer.cs, CreatePointShapefile.cs, CreatePolygonShapefile.cs, EditAttributes.cs, GenerateLabelsManually.cs, ImageLabels.cs, IntersectionLength.cs, LabelSelection.cs, LinePattern.cs, MarkPoints.cs, MinimalDistance.cs, PointIcons.cs, PolygonsWithHoles.cs, RemoveShape.cs, Segmentation.cs, SelectBox.cs, SelectByDistance.cs, SelectByQuery.cs, ShowAttributes.cs, SplitByAttribute.cs, ToolTip.cs, TrackCars.cs, Tracking.cs, and ZoomToValues.cs.

◆ AddLayerFromDatabase()

int AxMap.AddLayerFromDatabase ( string  connectionString,
string  layerNameOrQuery,
bool  visible 
)

Adds a layer from spatial database accessed via GDAL/OGR drivers.

This method will search if there is a layer with specified name in the datasource, and if so will open it. Otherwise it will run OgrDatasource.RunQuery method with provided layerNameOrQuery argument. Additional information on failure can be obtained through AxMap.FileManager property.

Parameters
connectionStringConnection string. See details for particular formats here.
layerNameOrQueryName of the layer (i.e. database table) or SQL query.
visibleA value indicating whether a new layer will be visible.
Returns
Handle of the newly added layer or -1 on failure.

The following example opens a temporary layer by querying PostGIS datatabase, adds the layer to the map and then accesses its data.

private static string CONNECTION_STRING = "PG:host=localhost dbname=london user=postgres password=1234";
string sqlOrLayerName = "SELECT * FROM Buildings WHERE gid < 50";
int handle = map.AddLayerFromDatabase(CONNECTION_STRING, sqlOrLayerName, true);
if (handle == -1)
{
Debug.Print("Failed to open layer: " + map.FileManager.get_ErrorMsg(map.FileManager.LastErrorCode));
// in case the reason of failure is still unclear, let's ask GDAL for details
var gs = new GlobalSettings();
Debug.Print("Last GDAL error: " + gs.GdalLastErrorMsg);
}
else
{
// now let's access the opened layer
var l = map.get_OgrLayer(handle);
if (l != null)
{
Debug.Print("Number of features: " + l.FeatureCount);
// no access the data
var sf = l.GetBuffer();
Debug.Print("Number of shapes: " + sf.NumShapes);
}
}
Holds global settings for MapWinGIS. Allows to retrieve GDAL errors.
Definition: GlobalSettings.cs:29
New API 4.9.3:
Added in version 4.9.3

◆ AddLayerFromFilename()

int AxMap.AddLayerFromFilename ( string  filename,
tkFileOpenStrategy  openStrategy,
bool  visible 
)

Adds layer from the specified datasource.

Additional information on failure can be obtained through AxMap.FileManager property.

Parameters
filenameFilename of datasource
openStrategyOpen strategy (fosAutoDetect the default recommended value).
visibleA value indicating whether a new layer will be visible.
Returns
Handle of the newly added layer or -1 on failure.
New API 4.9.1:
Added in version 4.9.1
Examples
TrackCars.cs.

◆ Clear()

void AxMap.Clear ( )

Removes all data from the map and sets its properties to the default state.

New API 4.9.1:
Added in version 4.9.1

◆ get_GetObject()

object AxMap.get_GetObject ( int  layerHandle)

Returns the layer object with the given handle. The object could be a Shapefile, Grid, or Image object.

For OGR layers this method will return underlying shapefile from OgrLayer.GetBuffer(). Use AxMap.get_OgrLayer to access instance of OgrLayer itself.

Parameters
layerHandleThe handle of the layer to be retrieved.
Returns
A Shapefile, Grid, or Image object.
Examples
SortLayers.cs.

◆ get_Image()

Image AxMap.get_Image ( int  layerHandle)

Gets image object associated with the layer.

This method along with AxMap.get_Shapefile() can used to substitute AxMap.get_GetObject().

Parameters
layerHandleThe handle of the layer.
Returns
The reference to the image or NULL reference in case of invalid handle or wrong layer type.
New API 4.8:
Added in version 4.8

◆ get_layerExtents()

Extents AxMap.get_layerExtents ( int  layerHandle)

Gets the layer extents

Parameters
layerHandleThe handle of the layer.
Returns
The extents
New API 5.1:
Added in version 5.1.0

◆ get_LayerHandle()

int AxMap.get_LayerHandle ( int  layerPosition)

Gets the handle of the layer at the given position in the map. Returns -1 if there is no layer at the specified position

Parameters
layerPositionThe position of the layer for which the layer handle is required.
Returns
The layer handle for the layer at the specified position.
Examples
EditAttributes.cs, RemoveShape.cs, SelectBox.cs, SortLayers.cs, SplitByAttribute.cs, and ToolTip.cs.

◆ get_LayerPosition()

int AxMap.get_LayerPosition ( int  layerHandle)

Gets the position of the specified layer in the map.

Parameters
layerHandleThe layer handle of the layer for which the layer position is required.
Returns
The layer position of the specified layer in the map.
Examples
SortLayers.cs.

◆ get_LayerVisibleAtCurrentScale()

bool AxMap.get_LayerVisibleAtCurrentScale ( int  layerHandle)

Gets a value which indicates whether a layer is visible at current map scale.

Parameters
layerHandleHandle of the layer.
Returns
True in case the layer is visible.

The property checks whether or not the layer is hidden because of AxMap.LayerDynamicVisibility property. However it doesn't check that the layer has any objects within the current map extents.

New API 4.9.3:
Added in version 4.9.3

◆ get_OgrLayer()

OgrLayer AxMap.get_OgrLayer ( int  layerHandle)

Gets instance of OGR layer object associated with the specified layer.

Parameters
layerHandleThe handle of the layer.
Returns
OGR layer or null in case of invalid layer index or wrong layer type.
New API 4.9.3:
Added in version 4.9.3

◆ get_Shapefile()

Shapefile AxMap.get_Shapefile ( int  layerHandle)

Gets shapefile object associated with the layer.

This method along with AxMap.get_Image() can be used to substitute AxMap.get_GetObject().

Parameters
layerHandleThe handle of the layer.
Returns
The reference to the shapefile or NULL reference in case of invalid handle or wrong layer type.
New API 4.8:
Added in version 4.8
Examples
AddCategoryRange.cs, CalculateArea.cs, CreateBuffer.cs, EditAttributes.cs, GenerateLabelsManually.cs, LabelSelection.cs, MarkPoints.cs, PointIcons.cs, RemoveShape.cs, SelectBox.cs, SelectByQuery.cs, ShowAttributes.cs, SortLayers.cs, SplitByAttribute.cs, ToolTip.cs, TrackCars.cs, and ZoomToValues.cs.

◆ get_WmsLayer()

WmsLayer AxMap.get_WmsLayer ( int  layerHandle)

Gets the WmsLayer

Parameters
layerHandleThe handle of the layer.
Returns
The WmsLayer object

◆ MoveLayer()

bool AxMap.MoveLayer ( int  initialPosition,
int  targetPosition 
)

Moves a layer in the map from the initial position to a target position.

Parameters
initialPositionThe initial position of the layer to be moved.
targetPositionThe final position of the layer being moved.
Returns

◆ MoveLayerBottom()

bool AxMap.MoveLayerBottom ( int  initialPosition)

Moves the specified layer below all other layers.

Parameters
initialPositionThe position of the layer to move to the bottom
Returns
Boolean value representing success when true, and failure when false.
Examples
SortLayers.cs.

◆ MoveLayerDown()

bool AxMap.MoveLayerDown ( int  initialPosition)

Moves the specified layer down one layer in the map.

Parameters
initialPositionThe position of the layer to be moved.
Returns
Boolean value representing success when true, and failure when false.

◆ MoveLayerTop()

bool AxMap.MoveLayerTop ( int  initialPosition)

Moves the specified layer to the top of all other layers.

Parameters
initialPositionThe position of the layer to be moved.
Returns
Boolean value representing success when true, failure when false.

◆ MoveLayerUp()

bool AxMap.MoveLayerUp ( int  initialPosition)

Moves the specified layer up one layer in the map.

Parameters
initialPositionThe initial position of the layer to be moved.
Returns
Boolean value representing success when true, failure when false.

◆ ReloadOgrLayerFromSource()

bool AxMap.ReloadOgrLayerFromSource ( int  ogrLayerHandle)

Performs the same operation as OgrLayer.ReloadFromSource, then compares projections with the Map, and if the settings allow, will reproject on-the-fly.

Parameters
ogrLayerHandleThe handle of the layer. Must be an OGR layer.
Returns
True if successful; False if not an OGR Layer, could not be reloaded, or could not be reprojected (if necessary)

Starting with version 5.2.0, this function will also attempt to maintain the current set of Hidden and Selected shapes within the associated Shapefile.

New API 5.2:
Updated in version 5.2

◆ RemoveAllLayers()

void AxMap.RemoveAllLayers ( )

Removes all layers from the map.

Examples
AddLayers.cs.

◆ RemoveLayer()

void AxMap.RemoveLayer ( int  layerHandle)

Removes the specified layer from the map

Parameters
layerHandleThe handle of the layer to be removed from the map.

◆ RemoveLayerWithoutClosing()

void AxMap.RemoveLayerWithoutClosing ( int  layerHandle)

Removes layer from the map without its closing.

Shapefile.Close or Image.Close won't be called while removing the layer.

Parameters
layerHandleThe handle of the layer.

◆ ReSourceLayer()

void AxMap.ReSourceLayer ( int  layerHandle,
string  newSrcPath 
)

Changes the data source for the specified layer without its closing.

The new data source must be of the same type, i.e. either Shapefile or Image.

Parameters
layerHandleThe handle of the layer.
newSrcPathThe the name of the new data source.

◆ RestartBackgroundLoading()

void AxMap.RestartBackgroundLoading ( int  ogrLayerHandle)

Restarts the background loading thread of dynamically loaded layers

Parameters
ogrLayerHandleThe handle of the layer. Must be an OGR layer.
New API 5.1:
Adding in v5.1.0

◆ set_Image()

void AxMap.set_Image ( int  layerHandle,
Image  newValue 
)

Replaces the image object associated with the layer.

The old image will not be closed.

Parameters
layerHandleThe handle of the layer.
newValueThe new image object.
New API 4.8:
Added in version 4.8

◆ set_Shapefile()

void AxMap.set_Shapefile ( int  layerHandle,
Shapefile  newValue 
)

Replaces the shapefile object associated with the layer.

The old shapefile will not be closed.

Parameters
layerHandleThe handle of the layer.
newValueThe new shapefile object.
New API 4.8:
Added in version 4.8

◆ StartNewBoundShape()

bool AxMap.StartNewBoundShape ( double  x,
double  y 
)

Allow to initiate digitizing a new shape with a starting point

Parameters
x
y
Returns
True on success
New API 5.1:
Added in v5.1.0

◆ StartNewBoundShapeEx()

bool AxMap.StartNewBoundShapeEx ( int  layerHandle)

Allow to initiate digitizing a new shape with a starting point

Parameters
layerHandle
Returns
True on success
New API 5.1:
Added in v5.1.0

Properties

◆ NumLayers

int AxMap.NumLayers
get

Gets the number of layers loaded in the map.

Examples
AddLayers.cs, SortLayers.cs, and SplitByAttribute.cs.