Dotspatial 按条件筛选要素

/// <summary>
/// 按条件筛选记录
/// </summary>
/// <param name="mapControl"></param>
/// <param name="sqlFilter"></param>
public static void SelectByAttribute(Map mapControl, string filter)
{
if (mapControl.Layers.Count > 0)
{
//Declare a MapPolygonLayer
MapPolygonLayer stateLayer = default(MapPolygonLayer);
//TypeCast the first layer from MapControl to MapPolygonLayer.
//Layers are 0 based, therefore 0 is going to grab the first layer from the MapControl
stateLayer = (MapPolygonLayer) mapControl.Layers[0];
//Check whether stateLayer is polygon layer or not
if (stateLayer == null)
{
MessageBox.Show("The layer is not a polygon layer.");
}
else
{
//SelectByAttribute method is used to implement the filter operations.
//In this example, STATE_NAME is used implement the filter operation
//We can see the IdhoSate on the map
stateLayer.SelectByAttribute(filter);
}
}
else
{
MessageBox.Show("Please add a layer to the map.");
}
}

调用方法:

string filter = "[小班号] = '2'";
SelectByAttribute(mapMain, filter);

原文地址:https://www.cnblogs.com/kogame/p/12268646.html