This example demonstrates how to remove shapes by mouse click and update their labels. Here is a screenshot with the results of the code execution.
using System;
using System.IO;
using System.Windows.Forms;
using AxMapWinGIS;
using MapWinGIS;
namespace Examples
{
public partial class MapExamples
{
public void RemoveShape(
AxMap axMap1,
string dataPath)
{
string filename = dataPath + "natural.shp";
if (!File.Exists(filename))
{
MessageBox.Show("Couldn't file the file: " + filename);
return;
}
sf.Open(filename, null);
int layerHandle = axMap1.
AddLayer(sf,
true);
if (!sf.StartEditingShapes(true, null))
{
MessageBox.Show("Failed to start edit mode: " + sf.ErrorMsg[sf.LastErrorCode]);
}
else
{
for (int i = 0; i < sf.NumShapes; i++)
sf.EditCellValue(fieldIndex, i, i);
sf.Labels.Synchronized = true;
sf.Labels.TextRenderingHint = tkTextRenderingHint.SystemDefault;
MapEvents.MouseDownEvent += AxMap1MouseDownEvent1;
}
}
private void AxMap1MouseDownEvent1(object sender, _DMapEvents_MouseDownEvent e)
{
if (sf != null)
{
double projX = 0.0;
double projY = 0.0;
object result = null;
ext.
SetBounds(projX, projY, 0.0, projX, projY, 0.0);
{
int[] shapes = result as int[];
if (shapes == null) return;
if (shapes.Length > 1)
{
string s = "More than one shapes were selected. Shape indices:";
for (int i = 0; i < shapes.Length; i++)
s += shapes[i] + Environment.NewLine;
MessageBox.Show(s);
}
else
{
{
MessageBox.Show(
"Failed to delete a shape: " + sf.ErrorMsg[sf.
LastErrorCode]);
}
else
{
MessageBox.Show("Shape was removed. Index = " + shapes[0]);
sf.
Labels.Label[i, 0].Text +=
"; " + i;
}
}
}
else
{
MessageBox.Show("Nothing was selected");
}
}
}
}
}
SelectMode
The selection mode, which determines which shapes will be considered as included in the rectangular s...
Definition: Enumerations.cs:149
tkLabelPositioning
The available positioning of the label relative to the parent shape.
Definition: Enumerations.cs:835
tkCursorMode
Available cursor modes. Determines the default respond of map to the action of user.
Definition: Enumerations.cs:344
FieldType
The available types of fields of dbf table.
Definition: Enumerations.cs:34
tkMapProjection
Commonly used map projections to be set in Form Designer (see AxMap.Projection property).
Definition: Enumerations.cs:1741
tkUnitsOfMeasure
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
void SetBounds(double xMin, double yMin, double zMin, double xMax, double yMax, double zMax)
Sets the bounds for the extents object.
Definition: Extents.cs:85
string Expression
Gets or sets the expression used to generate text of labels from the attribute table of the shapefile...
Definition: Labels.cs:158
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 Count
Gets the number of labels.
Definition: Labels.cs:476
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
tkCursorMode CursorMode
Gets or sets the cursor mode for the map.
Definition: AxMap.cs:456
bool SendMouseDown
Gets or sets whether the map sends mouse down events.
Definition: AxMap.cs:553
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 EditDeleteShape(int shapeIndex)
Deletes a shape from the shapefile.
Definition: Shapefile.cs:805
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
int EditAddField(string name, FieldType type, int precision, int width)
Adds a field to the attribute table of the shapefile. The table must be in editing mode.
Definition: Shapefile.cs:708