コード例 #1
0
        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("可能表达式有误,请先验证表达式");
            }
        }
コード例 #2
0
        public static ClsMapLayer QueryByAttribute(bool blnSelect, string whereClause, esriSelectionResultEnum pOperator, IFeatureClass pFeatCls, IFeatureLayer pFeatlayer)
        {
            ClsMapLayer pQueryByAttribute = new  ClsMapLayer();

            //IActiveView pActiveView;

            IQueryFilter pFilter = new QueryFilterClass();

            pFilter.SubFields   = "*";
            pFilter.WhereClause = whereClause;

            pQueryByAttribute.FeatCls = pFeatCls;
            IDataset pDataset;

            pDataset = (IDataset)pFeatCls;

            IFeatureSelection pFeatSelection;
            ICursor           pCursor;

            if (blnSelect == true)
            {
                pQueryByAttribute.FeatLayer = pFeatlayer;
                pFeatSelection = (IFeatureSelection)pFeatlayer;
                pFeatSelection.SelectFeatures(pFilter, pOperator, false);
                pQueryByAttribute.FeatSelectionSet = pFeatSelection.SelectionSet as ISelectionSet2;
                pQueryByAttribute.FeatSelectionSet.Search(null, false, out pCursor);
                if (pCursor is IFeatureCursor)
                {
                    pQueryByAttribute.FeatCur = (IFeatureCursor)pCursor;
                }
                return(pQueryByAttribute);

                //pActiveView = ClsDeclare.g_pMap as IActiveView;
                //pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null);
            }
            else
            {
                pQueryByAttribute.FeatLayer = pFeatlayer;
                //esriSelectionOption pSelectionOption=new esriSelectionOption();
                pQueryByAttribute.FeatSelectionSet = pQueryByAttribute.FeatCls.Select(pFilter, esriSelectionType.esriSelectionTypeHybrid, (esriSelectionOption)(int)pOperator, pDataset.Workspace) as ISelectionSet2;
                pQueryByAttribute.FeatSelectionSet.Search(null, false, out pCursor);

                if (pCursor is IFeatureCursor)
                {
                    pQueryByAttribute.FeatCur = (IFeatureCursor)pCursor;
                }
                return(pQueryByAttribute);
            }
        }
コード例 #3
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)
            {
            }
        }
コード例 #4
0
ファイル: ClsSearch.cs プロジェクト: johnforrest/GeoCoding
        public static void PfgisGetClosestFeature(IMap pMap, IPoint pSearchPt, ref Collection pSelected, ref IFeature pFeatureClosest)
        {
            ClsMapLayer pConvert = new ClsMapLayer();

            //初始化返回值
            pSelected       = new Collection();
            pFeatureClosest = null;
            //设置搜索范围
            IEnvelope pSrchEnv;

            pSrchEnv = pSearchPt.Envelope;
            double SearchDist;

            SearchDist = 4d;
            IActiveView pActiveView;

            pActiveView     = pMap as IActiveView;
            SearchDist      = ClsMapLayer.ConvertPixelsToMapUnits(pActiveView, SearchDist);
            pSrchEnv.Width  = SearchDist;
            pSrchEnv.Height = SearchDist;
            pSrchEnv.CenterAt(pSearchPt);

            UIDClass pUID = new UIDClass();

            pUID.Value = "{E156D7E5-22AF-11D3-9F99-00C04F6BC78E}";
            IEnumLayer pLayers;

            pLayers = pMap.get_Layers(pUID, true);

            ILayer pLayer;

            pLayer = pLayers.Next();

            while (pLayer != null)
            {
                IGeoFeatureLayer pGeoLayer;
                pGeoLayer = (IGeoFeatureLayer)pLayer;

                if (pGeoLayer.Selectable && pGeoLayer.Visible && pGeoLayer.FeatureClass != null)
                {
                    IIdentify2 pID;
                    pID = (IIdentify2)pGeoLayer;
                    //根据查询范围执行查询操作
                    IArray pArray;
                    pArray = pID.Identify(pSrchEnv, null);

                    IFeatureIdentifyObj pFeatIdObj;
                    IRowIdentifyObject  pRowObj;
                    IFeature            pFeature;

                    if (pArray != null)
                    {
                        for (int j = 0; j < pArray.Count; j++)
                        {
                            if (pArray.get_Element(j) is IFeatureIdentifyObj)
                            {
                                pFeatIdObj = pArray.get_Element(j) as IFeatureIdentifyObj;
                                pRowObj    = pFeatIdObj as IRowIdentifyObject;
                                pFeature   = pRowObj.Row as IFeature;
                                pSelected.Add(pFeature, null, null, null);
                            }
                        }
                        pArray.RemoveAll();
                    }
                }
                pLayer = pLayers.Next();
            }
            ClsSearch.PfgisGetClosestFeatureInCollection(SearchDist, pSelected, pSearchPt, ref pFeatureClosest);
        }
コード例 #5
0
        public void PopulateFeatColTree(ClsMapLayer pQueryResult)
        {
            if (pQueryResult == null)
            {
                return;
            }
            if (pQueryResult.FeatLayer == null || pQueryResult.FeatCln == null)
            {
                return;
            }
            if (pQueryResult.FeatCln.Count < 1)
            {
                return;
            }
            try
            {
                m_dictAdded = new Dictionary <object, string>();
                tvwFeatures.Nodes.Clear();
                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);
                TreeNode curNode = null;
                curNode     = RootNode.Nodes.Add(pQueryResult.FeatLayer.Name);
                curNode.Tag = "地物层";
                curNode.Expand();

                Collection pFeatCol;
                IFeature   pFeature;
                TreeNode   xNode = null;
                pFeatCol = pQueryResult.FeatCln;

                for (int i = 1; i <= pFeatCol.Count; i++)
                {
                    pFeature = pFeatCol[i] as IFeature;
                    if (pFeature == null)
                    {
                        continue;
                    }
                    if (!(m_dictAdded.ContainsValue(Convert.ToString(pFeature.OID))))
                    {
                        m_dictAdded.Add(pFeature, Convert.ToString(pFeature.OID));
                        xNode     = curNode.Nodes.Add(GetKey(pFeature, i), GetString(pFeature));
                        xNode.Tag = pFeature;
                    }
                }
                lblFeatCount.Text = "查找到 " + m_dictAdded.Count + " 个要素";
                this.tvwFeatures.ExpandAll();
                if (this.tvwFeatures.Nodes[0].Nodes.Count > 0)
                {
                    if (this.tvwFeatures.Nodes[0].Nodes[0].Nodes.Count > 0)
                    {
                        this.tvwFeatures.SelectedNode = this.tvwFeatures.Nodes[0].Nodes[0].Nodes[0];
                        pFeature = tvwFeatures.SelectedNode.Tag as IFeature;
                        PopulateGridFromFeature(pFeature);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("错误", ex.StackTrace, MessageBoxButtons.OK, MessageBoxIcon.Error);
                //ClsDeclare.g_ErrorHandler.HandleError(true, null, 0, null, ex.StackTrace);
                throw;
            }
        }
コード例 #6
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;
            }
        }
コード例 #7
0
        /// <summary>
        /// Occurs when this command is clicked
        /// </summary>
        public override void OnClick()
        {
            if (m_hookHelper != null)
            {
                ClsMapLayer       pConvertPixelDistanceToMapDistance = new ClsMapLayer();
                IEnvelope         pEnv;
                IFeature          pFeat = null;
                IActiveView       pActiveView;
                ICursor           pCursor = null;
                IFeatureCursor    pFeatCursor;
                IGeometry         pGeo;
                IFeatureLayer     pFeatLyr;
                ICompositeLayer   pGroupLyr;
                IFeatureSelection pFeatSel;
                pEnv = new EnvelopeClass();

                if (ClsDeclare.g_pMap.SelectionCount < 1)
                {
                    //ClsDeclare.g_ErrorHandler.DisplayInformation("图面上没有选择地物,无法放大", false, "确定",null);
                    return;
                }
                try
                {
                    for (int i = 0; i < ClsDeclare.g_pMap.LayerCount; i++)
                    {
                        if (ClsDeclare.g_pMap.get_Layer(i) is IGroupLayer && (ClsDeclare.g_pMap.get_Layer(i).Name != "示意图"))
                        {
                            pGroupLyr = ClsDeclare.g_pMap.get_Layer(i) as ICompositeLayer;
                            for (int j = 0; j < pGroupLyr.Count; j++)
                            {
                                if (pGroupLyr.get_Layer(j) is IGeoFeatureLayer)
                                {
                                    pFeatLyr = pGroupLyr.get_Layer(j) as IFeatureLayer;
                                    pFeatSel = (IFeatureSelection)pFeatLyr;
                                    if (pFeatSel.SelectionSet.Count == 0)
                                    {
                                        continue;
                                    }
                                    pFeatSel.SelectionSet.Search(null, false, out pCursor);
                                    pFeatCursor = (IFeatureCursor)pCursor;
                                    pFeat       = pFeatCursor.NextFeature();
                                    while (pFeat != null)
                                    {
                                        pGeo = pFeat.Shape;
                                        pEnv.Union(pGeo.Envelope);
                                        pFeat = pFeatCursor.NextFeature();
                                    }
                                }
                            }
                        }
                        else if (ClsDeclare.g_pMap.get_Layer(i) is IGeoFeatureLayer)
                        {
                            pFeatLyr = ClsDeclare.g_pMap.get_Layer(i) as IFeatureLayer;
                            pFeatSel = (IFeatureSelection)pFeatLyr;
                            if (pFeatSel.SelectionSet.Count == 0)
                            {
                                continue;
                            }
                            pFeatSel.SelectionSet.Search(null, false, out pCursor);
                            pFeatCursor = (IFeatureCursor)pCursor;
                            pFeat       = pFeatCursor.NextFeature();
                            while (pFeat != null)
                            {
                                pGeo = pFeat.Shape;
                                pEnv.Union(pGeo.Envelope);
                                pFeat = pFeatCursor.NextFeature();
                            }
                        }
                    }
                    pActiveView = (IActiveView)ClsDeclare.g_pMap;
                    double dblLen;
                    dblLen = pConvertPixelDistanceToMapDistance.ConvertPixelDistanceToMapDistance(pActiveView, 30);
                    pEnv.Expand(dblLen, dblLen, false);
                    pActiveView.Extent = pEnv;
                    pActiveView.Refresh();
                }
                catch (Exception)
                {
                    //ClsDeclare.g_ErrorHandler.DisplayInformation(ex.Message, false, "确定",null);
                    throw;
                }
            }
            else if (m_sceneHookHelper != null)
            {
            }
            else if (m_globeHookHelper != null)
            {
            }
        }
コード例 #8
0
        //private static Collection FunGetFeaLyrCol(IMap iMap)
        //{
        //    throw new NotImplementedException();
        //}
        /// <summary>
        /// 通过几何图形查询
        /// </summary>
        /// <param name="blnSelect"></param>
        /// <param name="pGeometry"></param>
        /// <param name="pFeatCls"></param>
        /// <param name="pselecttype"></param>
        /// <param name="pFeatlayer"></param>
        /// <returns></returns>
        public static ClsMapLayer QueryByGeometry(bool blnSelect, IGeometry pGeometry, IFeatureClass pFeatCls, esriSelectionResultEnum pselecttype, IFeatureLayer pFeatlayer)
        {
            ClsMapLayer pQueryByGeometry = new ClsMapLayer();

            pQueryByGeometry.FeatCls = pFeatCls;

            IDataset pDataset;

            pDataset = (IDataset)pFeatCls;
            IFeatureSelection pFeatSelection;
            ICursor           pCursor = null;

            ISpatialFilter pSpatialFilter = new SpatialFilterClass();

            pSpatialFilter.Geometry = pGeometry;

            switch (pFeatCls.ShapeType)
            {
            case esriGeometryType.esriGeometryPoint:
                pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains;
                break;

            case esriGeometryType.esriGeometryPolyline:
                pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
                break;

            case esriGeometryType.esriGeometryPolygon:
                pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
                break;

            default:
                pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelUndefined;
                break;
            }
            pSpatialFilter.GeometryField = pFeatCls.ShapeFieldName;

            ISpatialFilter pFilter;

            pFilter = pSpatialFilter;

            if (blnSelect == true)
            {
                pFeatSelection = (IFeatureSelection)pFeatlayer;
                pFeatSelection.SelectFeatures(pFilter, pselecttype, false);

                pQueryByGeometry.FeatLayer        = pFeatlayer;
                pQueryByGeometry.FeatSelectionSet = pFeatSelection.SelectionSet as ISelectionSet2;
                pQueryByGeometry.FeatSelectionSet.Search(null, false, out pCursor);

                if (pCursor is IFeatureCursor)
                {
                    pQueryByGeometry.FeatCur = (IFeatureCursor)pCursor;
                }
                return(pQueryByGeometry);
            }
            else
            {
                pFeatSelection = (IFeatureSelection)pFeatlayer;
                pFeatSelection.SelectFeatures(pFilter, pselecttype, false);

                //esriSelectionOption pSelectionOption;
                //pSelectionOption = pselecttype as esriSelectionResultEnum;

                pQueryByGeometry.FeatLayer        = pFeatlayer;
                pQueryByGeometry.FeatSelectionSet = pQueryByGeometry.FeatCls.Select(pFilter, esriSelectionType.esriSelectionTypeHybrid, (esriSelectionOption)((int)pselecttype), pDataset.Workspace) as ISelectionSet2;
                pQueryByGeometry.FeatSelectionSet.Search(null, false, out pCursor);
                if (pCursor is IFeatureCursor)
                {
                    pQueryByGeometry.FeatCur = (IFeatureCursor)pCursor;
                }
                return(pQueryByGeometry);
            }
        }