arcobjects update geometry Z values of line vertices with a given number

2941
4
Jump to solution
02-06-2013 03:54 AM
magdaw
by
New Contributor
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


Please your help in providing any hint or suggesting error in the code above is much appreciated!
0 Kudos
1 Solution

Accepted Solutions
JeffMatson
Occasional Contributor III
If it were me, I would change the SetZValueOnPoint into a Function that returns an IPoint.  In your main procedure you can create a new point and update the point collection.  Finally you'll need to set the feature shape back to the modified point collection and store the feature.  Hope that helps

Public Function SetZValueOnPoint(ByVal point As IPoint, ByVal zValue As Double) As IPoint      Dim zAware As IZAware     Set zAware = point     zAware.zAware = True     point.Z = zValue       Return point   End Function   ''inside main procedure: For lPnt = 0 To (pPointCollection.PointCount - 1)     Dim newPoint As IPoint = SetZValueOnPoint(pPointCollection.point(lPnt), Convert.ToDouble(txtZValue.Text))     pPointCollection.UpdatePoint lPnt, newPoint Next   '' Set pFeature.Shape = pPointCollection pFeature.Store '' id = pEnumID.Next  



Hi Jeff,

Many thanks for looking at this!Please see the procedure code:

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

View solution in original post

0 Kudos
4 Replies
JeffMatson
Occasional Contributor III
I'm assuming you have code for the SetZValueOnPoint procedure, can you post that as well?



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


Please your help in providing any hint or suggesting error in the code above is much appreciated!
0 Kudos
magdaw
by
New Contributor
Hi Jeff,

Many thanks for looking at this!Please see the procedure code:

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
0 Kudos
JeffMatson
Occasional Contributor III
If it were me, I would change the SetZValueOnPoint into a Function that returns an IPoint.  In your main procedure you can create a new point and update the point collection.  Finally you'll need to set the feature shape back to the modified point collection and store the feature.  Hope that helps

Public Function SetZValueOnPoint(ByVal point As IPoint, ByVal zValue As Double) As IPoint      Dim zAware As IZAware     Set zAware = point     zAware.zAware = True     point.Z = zValue       Return point   End Function   ''inside main procedure: For lPnt = 0 To (pPointCollection.PointCount - 1)     Dim newPoint As IPoint = SetZValueOnPoint(pPointCollection.point(lPnt), Convert.ToDouble(txtZValue.Text))     pPointCollection.UpdatePoint lPnt, newPoint Next   '' Set pFeature.Shape = pPointCollection pFeature.Store '' id = pEnumID.Next  



Hi Jeff,

Many thanks for looking at this!Please see the procedure code:

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
0 Kudos
magdaw
by
New Contributor
Hi Jeff,

That worked for me and it does what I wanted it to do- it updates the Z value of vertices in a line:)
Many Thanks for your help with that!

Magda
0 Kudos