前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >C#之ArcGIS二次开发

C#之ArcGIS二次开发

作者头像
全栈程序员站长
发布2022-09-14 14:06:23
7420
发布2022-09-14 14:06:23
举报
文章被收录于专栏:全栈程序员必看

大家好,又见面了,我是你们的朋友全栈君。

根据图层名称获取图层

代码语言: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 + "建立缓冲区失败\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);
    }
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档