Exemple #1
0
 //鼠标点击事件
 private void axMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
 {
     if (pMouseOperate == "ZoomIn")
     {
         axMapControl1.Extent = axMapControl1.TrackRectangle();
     }
     if (pMouseOperate == "ZoomOut")
     {
         IEnvelope penv = axMapControl1.Extent;
         penv.Expand(2, 2, true);
         axMapControl1.Extent = penv;
     }
     if (pMouseOperate == "Pan")
     {
         axMapControl1.Pan();
     }
     if (pMouseOperate == "Identify")
     {
         IPoint point = new ESRI.ArcGIS.Geometry.Point();
         point.PutCoords(e.mapX, e.mapY);
         IFeatureLayer pFeatureLayer  = axMapControl1.get_Layer(0) as IFeatureLayer;
         IFeatureClass pFeatureClass  = pFeatureLayer.FeatureClass;
         string        shapefieldname = pFeatureClass.ShapeFieldName;
         ESRI.ArcGIS.Geodatabase.ISpatialFilter pSpatialFilter = new ESRI.ArcGIS.Geodatabase.SpatialFilter();
         pSpatialFilter.Geometry   = point;
         pSpatialFilter.SpatialRel = ESRI.ArcGIS.Geodatabase.esriSpatialRelEnum.esriSpatialRelIntersects;
         pSpatialFilter.set_OutputSpatialReference(shapefieldname, axMapControl1.SpatialReference);
         pSpatialFilter.GeometryField = shapefieldname;
         ESRI.ArcGIS.Geodatabase.IFeatureCursor pFeatureCursor = pFeatureClass.Search(pSpatialFilter, false);
         ESRI.ArcGIS.Geodatabase.IFeature       pFeature       = pFeatureCursor.NextFeature();
         if (pFeature != null)
         {
             axMapControl1.FlashShape(pFeature.Shape);
         }
         IFields pField = pFeature.Fields;
         listFields.Items.Clear();
         for (int i = 0; i <= pField.FieldCount - 1; i++)
         {
             listFields.Items.Add(pField.get_Field(i).Name + "=" + pFeature.get_Value(i));
         }
     }
 }
Exemple #2
0
        // get features that intersect the buffered mouse click and return them as a list of IFeature
        public List <IFeature> checkForIntersectingSegments(IPoint mousePoint, double buffer, IFeatureClass featureClass)
        {
            var envelope = mousePoint.Envelope;

            envelope.Expand(buffer, buffer, false);
            var    geodataset     = (IGeoDataset)featureClass;
            string shapeFieldName = featureClass.ShapeFieldName;

            ESRI.ArcGIS.Geodatabase.ISpatialFilter spatialFilter = new ESRI.ArcGIS.Geodatabase.SpatialFilter();
            spatialFilter.Geometry   = envelope;
            spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelCrosses;  // website for other options edndoc.esri.com/arcobjects/9.2/ComponentHelp/esrigeodatabase/esrispatialrelenum.htm
            spatialFilter.set_OutputSpatialReference(shapeFieldName, geodataset.SpatialReference);

            ESRI.ArcGIS.Geodatabase.IFeatureCursor featureCursor = featureClass.Search(spatialFilter, false);

            var features = new List <IFeature>();

            ESRI.ArcGIS.Geodatabase.IFeature feature;
            while ((feature = featureCursor.NextFeature()) != null)
            {
                features.Add(feature);
            }
            return(features);
        }