zoukankan      html  css  js  c++  java
  • arcgis engine 基础代码

    1.开始编辑,save feature property,停止编辑

    IWorkspace workspace = ((IDataset)pFeatureClass).Workspace;
    IWorkspaceEdit workspaceEdit = workspace as IWorkspaceEdit;

    然后开启编辑状态:

    bool startEdit = workspaceEdit.IsBeingEdited();
    if (!startEdit)
    {
        workspaceEdit.StartEditing(false);
    }
    workspaceEdit.StartEditOperation();

    然后获取IFeatureCursor和IFeature:

    pFeatureCursor = pFeatureClass.Search(pQueryFilter, false);

    //注意这里一定要为false,因为http://forums.arcgis.com/threads/45879-Cannot-call-Store-on-a-recycled-row-while-editing

    //如果为true可能会产生0x80040958的错误
    pFeature = pFeatureCursor.NextFeature();

    然后用IFeature.set_Value()方法对Feature进行属性表值的修改:

    pFeature.set_Value(i, valueToSet);

    修改完成,要用IFeature.store()方法保存:

    pFeature.Store();

    然后最好将Feature释放掉,再进行接下来的修改:

    System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeature);
    pFeature = null;
    pFeature = pFeatureCursor.NextFeature();

    接下来用IFeatureCursor.Flush():

    pFeatureCursor.Flush();
    System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeatureCursor);

    最后停止编辑状态:
    workspaceEdit.StopEditOperation();
    startEdit = workspaceEdit.IsBeingEdited();
    if (!startEdit)
    {
       workspaceEdit.StopEditing(true);
    }

     2.获取图层

            public IFeatureLayer GetFeatureLayerFromMap(string LayerName, IMap pMap)
            {
                IFeatureLayer rLayer = null;
                for (int i = 0; i < pMap.LayerCount; i++)
                {
                    ESRI.ArcGIS.Carto.ILayer lyr = pMap.get_Layer(i);
                    if (lyr is FeatureLayer)
                    {
                        if (lyr.Name.ToUpper() == LayerName.ToUpper())
                        {
                            rLayer = lyr as IFeatureLayer;
                            break;
                        }
                        else
                        {
                            IFeatureClass tFeaCls = (lyr as IFeatureLayer).FeatureClass;
                            if (tFeaCls != null && (tFeaCls as IDataset).Name.ToUpper() == LayerName.ToUpper())
                            {
                                rLayer = lyr as IFeatureLayer;
                                return rLayer;
                            }
                            else if (tFeaCls != null && (tFeaCls as IDataset).Name.Contains("."))
                            {
                                if ((tFeaCls as IDataset).Name.Substring((tFeaCls as IDataset).Name.IndexOf(".") + 1).ToUpper() == LayerName.ToUpper())
                                {
                                    rLayer = lyr as IFeatureLayer;
                                    return rLayer;
                                }
                            }
                        }
                    }
                    else if (lyr is IGroupLayer)
                    {
                        rLayer = GetFeatureLayerFromGroupLayer(lyr, LayerName);
                        if (rLayer != null)
                            break;
                    }
                }
                return rLayer;
            }
    
    
    private static LayerHelper _mAppConst = null;
            private static readonly object _lockAssistant = new object();
            public static LayerHelper Instance
            {
                get
                {
                    if (_mAppConst == null)
                    {
                        lock (_lockAssistant)
                        {
                            if (_mAppConst == null)
                                _mAppConst = new LayerHelper();
                        }
                    }
                    return _mAppConst;
                }
            }
            private LayerHelper() { }
    
    
    
    
            ///
            /// 根据图层名(要素名)得到组合图层中的图层
            ///
            ///图层
            ///图层名(要素名)
            /// 图层
            public IFeatureLayer GetFeatureLayerFromGroupLayer(ESRI.ArcGIS.Carto.ILayer pLyr, string LyrName)
            {
                if (pLyr is ESRI.ArcGIS.Carto.IGroupLayer)
                {
                    ICompositeLayer pCompLayer = pLyr as ICompositeLayer;
    
                    for (int i = 0; i < pCompLayer.Count; i++)
                    {
                        IFeatureLayer rLayer = GetFeatureLayerFromGroupLayer(pCompLayer.get_Layer(i), LyrName);
                        if (rLayer != null)
                        {
                            return rLayer;
                        }
                    }
                }
                else if (pLyr is ESRI.ArcGIS.Carto.IFeatureLayer)
                {
                    if (pLyr.Name.ToUpper() == LyrName.ToUpper())
                    {
                        return pLyr as IFeatureLayer;
                    }
                    else
                    {
                        IFeatureClass tFeaCls = (pLyr as IFeatureLayer).FeatureClass;
                        if (tFeaCls != null && (tFeaCls as IDataset).Name.ToUpper() == LyrName.ToUpper())
                            return pLyr as IFeatureLayer;
                        else if (tFeaCls != null && (tFeaCls as IDataset).Name.Contains("."))
                        {
                            if ((tFeaCls as IDataset).Name.Substring((tFeaCls as IDataset).Name.IndexOf(".") + 1).ToUpper() == LyrName.ToUpper())
                                return pLyr as IFeatureLayer;
                        }
                        return null;
                    }
                }
                return null;
            }
    

      

  • 相关阅读:
    删除文件时,提示 "操作无法完成..." 怎么处理
    对象的理解
    TP5架构下链接SQL数据库的一种方法
    关于URL隐藏index.php方法
    非典型的千万用户后台之路
    就这样,再见2015
    理想的程序员
    4个小例子告诉你:如何成为一名数据极客
    馆中窥职:小公司没那么糟糕
    JAVA设计模式详解(六)----------状态模式
  • 原文地址:https://www.cnblogs.com/yansc/p/5788376.html
Copyright © 2011-2022 走看看