I have to add 3-D points to make a polygon in ArcGIS using VB.NET. I have defined an IpointCollection and want to add points to this. I have options to add 'point' or 'pointcollection' or 'WKSpointz'. Which one should I use? Please explain this as I am new to this field.
If you have an IPointCollection you can add points to it (IPoint), be careful which point you use as there are many types that are "point", the one you want is IPoint:
IPoint pPoint = new PointClass(); // in C# Dim pPoint as IPoint = new PointClass() ' in VB.net
Then add to the IPointCollection, assuming known X,Y and Z:
Dim pPntColl as IPointCollection = new RingClass() ' create a ring' Dim pGeomColl As IGeometryCollection = New PolygonClass() ' create a polygon' pPoint.PutCoords(X,Y) pPoint.Z = Z pPntColl.AddPoint(pPoint) ' do this a few more times' pGeomColl.AddGeometry(pPntColl) ' add the ring to the polygon' Dim pOutGeom as IGeometry = ctype(pGeomColl, IGeometry) ' turn into IGeometry' ' this bit is very important when working with 3d geometries' Dim pZaware as IZAware = ctype(pOutGeom,IZAware) pZaware.ZAware = True
This snippet shows how to create a 3d polygon, polyline is very similar: a polyline is made of paths (PathClass). Multipoints are made from points so are just added to the multipoint geometry collection.
When working with 3d geometries it is important to set the ZAware using the IZAware interface or the 'Z' values are forgotten.
WKSPointZ is utilized by IGeometryBridge, they have a less complex structure and are basically an array of X,Y,Z. You can use these too; they could be easier or lighter to instantiate but only a burn test would tell for sure. The geometry bridge interface is
I personally haven't used WKSPointZ but there is a C# sample showing how they work which I will attempt to translate to VB:
Dim length As Integer = 10 Dim pArray As WKSPointZ() For Cnt As Integer = 0 To length - 1 pArray(Cnt) = New WKSPointZ() ' Initialize object ' pArray(Cnt).X = X + Cnt ' give the object some values, ' pArray(Cnt).Y = Y + Cnt ' substitute with correct value' pArray(Cnt).Z = Z + Cnt ' when known' Next Dim pPntColl4 As IPointCollection4 = New MultipointClass() ' or path or ring' Dim pGeomBridge As IGeometryBridge2 = New GeometryEnvironmentClass() pGeomBridge.SetWKSPointZs(pPntColl4, pArray)