大家好,又见面了,我是你们的朋友全栈君。
根据图层名称获取图层
代码语言:javascript复制public IFeatureLayer getLayer(AxMapControl axMapControl, string layerName)
{
if (axMapControl.LayerCount > 0)
{
for (int i = 0; i < axMapControl.LayerCount; i )
{
ILayer pLayer = axMapControl.get_Layer(i);
if (pLayer.Name == layerName)
return pLayer as FeatureLayer;
}
}
return null;
}
按条件查询图层要素,并闪烁
代码语言:javascript复制public void searchFeatures(AxMapControl mapControl,string sqlfilter,IFeatureLayer pFeatureLayer)
{
IFeatureLayer pFeatLyr = pFeatureLayer;
IQueryFilter pFilter = new QueryFilterClass();
pFilter.WhereClause = sqlfilter;
IFeatureCursor pFeatCursor = pFeatLyr.Search(pFilter,true);
IFeature pFeat = pFeatCursor.NextFeature();
while (pFeat != null)
{
if (pFeat != null)
{
ISimpleFillSymbol pFillsyl = new SimpleFillSymbolClass();
RgbColor pRgbColor=new RgbColor();
pRgbColor.Red=255;
pRgbColor.Green=0;
pRgbColor.Blue=0;
pFillsyl.Color = pRgbColor;
object oFillsyl = pFillsyl;
IPolygon pPolygon = pFeat.Shape as IPolygon;
mapControl.FlashShape(pPolygon, 15, 20, pFillsyl);
mapControl.DrawShape(pPolygon, ref oFillsyl);
}
pFeat = pFeatCursor.NextFeature();
}
}
sqlfilter为查询条件,如查询layer图层中,属性字段ID<10的要素:searchFeatures(axMapControl1, “ID < 10”, layer);
建立缓冲区,并添加到图层
代码语言:javascript复制public void SetBuffer(AxMapControl m_map, string LayerName, double bufferDistance,string OutputPath)
{
try
{
IFeatureLayer layer = getLayer(m_map,LayerName);
if (layer == null)
{
LogHelper.Debug("图层不存在"); #这里是自己写的日志记录方法
return;
}
Geoprocessor gp = new Geoprocessor();
gp.OverwriteOutput = true;
ESRI.ArcGIS.AnalysisTools.Buffer buffer = new ESRI.ArcGIS.AnalysisTools.Buffer(layer, OutputPath, bufferDistance.ToString() " Meters");
IGeoProcessorResult results = (IGeoProcessorResult)gp.Execute(buffer, null);
if (results.Status != esriJobStatus.esriJobSucceeded)
{
LogHelper.Debug("为图层" layer.Name "建立缓冲区失败rn");
}
int k = OutputPath.LastIndexOf('\');
string pOutFeatclsName = OutputPath.Substring((k 1)).Trim();
string strFolder = OutputPath.Substring(0, k);
m_map.AddShapeFile(strFolder, pOutFeatclsName); #添加到图层
}
catch (Exception ex)
{
LogHelper.Error(ex.Message);
}
}