ArcEngine Geometry库定义了基本几何图形的矢量表达形式,顶级的几何图形有Points、Multipoints、Polylines、Polygons、Multipatches,Geodatabase和绘图系统使用这些几何图形来定义其他各种形状的特征和图形,提供了编辑图形的操作方法和地图符号系统符号化特征数据的途径。 public IPolyline TestGeometryEnvironment()![]() ![]() { ISpatialReferenceFactory spatialReferenceFactory = new SpatialReferenceEnvironmentClass();![]() //Create a projected coordinate system and define its domain, resolution, and x,y tolerance. ISpatialReferenceResolution spatialReferenceResolution = spatialReferenceFactory.CreateProjectedCoordinateSystem((int)esriSRProjCSType.esriSRProjCS_NAD1983UTM_11N) as ISpatialReferenceResolution; spatialReferenceResolution.ConstructFromHorizon(); ISpatialReferenceTolerance spatialReferenceTolerance = spatialReferenceResolution as ISpatialReferenceTolerance; spatialReferenceTolerance.SetDefaultXYTolerance(); ISpatialReference spatialReference = spatialReferenceResolution as ISpatialReference;![]() //Create an array of WKSPoint structures starting in the middle of the x,y domain of the //projected coordinate system.![]() double xMin; double xMax; double yMin; double yMax; spatialReference.GetDomain(out xMin, out xMax, out yMin, out yMax);![]() double xFactor = (xMin + xMax) * 0.5; double yFactor = (yMin + yMax) * 0.5;![]() WKSPoint[] wksPoints = new WKSPoint[10]; for (int i = 0; i < wksPoints.Length; i++)![]() { wksPoints[i].X = xFactor + i; wksPoints[i].Y = yFactor + i; }![]() IPointCollection4 pointCollection = new PolylineClass();![]() IGeometryBridge2 geometryBridge = new GeometryEnvironmentClass(); geometryBridge.AddWKSPoints(pointCollection, ref wksPoints);![]() IPolyline polyline = pointCollection as IPolyline; polyline.SpatialReference = spatialReference;![]() return polyline; }
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; }
public IPolyline ConstructMultiPartPolyline(IPolyline inputPolyline)![]() ![]() { IGeometry outGeometry = new PolylineClass();![]() //Always associate new, top-level geometries with an appropriate spatial reference. outGeometry.SpatialReference = inputPolyline.SpatialReference; IGeometryCollection geometryCollection = outGeometry as IGeometryCollection;![]() ISegmentCollection segmentCollection = inputPolyline as ISegmentCollection;![]() //Iterate over existing polyline segments using a segment enumerator. IEnumSegment segments = segmentCollection.EnumSegments;![]() ISegment currentSegment; int partIndex = 0;; int segmentIndex = 0;; segments.Next(out currentSegment,ref partIndex, ref segmentIndex); while(currentSegment != null)![]() { ILine normal = new LineClass();![]() //Geometry methods with _Query_ in their name expect to modify existing geometries. //In this case, the QueryNormal method modifies an existing line //segment (normal) to be the normal vector to //currentSegment at the specified location along currentSegment. currentSegment.QueryNormal(esriSegmentExtension.esriNoExtension, 0.5, true, currentSegment.Length / 3, normal); //Since each normal vector is not connected to others, create a new path for each one. ISegmentCollection newPath = new PathClass(); object missing = Type.Missing; newPath.AddSegment(normal as ISegment, ref missing, ref missing); //The spatial reference associated with geometryCollection will be assigned to all incoming paths and segments. geometryCollection.AddGeometry(newPath as IGeometry, ref missing, ref missing);![]() segments.Next(out currentSegment,ref partIndex, ref segmentIndex); } //The geometryCollection now contains the new, multipart polyline. return geometryCollection as IPolyline; }
Polygons public IMultiPatch CreateMultipatch()![]() ![]() { //Prepare the geometry material list. IGeometryMaterial texture = new GeometryMaterialClass(); texture.TextureImage = C:TempMyImage.bmp;![]() IGeometryMaterialList materialList = new GeometryMaterialListClass(); materialList.AddMaterial(texture);![]() //Create the multipatch. IGeneralMultiPatchCreator multiPatchCreator = new GeneralMultiPatchCreatorClass(); multiPatchCreator.Init(4, 1, false, false, false, 4, materialList);![]() //Set up part.![]() //Could also use a Ring or a TriangleFan. multiPatchCreator.SetPatchType(0, esriPatchType.esriPatchTypeTriangleStrip); multiPatchCreator.SetMaterialIndex(0, 0); multiPatchCreator.SetPatchPointIndex(0, 0); multiPatchCreator.SetPatchTexturePointIndex(0, 0);![]() //Set real-world points. WKSPointZ upperLeft = new WKSPointZ(); WKSPointZ lowerLeft = new WKSPointZ(); WKSPointZ upperRight = new WKSPointZ(); WKSPointZ lowerRight = new WKSPointZ();![]() upperLeft.X = 0; upperLeft.Y = 0; upperLeft.Z = 0; upperRight.X = 300; upperRight.Y = 0; upperRight.Z = 0; lowerLeft.X = 0; lowerLeft.Y = 0; lowerLeft.Z = -100; lowerRight.X = 300; lowerRight.Y = 1; lowerRight.Z = -100;![]() multiPatchCreator.SetWKSPointZ(0, ref upperRight); multiPatchCreator.SetWKSPointZ(1, ref lowerRight); multiPatchCreator.SetWKSPointZ(2, ref upperLeft); multiPatchCreator.SetWKSPointZ(3, ref lowerLeft);![]() //Set texture points. //Set the texture coordinates for a panel. WKSPoint textureUpperLeft = new WKSPoint(); WKSPoint textureLowerLeft = new WKSPoint(); WKSPoint textureUpperRight = new WKSPoint(); WKSPoint textureLowerRight = new WKSPoint();![]() textureUpperLeft.X = 0; textureUpperLeft.Y = 0; textureUpperRight.X = 1; textureUpperRight.Y = 0; textureLowerLeft.X = 0; textureLowerLeft.Y = 1; textureLowerRight.X = 1; textureLowerRight.Y = 1;![]() multiPatchCreator.SetTextureWKSPoint(0, ref textureUpperRight); multiPatchCreator.SetTextureWKSPoint(1, ref textureLowerRight); multiPatchCreator.SetTextureWKSPoint(2, ref textureUpperLeft); multiPatchCreator.SetTextureWKSPoint(3, ref textureLowerLeft); IMultiPatch multiPatch = multiPatchCreator.CreateMultiPatch() as IMultiPatch;![]() return multiPatch; } |
public IPolyline TestGeometryEnvironment()

{
ISpatialReferenceFactory spatialReferenceFactory = new SpatialReferenceEnvironmentClass();
}
}



