0

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.

3

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)
  • hi thankyou! I'm using WKSpointZ method. At the point of initializing (i mean after reaching the line "pArray(cnt) = New WKSpointz()") it is showing an error as NullReferenceException unhandled! But I think we have initialized properly using 'New' what might be the problem? – thiszjithu Jun 25 '14 at 4:29
  • That sounds like it. It's usually the simple things! Until you initialize it no memory is allocated against it so there's your exception: you're trying to put values into memory you don't have. – Michael Stimson Jun 25 '14 at 4:36
  • well I used the first method u given and looks like it worked! one more thing, I want to make sure if the polygon is created. how to access the polygon and check the points in it? – thiszjithu Jun 25 '14 at 4:59
  • You could go back to the point collection or use IGeometry.IsEmpty - true if it's made of nothing, false if it's got something in there. Also the IGeometry.Envelope, see if that's what you're expecting, it should be a box from the minimum to maximum coordinates. Both would be a good check of what you've created. – Michael Stimson Jun 25 '14 at 5:02
  • Hello @Michael I created the plane following your help and now I have to find some distances using "Near Tool" Can you please help me in taking off this code to the next level. Thank you.. here is the link : link – thiszjithu Jun 25 '14 at 13:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.