Skip to main content
deleted 61 characters in body
Source Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345

This is not an answer but some extra info for this question. The sinister behaviour is not occurring at arcpy.Polygon as suggested by @FelixIP, it is occuring at the getPart() bit of code. I tweaked your code and ran it on a dataset with just a triangle. I had set the coordinate system to be British National Grid when I had created it.

import arcpy
arcpy.env.addOutputsToMap = True
infc = "tri"
outBuffer=r'c:\scratch\OUT_BUFFER.shp'
outPart=r'c:\scratch\OUT_PART.shp'
d=arcpy.Describe(infc)
SR=d.spatialReference
with arcpy.da.SearchCursor(infc, ("SHAPE@","LABEL")) as rows:
    for shp,label in rows:
        buf=shp.buffer(5)
        arcpy.CopyFeatures_management(buf, outBuffer)
        n=buf.partCount
        for i in xrange (n):
            prt=buf.getPart(i)
            # Print out sequence of XY points
            print(prt)
            for p in prt:
                print str(p.X ) + "," + str(p.Y)
            pgon=arcpy.Polygon(prt,SR)
            arcpy.CopyFeatures_management(pgon, outPart)
            break

Zooming into one corner of the buffer of the triangle in edit mode we can see many vertices:

Vertices of buffer

Infact there are 42 vertices for the whole geometry. My adjusted code reading the output of the getPart() returns only 11.

Clipped part

So the bug is occuring when the getPart() is called to return the Array of Points.

This is not an answer but some extra info for this question. The sinister behaviour is not occurring at arcpy.Polygon as suggested by @FelixIP, it is occuring at the getPart() bit of code. I tweaked your code and ran it on a dataset with just a triangle. I had set the coordinate system to be British National Grid when I had created it.

import arcpy
arcpy.env.addOutputsToMap = True
infc = "tri"
outBuffer=r'c:\scratch\OUT_BUFFER.shp'
outPart=r'c:\scratch\OUT_PART.shp'
d=arcpy.Describe(infc)
SR=d.spatialReference
with arcpy.da.SearchCursor(infc, ("SHAPE@","LABEL")) as rows:
    for shp,label in rows:
        buf=shp.buffer(5)
        arcpy.CopyFeatures_management(buf, outBuffer)
        n=buf.partCount
        for i in xrange (n):
            prt=buf.getPart(i)
            # Print out sequence of XY points
            print(prt)
            for p in prt:
                print str(p.X ) + "," + str(p.Y)
            pgon=arcpy.Polygon(prt,SR)
            arcpy.CopyFeatures_management(pgon, outPart)
            break

Zooming into one corner of the buffer of the triangle in edit mode we can see many vertices:

Vertices of buffer

Infact there are 42 vertices for the whole geometry. My adjusted code reading the output of the getPart() returns only 11.

Clipped part

So the bug is occuring when the getPart() is called to return the Array of Points.

The sinister behaviour is not occurring at arcpy.Polygon as suggested by @FelixIP, it is occuring at the getPart() bit of code. I tweaked your code and ran it on a dataset with just a triangle. I had set the coordinate system to be British National Grid when I had created it.

import arcpy
arcpy.env.addOutputsToMap = True
infc = "tri"
outBuffer=r'c:\scratch\OUT_BUFFER.shp'
outPart=r'c:\scratch\OUT_PART.shp'
d=arcpy.Describe(infc)
SR=d.spatialReference
with arcpy.da.SearchCursor(infc, ("SHAPE@","LABEL")) as rows:
    for shp,label in rows:
        buf=shp.buffer(5)
        arcpy.CopyFeatures_management(buf, outBuffer)
        n=buf.partCount
        for i in xrange (n):
            prt=buf.getPart(i)
            # Print out sequence of XY points
            print(prt)
            for p in prt:
                print str(p.X ) + "," + str(p.Y)
            pgon=arcpy.Polygon(prt,SR)
            arcpy.CopyFeatures_management(pgon, outPart)
            break

Zooming into one corner of the buffer of the triangle in edit mode we can see many vertices:

Vertices of buffer

Infact there are 42 vertices for the whole geometry. My adjusted code reading the output of the getPart() returns only 11.

Clipped part

So the bug is occuring when the getPart() is called to return the Array of Points.

Source Link
Hornbydd
  • 44.6k
  • 5
  • 42
  • 84

This is not an answer but some extra info for this question. The sinister behaviour is not occurring at arcpy.Polygon as suggested by @FelixIP, it is occuring at the getPart() bit of code. I tweaked your code and ran it on a dataset with just a triangle. I had set the coordinate system to be British National Grid when I had created it.

import arcpy
arcpy.env.addOutputsToMap = True
infc = "tri"
outBuffer=r'c:\scratch\OUT_BUFFER.shp'
outPart=r'c:\scratch\OUT_PART.shp'
d=arcpy.Describe(infc)
SR=d.spatialReference
with arcpy.da.SearchCursor(infc, ("SHAPE@","LABEL")) as rows:
    for shp,label in rows:
        buf=shp.buffer(5)
        arcpy.CopyFeatures_management(buf, outBuffer)
        n=buf.partCount
        for i in xrange (n):
            prt=buf.getPart(i)
            # Print out sequence of XY points
            print(prt)
            for p in prt:
                print str(p.X ) + "," + str(p.Y)
            pgon=arcpy.Polygon(prt,SR)
            arcpy.CopyFeatures_management(pgon, outPart)
            break

Zooming into one corner of the buffer of the triangle in edit mode we can see many vertices:

Vertices of buffer

Infact there are 42 vertices for the whole geometry. My adjusted code reading the output of the getPart() returns only 11.

Clipped part

So the bug is occuring when the getPart() is called to return the Array of Points.