陌生的不再陌生

导航

Dotspatial 分类专题图专题图

/// <summary>
/// 按多条件进行筛选记录,并显示颜色
/// </summary>
/// <param name="mapControl">地图控件</param>
/// <param name="filter">筛选条件</param>
/// <param name="legendText">图例文本</param>
public static void ThemeCategory(Map mapControl, string filter, string legendText)
{
if (mapControl.Layers.Count > 0)
{
//Delacre a MapPolygonLayer
MapPolygonLayer stateLayer = default(MapPolygonLayer);

//Type cast the FirstLayer of MapControl to MapPolygonLayer
stateLayer = (MapPolygonLayer) mapControl.Layers[0];

//Check the MapPolygonLayer ( Make sure that it has a polygon layer)
if (stateLayer == null)
{
MessageBox.Show("The layer is not a polygon layer.");
}
else
{
//!!! this line is necessary otherwise the code doesn't work
//this will load the attribute table of the layer into memory.
stateLayer.DataSet.FillAttributes();

//Create a new PolygonScheme
PolygonScheme scheme = new PolygonScheme();

//Create a new PolygonCategory
PolygonCategory category = new PolygonCategory(Color.Yellow, Color.Red, 1);

//Declare a filter string
//[POP1990],[STATE_NAME] are attributes from the attribute table of the given shape file.

//string filter = "[小班面积] <2 AND [林班号] = '3' and [小班号]<3";

//Set/Assign the filter expression to PolygonCategory
category.FilterExpression = filter;

//Set the Legend Text
category.LegendText = legendText; // "林班号=3";

//Add the PolygonCategory in to the PolygonScheme
scheme.AddCategory(category);

//Set the scheme in to the MapPolygonLayer's symbology
stateLayer.Symbology = scheme;
}
}
else
{
MessageBox.Show("Please add a layer to the map.");
}
}

 

 

调用方法:

//分类专题图专题图
string filter = "[面积] >2 AND [林班号] = '2'";
string legendText = "面积>2";
Lzq_Theme.ThemeCategory(mapMain, filter, legendText);

posted on 2020-02-06 14:42  陌生的不再陌生  阅读(472)  评论(0编辑  收藏  举报