private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.txtExpress.Text == "")
                {
                    //ClsDeclare.g_ErrorHandler.DisplayInformation("请选择查询表达式", false, "确定", null);
                    return;
                }
                if (m_frmQuery != null)
                {
                    if (m_frmQuery.IsDisposed == false)
                    {
                        m_frmQuery.Close();
                        m_frmQuery = null;
                    }
                }
                esriSelectionResultEnum pResult;
                pResult = esriSelectionResultEnum.esriSelectionResultAdd;
                switch (this.cboSelectMethod.Text)
                {
                case "创建一个新的选择结果":
                    pResult = esriSelectionResultEnum.esriSelectionResultNew;
                    break;

                case "添加到当前选择集中":
                    pResult = esriSelectionResultEnum.esriSelectionResultAdd;
                    break;

                case "从当前选择结果中移除":
                    pResult = esriSelectionResultEnum.esriSelectionResultSubtract;
                    break;

                case "从当前选择结果中选择":
                    pResult = esriSelectionResultEnum.esriSelectionResultAnd;
                    break;
                }
                if (m_pCurrentFeatCls == null)
                {
                    return;
                }
                m_blnSelect    = true;
                m_pQueryResult = ClsSelectQuery.QueryByAttribute(m_blnSelect, txtExpress.Text.Trim(), pResult, m_pCurrentFeatCls, m_pCurrentLayer);
                m_pQueryResultCln.Clear();
                m_pQueryResultCln.Add(m_pQueryResult, null, null, null);

                m_frmQuery = new FrmQuery();
                m_frmQuery.QueryResultCln = m_pQueryResultCln;
                m_frmQuery.Show();
                ClsDeclare.g_Sys.MapControl.ActiveView.Refresh();
            }
            catch (Exception)
            {
                //ClsDeclare.g_ErrorHandler.DisplayInformation("可能表达式有误,请先验证表达式", false, "确定",null);
                //throw;
                MessageBoxEx.Show("可能表达式有误,请先验证表达式");
            }
        }
        private void btnVerify_Click(object sender, EventArgs e)
        {
            IQueryFilter   pQueryFilter;
            IFeatureClass  pFeatCls;
            IFeatureCursor pFeatCursor;
            IFeature       pFeat;
            IFeatureLayer  pFeatLayer;

            if (this.txtExpress.Text == "")
            {
                //ClsDeclare.g_ErrorHandler.DisplayInformation("请输入表达式", false, "确定",null);
                return;
            }
            pFeatLayer = ClsSelectQuery.FunFindFeatureLayerByName(cboLayerList.Text, ClsDeclare.g_pMap);
            if (pFeatLayer == null)
            {
                return;
            }
            try
            {
                pFeatCls                 = pFeatLayer.FeatureClass;
                pQueryFilter             = new QueryFilterClass();
                pQueryFilter.SubFields   = "*";
                pQueryFilter.WhereClause = this.txtExpress.Text.Trim();
                pFeatCls.Search(pQueryFilter, false);
                pFeatCursor = pFeatCls.Search(pQueryFilter, false);
                pFeat       = pFeatCursor.NextFeature();

                //if (pFeat != null)
                //    ClsDeclare.g_ErrorHandler.DisplayInformation("表达式正确!", false, null, null);
                //else
                //    ClsDeclare.g_ErrorHandler.DisplayInformation("此表达式搜索不到要素,请检查表达式!", false, null, null);
                if (pFeat != null)
                {
                    MessageBox.Show("表达式正确!");
                }
                else
                {
                    MessageBox.Show("此表达式搜索不到要素,请检查表达式!");
                }
                //ClsDeclare.g_ErrorHandler.DisplayInformation("此表达式搜索不到要素,请检查表达式!", false, null, null);
            }
            catch (Exception)
            {
                //ClsDeclare.g_ErrorHandler.DisplayInformation("查询表达式不合法!", false, null, null);
                MessageBoxEx.Show("查询表达式不合法!请修改");
            }
            finally
            {
                pQueryFilter = null;
                pFeatCls     = null;
                pFeatCursor  = null;
                pFeat        = null;
            }
        }
        /// <summary>
        /// 初始化图层下拉菜单
        /// </summary>
        private void InitCtlComboLayer()
        {
            try
            {
                int           i;
                ILayer        pLayer;
                IFeatureLayer pFeatlayer;
                IFeatureClass pFeatCls;
                Collection    pLyrCol;
                Collection    LyrCol = null;
                if (m_FeatClsCln == null)
                {
                    pLyrCol = ClsSelectQuery.FunGetFeaLyrCol(ClsDeclare.g_pMap, null, LyrCol);
                    for (i = 1; i <= pLyrCol.Count; i++)
                    {
                        pLayer = pLyrCol[i] as ILayer;
                        if (pLayer is IFeatureLayer)
                        {
                            IFeatureLayer pFeatureLayer;
                            pFeatureLayer = pLayer as IFeatureLayer;
                            if (pFeatureLayer.Selectable)
                            {
                                cboLayerList.Items.Add(pLayer.Name);
                            }
                        }
                    }
                }
                else
                {
                    for (i = 1; i <= m_FeatClsCln.Count; i++)
                    {
                        pLayer = m_FeatClsCln[i] as ILayer;
                        if (pLayer is IFeatureLayer)
                        {
                            pFeatlayer = pLayer as IFeatureLayer;
                            pFeatCls   = pFeatlayer.FeatureClass;
                            cboLayerList.Items.Add(pFeatCls.AliasName);
                        }
                    }
                }

                if (cboLayerList.Items.Count > 0)
                {
                    cboLayerList.Text = cboLayerList.Items[0].ToString();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("错误", ex.StackTrace, MessageBoxButtons.OK, MessageBoxIcon.Error);
                throw;
            }
        }
Esempio n. 4
0
        /// <summary>
        /// 把pQueryResultCln内容填充到vTree中
        /// </summary>
        /// <param name="pQueryResultCln"></param>
        /// <param name="vTree"></param>
        public void PopulateQueryTree(Collection pQueryResultCln, TreeView vTree)
        {
            m_FeaturesInTree = new Collection();
            tvwFeatures.Nodes.Clear();
            if (pQueryResultCln == null)
            {
                return;
            }
            ESRI.ArcGIS.Carto.ILayer pTempLyr;
            TreeNode RootNode = new TreeNode();

            RootNode.Text = "查询结果";
            RootNode.Tag  = "查询结果";

            this.tvwFeatures.Nodes.Add(RootNode);
            //TreeNode pNewNode = new TreeNode();
            //pNewNode.Text = "当前链接信息";
            //pNewNode.Tag = "当前链接信息";
            //this.tvwFeatures.Nodes.Add(pNewNode);
            IFeatureClass  pFeatCls;
            IFeatureCursor pFeatCur;
            ISelectionSet  pSelectionSet;
            ClsMapLayer    pQueryResult;

            for (int i = 0; i < pQueryResultCln.Count; i++)
            {
                pQueryResult = pQueryResultCln[i + 1] as ClsMapLayer;
                pFeatCls     = pQueryResult.FeatCls;
                pTempLyr     = ClsSelectQuery.FunFindLayer(pFeatCls, ClsDeclare.g_pMap) as ESRI.ArcGIS.Carto.ILayer;

                pFeatCur      = pQueryResult.FeatCur;
                pSelectionSet = pQueryResult.FeatSelectionSet;
                AddQueryResult(RootNode, pQueryResult.FeatLayer, pSelectionSet);
            }
            lblFeatCount.Text = "查找到 " + m_FeaturesInTree.Count + " 个要素";
            this.tvwFeatures.ExpandAll();
            if (this.tvwFeatures.Nodes[0].Nodes.Count > 0)
            {
                if (this.tvwFeatures.Nodes[0].Nodes[0].Nodes.Count > 0)
                {
                    this.tvwFeatures.Focus();
                    this.tvwFeatures.SelectedNode = this.tvwFeatures.Nodes[0].Nodes[0].Nodes[0];
                    IFeature pFeature;
                    pFeature          = tvwFeatures.SelectedNode.Tag as IFeature;
                    tvwFeatures.Tag   = tvwFeatures.SelectedNode.Parent.Text;
                    dgvAttributes.Tag = pFeature;
                    PopulateGridFromFeature(pFeature);
                }
            }
        }
        private void Verify()
        {
            IQueryFilter   pQueryFilter;
            IFeatureClass  pFeatCls;
            IFeatureCursor pFeatCursor;
            IFeature       pFeat;
            IFeatureLayer  pFeatLayer;


            if (this.txtExpress.Text == "")
            {
                //ClsDeclare.g_ErrorHandler.DisplayInformation("请输入表达式",false,"确定",null);
                return;
            }
            pFeatLayer = ClsSelectQuery.FunFindFeatureLayerByName(cboLayerList.Text, ClsDeclare.g_pMap);
            if (pFeatLayer == null)
            {
                return;
            }
            try
            {
                pFeatCls                 = pFeatLayer.FeatureClass;
                pQueryFilter             = new QueryFilterClass();
                pQueryFilter.SubFields   = "*";
                pQueryFilter.WhereClause = this.txtExpress.Text.Trim();
                pFeatCls.Search(pQueryFilter, false);
                pFeatCursor = pFeatCls.Search(pQueryFilter, false);
                pFeat       = pFeatCursor.NextFeature();

                if (pFeat == null)
                {
                    //ClsDeclare.g_ErrorHandler.DisplayInformation("此表达式搜索不到要素,请检查表达式!", false, null, null);
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("错误", ex.StackTrace, MessageBoxButtons.OK, MessageBoxIcon.Error);
                //ClsDeclare.g_ErrorHandler.HandleError(true, null, 0, null, ex.StackTrace);
                throw;
            }
            finally
            {
                pQueryFilter = null;
                pFeatCls     = null;
                pFeatCursor  = null;
                pFeat        = null;
            }
        }
        private void ListField()
        {
            try
            {
                ILayer        pLayer;
                IFeatureLayer pFeatlayer;
                IFeatureClass pFeatCls;
                int           i;

                if (m_FeatClsCln == null)
                {
                    m_pCurrentLayer   = ClsSelectQuery.FunFindFeatureLayerByName(cboLayerList.Text, ClsDeclare.g_pMap);
                    m_pCurrentFeatCls = m_pCurrentLayer.FeatureClass;
                }
                else
                {
                    for (i = 1; i <= m_FeatClsCln.Count; i++)
                    {
                        pLayer = m_FeatClsCln[i] as ILayer;
                        if (pLayer is IFeatureLayer)
                        {
                            pFeatlayer = pLayer as IFeatureLayer;
                            pFeatCls   = pFeatlayer.FeatureClass;
                            if (pFeatCls.AliasName == cboLayerList.Text)
                            {
                                m_pCurrentFeatCls = pFeatCls;
                                break;
                            }
                        }
                    }
                }
                lstField.Items.Clear();
                for (i = 0; i < m_pCurrentFeatCls.Fields.FieldCount; i++)
                {
                    if (Convert.ToUInt32(m_pCurrentFeatCls.Fields.get_Field(i).Type) < 5 && m_pCurrentFeatCls.Fields.get_Field(i).Editable == true)
                    {
                        lstField.Items.Add(m_pCurrentFeatCls.Fields.get_Field(i).AliasName + "【" + m_pCurrentFeatCls.Fields.get_Field(i).Name + "】");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("错误", ex.StackTrace, MessageBoxButtons.OK, MessageBoxIcon.Error);
                throw;
            }
        }
Esempio n. 7
0
        private void PopGrid()
        {
            int               i;
            IFeatureLayer     pFeatureLayer;
            IFeatureSelection pFeatSel;
            int               pRow;
            Collection        pLyrCol;
            Collection        LyrCol = null;

            pLyrCol        = ClsSelectQuery.FunGetFeaLyrCol(ClsDeclare.g_pMap, null, LyrCol);
            m_ChangeSelect = new int[pLyrCol.Count];

            for (i = 1; i <= pLyrCol.Count; i++)
            {
                ILayer pLayer;
                pLayer = pLyrCol[i] as ILayer;

                if (pLayer is IFeatureLayer)
                {
                    pFeatureLayer = pLayer as IFeatureLayer;
                    pFeatSel      = pFeatureLayer as IFeatureSelection;
                    if (pFeatSel.SelectionSet != null)
                    {
                        dgvGridList.Rows.Add();
                        pRow = dgvGridList.RowCount;
                        if (pFeatureLayer.Selectable)
                        {
                            dgvGridList.Rows[pRow - 2].Cells[0].Value = true;
                            m_ChangeSelect[i - 1] = 1;
                        }
                        else
                        {
                            dgvGridList.Rows[pRow - 2].Cells[0].Value = false;
                            m_ChangeSelect[i] = 0;
                        }
                        dgvGridList.Rows[pRow - 2].Cells[1].Value = pFeatureLayer.Name;
                    }
                }
            }
        }
Esempio n. 8
0
        public override void OnMouseDown(int Button, int Shift, int X, int Y)
        {
            if (m_hookHelper != null)
            {
                ClsMapLayer pConvert = new ClsMapLayer();
                IGeometry   pGeometry;
                IActiveView pActiveView = m_hookHelper.ActiveView;
                IPoint      pPoint      = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y);
                pGeometry = (IGeometry)pPoint;

                if (ClsDeclare.g_pMap.SelectionCount != 0)
                {
                    ClsDeclare.g_pMap.ClearSelection();
                }
                pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null);
                ISelectionEnvironment pSelectEnv = new SelectionEnvironment();

                double Length;
                Length = pConvert.ConvertPixelDistanceToMapDistance(pActiveView, pSelectEnv.SearchTolerance);
                ITopologicalOperator pTopoOpera;
                IGeometry            pBuffer;
                pTopoOpera = (ITopologicalOperator)pGeometry;
                pBuffer    = pTopoOpera.Buffer(Length);

                pGeometry = (IGeometry)m_pMapControl.TrackCircle();
                Application.DoEvents();
                m_pMapControl.MousePointer = esriControlsMousePointer.esriPointerHourglass;
                if (pGeometry != null)
                {
                    if (pGeometry.Envelope.IsEmpty)
                    {
                        pGeometry = pBuffer.Envelope;
                    }
                }
                esriSelectionResultEnum pselecttype = new esriSelectionResultEnum();

                switch (Shift)
                {
                case 0:
                {
                    pselecttype = esriSelectionResultEnum.esriSelectionResultNew;
                    switch (mvarSelectMethod)
                    {
                    case "New":
                        pselecttype = esriSelectionResultEnum.esriSelectionResultNew;
                        break;

                    case "Add":
                        pselecttype = esriSelectionResultEnum.esriSelectionResultAnd;
                        break;

                    case "Sub":
                        pselecttype = esriSelectionResultEnum.esriSelectionResultSubtract;
                        break;

                    case "Xor":
                        pselecttype = esriSelectionResultEnum.esriSelectionResultXOR;
                        break;
                    }
                    break;
                }

                case 1:
                    pselecttype = esriSelectionResultEnum.esriSelectionResultAdd;
                    break;

                case 2:
                    pselecttype = esriSelectionResultEnum.esriSelectionResultXOR;
                    break;

                case 3:
                    pselecttype = esriSelectionResultEnum.esriSelectionResultNew;
                    break;

                case 4:
                    pselecttype = esriSelectionResultEnum.esriSelectionResultSubtract;
                    break;
                }
                if (m_FeatClsCln == null)
                {
                    bool blntemp = false;
                    m_pQueryResultCln = new Collection();
                    ClsSelectQuery.SelectGeometry(ref blntemp, pGeometry, pselecttype, ref m_pQueryResultCln);
                    pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null);

                    if (m_frmQuery == null)
                    {
                        m_frmQuery = new FrmQuery();
                    }
                    if (m_frmQuery.IsDisposed)
                    {
                        m_frmQuery = new FrmQuery();
                    }
                    m_frmQuery.QueryResultCln = m_pQueryResultCln;
                    m_frmQuery.ReLoadQueryResult();
                    m_frmQuery.Visible = false;
                    m_frmQuery.Show((Form)(ClsDeclare.g_Sys.FrmMain));
                }
                m_pQueryResultCln          = null;
                m_pMapControl.MousePointer = esriControlsMousePointer.esriPointerDefault;
            }
            else if (m_sceneHookHelper != null)
            {
            }
            else if (m_globeHookHelper != null)
            {
            }
        }
        private void btnApply_Click(object sender, EventArgs e)
        {
            try
            {
                Verify();
                string strQuery;
                strQuery = this.txtExpress.Text;
                if (strQuery == "")
                {
                    return;
                }
                ILayer pLayer;
                pLayer = ClsSelectQuery.FunFindFeatureLayerByName(cboLayerList.Text, ClsDeclare.g_pMap);
                if (pLayer == null)
                {
                    return;
                }
                IFeatureLayer pFeatLayer;
                pFeatLayer = pLayer as IFeatureLayer;

                if (pFeatLayer.Visible == false)
                {
                }
                //ClsDeclare.g_ErrorHandler.DisplayInformation("请选择可见图层",false,"确定",null);
                IFeatureSelection pFeatureSelection;
                pFeatureSelection = pFeatLayer as IFeatureSelection;

                IQueryFilter pQueryFilter = new QueryFilterClass();
                pQueryFilter.WhereClause = strQuery;

                esriSelectionResultEnum SelType;
                SelType = esriSelectionResultEnum.esriSelectionResultNew;

                switch (this.cboSelectMethod.Text)
                {
                case "创建一个新的选择结果":
                {
                    if (ClsDeclare.g_pMap.SelectionCount > 0)
                    {
                        ClsDeclare.g_pMap.ClearSelection();
                    }
                    SelType = esriSelectionResultEnum.esriSelectionResultNew;
                }
                break;

                case "添加到当前选择集中":
                    SelType = esriSelectionResultEnum.esriSelectionResultAdd;
                    break;

                case "从当前选择结果中移除":
                    SelType = esriSelectionResultEnum.esriSelectionResultSubtract;
                    break;

                case "从当前选择结果中选择":
                    SelType = esriSelectionResultEnum.esriSelectionResultAnd;
                    break;
                }
                if (pFeatLayer.Selectable)
                {
                    pFeatureSelection.SelectFeatures(pQueryFilter, SelType, false);
                }

                IActiveView pActiveView;
                pActiveView = ClsDeclare.g_pMap as IActiveView;
                pActiveView.Refresh();

                IFeatureClass       pFeatCls;
                IGeometryCollection pGeometryCol;
                IGeometryBag        pGeometryBag;
                IEnumIDs            pEnumIDs;
                IFeature            pFeature;
                int iOBJID;

                pGeometryCol = new GeometryBagClass();
                pGeometryBag = pGeometryCol as IGeometryBag;
                pFeatCls     = pFeatLayer.FeatureClass;
                pEnumIDs     = pFeatureSelection.SelectionSet.IDs;
                iOBJID       = pEnumIDs.Next();
                object Missing  = Type.Missing;
                object Missing1 = Type.Missing;
                while (iOBJID != -1)
                {
                    pFeature = pFeatCls.GetFeature(iOBJID);
                    pGeometryCol.AddGeometry(pFeature.Shape, ref Missing, ref Missing1);
                    iOBJID = pEnumIDs.Next();
                }

                IHookActions pHookActions;
                IHookHelper  pHookHelper;
                pHookHelper      = new HookHelperClass();
                pHookHelper.Hook = ClsDeclare.g_Sys.MapControl.Object;
                pHookActions     = pHookHelper as IHookActions;
                if (pHookActions.get_ActionSupported(pGeometryBag.Envelope, esriHookActions.esriHookActionsPan))
                {
                    pHookActions.DoAction(pGeometryBag.Envelope, esriHookActions.esriHookActionsPan);
                }
                Application.DoEvents();
            }
            catch (Exception ex)
            {
                MessageBox.Show("错误", ex.StackTrace, MessageBoxButtons.OK, MessageBoxIcon.Error);
                //ClsDeclare.g_ErrorHandler.HandleError(true,null,0,null,ex.StackTrace);
                throw;
            }
        }
Esempio n. 10
0
        public override void OnMouseDown(int Button, int Shift, int X, int Y)
        {
            try
            {
                //if (ClsDeclare.g_pMap.SelectionCount != 0)
                //    ClsDeclare.g_pMap.ClearSelection();
                ClsMapLayer pConvert = new ClsMapLayer();
                IActiveView pActiveView;
                pActiveView = m_hookHelper.ActiveView;

                IPoint pPoint;
                pPoint = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y);

                ISelectionEnvironment pSelectEnv = new SelectionEnvironmentClass();
                double Length;
                Length = pConvert.ConvertPixelDistanceToMapDistance(pActiveView, pSelectEnv.SearchTolerance);

                ITopologicalOperator pTopoOpera;
                IGeometry            pBuffer;
                pTopoOpera  = (ITopologicalOperator)pPoint;
                pBuffer     = pTopoOpera.Buffer(Length);
                m_pGeometry = pBuffer.Envelope;
                esriSelectionResultEnum pSelectType = new esriSelectionResultEnum();
                switch (Shift)
                {
                case 0:
                {
                    pSelectType = esriSelectionResultEnum.esriSelectionResultNew;
                    switch (mvarSelectMethod)
                    {
                    case "New":               //新建选择结果集
                        pSelectType = esriSelectionResultEnum.esriSelectionResultNew;
                        break;

                    case "Add":               //增加选择结果集 按下Shift键
                        pSelectType = esriSelectionResultEnum.esriSelectionResultAnd;
                        break;

                    case "Sub":              //减少选择结果集 按下Alt键
                        pSelectType = esriSelectionResultEnum.esriSelectionResultSubtract;
                        break;

                    case "Xor":               //对已有的选择集做异或 按下Ctrl键
                        pSelectType = esriSelectionResultEnum.esriSelectionResultXOR;
                        break;
                    }
                    break;
                }

                case 1:
                    pSelectType = esriSelectionResultEnum.esriSelectionResultAdd;
                    break;

                case 2:
                    pSelectType = esriSelectionResultEnum.esriSelectionResultXOR;
                    break;

                case 3:
                    pSelectType = esriSelectionResultEnum.esriSelectionResultNew;
                    break;

                case 4:
                    pSelectType = esriSelectionResultEnum.esriSelectionResultSubtract;
                    break;
                }
                if (m_FeatClsCln == null)
                {
                    bool blntemp = true;
                    m_pQueryResultCln = new Collection();
                    ClsSelectQuery.SelectGeometry(ref blntemp, m_pGeometry, pSelectType, ref m_pQueryResultCln);
                    pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null);
                    //TODO: FrmQuery的用法
                    if (m_frmQuery == null)
                    {
                        m_frmQuery = new FrmQuery();
                    }
                    if (m_frmQuery.IsDisposed)
                    {
                        m_frmQuery = new FrmQuery();
                    }

                    m_frmQuery.QueryResultCln = m_pQueryResultCln;
                    m_frmQuery.ReLoadQueryResult();
                    m_frmQuery.Visible = false;
                    m_frmQuery.Show((Form)(ClsDeclare.g_Sys.FrmMain));
                }
                m_pQueryResultCln = null;
                if ((ClsDeclare.g_pMap.SelectionCount > ClsDeclare.g_Sys.MaxSelectCount) && (ClsDeclare.g_Sys.MaxSelectCount != 0))
                {
                    //if (ClsDeclare.g_ErrorHandler.DisplayInformation("你选择的结果大于" + Convert.ToString(ClsDeclare.g_Sys.MaxSelectCount) + "个地物,是否继续选择操作?", true, "确定", "取消") == false)
                    {
                        pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null);
                        ClsDeclare.g_pMap.ClearSelection();
                        pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null);
                    }
                }
            }
            catch (Exception)
            {
                //ClsDeclare.g_ErrorHandler.HandleError(true, null, 0, null, ex.StackTrace);
                throw;
            }
        }
Esempio n. 11
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            int           i;
            IFeatureLayer pFeatureLayer;
            bool          bClearSelect;
            IActiveView   pActiveView;

            m_pSelectEnv = new SelectionEnvironmentClass();
            bClearSelect = false;
            for (i = 0; i < dgvGridList.RowCount; i++)
            {
                pFeatureLayer = ClsSelectQuery.FunFindFeatureLayerByName(dgvGridList.Rows[i].Cells[1].Value.ToString(), ClsDeclare.g_pMap);
                if (pFeatureLayer is IFeatureLayer)
                {
                    if (this.dgvGridList.Rows[i].Cells[0].Value != null)
                    {
                        pFeatureLayer.Selectable = true;
                    }
                    else
                    {
                        pFeatureLayer.Selectable = false;
                    }
                    if (pFeatureLayer.Selectable == false && m_ChangeSelect[i] == 1)
                    {
                        bClearSelect = true;
                    }
                }
            }
            IRgbColor pRGBColor = new RgbColorClass();

            pRGBColor.Red             = cColorPicker.SelectedColor.R;
            pRGBColor.Green           = cColorPicker.SelectedColor.G;
            pRGBColor.Blue            = cColorPicker.SelectedColor.B;
            m_pSelectEnv.DefaultColor = pRGBColor;

            if (txtTolerance != null)
            {
                m_pSelectEnv.SearchTolerance = Convert.ToInt32(txtTolerance.Text);
            }

            if (this.txtSelectCount != null)
            {
                if (this.txtSelectCount.Text == "")
                {
                    m_MaxSelectCount = 0;
                }
                else
                {
                    m_MaxSelectCount = Convert.ToInt64(this.txtSelectCount.Text);
                }
                ClsDeclare.g_Sys.MaxSelectCount = m_MaxSelectCount;
            }
            if (bClearSelect == true)
            {
                pActiveView = ClsDeclare.g_pMap as IActiveView;
                pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null);
                ClsDeclare.g_pMap.ClearSelection();
                pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null);
            }
            this.Close();
        }
Esempio n. 12
0
        public override void OnMouseDown(int Button, int Shift, int X, int Y)
        {
            if (m_hookHelper != null)
            {
                try
                {
                    IActiveView pActiveView;
                    pActiveView = m_hookHelper.ActiveView;

                    IEnvelope pEnv;
                    pEnv        = m_pMapControl.TrackRectangle();
                    m_pGeometry = (IGeometry)pEnv;

                    esriSelectionResultEnum pselecttype = new esriSelectionResultEnum();
                    switch (Shift)
                    {
                    case 0:
                    {
                        pselecttype = esriSelectionResultEnum.esriSelectionResultNew;
                        switch (mvarSelectMethod)
                        {
                        case "New":
                            pselecttype = esriSelectionResultEnum.esriSelectionResultNew;
                            break;

                        case "Add":
                            pselecttype = esriSelectionResultEnum.esriSelectionResultAnd;
                            break;

                        case "Sub":
                            pselecttype = esriSelectionResultEnum.esriSelectionResultSubtract;
                            break;

                        case "Xor":
                            pselecttype = esriSelectionResultEnum.esriSelectionResultXOR;
                            break;
                        }
                        break;
                    }

                    case 1:
                        pselecttype = esriSelectionResultEnum.esriSelectionResultAdd;
                        break;

                    case 2:
                        pselecttype = esriSelectionResultEnum.esriSelectionResultXOR;
                        break;

                    case 3:
                        pselecttype = esriSelectionResultEnum.esriSelectionResultNew;
                        break;

                    case 4:
                        pselecttype = esriSelectionResultEnum.esriSelectionResultSubtract;
                        break;
                    }
                    if (m_FeatClsCln == null)
                    {
                        bool blntemp = true;
                        m_pQueryResultCln = new Collection();
                        ClsSelectQuery.SelectGeometry(ref blntemp, m_pGeometry, pselecttype, ref m_pQueryResultCln);
                        pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null);
                        if (m_frmQuery == null)
                        {
                            m_frmQuery = new FrmQuery();
                        }
                        if (m_frmQuery.IsDisposed)
                        {
                            m_frmQuery = new FrmQuery();
                        }
                        m_frmQuery.QueryResultCln = m_pQueryResultCln;
                        m_frmQuery.ReLoadQueryResult();
                        m_frmQuery.Visible = false;
                        m_frmQuery.Show((Form)(ClsDeclare.g_Sys.FrmMain));
                    }
                    m_pQueryResultCln = null;
                    if (ClsDeclare.g_pMap.SelectionCount > ClsDeclare.g_Sys.MaxSelectCount && ClsDeclare.g_Sys.MaxSelectCount != 0)
                    {
                        //if ((ClsDeclare.g_ErrorHandler.DisplayInformation("你选择的结果大于" + Convert.ToString(ClsDeclare.g_Sys.MaxSelectCount) + "个地物,是否继续选择操作?", true, "确定", "取消"))==false)
                        {
                            pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null);
                            ClsDeclare.g_pMap.ClearSelection();
                            pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null);
                        }
                    }
                }
                catch (Exception)
                {
                    //ClsDeclare.g_ErrorHandler.HandleError(true, null, 0, null, ex.StackTrace);
                    throw;
                }
            }
            else if (m_sceneHookHelper != null)
            {
            }
            else if (m_globeHookHelper != null)
            {
            }
        }
Esempio n. 13
0
        /// <summary>
        /// 选择几何图形
        /// </summary>
        /// <param name="blnSelect"></param>
        /// <param name="pGeometry"></param>
        /// <param name="pselecttype"></param>
        /// <param name="m_pQueryResultCln"></param>
        public static void SelectGeometry(ref bool blnSelect, IGeometry pGeometry, esriSelectionResultEnum pselecttype, ref Collection m_pQueryResultCln)
        {
            ClsMapLayer pQueryResult;

            try
            {
                if (pGeometry == null)
                {
                    return;
                }

                if (!(pGeometry is IEnvelope))
                {
                    ITopologicalOperator pTop;
                    pTop = (ITopologicalOperator)pGeometry;
                    pTop.Simplify();
                }
                ILayer                  pLayer;
                IFeatureLayer           pFeatLayer;
                IFeatureClass           pFeatCls;
                int                     i;
                IFeatureLayerDefinition pFeaLyrDefine;

                Collection pLyrCol;
                Collection LyrCol = null;
                pLyrCol = ClsSelectQuery.FunGetFeaLyrCol(ClsDeclare.g_pMap, null, LyrCol);
                if (pLyrCol == null)
                {
                    return;
                }
                for (i = 1; i <= pLyrCol.Count; i++)
                {
                    pLayer = pLyrCol[i] as ILayer;
                    if (pLayer is IFeatureLayer)
                    {
                        pFeatLayer = (IFeatureLayer)pLayer;
                        bool bOutOfRange;
                        bOutOfRange = false;
                        if ((ClsDeclare.g_Sys.MapControl) != null)
                        {
                            IActiveView pActiveView;
                            ESRI.ArcGIS.Display.IDisplayTransformation pDisplayTransform;
                            pActiveView       = ClsDeclare.g_Sys.MapControl.ActiveView.FocusMap as IActiveView;
                            pDisplayTransform = pActiveView.ScreenDisplay.DisplayTransformation;

                            if (pFeatLayer.MaximumScale == 0 && pFeatLayer.MinimumScale == 0)
                            {
                                bOutOfRange = false;
                            }
                            if (pFeatLayer.MaximumScale != 0 && pFeatLayer.MinimumScale != 0)
                            {
                                if (pDisplayTransform.ScaleRatio > pFeatLayer.MaximumScale && pDisplayTransform.ScaleRatio < pFeatLayer.MinimumScale)
                                {
                                    bOutOfRange = false;
                                }
                                else
                                {
                                    bOutOfRange = true;
                                }
                            }
                            if (pFeatLayer.MaximumScale == 0 && pFeatLayer.MinimumScale != 0)
                            {
                                if (pDisplayTransform.ScaleRatio < pFeatLayer.MinimumScale)
                                {
                                    bOutOfRange = false;
                                }
                                else
                                {
                                    bOutOfRange = true;
                                }
                            }
                            if (pFeatLayer.MaximumScale != 0 && pFeatLayer.MinimumScale == 0)
                            {
                                if (pDisplayTransform.ScaleRatio > pFeatLayer.MaximumScale)
                                {
                                    bOutOfRange = false;
                                }
                                else
                                {
                                    bOutOfRange = true;
                                }
                            }
                        }
                        if (bOutOfRange == false && pFeatLayer.Selectable)
                        {
                            ClsSelectQuery.RemoveSelection(pFeatLayer);
                            if (pFeatLayer.Visible == true)
                            {
                                pFeatCls      = pFeatLayer.FeatureClass;
                                pFeaLyrDefine = (IFeatureLayerDefinition)pFeatLayer;

                                if (pFeaLyrDefine.DefinitionSelectionSet != null || pFeaLyrDefine.DefinitionExpression != "")
                                {
                                    blnSelect = true;
                                }
                                else
                                {
                                    blnSelect = false;
                                }
                                pQueryResult = ClsSelectQuery.QueryByGeometry(blnSelect, pGeometry, pFeatCls, pselecttype, pFeatLayer);

                                if (pQueryResult != null)
                                {
                                    m_pQueryResultCln.Add(pQueryResult, null, null, null);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
                return;

                throw;
            }
            finally
            {
                IActiveView pActiveView;
                pActiveView = (IActiveView)ClsDeclare.g_pMap;
                //pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, pActiveView.Extent);
                pActiveView.Refresh();
            }
        }