problem creating arcpy polygon

303
1
09-29-2011 02:12 PM
DustinReagan
New Contributor
I was having a problem creating certain polygons programmatically, so I put together this simple example to illustrate the issue.

The following code works as expected (creates a simple square):

outputFeatureClass = r"c:\temp\test.shp"

coordList = [[0, 0],
             [0, -0.01],
             [.01, -.01],
             [.01, 0],
             [0, 0]]

def main():
    array = arcpy.Array()
    point = arcpy.Point()
    # Create a list to store the features
    features = []
    # Read the coordinates
    for coordPair in coordList:
        point.X = coordPair[0]
        point.Y = coordPair[1]
        array.add(point)

    polygon = arcpy.Polygon(array)
    # Append to the feature list
    features.append(polygon)

    # Copy the features to an output feature class
    arcpy.CopyFeatures_management(features, outputFeatureClass)

if __name__ == '__main__':
    import arcpy
    arcpy.env.overwriteOutput = True
    main()


However, if i change coordList to:

coordList = [[0, 0],
             [0, -0.001],
             [0.001, -0.001],
             [0.001, 0],
             [0, 0]]


The script completes successfully, but the resulting geometry is a "null" shape, according to the check geometry tool.

My guess is that the vertices are all getting merged at some point?  If so, why, and how can i prevent it?

Thanks,
Dustin
Tags (2)
0 Kudos
1 Reply
MarcNakleh
New Contributor III
Hello Dustin,

I'm thinking that it's because of the XY Tolerance described on this ArcGIS page that is imposed on the CopyFeatures_management tool, as the data is originally unprojected.

Quoting:
The XY Tolerance default for an unknown coordinate system is 0.001 units


I've tried playing around with arcpy.env.XYolerance, but I don't think it's applied when creating a shapefile from nothing. You might have more luck using arcpy.CreateFeatureClass_management with the proper projection, modifying arcpy.env.XYTolerance, and then using an insert cursor or append or somesuch to generate your polygon.

Cheers,
0 Kudos