5

I am trying to develop arcgis 10.0 addin to update Z values of vertices of a selected line. Scenario: The tool scans all features in a given shape file and populates the list of features which has at least one vertex with a Z vlaue = 0. User then selects a feature from the list and clicks a button to update Z values to a given height - this last part does not work.

I have tried the following for updating Z values of a selected polyline feature with no luck:

    Dim pFeatureSelection As IFeatureSelection
            pFeatureSelection = pFLayer
            Dim pEnumID As IEnumIDs
            pEnumID = pFeatureSelection.SelectionSet.IDs
            Dim id As Long
            id = pEnumID.Next
            Dim pPointCollection As IPointCollection
            Dim pFeature As IFeature
            Do While Not id = -1
                pFeature = pFLayer.FeatureClass.GetFeature(id)
                pPointCollection = pFeature.Shape

                For lPnt = 0 To (pPointCollection.PointCount - 1)
                     SetZValueOnPoint(pPointCollection.Point(lPnt), Convert.ToDouble(txtZValue.Text))

                Next

                id = pEnumID.Next
            Loop

3 Answers 3

3

Thanks to Jeff's help we got the answer via the ArcGIS Discussion Forum:

Public Sub SetZValueOnPoint(ByVal point As ESRI.ArcGIS.Geometry.IPoint, ByVal zValue As System.Double)  

   If point Is Nothing OrElse point.IsEmpty Then  
       Return  
   End If  

   Dim zAware As ESRI.ArcGIS.Geometry.IZAware = CType(point, ESRI.ArcGIS.Geometry.IZAware) ' Explicit Cast  
    zAware.ZAware = True  
    point.Z = zValue  

End Sub  
3

If the desire is to make the polyline the same Z value all the way from start to finish then use IZ interface. This interface has a method SetConstantZ ( Double ZLevel ) which works for polygons and polylines that will set every vertex to the same Z value. This approach is much simpler than the GeometryCollection / PointCollection / IZaware approach which I have used previously to set individual Z values of points (i.e. all different).

0

if IPolyLine was used. you have to only set zAware to true to solve this problem.

 Dim newSegCollection As ISegmentCollection = New Polyline
 Dim zAware As IZAware = CType(newSegCollection, IZAware)
 zAware.ZAware = True

then you can set z for FromPoint and ToPoint for each line in your IPolyLine shape.

and if you want to set same z for all lines in IPolyLine you can use IZ interface and SetConstantZ.

Dim iz As IZ2 = newSegCollection
iz.SetConstantZ(12.12)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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