技术开发 频道

Geometry 对象浅析

 GeometryBag

    GeometryBag是支持IGeometry接口的几何对象引用的集合,任何几何对象都可以通过IGeometryCollection接口添加到 GeometryBag中,但是在使用拓扑操作的时候,需要注意不同类型的几何类型可能会有相互不兼容的情况。在向GeometryBag中添加几何对象的时候,GeometryBag对象需要指定空间参考,添加到其中的几何对象均拥有和GeometryBag对象一样的空间参考。
private IPolygon GeometryBag_Example(IFeatureClass featureClass) { //Check input objects. if (featureClass == null) { return null; } IGeoDataset geoDataset = featureClass as IGeoDataset; ISpatialFilter queryFilter = new SpatialFilterClass(); //Set the properties of the spatial filter here. IGeometry geometryBag = new GeometryBagClass(); //Define the spatial reference of the bag before adding geometries to it. geometryBag.SpatialReference = geoDataset.SpatialReference; //Use a nonrecycling cursor so each returned geometry is a separate object. IFeatureCursor featureCursor = featureClass.Search(queryFilter, false); IGeometryCollection geometryCollection = geometryBag as IGeometryCollection; IFeature currentFeature = featureCursor.NextFeature(); while (currentFeature != null) { //Add a reference to this feature's geometry into the bag. //You don't specify the before or after geometry (missing), //so the currentFeature.Shape IGeometry is added to the end of the geometryCollection. object missing = Type.Missing; geometryCollection.AddGeometry(currentFeature.Shape, ref missing, ref missing); currentFeature = featureCursor.NextFeature(); } // Create the polygon that will be the union of the features returned from the search cursor. // The spatial reference of this feature does not need to be set ahead of time. The // ConstructUnion method defines the constructed polygon's spatial reference to be the same as // the input geometry bag. ITopologicalOperator unionedPolygon = new PolygonClass(); unionedPolygon.ConstructUnion(geometryBag as IEnumGeometry); return unionedPolygon as IPolygon; }
0