The Arcengine geometry library defines the vector representation of the basic geometry, with the top geometries of points, multipoints, polylines, polygons, multipatches, The Geodatabase and drawing systems use these geometries to define the features and graphics of various other shapes, providing the means to edit the graphics and the symbolic feature data of the map symbol system.
Several core classes and interfaces in the Geometry library form the basic framework of Geometry objects.
Geometryenvironment
Geometryenvironment provides a way to create geometries from different inputs, settings, or get global variables to control the behavior of the geometry method. The Geometryenvironment object is a single instance object.
The following are the referenced contents: 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 of xmin, out of Xmax, out of 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; } |
The new Geometryenvironmentclass simply creates a reference to an existing geometryenvironmentclass. Note the use of the IGeometryBridge2 interface, the Addwkspoints method adds wkspoint two-dimension points to pointcollection to build path, ring, polyline, Polygon, Or add new points to multipoint, Trianglefan, TriangleStrip. In the Geometry library, in addition to the IGeometryBridge2 and Igeometrybridge interfaces, the latter inherits the former and adds some editing features (add points, insertion points, reset points, segments, and so on).
Geometrybag
Geometrybag is a collection of geometric object references that support the Igeometry interface, and any geometry object can be added to the geometrybag through the Igeometrycollection interface, but when using a topology operation, It is necessary to note that different types of geometric types may be incompatible with each other. When adding a geometric object to the Geometrybag, the Geometrybag object needs to specify a space reference, and the Geometry object added to it has the same space reference as the Geometrybag object.
The following are the referenced contents: 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 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 are 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 is the union of the features returned from the search cursor. The spatial reference of this feature does is not need to is 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; } |
Points
A point includes the x, y coordinates, and can increase the function of the point by increasing the M, z, and ID attributes.
Multipoints
The collection of points, the multipoint geometry types, the Ipointcollection interfaces implemented using the Multipoint object can access all the point elements, which can also have the M, z values, and ID attributes to obtain more geospatial connotations.
Here is an example of a new multipart polyline defined by a known polyline.
The following are the referenced contents: Public Ipolyline constructmultipartpolyline (Ipolyline inputpolyline) { Igeometry outgeometry = new Polylineclass ();
Always Associate new, top-level geometries with a 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. In this case, the Querynormal method modifies a existing line Segment (normal) to is 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 are 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 is 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; } |
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, specifying its length, so that a new segment is generated, and multiple path is added to the geometrycollection. Returned in ipolyline form.
Polylines
Polylines is a collection of ordered path that can have M, z, and id attribute values. The Ipointcollection interface of the Polyline object contains the replication of all nodes, and the Igeometrycollection interface can obtain the polyline Paths,isegmentcollection interface to obtain Polyline's segments.
Polyline structure diagram
Polygons
Polygon is a collection of rings that can have M, z, and id attribute values. Each ring consists of one or more segment, the Ipointcollection interface of the polygon or ring object contains the replication of all nodes, and the Igeometrycollection interface can obtain polygon rings, The Isegmentcollection interface can obtain polygon segments.
Polygon Structure diagram
Multipatch
Multipatch is used to describe 3D surface geometry types, consisting of a series of vector triangles, if part is a ring, then it must be closed, the first node is the same as the last, and the order of the nodes contained in each part is very important, Inner Rings after outer rings, a series of rings representing a single surface patch must start with the first ring.
In the development package after 9.0, use Igeneralmultipatchcreator to create a new multipatch,igeometrymaterial for texture mapping.
The following are the referenced contents: 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, 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; } |