3

I need to create a grid of polygons. Each polygon is rectangle, thus has 4 corners (vertices). When I create polygon features using ArcObjects they seem to have wrong geometry, which results in wrong label placement (outside polygons).

I use the following approach:

Dim pPntColl As IPointCollection
pPntColl = New Polygon

Dim pPoint As IPoint
pPoint = New Point
pPoint.PutCoords(dX, dY)
pPntColl.AddPoint(pPoint)

...

When I use 4 vertices I get a polygon which has one segment missing (visible in Edit session). polygon made of 4 points

When I add the first point at the end of polygon (as a 5th point), geometry looks good, but the label is still off.

polygon made of 5 points

I know I can use ITopologicalOperator2 and Simplify() method but:

  1. This affects the performance (I need to create many thousands of polygons).
  2. I don't understand, what is the reason of the problem. I have 4 points, they should create a topologically correct polygons...

So, my question is: what is the best way of creating polygon features within a polygon feature class using ArcObjects?

I already checked some ESRI recommended approaches, e.g.: http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#//0001000002wm000000 but the problem is still the same: I need to use Simplify() to get polygons right.

Any help and hints how to optimize this will be appreciated.

  • 1
    Are you adding the points in a clockwise direction? Also did, you try IGeometryBridge2.AddPoints? – Kirk Kuykendall Dec 5 '12 at 19:14
  • I tried IGeometryBridge2.AddPoints and the result was the same. Adding points in a clockwise direction solved the problem! Thanks Kirk. – jan_b Dec 6 '12 at 7:33
  • Did you already rule out using the Create Fishnet geoprocessing tool? – blah238 Dec 6 '12 at 17:23
  • Yes, I did. But I need a bit more control over created grid, that's why need to use ArcObjects. Thanks for a hint, though. – jan_b Dec 6 '12 at 19:22
2

Add the points in a clockwise order.

When you call IPointCollection.AddPoint, on a polygon the point is added to the exterior ring of the polygon. Vertices in exterior rings are expected to be clockwise, so if you don't add them in clockwise order ArcObjects will need to do more work to re-order them.

Interior rings (e.g. donut holes) are counter-clockwise.

  • easy way for inner rings (inRing) IRing ring = inRing as IRing; ring.ReverseOrientation(); ring.Close(); – Paulo Moreno Nov 15 '16 at 7:28
  • This doesn't seem to answer the original question, rather it appears to be a comment on the original answer – nmtoken Nov 15 '16 at 8:37
0

Try casting the IPointCollection to an IPolygon and closing it using IPolygon.Close().

You need to use only four vertices (no need to duplicate first and last vertices).

It could be something like below in VBA(not tested)..

pPoint.PutCoords(dX, dY)
pPntColl.AddPoint(pPoint)

dim pPolygon as IPolygon
set pPolygon = pPntColl
pPolygon.Close()

dim pFeature as IFeature
set pFeature = pFeatureClass.CreateFeature()

pFeature.Shape = pPolygon
pFeature.Store()
  • I tried this. Closing a polygon helps, i.e. the feature has all four segments but labels are still misplaced... – jan_b Dec 5 '12 at 12:31

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.