The ArcEngine Geometry library defines the vector expression of the basic ry. Top-level ry types include Points, Multipoints, Polylines, Polygons, and Multipatches, geodatabase and the drawing system use these ry to define features and graphics of other shapes, and provide operations for editing graphics and ways for the Map Symbol System to symbolize feature data.
Several core classes and interfaces in the Geometry database constitute the basic framework of the Geometry object.
GeometryEnvironment
GeometryEnvironment provides methods to create Ry from different inputs, settings, or obtain global variables to control the behavior of geometry methods. The GeometryEnvironment object is a singleton object.
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. Duplicate) as ISpatialReferenceResolution;
SpatialReferenceResolution. ConstructFromHorizon ();
ISpatialReferenceTolerance spatialReferenceTolerance = spatialReferenceResolution as ISpatialReferenceTolerance;
SpatialReferenceTolerance. setdefaxyxytolerance ();
ISpatialReference spatialReference = spatialReferenceResolution as ISpatialReference;
// Create an array of WKSPoint structures starting in the middle of the x, y domain of
// 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 ipolympus line;
Polyline. SpatialReference = spatialReference;
Return polyline;
}
New GeometryEnvironmentClass only creates a reference pointing to an existing GeometryEnvironmentClass. Note the use of the IGeometryBridge2 interface. The addWKSPoints method adds two-dimensional WKSPoint points to the PointCollection to build path, ring, polyline, polygon, or add new points to Multipoint, TriangleFan, and TriangleStrip. In the Geometry database, besides IGeometryBridge2 and IGeometryBridge interfaces, the latter inherits the former and adds some editing functions (add vertex, insert vertex, reset vertex, and segment ).
GeometryBag
GeometryBag is a collection of geometric object references that support the IGeometry interface. Any geometric object can be added to GeometryBag through the IGeometryCollection interface. However, when using topology operations, note that different types of geometric types may be incompatible with each other. When adding a geometric object to GeometryBag, you must specify a space reference for the GeometryBag object. All the geometric objects added to it have the same space reference as the GeometryBag object.
Private ipolympus Gon 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 nonreconfiguring 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.
// ConstructUnion method defines the constructed polygon's spatial reference to be the same
// The input geometry bag.
ITopologicalOperator unionedPolygon = new PolygonClass ();
UnionedPolygon. ConstructUnion (geometryBag as IEnumGeometry );
Return unionedPolygon as ipolympus gon;
}
Points
A vertex includes X and Y coordinates, and the M, Z, and ID attributes can be added to expand the vertex function.
Multipoints
Point Set. Multiple points constitute the Multipoint geometric type. The IPointCollection interface implemented by the multipoint object can be used to access all point elements, these points can also have M, Z, and ID attributes to gain more geographical spatial connotations.
The following is an example of defining a new multipart polyline with a known polyline.
Public ipolympus line ConstructMultiPartPolyline (ipolympus 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 until CT to modify existing geometries.
// In this case, the QueryNormal method modifies an existing line
// Segment (normal) to be the normal vector
// 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 ipolympus line;
}
The QueryNormal method of the ISegment interface is used to generate the normal of the arc segment at a certain point on the arc segment and specify its length. In this way, a new segment is generated and multiple paths are added to geometryCollection, returned in the form of ipolympus.
Polylines
Polylines is a set composed of ordered paths and can have M, Z, and ID attribute values. The IPointCollection interface of the Polyline Object contains the replication of all nodes. The IGeometryCollection interface can obtain the polyline paths and the ISegmentCollection interface can obtain the segments of the polyline.
Polyline Structure
Polygons
Polygon is a collection of rings that can have M, Z, and ID attribute values. Each ring is composed of one or more segments. The IPointCollection interface of the Polygon or ring object contains the replication of all nodes. The IGeometryCollection interface can obtain the rings of polygon and the ISegmentCollection interface can obtain the segments of polygon.
Polygon Structure Diagram
Multipatch
Multipatch is used to describe the 3D surface geometric type, which consists of a series of vector triangles. If the part is a ring, it must be closed. The first node is the same as the last one, in addition, the order of nodes contained in each part is very important. After the Inner Rings is Outer Rings, a series of rings representing a single surface patch must start with the first ring.
In the Development Kit later than 9.0, use IGeneralMultiPatchCreator to create a new Multipatch and IGeometryMaterial for texture textures.
Public IMultiPatch CreateMultipatch ()
{
// Prepare the geometry material list.
IGeometryMaterial texture = new GeometryMaterialClass ();
Texture. TextureImage = "C :\\ Temp \ MyImage.bmp ";
IGeometryMaterialList materialList = new GeometryMaterialListClass ();
MaterialList. AddMaterial (texture );
// Create the multipatch.
IGeneralMultiPatchCreator multiPatchCreator = new GeneralMultiPatchCreatorClass ();
MultiPatchCreator. Init (4, 1, false, 4, materialList );
// Set up part.
// Cocould 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;
}