コード例 #1
0
ファイル: Selection.cs プロジェクト: tomorrgod/ArcEngine
        //Query Filter
        private void btnOK_Click(object sender, EventArgs e)
        {
            m_spatialFilter.WhereClause = tbQuery.Text;

            IFeatureSelection featureSelection = (IFeatureSelection)m_layer;

            try
            {
                if (cbMethod.Text == "Create a new selection")
                {
                    featureSelection.SelectFeatures(m_spatialFilter, esriSelectionResultEnum.esriSelectionResultNew, false);
                }
                else if (cbMethod.Text == "Add to current selection")
                {
                    featureSelection.SelectFeatures(m_spatialFilter, esriSelectionResultEnum.esriSelectionResultAdd, false);
                }
                else if (cbMethod.Text == "Remove from current selection")
                {
                    featureSelection.SelectFeatures(m_spatialFilter, esriSelectionResultEnum.esriSelectionResultSubtract, false);
                }
                else if (cbMethod.Text == "Select from current selection")
                {
                    featureSelection.SelectFeatures(m_spatialFilter, esriSelectionResultEnum.esriSelectionResultAnd, false);
                }
            }
            catch
            {
                MessageBox.Show("Invalid query!");
                this.Close();
            }

            //Show the attributes of the selected features
            ISelectionSet selectionSet = featureSelection.SelectionSet;
            ICursor       cursor;

            selectionSet.Search(null, true, out cursor); //Get the cursor
            m_FeatureCursor = cursor as IFeatureCursor;

            IFeatureLayer featureLayer = m_layer as IFeatureLayer;
            DataOperator  dataOperator = new DataOperator(m_map);

            if (selectionSet.Count > 0)
            {
                DataTable dataTable = dataOperator.GetDataTable(m_FeatureCursor, featureLayer);
                selectionSet.Search(null, true, out cursor); //Get the cursor
                m_FeatureCursor = cursor as IFeatureCursor;
                DataBoard dataBoard = new DataBoard(m_map, dataTable, m_FeatureCursor, selectionSet);
                dataBoard.SetSelectedLayer(m_layer.Name);
                dataBoard.cbEnabledFalse();
                dataBoard.Show();
            }

            m_frmMain.ActiveViewPartialRefresh();
            MessageBox.Show(selectionSet.Count + " features are selected.");
            this.Close();
        }
コード例 #2
0
ファイル: TryMapAnalysis.cs プロジェクト: tomorrgod/ArcEngine
        public bool QueryIntersect(string srcLayerName, string tgtLayerName,
                                   IMap iMap, esriSpatialRelationEnum spatialRel)
        {
            DataOperator dataOperator = new DataOperator(iMap);

            //Get layer by name
            IFeatureLayer iSrcLayer = (IFeatureLayer)dataOperator.GetLayerByName(srcLayerName);
            IFeatureLayer iTgtLayer = (IFeatureLayer)dataOperator.GetLayerByName(tgtLayerName);

            //using query filter to get geom
            IGeometry      geom;
            IFeature       feature;
            IFeatureCursor featCursor;
            IFeatureClass  srcFeatClass;
            IQueryFilter   queryFilter = new QueryFilter();

            queryFilter.WhereClause = "CONTINENT='Asia'"; //set query clause
            featCursor = iTgtLayer.FeatureClass.Search(queryFilter, false);
            feature    = featCursor.NextFeature();
            geom       = feature.Shape;

            //city attributes filter
            srcFeatClass = iSrcLayer.FeatureClass;
            ISpatialFilter spatialFilter = new SpatialFilter();

            spatialFilter.Geometry    = geom;
            spatialFilter.WhereClause = "POP_RANK>5";
            spatialFilter.SpatialRel  = (ESRI.ArcGIS.Geodatabase.esriSpatialRelEnum)spatialRel;

            //select features
            IFeatureSelection featureSelection = (IFeatureSelection)iSrcLayer;

            featureSelection.SelectFeatures(spatialFilter, esriSelectionResultEnum.esriSelectionResultNew, false);

            ISelectionSet selectionSet = featureSelection.SelectionSet;
            ICursor       cursor;

            selectionSet.Search(null, true, out cursor);
            IFeatureCursor featureCursor = cursor as IFeatureCursor;

            if (selectionSet.Count > 0)
            {
                DataBoard dataBoard = new DataBoard(iMap, dataOperator.GetDataTable(featureCursor, iSrcLayer));
                dataBoard.cbEnabledFalse();
                dataBoard.Show();
            }


            return(true);
        }