This example demonstrates how to manually select shapes and to show information about the their relative area. The shapes area selected by mouse dragging. Chart is update automatically. Here is a screenshot with the results of the code execution.

using System.IO;
using System.Windows.Forms;
using AxMapWinGIS;
using MapWinGIS;
namespace Examples
public partial class MapExamples
// <summary>
// Adds the layers and register event handler.
// </summary>
public void SelectBox(AxMap axMap1, string dataPath)
axMap1.Projection = tkMapProjection.PROJECTION_GOOGLE_MERCATOR;
string filename = dataPath + "landuse.shp";
if (!File.Exists(filename))
MessageBox.Show("Couldn't file the file: " + filename);
Shapefile sf = new Shapefile();
sf.Open(filename, null);
if (!sf.StartEditingShapes(true, null))
MessageBox.Show("Failed to start edit mode: " + sf.Table.ErrorMsg[sf.LastErrorCode]);
sf.UseQTree = true;
sf.Labels.Generate("[Name]", tkLabelPositioning.lpCentroid, false);
axMap1.AddLayer(sf, true);
axMap1.SendSelectBoxFinal = true;
MapEvents.SelectBoxFinal += AxMap1SelectBoxFinal; // change MapEvents to axMap1
axMap1.MapUnits = tkUnitsOfMeasure.umMeters;
axMap1.CurrentScale = 50000;
axMap1.CursorMode = tkCursorMode.cmSelection;
// <summary>
// Performs selection, updates charts
// </summary>
void AxMap1SelectBoxFinal(object sender, _DMapEvents_SelectBoxFinalEvent e)
// it's assumed here that the layer we want to edit is the first 1 (with 0 index)
int layerHandle = axMap1.get_LayerHandle(0);
Shapefile sf = axMap1.get_Shapefile(layerHandle);
if (sf != null)
double left = 0.0;
double top = 0.0;
double bottom = 0.0;
double right = 0.0;
axMap1.PixelToProj(e.left,, ref left, ref top);
axMap1.PixelToProj(e.right, e.bottom, ref right, ref bottom);
object result = null;
var ext = new Extents();
ext.SetBounds(left, bottom, 0.0, right, top, 0.0);
if (sf.SelectShapes(ext, 0.0, SelectMode.INTERSECTION, ref result))
int[] shapes = result as int[];
if (shapes == null) return;
for (int i = 0; i < shapes.Length; i++)
sf.set_ShapeSelected(shapes[i], true);
The selection mode, which determines which shapes will be considered as included in the rectangular s...
Definition: Enumerations.cs:149
The available positioning of the label relative to the parent shape.
Definition: Enumerations.cs:835
Available cursor modes. Determines the default respond of map to the action of user.
Definition: Enumerations.cs:344
Commonly used map projections to be set in Form Designer (see AxMap.Projection property).
Definition: Enumerations.cs:1741
The possible units of measure for the data being displaying on map.
Definition: Enumerations.cs:1397
Map component for visualization of vector, raster or grid data.
Definition: AxMap.cs:56
void Redraw()
Redraws all layers in the map if the map is not locked.
Definition: AxMap.cs:183
Represents a rectangle on the map.
Definition: Extents.cs:49
Provides a functionality for accessing and editing ESRI shapefiles.
Definition: Shapefile.cs:72
Labels Labels
Gets or sets the instance of the Labels class associated with the shapefile.
Definition: Shapefile.cs:184
int LastErrorCode
Gets the code of last error which took place inside this object.
Definition: Shapefile.cs:249
int Generate(string Expression, tkLabelPositioning Method, bool LargestPartOnly)
Generates labels for each shape of the parent shapefile.
Definition: Labels.cs:490
void PixelToProj(double pixelX, double pixelY, ref double projX, ref double projY)
Converts pixel coordinates to projected map coordinates
Definition: AxMap.cs:2634
tkUnitsOfMeasure MapUnits
Gets or sets the units of measure for the map.
Definition: AxMap.cs:2622
tkMapProjection Projection
Sets projection of the map. It providers 2 most commonly used coordinate system/projections to be eas...
Definition: AxMap.cs:2709
double CurrentScale
Gets or sets the current map scale.
Definition: AxMap.cs:2395
bool SendSelectBoxFinal
Gets or sets whether the map sends the SelectBoxFinal event.
Definition: AxMap.cs:598
tkCursorMode CursorMode
Gets or sets the cursor mode for the map.
Definition: AxMap.cs:456
int 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...
Definition: AxMap.cs:1352
int AddLayer(object Object, bool visible)
Adds a layer to the map.
Definition: AxMap.cs:1342
Shapefile get_Shapefile(int layerHandle)
Gets shapefile object associated with the layer.
Definition: AxMap.cs:1546
bool StartEditingShapes(bool startEditTable, ICallback cBack)
Starts editing mode for the shapefile.
Definition: Shapefile.cs:840
bool Open(string shapefileName, ICallback cBack)
Opens shapefile from the disk.
Definition: Shapefile.cs:1430
void SelectNone()
Clears selection from all shapes.
Definition: Shapefile.cs:1803
void set_ShapeSelected(int shapeIndex, bool pVal)
Selects or deselects the specified shape. The _DMapEvents.SelectionChanged event is not fired.
Definition: Shapefile.cs:1768
bool SelectShapes(Extents boundBox, double tolerance, SelectMode selectMode, ref object result)
Returns an array with indices of shapes which are located inside specified bounds.
Definition: Shapefile.cs:1877
bool UseQTree
Gets or sets a value which indicates whether built-in quad-tree spatial index should be used for shap...
Definition: Shapefile.cs:1963
Table Table
Gets the reference to the attribute table associated with the shapefile.
Definition: Shapefile.cs:677