根据图层名称获取图层
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;
}
按条件查询图层要素,并闪烁
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);
建立缓冲区,并添加到图层
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 + "建立缓冲区失败\r\n"); } 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); } }
今天的文章C#之ArcGIS二次开发分享到此就结束了,感谢您的阅读。
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/6035.html