3

I am developing a toolbar for ArcMap with .NET ArcObjects and I made an option to round vertices coordinates to meters (no decimals). So I change X and Y of each vertex on each feature. The problem is that if I do a Check Geometry after, I get bad envelope on all features. I guess that it's because the envelope doesn't update itself after changing the vertices.

Is there a way to update envelopes without using Repair Geometry?

I don't want to use it because it does a lot more than just updating envelopes.

Here is the code I am using

lIGeometryCollection = layerFeature.Shape
For idx_geometrie As Integer = 0 To lIGeometryCollection.GeometryCount - 1
    Dim pointCollection As IPointCollection = lIGeometryCollection.Geometry(idx_geometrie)
    For idx_point As Integer = pointCollection.PointCount - 1 To 0 Step -1
        Dim lPoint As IPoint = New ESRI.ArcGIS.Geometry.Point
        lPoint.PutCoords(
            Math.Round(pointCollection.Point(idx_point).X / ResolutionXY, 0, MidpointRounding.AwayFromZero) * ResolutionXY,
            Math.Round(pointCollection.Point(idx_point).Y / ResolutionXY, 0, MidpointRounding.AwayFromZero) * ResolutionXY)
        pointCollection.UpdatePoint(idx_point, lPoint)
        System.Runtime.InteropServices.Marshal.ReleaseComObject(lPoint)
    Next
Next
layerFeature.Store()
  • I think you need to be showing us your code as this is an ArcObjects question. Amend your question to show this. – Hornbydd Jan 23 '18 at 14:24
  • 1
    Ok, I just edited my question to add code. – Math Jan 23 '18 at 14:32
2

Don't know if this will help but is good practise:

The remarks section of IPointCollection states -

For efficiency UpdatePoint does not check if the spatial reference of the input point is equal to the spatial reference of the PointCollection. Please make sure that the spatial reference of the input point is equal to the spatial reference of the PointCollection before you pass the point in.

As you are creating new point objects and then setting the XY based on the truncated XY values, you are overwriting points in IPointCollection with points that don't have any spatial reference. You can set the spatialreference of points before you update.

Also look into IGeometryCollection.GeometriesChanged.

Finally I have found ITopologicalOperator.Simplify can fix geometry problems.

  • 1
    It worked with IGeometryCollection.GeometriesChanged. I cast layerFeature.shape to IGeometryCollection and I call GeometriesChanged just before layerFeature.Store. Now I got no bad envelope! I also set the spatial reference of the point since it is logicial to do it.Thank you! – Math Jan 23 '18 at 16:01

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.