Esempio n. 1
0
        public override void OnClick()
        {
            if (m_pCommand == null)
            {
                return;
            }
            (m_pCommand as GeoProperties.LayerPropertiesTool).CurLayer = _AppHk.MapControl.CustomProperty as ILayer;

            // shduan 20110721 增加RasterLayer和RasterCatalog图层属性*************************
            if (_AppHk.MapControl.CustomProperty is IFeatureLayer)
            {
                IFeatureLayer           pFeatLayer    = _AppHk.MapControl.CustomProperty as IFeatureLayer;
                IFeatureLayerDefinition pFLDefinition = pFeatLayer as IFeatureLayerDefinition;

                IFeatureClass pFeatClass = pFeatLayer.FeatureClass;
            }
            else if (_AppHk.MapControl.CustomProperty is  IRasterLayer)
            {
                IRasterLayer pRasterLayer = _AppHk.MapControl.CustomProperty as IRasterLayer;
            }
            else if (_AppHk.MapControl.CustomProperty is IRasterCatalog)
            {
                IRasterCatalog pRC = _AppHk.MapControl.CustomProperty as IRasterCatalog;
            }
            //end ******************************************************************************
            if (this.WriteLog)
            {
                Plugin.LogTable.Writelog("打开" + Message);//xisheng 2011.07.08 增加日志
            }
            m_pCommand.OnClick();
        }
Esempio n. 2
0
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            string        selCity     = comboBox1.SelectedItem.ToString();
            IFeatureLayer lyrProVince = Utilities.GetLayerByName("省市_Mask", axMapControl1.Map) as IFeatureLayer;

            if (selCity != "全国")
            {
                IFeatureClass  featClsProvince = lyrProVince.FeatureClass;
                IFeatureCursor feaCursor       = null;
                IQueryFilter   queryFilter     = new QueryFilterClass();
                string         whereClause     = "[NAME] = '" + selCity + "'";
                queryFilter.WhereClause = whereClause;
                feaCursor = featClsProvince.Search(queryFilter, false);
                IFeature pFeature = feaCursor.NextFeature();

                if (pFeature != null)
                {
                    Utilities.ZoomToFeature(pFeature, axMapControl1.Object as IMapControlDefault);
                    IFeatureLayerDefinition lyrDef = lyrProVince as IFeatureLayerDefinition;
                    lyrDef.DefinitionExpression = whereClause;
                    lyrProVince.Visible         = true;
                }
            }
            else
            {
                axMapControl1.Map.ClipGeometry = null;
                axMapControl1.Extent           = axMapControl1.FullExtent;
                lyrProVince.Visible            = false;
            }
        }
Esempio n. 3
0
        public static IArray Identity(IFeatureClass featureclass, IGeometry geometry, string whereClause)
        {
            if (geometry == null)
            {
                return(null);
            }
            if (geometry.GeometryType == esriGeometryType.esriGeometryPoint)
            {
                ITopologicalOperator topop = geometry as ITopologicalOperator;
                double buffer = 0.0;
                if (double.TryParse(System.Configuration.ConfigurationManager.AppSettings["BUFFER"], out buffer))
                {
                    geometry = topop.Buffer(buffer);
                }
            }
            IFeatureLayer featureLayer = new FeatureLayerClass();

            featureLayer.FeatureClass = featureclass;
            IFeatureLayerDefinition featureLayerDefinition = featureLayer as IFeatureLayerDefinition;

            featureLayerDefinition.DefinitionExpression = whereClause;
            IFeatureLayer newfeatureLayer = featureLayerDefinition.CreateSelectionLayer(featureclass.AliasName, false, null, whereClause);
            IIdentify     identify        = featureLayer as IIdentify;
            IArray        identifyObjs    = identify.Identify(geometry);

            return(identifyObjs);
        }
Esempio n. 4
0
        public void ApplyDefinisionQuery(string Field, string Condition, string Value)
        {
            try
            {
                IFeatureLayer FocusedLayer = axMapControl1.ActiveView.FocusMap.get_Layer(comboBox2.SelectedIndex) as IFeatureLayer;

                IFeatureLayerDefinition DefinisionQuery = FocusedLayer as IFeatureLayerDefinition;
                string ConditionToBeApplyed;
                char   FirstCharOfValue = comboBox9.Text[0];
                int    FirstNumAsci     = 48;
                int    SecondNumAsci    = 57;
                if (FirstCharOfValue >= FirstNumAsci && FirstCharOfValue <= SecondNumAsci)
                {
                    ConditionToBeApplyed = Field + Condition + Value;
                }
                else
                {
                    string ValueinQoutes = "'" + Value + "'";
                    ConditionToBeApplyed = Field + Condition + ValueinQoutes;
                }
                DefinisionQuery.DefinitionExpression = ConditionToBeApplyed;
                axMapControl1.ActiveView.Refresh();
            }
            catch
            {
                MessageBox.Show("Error");
            }
        }
        /// <summary>
        /// Occurs when this command is clicked
        /// </summary>
        public override void OnClick()
        {
            try
            {
                //ILayer player = ClsGlobal.GetSelectedLayer(m_hookHelper);
                IBasicMap map   = null;
                ILayer    layer = null;
                ClsGlobal.GetSelectedMapAndLayer(m_pTocCtl, ref map, ref layer);
                if (map == null || layer == null)
                {
                    return;
                }

                IFeatureLayer           pFLayer = (IFeatureLayer)layer;
                IFeatureLayerDefinition pFLDef  = (IFeatureLayerDefinition)pFLayer;
                IFeatureSelection       pFSel   = (IFeatureSelection)pFLayer;
                ISelectionSet           pSSet   = pFSel.SelectionSet;
                if (pSSet.Count > 0)
                {
                    IFeatureLayer pSelFL = pFLDef.CreateSelectionLayer(layer.Name + "Selection", true, null, null);
                    map.AddLayer(pSelFL);
                    IActiveView activiView = map as IActiveView;
                    activiView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
                    m_pTocCtl.Update();
                }
            }
            catch (Exception ex)
            {
                ;
            }
        }
        /// <summary>
        /// 根据指定的查询条件查询获取IFeature
        /// </summary>
        /// <param name="myIFeatureLayer">IFeatureLayer扩展对象</param>
        /// <param name="strWhereClause">查询条件</param>
        /// <param name="blResetLayerDefinition">是否重置LayerDefinition进行查询</param>
        /// <returns>IFeature列表</returns>
        public static List <IFeature> GetLstIFeature(this IFeatureLayer myIFeatureLayer, string strWhereClause, bool blResetLayerDefinition)
        {
            if (myIFeatureLayer == null)
            {
                return(new List <IFeature>());
            }
            IFeatureLayerDefinition myIFeatureLayerDefinition = myIFeatureLayer as IFeatureLayerDefinition;
            string strOldIFeatureLayerDefinition = myIFeatureLayerDefinition.DefinitionExpression;

            if (blResetLayerDefinition)
            {
                myIFeatureLayerDefinition.DefinitionExpression = "";
            }
            IQueryFilter myIQueryFilter = new QueryFilterClass();

            myIQueryFilter.WhereClause = strWhereClause;
            List <IFeature> lstIFeature      = new List <IFeature>();
            IFeatureCursor  myIFeatureCursor = myIFeatureLayer.Search(myIQueryFilter, false);

            for (IFeature eachIFeature = myIFeatureCursor.NextFeature(); null != eachIFeature; eachIFeature = myIFeatureCursor.NextFeature())
            {
                lstIFeature.Add(eachIFeature);
            }
            if (blResetLayerDefinition)
            {
                myIFeatureLayerDefinition.DefinitionExpression = strOldIFeatureLayerDefinition;
            }
            return(lstIFeature);
        }
Esempio n. 7
0
        /// <summary>
        /// 点击事件
        /// </summary>
        public override void OnClick()
        {
            DataEditCommon.g_pAxMapControl.CurrentTool = null;

            IMap pMap = m_hookHelper.FocusMap;
            UID  puid = new UID();

            puid.Value = "{40A9E885-5533-11d0-98BE-00805F7CED21}";//IFeatureLayer
            IEnumLayer enumLayer = pMap.get_Layers(puid, true);

            enumLayer.Reset();
            ILayer player;

            player = enumLayer.Next();
            IFeatureLayer featureLayer = null;

            while (player != null)
            {
                featureLayer = player as IFeatureLayer;
                IFeatureLayerDefinition featureLayerDef = featureLayer as IFeatureLayerDefinition;
                string sWhereClause = "";//定义筛选条件
                featureLayerDef.DefinitionExpression = sWhereClause;

                player = enumLayer.Next();
            }

            m_hookHelper.ActiveView.Extent = m_hookHelper.ActiveView.FullExtent;
            m_hookHelper.ActiveView.Refresh();
        }
Esempio n. 8
0
        private void 打开属性表ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ITable table = _toccSelectedLayer as ITable;

            if (table != null)
            {
                if (_attributeForm == null || _attributeForm.IsDisposed)
                {
                    _attributeForm = new AttributeForm();
                    _attributeForm.FeatureLocation += _attributeForm_FeatureLocation;
                }
                else
                {
                    _attributeForm.FeatureLocation -= _attributeForm_FeatureLocation;
                    _attributeForm.FeatureLocation += _attributeForm_FeatureLocation;
                    _attributeForm.Activate();//之前已打开,则给予焦点,置顶。
                }
                if (!_attributeForm.Visible)
                {
                    _attributeForm.Show(this);
                }

                IFeatureLayerDefinition featureLyrDef = _toccSelectedLayer as IFeatureLayerDefinition;
                string whereClause = featureLyrDef?.DefinitionExpression;
                _attributeForm.LoadAttribute(_toccSelectedLayer as IFeatureLayer, whereClause);
            }
        }
Esempio n. 9
0
 private void btncreat_Click(object sender, EventArgs e)
 {
     try
     {
         ILayer player = null;
         for (int j = 0; j < pMapControl.Map.LayerCount; j++)
         {
             if (cmblayer.SelectedItem.ToString() == pMapControl.Map.Layer[j].Name)
             {
                 player = pMapControl.Map.Layer[j];
                 break;
             }
         }
         IFeatureLayer           pFLayer = (IFeatureLayer)player;
         IFeatureLayerDefinition pFLDef  = (IFeatureLayerDefinition)pFLayer;
         IFeatureSelection       pFSel   = (IFeatureSelection)pFLayer;
         ISelectionSet           pSSet   = pFSel.SelectionSet;
         if (pSSet.Count > 0)
         {
             IFeatureLayer pSelFL = pFLDef.CreateSelectionLayer(player.Name + "Selection", true, null, null);
             pMapControl.Map.AddLayer(pSelFL);
         }
         else
         {
             MessageBox.Show("没有选中的对象!");
         }
         this.Close();
     }
     catch (System.Exception ex)
     {
         MessageBox.Show(ex.ToString(), "错误!", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     this.Close();
 }
Esempio n. 10
0
        private void ChangeLayersDef()
        {
            for (int i = 0; i < axMapControl.Map.LayerCount; i++)
            {
                IFeatureLayer           featLay    = axMapControl.Map.get_Layer(i) as IFeatureLayer;
                IFeatureLayerDefinition featLayDef = featLay as IFeatureLayerDefinition;
                featLayDef.DefinitionExpression = "FromDate<='" + comboBoxItem.Items[comboBoxItem.SelectedIndex].ToString() + "' and ToDate>'" + comboBoxItem.Items[comboBoxItem.SelectedIndex].ToString() + "'";
            }

            axMapControl.ActiveView.Refresh();
        }
Esempio n. 11
0
        private void fillDefQueryProps(IFeatureLayer flyr)
        {
            IFeatureLayerDefinition flyrdef = flyr as IFeatureLayerDefinition;

            if (flyrdef != null)
            {
                if (flyrdef.DefinitionExpression != "")
                {
                    defquery = flyrdef.DefinitionExpression;
                }
            }
        }
        /// <summary>
        /// 根据制定的查询条件获取IFeature
        /// </summary>
        /// <param name="myIFeatureLayer">IFeatureLayer扩展对象</param>
        /// <param name="myIGeometry">查询地理要素</param>
        /// <param name="strWhereClause">查询条件</param>
        /// <param name="_EsriSpatialRelEnum">查询的图元和查询地理要素的空间关系</param>
        /// <param name="blReSetLayerDefinition">是否重置LayerDefinition进行查询</param>
        /// <returns>IFeature列表</returns>
        public static List <IFeature> GetLstIFeature(this IFeatureLayer myIFeatureLayer, IGeometry myIGeometry, string strWhereClause, esriSpatialRelEnum myEsriSpatialRelEnum, bool blReSetLayerDefinition)
        {
            if (myIFeatureLayer == null)
            {
                return(new List <IFeature>());
            }
            if (myEsriSpatialRelEnum == esriSpatialRelEnum.esriSpatialRelUndefined)
            {
                switch (myIFeatureLayer.FeatureClass.ShapeType)
                {
                case esriGeometryType.esriGeometryPoint:
                    myEsriSpatialRelEnum = esriSpatialRelEnum.esriSpatialRelContains;
                    break;

                case esriGeometryType.esriGeometryPolyline:
                    myEsriSpatialRelEnum = esriSpatialRelEnum.esriSpatialRelCrosses;
                    break;

                case esriGeometryType.esriGeometryPolygon:
                    myEsriSpatialRelEnum = esriSpatialRelEnum.esriSpatialRelIntersects;
                    break;
                }
            }
            ISpatialFilter myISpatialFilter = new SpatialFilterClass();

            if (!string.IsNullOrEmpty(strWhereClause))
            {
                myISpatialFilter.WhereClause = strWhereClause;
            }
            myISpatialFilter.Geometry      = myIGeometry;
            myISpatialFilter.SpatialRel    = myEsriSpatialRelEnum;
            myISpatialFilter.GeometryField = myIFeatureLayer.FeatureClass.ShapeFieldName;
            IFeatureLayerDefinition myIFeatureLayerDefinition = myIFeatureLayer as IFeatureLayerDefinition;
            string strOldIFeatureLayerDefinition = myIFeatureLayerDefinition.DefinitionExpression;

            if (blReSetLayerDefinition)
            {
                myIFeatureLayerDefinition.DefinitionExpression = "";
            }
            IFeatureCursor  myIFeatureCursor = myIFeatureLayer.Search(myISpatialFilter, false);
            List <IFeature> lstIFeature      = new List <IFeature>();

            for (IFeature eachIFeature = myIFeatureCursor.NextFeature(); null != eachIFeature; eachIFeature = myIFeatureCursor.NextFeature())
            {
                lstIFeature.Add(eachIFeature);
            }
            if (blReSetLayerDefinition)
            {
                myIFeatureLayerDefinition.DefinitionExpression = strOldIFeatureLayerDefinition;
            }
            return(lstIFeature);
        }
Esempio n. 13
0
        public uctrDefinitionQuery(ILayer pLayer, string Layerid)
        {
            try
            {
                LayerID                   = Layerid;
                m_pLayer                  = pLayer;
                m_pCurrentLayer           = (IFeatureLayer)m_pLayer;
                m_pFeatureLayerDefinition = (IFeatureLayerDefinition)m_pCurrentLayer;

                InitializeComponent();
            }
            catch { }
        }
Esempio n. 14
0
 /// <summary>
 /// 给定过滤条件,显示符合条件的纪录
 /// </summary>
 /// <params name="pMap">IMap</params>
 /// <params name="p2DLayer">ILayer</params>
 /// <params name="strFilter">sql语句where 后面的条件</params>
 public static void Show_IsVisiable(IMap pMap, ILayer p2DLayer, string strFilter)
 {
     try
     {
         IFeatureLayer           p2DFeatureLayer           = (IFeatureLayer)p2DLayer;
         IFeatureLayerDefinition p2DFeatureLayerDefinition = (IFeatureLayerDefinition)p2DFeatureLayer;
         p2DFeatureLayerDefinition.DefinitionExpression = strFilter;
         IActiveView pActive = (IActiveView)pMap;
         pActive.PartialRefresh(esriViewDrawPhase.esriViewBackground, null, null);
     }
     catch (Exception ex)
     {
     }
 }
Esempio n. 15
0
        public void RemoveDefinisionQuery(int LayerIndex)
        {
            try
            {
                IFeatureLayer           FocusedLayer    = axMapControl1.ActiveView.FocusMap.get_Layer(LayerIndex) as IFeatureLayer;
                IFeatureLayerDefinition DefinisionQuery = FocusedLayer as IFeatureLayerDefinition;

                DefinisionQuery.DefinitionExpression = "";
                axMapControl1.ActiveView.Refresh();
            }
            catch
            {
            }
        }
Esempio n. 16
0
        private void ChangeLayersDef()
        {
            for (int i = 0; i < Mapcontrol.Map.LayerCount; i++)
            {
                //cyf 20110706 add
                ILayer mLayer = Mapcontrol.Map.get_Layer(i);
                if (mLayer is IGroupLayer)
                {
                    ICompositeLayer pComlayer = mLayer as ICompositeLayer;
                    for (int j = 0; j < pComlayer.Count; j++)
                    {
                        IFeatureLayer featLay = pComlayer.get_Layer(j) as IFeatureLayer;
                        if (featLay == null)
                        {
                            continue;
                        }
                        if (!(featLay.FeatureClass as IDataset).Name.EndsWith("_GOH"))
                        {
                            continue;
                        }
                        if (featLay.FeatureClass.Fields.FindField("FromDate") < 0 || featLay.FeatureClass.Fields.FindField("ToDate") < 0)
                        {
                            continue;
                        }
                        IFeatureLayerDefinition featLayDef = featLay as IFeatureLayerDefinition;
                        featLayDef.DefinitionExpression = "FromDate<='" + comboBoxItem.Items[comboBoxItem.SelectedIndex].ToString() + "' and ToDate>'" + comboBoxItem.Items[comboBoxItem.SelectedIndex].ToString() + "'";
                    }
                }//end
                else
                {
                    IFeatureLayer featLay = Mapcontrol.Map.get_Layer(i) as IFeatureLayer;
                    if (featLay == null)
                    {
                        continue;
                    }
                    if (!(featLay.FeatureClass as IDataset).Name.EndsWith("_GOH"))
                    {
                        continue;
                    }
                    if (featLay.FeatureClass.Fields.FindField("FromDate") < 0 || featLay.FeatureClass.Fields.FindField("ToDate") < 0)
                    {
                        continue;
                    }
                    IFeatureLayerDefinition featLayDef = featLay as IFeatureLayerDefinition;
                    featLayDef.DefinitionExpression = "FromDate<='" + comboBoxItem.Items[comboBoxItem.SelectedIndex].ToString() + "' and ToDate>'" + comboBoxItem.Items[comboBoxItem.SelectedIndex].ToString() + "'";
                }
            }

            Mapcontrol.ActiveView.Refresh();
        }
Esempio n. 17
0
        /// <summary>
        /// 以SQL where 条件创建IFeatureLayer
        /// </summary>
        /// <param name="layer"></param>
        /// <param name="newLayerName"></param>
        /// <param name="whereClause"></param>
        /// <returns></returns>
        public static IFeatureLayer createFilterLayer(IFeatureLayer layer, string newLayerName, string whereClause)
        {
            IQueryFilter qf = new QueryFilterClass();

            qf.WhereClause = whereClause;

            IFeatureSelection fSelection = layer as IFeatureSelection;

            fSelection.SelectFeatures(qf, esriSelectionResultEnum.esriSelectionResultNew, false);

            IFeatureLayerDefinition layer_def      = fSelection as IFeatureLayerDefinition;
            IFeatureLayer           layer_filtered = layer_def.CreateSelectionLayer(newLayerName, true, null, null);

            return(layer_filtered);
        }
Esempio n. 18
0
        /// <summary>
        /// Occurs when this command is clicked
        /// </summary>
        public override void OnClick()
        {
            // TODO: Add LHSBBaseCommand.OnClick implementation
            //get the count of layers in this current subject
            int countofLayers = m_hookHelper.FocusMap.LayerCount;

            //build a loop to act our action
            for (int i = 0; i < countofLayers; i++)
            {
                ILayer lyr = m_hookHelper.FocusMap.get_Layer(i);
                IFeatureLayerDefinition fLyrDef = lyr as IFeatureLayerDefinition;
                fLyrDef.DefinitionExpression = "ÈË¿Ú>= 50";
                m_hookHelper.ActiveView.Refresh();
            }
        }
Esempio n. 19
0
 private void button3_Click(object sender, EventArgs e)
 {
     if (comboBox2.Text == "")
     {
         MessageBox.Show("Please select a layer from the comboBox firstly!");
         return;
     }
     if (textBox2.Text != "")
     {
         ILayer                  sheyakhaLayer  = axMapControl1.ActiveView.FocusMap.get_Layer(comboBox2.SelectedIndex);
         IFeatureLayer           fsheyakhalayer = sheyakhaLayer as FeatureLayer;
         IFeatureLayerDefinition dlayer         = fsheyakhalayer as IFeatureLayerDefinition;
         dlayer.DefinitionExpression = textBox2.Text;
         axMapControl1.Refresh();
     }
 }
Esempio n. 20
0
        /// <summary>
        /// 根据拉框范围选择要素
        /// </summary>
        /// <params name="pGeometry"></params>
        private void GetFeaturesByShape(IGeometry pGeometry)
        {
            IMap pMap = m_hookHelper.FocusMap;
            UID  puid = new UID();

            puid.Value = "{40A9E885-5533-11d0-98BE-00805F7CED21}";//IFeatureLayer
            IEnumLayer enumLayer = pMap.get_Layers(puid, true);

            enumLayer.Reset();
            ILayer player;

            player = enumLayer.Next();
            IFeatureLayer featureLayer = null;

            while (player != null)
            {
                featureLayer = player as IFeatureLayer;
                string layerName    = featureLayer.Name;
                string feaSelectSet = GetLayerFeatureSelectSet(pGeometry, featureLayer);

                //新建 IFeatureLayerDefinition 接口实例
                IFeatureLayerDefinition featureLayerDef = featureLayer as IFeatureLayerDefinition;
                string sWhereClause;
                if (feaSelectSet == "")
                {
                    ///如果当前图层无选中要素情况处理:获得所有要素OID,
                    ///让该图层所有要素不可见
                    string sLyrAllFeatureIDs = GetLayerAllFeatures(featureLayer);
                    if (sLyrAllFeatureIDs == "")
                    {
                        player = enumLayer.Next();
                        continue;
                    }
                    else
                    {
                        sWhereClause = featureLayer.FeatureClass.OIDFieldName + " Not In (" + sLyrAllFeatureIDs + " )";
                    }
                }
                else
                {
                    sWhereClause = featureLayer.FeatureClass.OIDFieldName + " In (" + feaSelectSet + " )";//定义筛选条件
                }
                featureLayerDef.DefinitionExpression = sWhereClause;

                player = enumLayer.Next();
            }
        }
Esempio n. 21
0
        private void InitialFrm(List <IFeatureLayer> layerList)
        {
            foreach (IFeatureLayer aFeatLay in layerList)
            {
                IFeatureSelection featSel = aFeatLay as IFeatureSelection;
                int fdIndex = aFeatLay.FeatureClass.Fields.FindField("SourceOID");
                if (fdIndex == -1)
                {
                    continue;
                }
                IEnumIDs      pEnumIDs = featSel.SelectionSet.IDs;
                int           ID       = pEnumIDs.Next();
                StringBuilder sb       = new StringBuilder();
                while (ID != -1)
                {
                    IFeature pFeat = aFeatLay.FeatureClass.GetFeature(ID);
                    if (sb.Length != 0)
                    {
                        sb.Append(",");
                    }
                    sb.Append(pFeat.get_Value(fdIndex).ToString());
                    ID = pEnumIDs.Next();
                }

                IQueryFilter queryFilter = new QueryFilterClass();
                queryFilter.WhereClause = "SourceOID in (" + sb.ToString() + ")";
                IFeatureLayerDefinition featLayDef = aFeatLay as IFeatureLayerDefinition;
                featLayDef.DefinitionExpression = "";
                featSel.SelectFeatures(queryFilter, esriSelectionResultEnum.esriSelectionResultNew, false);
                featSel.SelectionChanged();

                IFeatureLayer    selFeatLay       = featLayDef.CreateSelectionLayer(aFeatLay.Name, true, "", "");
                IGeoFeatureLayer pGeoFeatureLayer = aFeatLay as IGeoFeatureLayer;
                if (pGeoFeatureLayer != null)
                {
                    (selFeatLay as IGeoFeatureLayer).Renderer = pGeoFeatureLayer.Renderer;
                }
                this.axMapControl.Map.AddLayer(selFeatLay);
            }
            SysCommon.Gis.ModGisPub.LayersCompose(this.axMapControl.Object as IMapControlDefault);

            InitialSliderItem(this.axMapControl.Object as IMapControlDefault);

            InitialbarMap();
        }
Esempio n. 22
0
        private IFeature ZoomtoProvince(string cityName) //Form1中的帮助函数
        {
            IFeatureLayer lyrCity     = Utilities.GetLayerByName("县区_Mask", axMapControl1.Map) as IFeatureLayer;
            IFeatureLayer lyrProVince = Utilities.GetLayerByName("省市_Mask", axMapControl1.Map) as IFeatureLayer;
            string        cityCode    = string.Empty;

            #region 获取县区的行政代码
            IFeatureClass featCls = lyrCity.FeatureClass;
            IFields       pFields = featCls.Fields;
            int           index   = pFields.FindField("ADCODE99");
            //查找要素
            IFeatureCursor pFeatCursor  = null;
            IQueryFilter   pQueryFilter = new QueryFilterClass();
            string         whereClause  = "[NAME99] like '" + cityName + "*'";
            pQueryFilter.WhereClause = whereClause;
            pFeatCursor = featCls.Search(pQueryFilter, false);
            IFeature pFeat = pFeatCursor.NextFeature();
            if (pFeat != null)
            {
                cityCode = pFeat.get_Value(index).ToString().Substring(0, 2) + "0000";
                IFeatureLayerDefinition pFeatDef = (IFeatureLayerDefinition)lyrCity;
                pFeatDef.DefinitionExpression = whereClause;
                lyrCity.Visible = true;
            }
            #endregion
            //缩放到省份
            if (cityCode != string.Empty)
            {
                IFeatureClass  featClsProvince = lyrProVince.FeatureClass;
                IFeatureCursor featCursor      = null;
                IQueryFilter   queryFilter     = new QueryFilterClass();
                whereClause             = "[ADCODE99] = " + cityCode;
                queryFilter.WhereClause = whereClause;
                featCursor = featClsProvince.Search(queryFilter, false);
                IFeature pFeature = featCursor.NextFeature();
                if (pFeature != null)
                {
                    Utilities.ZoomToFeature(pFeature, axMapControl1.Object as IMapControlDefault);
                    IFeatureLayerDefinition lyrDef = (IFeatureLayerDefinition)lyrProVince;
                    lyrDef.DefinitionExpression = whereClause;
                    lyrProVince.Visible         = true;
                }
            }
            return(pFeat);
        }
Esempio n. 23
0
        /// <summary>
        /// Gets the number of rows, belonging to a given layer, filtered by the layer.
        /// </summary>
        /// <param name="layer">Esri layer of the TOC</param>
        /// <returns>Number of rows or Null if the layer is invalid or not filtered.</returns>
        public static int?GetFilteredLayerRowCount(IFeatureLayer layer)
        {
            IDisplayTable displayTable = (IDisplayTable)layer;

            if ((layer.Valid) && (displayTable != null))
            {
                IFeatureLayerDefinition layerDefinition = layer as IFeatureLayerDefinition;
                string filter = layerDefinition?.DefinitionExpression;
                if (!string.IsNullOrEmpty(filter))
                {
                    IQueryFilter queryFilter = new QueryFilterClass();
                    queryFilter.WhereClause = filter;
                    queryFilter.AddField(layer.FeatureClass.OIDFieldName);
                    return(displayTable.DisplayTable.RowCount(queryFilter));
                }
            }
            return(null);
        }
Esempio n. 24
0
 private void btnOK_Click(object sender, EventArgs e)
 {
     //刷新地图
     if (m_MapControl != null)
     {
         ILayer m_layer = GetLayerByName(m_MapControl, m_pCurrentLayer.Name);
         if (m_layer == null)
         {
             MessageBox.Show("在地图中未找到选择图层,请重新选择查看图层!", "提示");
             return;
         }
         IFeatureLayer pFeatureLayer = (IFeatureLayer)m_layer;
         m_pFeatureLayerDefinition = (IFeatureLayerDefinition)pFeatureLayer;
         m_pFeatureLayerDefinition.DefinitionExpression = RichTxtCondition.Text.Trim();
         m_MapControl.Refresh(esriViewDrawPhase.esriViewBackground, m_layer, null);
     }
     this.Close();
 }
Esempio n. 25
0
        private void txtLayerName_Click(object sender, EventArgs e)
        {
            Plugin.SelectLayerByTree frm = new Plugin.SelectLayerByTree(1);
            SysCommon.ModSysSetting.CopyLayerTreeXmlFromDataBase(Plugin.ModuleCommon.TmpWorkSpace, frm._LayerTreePath);
            if (frm.ShowDialog() == DialogResult.OK)
            {
                if (frm.m_NodeKey.Trim() != "")
                {
                    m_pCurrentLayer = new FeatureLayerClass();
                    IFeatureClass pFeatureClass = null;
                    pFeatureClass = SysCommon.ModSysSetting.GetFeatureClassByNodeKey(Plugin.ModuleCommon.TmpWorkSpace, frm._LayerTreePath, frm.m_NodeKey);
                    if (pFeatureClass == null)
                    {
                        return;
                    }
                    m_pCurrentLayer.FeatureClass = pFeatureClass;
                    LayerID = frm.m_NodeKey;
                }

                if (m_pCurrentLayer.FeatureClass != null)
                {
                    txtLayerName.Text    = frm.m_NodeText;
                    m_pCurrentLayer.Name = frm.m_NodeText;// xisheng 20111122 自定义查询无名称BUG修改
                }
            }
            else
            {
                return;
            }
            ILayer pLayer = GetLayerByName(m_MapControl, m_pCurrentLayer.Name);

            if (pLayer == null)
            {
                return;
            }
            IFeatureLayer           pFeatureLayer = (IFeatureLayer)pLayer;
            IFeatureLayerDefinition pDefinition   = (IFeatureLayerDefinition)pFeatureLayer;

            if (pDefinition.DefinitionExpression != null || pDefinition.DefinitionExpression != "")
            {
                RichTxtCondition.Text = pDefinition.DefinitionExpression;
            }
        }
Esempio n. 26
0
        //空间过滤图层的要素显示
        private void filterLyrBySpatial(ILayer inLayer, IGeometry inGeometry)
        {
            IFeatureLayer pFL = inLayer as IFeatureLayer;

            if (pFL == null)
            {
                return;
            }
            ISpatialFilter pSF = new SpatialFilterClass();

            pSF.Geometry   = (inGeometry as ITopologicalOperator).Boundary;
            pSF.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains;
            //pSF.SpatialRelDescription = "****T****";
            IFeatureCursor pFC = pFL.Search(pSF, false);

            if (pFC == null)
            {
                return;
            }
            string   lyrDef   = pFL.FeatureClass.OIDFieldName + " IN(";
            IFeature pFeature = pFC.NextFeature();

            while (pFeature != null)
            {
                lyrDef += pFeature.OID.ToString() + ",";

                pFeature = pFC.NextFeature();
            }
            System.Runtime.InteropServices.Marshal.ReleaseComObject(pFC);
            pFC = null;
            if (lyrDef.EndsWith("IN("))
            {
                return;
            }
            lyrDef  = lyrDef.Substring(0, lyrDef.Length - 1);
            lyrDef += ")";

            IFeatureLayerDefinition pFLD = pFL as IFeatureLayerDefinition;

            pFLD.DefinitionExpression = lyrDef;
        }
Esempio n. 27
0
        private void button20_Click_1(object sender, EventArgs e)
        {
            try
            {
                if (textBox1.Text != "")
                {
                    ILayer                  sheyakhaLayer  = axMapControl1.ActiveView.FocusMap.get_Layer(layerIndex);
                    IFeatureLayer           fsheyakhalayer = sheyakhaLayer as FeatureLayer;
                    IFeatureLayerDefinition dlayer         = fsheyakhalayer as IFeatureLayerDefinition;
                    dlayer.DefinitionExpression = textBox1.Text;
                    axMapControl1.Refresh();
                }

                this.Close();
                f1.Show();
            }
            catch (Exception)
            {
                MessageBox.Show("There was an error with the expression. \nGeneral function failure [" + Layer + "] \nSyntax error (missing operator) in query expression '" + textBox1.Text.ToString() + "'.");
            }
        }
Esempio n. 28
0
        /// <summary>
        /// 创建新图层
        /// </summary>
        /// <param name="saveFile">保存路径</param>
        /// <returns></returns>
        private IFeatureLayer CreateNewLayer(string saveFile)
        {
            string saveName = Path.GetFileNameWithoutExtension(saveFile);
            IFeatureLayerDefinition featureLayerDefinition = oldFeatureLayer as IFeatureLayerDefinition;

            if (featureLayerDefinition == null)
            {
                return(null);
            }
            //从要素图层的选择集中创建新要素图层
            IFeatureLayer selectionLayer = featureLayerDefinition.CreateSelectionLayer(saveName, true, null, null);
            //打开要素工作空间
            IFeatureWorkspace pFeatureWorkspace = (IFeatureWorkspace)FeatureInfoClass.GetShapefileWorkspace(saveFile);

            if (pFeatureWorkspace == null || selectionLayer == null)
            {
                return(null);
            }
            IFeatureLayer copyFeatureLayer = CopyOldFeatureLayerWithSelectFiled(pFeatureWorkspace, selectionLayer, saveName);

            return(copyFeatureLayer);
        }
        /// <summary>
        /// 得到指定图层所有的IFeature
        /// </summary>
        /// <param name="myIFeatureLayer">IFeatureLayer扩展对象</param>
        /// <param name="blReSetLayerDefinition">是否重置LayerDefinition进行查询</param>
        /// <returns>IFeature列表</returns>
        public static List <IFeature> GetAllLstIFeature(this IFeatureLayer myIFeatureLayer, bool blReSetLayerDefinition)
        {
            if (myIFeatureLayer == null)
            {
                return(new List <IFeature>());
            }
            IFeatureLayerDefinition myIFeatureLayerDefinition = myIFeatureLayer as IFeatureLayerDefinition;
            string strOldIFeatureLayerDefinition = myIFeatureLayerDefinition.DefinitionExpression;

            if (blReSetLayerDefinition)
            {
                myIFeatureLayerDefinition.DefinitionExpression = "";
            }
            IFeatureCursor  myIFeatureCursor = myIFeatureLayer.Search(null, false);
            List <IFeature> lstIFeature      = new List <IFeature>();

            for (IFeature eachIFeature = myIFeatureCursor.NextFeature(); eachIFeature != null; eachIFeature = myIFeatureCursor.NextFeature())
            {
                lstIFeature.Add(eachIFeature);
            }
            myIFeatureLayerDefinition.DefinitionExpression = strOldIFeatureLayerDefinition;
            return(lstIFeature);
        }
Esempio n. 30
0
        private static LayerInfoViewModel LoadLayerInfoFromArcMap(IFeatureLayer layer)
        {
            // tablename
            IDataset dataset   = (IDataset)layer.FeatureClass;
            string   tableName = ArcobjWorkspaceUtils.GetTableName(dataset);

            IFeatureLayerDefinition layerDefinition = layer as IFeatureLayerDefinition;
            string filter = layerDefinition?.DefinitionExpression;

            int?[] rowCounts =
            {
                ArcmapLayerUtils.GetFilteredLayerRowCount(layer),
                ArcmapLayerUtils.GetLayerRowCount(layer)
            };

            return(new LayerInfoViewModel
            {
                Title = layer.Name,
                Layer = layer,
                TableName = tableName,
                Filter = filter,
                RowCount = string.Join(" / ", rowCounts.Where(item => item != null)),
            });
        }
Esempio n. 31
0
 public static void LayerDefinitionUpdate(ref IFeatureLayerDefinition layerDefinition, ref IFeatureLayer flayerHistorico, string condicao)
 {
     layerDefinition = (IFeatureLayerDefinition)flayerHistorico;
     layerDefinition.DefinitionExpression = condicao;
 }