ArcEngine空间分析

  这里提到的空间分析(SpatialAnalysis)特指ArcEngine中使用空间筛选器(SpatialFilter)来实现的空间筛选分析,可以使用其自带的空间交互类型(如:相交、包含、相切等)进行分析,也可以使用九交模型来分析,不管使用哪种方式,这种分析都是精确的无差别的,也就是说不能设置容差的,这种分析在实际使用中是有一定的局限性的,后续的文章我们可能会讲到。同时,空间筛选器是属性筛选器的扩展和延伸,因此空间分析还具备了属性筛选的功能,这个特性很有用,可以缩小筛选范围,辅助空间分析定位。

涉及接口

IFeatureClass、ISpatialFilter、IQueryFilter、IFeatureCursor

代码实现

 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);

 

posted on 2018-04-25 19:14  Helsing·Wang  阅读(541)  评论(0编辑  收藏  举报

导航