private void axMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
        {
            if (DoQueryIndex == 1)//点击查询
            {
                ESRI.ArcGIS.Carto.IFeatureLayer pFeatureLayer = axMapControl1.get_Layer(layerComboBox.SelectedIndex) as ESRI.ArcGIS.Carto.IFeatureLayer;
                ESRI.ArcGIS.Geometry.IPoint     point         = new ESRI.ArcGIS.Geometry.PointClass();
                point.PutCoords(e.mapX, e.mapY);

                ESRI.ArcGIS.Geodatabase.ISpatialFilter spatialFilter = new ESRI.ArcGIS.Geodatabase.SpatialFilterClass();
                spatialFilter.Geometry   = point;
                spatialFilter.SpatialRel = ESRI.ArcGIS.Geodatabase.esriSpatialRelEnum.esriSpatialRelIntersects;
                ESRI.ArcGIS.Geodatabase.IFeatureCursor featureCursor = pFeatureLayer.Search(spatialFilter, false);

                ESRI.ArcGIS.Geodatabase.IFeature pFeature;
                while ((pFeature = featureCursor.NextFeature()) != null)
                {
                    axMapControl1.FlashShape(pFeature.Shape);
                }
            }
            else if (DoQueryIndex == 2)//面范围查询
            {
                ESRI.ArcGIS.Geometry.IPoint point = new ESRI.ArcGIS.Geometry.PointClass();
                point.PutCoords(e.mapX, e.mapY);

                pointCollection.AddPoints(1, ref point);

                if (pointCollection.PointCount > 1)
                {
                    DrawPolygon(pointCollection, axMapControl1);
                }
            }
        }
Exemple #2
0
        //获取地区名,用于更新图名
        private string GetXZQName(IPoint pCentPoint)
        {
            string            sXZQName         = string.Empty;
            IFeatureWorkspace featureWorkspace = null;
            IFeatureCursor    pFeatureCursor   = null;

            try
            {
                AccessWorkspaceFactory accessWorkspaceFactory = new AccessWorkspaceFactoryClass();
                featureWorkspace = (IFeatureWorkspace)accessWorkspaceFactory.OpenFromFile(dataFile, 0);
                IFeatureClass featureClass = featureWorkspace.OpenFeatureClass("town_code");

                IGeoDataset pGeoDataset = featureClass as IGeoDataset;
                if (pCentPoint.SpatialReference.FactoryCode != pGeoDataset.SpatialReference.FactoryCode)
                {
                    pCentPoint.Project(pGeoDataset.SpatialReference);
                }

                ISpatialFilter spatialFilter = new ESRI.ArcGIS.Geodatabase.SpatialFilterClass();
                spatialFilter.Geometry   = pCentPoint;
                spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
                pFeatureCursor           = featureClass.Search(spatialFilter, true);
                IFeature pFeature = pFeatureCursor.NextFeature();
                if (pFeature != null)
                {
                    int iIndex = pFeature.Fields.FindField("NAME");
                    if (iIndex > -1)
                    {
                        object obVaue = pFeature.get_Value(iIndex);
                        if (obVaue != null)
                        {
                            sXZQName = obVaue.ToString();
                        }
                    }
                }
            }
            catch (Exception)
            {
            }
            finally
            {
                MathComm.ReleaseCOMObject(pFeatureCursor);
                MathComm.ReleaseCOMObject(featureWorkspace);
            }
            return(sXZQName);
        }
Exemple #3
0
        public static void SelectMapFeaturesByGeometryQuery(IActiveView activeView, IFeatureLayer featureLayer, IGeometry geometry)
        {
            if (activeView == null || featureLayer == null || geometry == null)
            {
                return;
            }
            ESRI.ArcGIS.Geodatabase.IFeatureClass pFeatureClass = featureLayer.FeatureClass;
            //空间过滤器
            ESRI.ArcGIS.Geodatabase.ISpatialFilter pSpatialFilter = new ESRI.ArcGIS.Geodatabase.SpatialFilterClass();
            pSpatialFilter.Geometry = geometry;
            //根据图层类型选择缓冲方式
            switch (pFeatureClass.ShapeType)
            {
            case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryMultipoint:
                pSpatialFilter.SpatialRel = ESRI.ArcGIS.Geodatabase.esriSpatialRelEnum.esriSpatialRelContains;
                break;

            case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline:
                pSpatialFilter.SpatialRel = ESRI.ArcGIS.Geodatabase.esriSpatialRelEnum.esriSpatialRelCrosses;
                break;

            case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon:
                pSpatialFilter.SpatialRel = ESRI.ArcGIS.Geodatabase.esriSpatialRelEnum.esriSpatialRelIntersects;
                break;
            }

            //定义空间过滤器的空间字段
            pSpatialFilter.GeometryField = pFeatureClass.ShapeFieldName;
            ESRI.ArcGIS.Geodatabase.IQueryFilter pQueryFilter;
            //利用要素过滤器查询要素
            pQueryFilter = pSpatialFilter as ESRI.ArcGIS.Geodatabase.IQueryFilter;
            IFeatureSelection featureSelection = featureLayer as IFeatureSelection; // Dynamic Cast

            // Invalidate only the selection cache. Flag the original selection
            activeView.PartialRefresh(ESRI.ArcGIS.Carto.esriViewDrawPhase.esriViewGeoSelection, null, null);

            // Perform the selection
            featureSelection.SelectFeatures(pQueryFilter, ESRI.ArcGIS.Carto.esriSelectionResultEnum.esriSelectionResultNew, false);

            // Flag the new selection
            activeView.PartialRefresh(ESRI.ArcGIS.Carto.esriViewDrawPhase.esriViewGeoSelection, null, null);
        }
        /// <summary>
        /// Returns all features from a given feature class that have a vertex or endpoint coincident with a given point 
        /// </summary>
        /// <param name="point">IPoint to use as the spatial filter</param>
        /// <param name="searchFtClass">IFeatureClass to search in</param>
        /// <param name="linearEndpointsOnly">Flag to use only the endpoints of a line instead of all vertices</param>
        /// <param name="buffer">Search geometry buffer in map units</param>
        /// <returns>List of IFeature</returns>
        public static List<ESRI.ArcGIS.Geodatabase.IFeature> GetFeaturesWithCoincidentVertices(ESRI.ArcGIS.Geometry.IPoint point, ESRI.ArcGIS.Geodatabase.IFeatureClass searchFtClass, bool linearEndpointsOnly, double buffer)
        {
            List<ESRI.ArcGIS.Geodatabase.IFeature> result = new List<ESRI.ArcGIS.Geodatabase.IFeature>();

            using (ESRI.ArcGIS.ADF.ComReleaser releaser = new ESRI.ArcGIS.ADF.ComReleaser())
            {
                ESRI.ArcGIS.Geodatabase.ISpatialFilter filter = new ESRI.ArcGIS.Geodatabase.SpatialFilterClass();
                releaser.ManageLifetime(filter);

                ESRI.ArcGIS.Geometry.IEnvelope filterGeometry = point.Envelope;
                if (0 < buffer)
                {
                    filterGeometry.Expand(buffer, buffer, false);
                }

                filter.SpatialRel = ESRI.ArcGIS.Geodatabase.esriSpatialRelEnum.esriSpatialRelIntersects;
                filter.Geometry = filterGeometry;

                ESRI.ArcGIS.Geodatabase.IFeatureCursor fts = searchFtClass.Search(filter, false);
                releaser.ManageLifetime(fts);

                ESRI.ArcGIS.Geodatabase.IFeature ft = fts.NextFeature();
                while (null != ft)
                {
                    if (searchFtClass.ShapeType == ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint)
                    {
                        result.Add(ft);
                    }
                    else if (searchFtClass.ShapeType == ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline && linearEndpointsOnly)
                    {
                        ESRI.ArcGIS.Geometry.IPolyline polyline = (ESRI.ArcGIS.Geometry.IPolyline)ft.Shape;
                        ESRI.ArcGIS.Geometry.IRelationalOperator fromPoint = polyline.FromPoint as ESRI.ArcGIS.Geometry.IRelationalOperator;
                        ESRI.ArcGIS.Geometry.IRelationalOperator toPoint = polyline.ToPoint as ESRI.ArcGIS.Geometry.IRelationalOperator;

                        if (fromPoint.Equals(point) || toPoint.Equals(point))
                        {
                            result.Add(ft);
                        }
                    }
                    else
                    {
                        ESRI.ArcGIS.Geometry.IPointCollection pointCollection = ft.Shape as ESRI.ArcGIS.Geometry.IPointCollection;
                        if (null != pointCollection)
                        {
                            for (int i = 0; i < pointCollection.PointCount; i++)
                            {
                                ESRI.ArcGIS.Geometry.IRelationalOperator testPoint = pointCollection.get_Point(i) as ESRI.ArcGIS.Geometry.IRelationalOperator;
                                if (testPoint.Equals(point))
                                {
                                    result.Add(ft);
                                    break;
                                }
                            }
                        }
                    }

                    ft = fts.NextFeature();
                }
            }

            return result;
        }
		private void button_Import_Click(object sender, System.EventArgs e)
		{
			// point to the first selected feature:
			ESRI.ArcGIS.Animation.IAGImportPathOptions AGImportPathOptionsCls = new ESRI.ArcGIS.Animation.AGImportPathOptionsClass();

			// Set properties for AGImportPathOptions
			AGImportPathOptionsCls.BasicMap = (ESRI.ArcGIS.Carto.IBasicMap)globe; // Explicit Cast
			AGImportPathOptionsCls.AnimationTracks = (ESRI.ArcGIS.Animation.IAGAnimationTracks)globe; // Explicit Cast
			AGImportPathOptionsCls.AnimationType = new ESRI.ArcGIS.GlobeCore.AnimationTypeGlobeCameraClass();
			AGImportPathOptionsCls.AnimatedObject = globe.GlobeDisplay.ActiveViewer.Camera; 
			
			if (this.radioButton_flyby.Checked == true)
			{
				AGImportPathOptionsCls.ConversionType = esriFlyFromPathType.esriFlyFromPathObsAndTarget;
				AGImportPathOptionsCls.PutAngleCalculationMethods(esriPathAngleCalculation.esriAngleAddRelative, esriPathAngleCalculation.esriAngleAddRelative, esriPathAngleCalculation.esriAngleAddRelative);
				AGImportPathOptionsCls.PutAngleCalculationValues(0.0, 0.0, 0.0);
			}
			else if (this.radioButton_currentTarget.Checked == true)
			{
				AGImportPathOptionsCls.ConversionType = esriFlyFromPathType.esriFlyFromPathObserver;
			}
			else if (this.radioButton_currentObserver.Checked == true)
			{
				AGImportPathOptionsCls.ConversionType = esriFlyFromPathType.esriFlyFromPathTarget;
			}
			
			double pAzimuth, pInclination, pRollVal;
			AGImportPathOptionsCls.GetAngleCalculationValues(out pAzimuth, out pInclination, out pRollVal);
			
			AGImportPathOptionsCls.LookaheadFactor = this.trackBarSimplificationFactor.Value/100;
			AGImportPathOptionsCls.TrackName = this.textBox_TrackName.Text;
			AGImportPathOptionsCls.OverwriteExisting = Convert.ToBoolean(this.checkBox_Overwrite.CheckState);
			AGImportPathOptionsCls.VerticalOffset = Convert.ToDouble(this.textBox_VertOffset.Text);
			AGImportPathOptionsCls.ReversePath = Convert.ToBoolean(this.checkBox_ReverseOrder.CheckState);
			
			// get the layer selected in the combo box
			if (this.comboBoxLayers.SelectedIndex == -1) 
			{
				MessageBox.Show("Please select a layer before you proceed");
			}
			else
			{
				//set the layer based on the item selected in the combo box
				ESRI.ArcGIS.Carto.ILayer layer = (ESRI.ArcGIS.Carto.ILayer) layerArray.get_Element(this.comboBoxLayers.SelectedIndex); // Explicit Cast
				
				// Get the line feature selected in the layer
				ESRI.ArcGIS.Carto.IFeatureLayer featureLayer = (ESRI.ArcGIS.Carto.IFeatureLayer)layer; // Explicit Cast
				ESRI.ArcGIS.Carto.IFeatureSelection featureSelection = (ESRI.ArcGIS.Carto.IFeatureSelection)layer; // Explicit Cast
				ESRI.ArcGIS.Geodatabase.ISelectionSet selectionSet = featureSelection.SelectionSet;
				ESRI.ArcGIS.Geodatabase.IFeatureClass featureClass = featureLayer.FeatureClass;
				string shapeField = featureClass.ShapeFieldName;
				ESRI.ArcGIS.Geodatabase.ISpatialFilter spatialFilterCls = new ESRI.ArcGIS.Geodatabase.SpatialFilterClass();
				
				IScene scene = globe.GlobeDisplay.Scene;

				ESRI.ArcGIS.Geometry.ISpatialReference spatialReference = scene.SpatialReference;
				spatialFilterCls.GeometryField = shapeField;
				spatialFilterCls.set_OutputSpatialReference(shapeField, spatialReference);
				ESRI.ArcGIS.Geodatabase.ICursor cursor;
				selectionSet.Search(spatialFilterCls, true, out cursor);
				ESRI.ArcGIS.Geodatabase.IFeatureCursor featureCursor = (ESRI.ArcGIS.Geodatabase.IFeatureCursor)cursor; // Explicit Cast

				ESRI.ArcGIS.Geodatabase.IFeature lineFeature;
				lineFeature = featureCursor.NextFeature();
				if (lineFeature == null)
				{
					MessageBox.Show("Please select a feature in the feature layer selected");
				}
				else
				{
					CreateFlybyFromPathAnimation(globe, lineFeature, AGImportPathOptionsCls);
				}
            }
			this.Close();
		}
Exemple #6
0
        /// <summary>
        /// Returns all features from a given feature class that have a vertex or endpoint coincident with a given point
        /// </summary>
        /// <param name="point">IPoint to use as the spatial filter</param>
        /// <param name="searchFtClass">IFeatureClass to search in</param>
        /// <param name="linearEndpointsOnly">Flag to use only the endpoints of a line instead of all vertices</param>
        /// <param name="buffer">Search geometry buffer in map units</param>
        /// <returns>List of IFeature</returns>
        public static List <ESRI.ArcGIS.Geodatabase.IFeature> GetFeaturesWithCoincidentVertices(ESRI.ArcGIS.Geometry.IPoint point, ESRI.ArcGIS.Geodatabase.IFeatureClass searchFtClass, bool linearEndpointsOnly, double buffer)
        {
            List <ESRI.ArcGIS.Geodatabase.IFeature> result = new List <ESRI.ArcGIS.Geodatabase.IFeature>();

            using (ESRI.ArcGIS.ADF.ComReleaser releaser = new ESRI.ArcGIS.ADF.ComReleaser())
            {
                ESRI.ArcGIS.Geodatabase.ISpatialFilter filter = new ESRI.ArcGIS.Geodatabase.SpatialFilterClass();
                releaser.ManageLifetime(filter);

                ESRI.ArcGIS.Geometry.IEnvelope filterGeometry = point.Envelope;
                if (0 < buffer)
                {
                    filterGeometry.Expand(buffer, buffer, false);
                }

                filter.SpatialRel = ESRI.ArcGIS.Geodatabase.esriSpatialRelEnum.esriSpatialRelIntersects;
                filter.Geometry   = filterGeometry;

                ESRI.ArcGIS.Geodatabase.IFeatureCursor fts = searchFtClass.Search(filter, false);
                releaser.ManageLifetime(fts);

                ESRI.ArcGIS.Geodatabase.IFeature ft = fts.NextFeature();
                while (null != ft)
                {
                    if (searchFtClass.ShapeType == ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint)
                    {
                        result.Add(ft);
                    }
                    else if (searchFtClass.ShapeType == ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline && linearEndpointsOnly)
                    {
                        ESRI.ArcGIS.Geometry.IPolyline           polyline  = (ESRI.ArcGIS.Geometry.IPolyline)ft.Shape;
                        ESRI.ArcGIS.Geometry.IRelationalOperator fromPoint = polyline.FromPoint as ESRI.ArcGIS.Geometry.IRelationalOperator;
                        ESRI.ArcGIS.Geometry.IRelationalOperator toPoint   = polyline.ToPoint as ESRI.ArcGIS.Geometry.IRelationalOperator;

                        if (fromPoint.Equals(point) || toPoint.Equals(point))
                        {
                            result.Add(ft);
                        }
                    }
                    else
                    {
                        ESRI.ArcGIS.Geometry.IPointCollection pointCollection = ft.Shape as ESRI.ArcGIS.Geometry.IPointCollection;
                        if (null != pointCollection)
                        {
                            for (int i = 0; i < pointCollection.PointCount; i++)
                            {
                                ESRI.ArcGIS.Geometry.IRelationalOperator testPoint = pointCollection.get_Point(i) as ESRI.ArcGIS.Geometry.IRelationalOperator;
                                if (testPoint.Equals(point))
                                {
                                    result.Add(ft);
                                    break;
                                }
                            }
                        }
                    }

                    ft = fts.NextFeature();
                }
            }

            return(result);
        }
Exemple #7
0
        private void button_Import_Click(object sender, System.EventArgs e)
        {
            // point to the first selected feature:
            ESRI.ArcGIS.Animation.IAGImportPathOptions AGImportPathOptionsCls = new ESRI.ArcGIS.Animation.AGImportPathOptionsClass();

            // Set properties for AGImportPathOptions
            AGImportPathOptionsCls.BasicMap        = (ESRI.ArcGIS.Carto.IBasicMap)globe;              // Explicit Cast
            AGImportPathOptionsCls.AnimationTracks = (ESRI.ArcGIS.Animation.IAGAnimationTracks)globe; // Explicit Cast
            AGImportPathOptionsCls.AnimationType   = new ESRI.ArcGIS.GlobeCore.AnimationTypeGlobeCameraClass();
            AGImportPathOptionsCls.AnimatedObject  = globe.GlobeDisplay.ActiveViewer.Camera;

            if (this.radioButton_flyby.Checked == true)
            {
                AGImportPathOptionsCls.ConversionType = esriFlyFromPathType.esriFlyFromPathObsAndTarget;
                AGImportPathOptionsCls.PutAngleCalculationMethods(esriPathAngleCalculation.esriAngleAddRelative, esriPathAngleCalculation.esriAngleAddRelative, esriPathAngleCalculation.esriAngleAddRelative);
                AGImportPathOptionsCls.PutAngleCalculationValues(0.0, 0.0, 0.0);
            }
            else if (this.radioButton_currentTarget.Checked == true)
            {
                AGImportPathOptionsCls.ConversionType = esriFlyFromPathType.esriFlyFromPathObserver;
            }
            else if (this.radioButton_currentObserver.Checked == true)
            {
                AGImportPathOptionsCls.ConversionType = esriFlyFromPathType.esriFlyFromPathTarget;
            }

            double pAzimuth, pInclination, pRollVal;

            AGImportPathOptionsCls.GetAngleCalculationValues(out pAzimuth, out pInclination, out pRollVal);

            AGImportPathOptionsCls.LookaheadFactor   = this.trackBarSimplificationFactor.Value / 100;
            AGImportPathOptionsCls.TrackName         = this.textBox_TrackName.Text;
            AGImportPathOptionsCls.OverwriteExisting = Convert.ToBoolean(this.checkBox_Overwrite.CheckState);
            AGImportPathOptionsCls.VerticalOffset    = Convert.ToDouble(this.textBox_VertOffset.Text);
            AGImportPathOptionsCls.ReversePath       = Convert.ToBoolean(this.checkBox_ReverseOrder.CheckState);

            // get the layer selected in the combo box
            if (this.comboBoxLayers.SelectedIndex == -1)
            {
                MessageBox.Show("Please select a layer before you proceed");
            }
            else
            {
                //set the layer based on the item selected in the combo box
                ESRI.ArcGIS.Carto.ILayer layer = (ESRI.ArcGIS.Carto.ILayer)layerArray.get_Element(this.comboBoxLayers.SelectedIndex);                  // Explicit Cast

                // Get the line feature selected in the layer
                ESRI.ArcGIS.Carto.IFeatureLayer       featureLayer     = (ESRI.ArcGIS.Carto.IFeatureLayer)layer;       // Explicit Cast
                ESRI.ArcGIS.Carto.IFeatureSelection   featureSelection = (ESRI.ArcGIS.Carto.IFeatureSelection)layer;   // Explicit Cast
                ESRI.ArcGIS.Geodatabase.ISelectionSet selectionSet     = featureSelection.SelectionSet;
                ESRI.ArcGIS.Geodatabase.IFeatureClass featureClass     = featureLayer.FeatureClass;
                string shapeField = featureClass.ShapeFieldName;
                ESRI.ArcGIS.Geodatabase.ISpatialFilter spatialFilterCls = new ESRI.ArcGIS.Geodatabase.SpatialFilterClass();

                IScene scene = globe.GlobeDisplay.Scene;

                ESRI.ArcGIS.Geometry.ISpatialReference spatialReference = scene.SpatialReference;
                spatialFilterCls.GeometryField = shapeField;
                spatialFilterCls.set_OutputSpatialReference(shapeField, spatialReference);
                ESRI.ArcGIS.Geodatabase.ICursor cursor;
                selectionSet.Search(spatialFilterCls, true, out cursor);
                ESRI.ArcGIS.Geodatabase.IFeatureCursor featureCursor = (ESRI.ArcGIS.Geodatabase.IFeatureCursor)cursor;                 // Explicit Cast

                ESRI.ArcGIS.Geodatabase.IFeature lineFeature;
                lineFeature = featureCursor.NextFeature();
                if (lineFeature == null)
                {
                    MessageBox.Show("Please select a feature in the feature layer selected");
                }
                else
                {
                    CreateFlybyFromPathAnimation(globe, lineFeature, AGImportPathOptionsCls);
                }
            }
            this.Close();
        }
        public ESRI.ArcGIS.Geodatabase.IFeatureCursor GetAllFeaturesFromPointSearchInGeoFeatureLayer(Double pSearchTolerance, IPoint pPoint, IFeatureClass pFeatureClass)
        {
            if (pSearchTolerance < 0 || pPoint == null || pFeatureClass == null)
               {
               return null;
               }

               ESRI.ArcGIS.Geometry.IEnvelope pEnvelope = pPoint.Envelope;
               pEnvelope.Expand(pSearchTolerance, pSearchTolerance, false);

               //ITopologicalOperator pTopo = pPoint as ITopologicalOperator;

               //IGeometry pGeo = pTopo.Buffer(pSearchTolerance);

               System.String pShapeFieldName = pFeatureClass.ShapeFieldName;

               ESRI.ArcGIS.Geodatabase.ISpatialFilter pSpatialFilter = new ESRI.ArcGIS.Geodatabase.SpatialFilterClass();
               pSpatialFilter.Geometry = pEnvelope;
               pSpatialFilter.SpatialRel = ESRI.ArcGIS.Geodatabase.esriSpatialRelEnum.esriSpatialRelEnvelopeIntersects;
               pSpatialFilter.GeometryField = pShapeFieldName;

               ESRI.ArcGIS.Geodatabase.IFeatureCursor pFeatureCursor = pFeatureClass.Search(pSpatialFilter, false);

               return pFeatureCursor;
        }