Point In Polygon Testing
This example uses selection, but is not the easiest way to select in response to mouse clicks, which is already provided as a MapFunction. Instead, this give an idea of a practical application of selecting a polygon based on the fact that it intersects with
a coordinate that is clicked. This relies on a very new fix to the code base to work correctly, but if you have the latest version it should work fine.
public partial class Form1 : Form
map1.MouseUp += map1_MouseUp;
map1.FunctionMode = FunctionModes.Pan;
// Handle the mouse up event
void map1_MouseUp(object sender, MouseEventArgs e)
// only select polygons with the right button
if(e.Button != MouseButtons.Right) return;
// Get the geographic location of the mouse click
Coordinate c = map1.PixelToProj(e.Location);
// Return if no data layers exist
if(map1.Layers.Count < 1) return;
// Also, mpl can be used to change the selection color.
IMapPolygonLayer mpl = map1.Layers as IMapPolygonLayer;
// If the first layer is not a polygon layer, exit.
if(mpl == null) return;
// Get the featureset that contains the actual polygon data for the layer
IFeatureSet fs = map1.Layers.DataSet as IFeatureSet;
// If this is null or not a featureset, exit
if(fs == null) return;
// Set up an index
int iShape = 0;
// Cycle through the shapes
foreach (ShapeRange shape in fs.ShapeIndices)
// Test if the coordinate is in the polygon
// Select the polygon if the the coordinate intersects.
// Allow the addition of background layers
private void btnAdd_Click(object sender, EventArgs e)