ArcEngine Spatial Analysis

  The spatial analysis (SpatialAnalysis) mentioned here refers specifically to the spatial filtering analysis implemented by the spatial filter (SpatialFilter) in ArcEngine, which can be analyzed using its own spatial interaction types (such as intersection, inclusion, tangent, etc.), The nine-cross model can also be used for analysis. No matter which method is used, this analysis is accurate and indistinguishable, that is to say, no tolerance can be set. This kind of analysis has certain limitations in actual use. We may talk about it in a follow-up article. At the same time, the spatial filter is an extension and extension of the attribute filter, so the spatial analysis also has the function of attribute filtering. This feature is very useful, which can narrow the screening range and assist the spatial analysis and positioning.

Involving the interface

IFeatureClass、ISpatialFilter、IQueryFilter、IFeatureCursor

Code

 1 IGraphicsContainer container = axMapControl1.ActiveView as IGraphicsContainer;
 2 IGeometry geometry = axMapControl1.TrackPolygon();
 3 
 4 IElement element = new PolygonElementClass();
 5 element.Geometry = geometry;
 6 container.AddElement(element, 0);
 7 axMapControl1.Refresh(esriViewDrawPhase.esriViewGraphics, null, null);
 8 Application.DoEvents();
 9 
10 
11 ILayer layer = this.axMapControl1.get_Layer(0);
12 IFeatureLayer featureLayer = layer as IFeatureLayer;
13 IFeatureClass featureClass = featureLayer.FeatureClass;
14 
15 ISpatialFilter filter = new SpatialFilterClass();
16 filter.Geometry = geometry;
17 filter.GeometryField = featureClass.ShapeFieldName;
18 filter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
19 
20 IFeatureCursor cursor = featureClass.Search(filter, false);
21 IFeature feature = cursor.NextFeature();
22 while (feature != null)
23 {
24     axMapControl1.FlashShape(feature.Shape);
25 
26     IElement featureElement = new PolygonElementClass();
27     featureElement.Geometry = feature.Shape;
28     container.AddElement(featureElement, 99);
29 
30     feature = cursor.NextFeature();
31 }
32 
33 axMapControl1.Refresh(esriViewDrawPhase.esriViewGraphics, null, null);
34 System.Runtime.InteropServices.Marshal.ReleaseComObject(cursor);

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324854875&siteId=291194637