C#之ArcGIS二次开发

C#之ArcGIS二次开发根据图层名称获取图层publicIFeatureLayergetLayer(AxMapControlaxMapControl,stringlayerName){if(axMapControl.LayerCount>0){for(inti=0;i

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

根据图层名称获取图层

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);
    }
}


版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/148699.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 最全中文停用词表

    最全中文停用词表本文将github上包括哈工大停用词、四川大学机器智能实验室停用词、百度停用词、中文停用https://github.com/goto456/stopwords以及最全中文停用词表(1893)https://blog.csdn.net/shijiebei2009/article/details/39696571进行整合得到新的中文停用词表,总共2462个为止纵然all例如[④e…

    2022年6月15日
    32
  • 使用虚拟环境virtualenv/Virtualenvwrapper隔离多个python

    使用虚拟环境virtualenv/Virtualenvwrapper隔离多个python

    2021年11月21日
    46
  • 正则表达式匹配任意字符(包括换行符)[通俗易懂]

    正则表达式匹配任意字符(包括换行符)[通俗易懂]可以用([\s\S]*),也可以用“([\d\D]*)”、“([\w\W]*)”来匹配,就可以匹配包括换行符在内的任意字符。http://tools.jb51.net/regex/javas

    2022年7月1日
    33
  • 用C++实现五子棋人机对战小游戏

    用C++实现五子棋人机对战小游戏如何用C++实现五子棋小游戏呢?五子棋可谓是家喻户晓了,在科技如此发达的今天,我们能不能用电脑实现五子棋人机对弈呢?答案当然是可以的首先,思考一下我们需要完成哪些步骤1、打印棋盘(使用二维数组即可)2、判断胜负(可以考虑深搜,但是暴力似乎能让代码更简洁)3、思考下一部棋该怎么走先从最简单的一部开始:打印棋盘voidout(){for(inti=0;i<=24;i++){for(intj=0;j<=24;j++){if(

    2022年6月16日
    63
  • 利用番茄钟来求职「建议收藏」

    利用番茄钟来求职「建议收藏」利用番茄钟来求职

    2022年4月21日
    38
  • 用c#实现简单的登录和注册功能

    用c#实现简单的登录和注册功能这两天c#大作业要求做一个简单的通讯录系统,我就先做了登录和注册的功能,在网上看了一些代码,自己再做,终于做出来了。做的不是很美观,但是可以简单实现。首先用sqlserver建表。我建了一个名为user_info的表,添加username和passdword两个字段。创建登录页面,改了一些控件的名称,效果如下图:登录界面代码如下:privatevoidbtn_Login…

    2022年8月22日
    4

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号