Monday, 5 August 2013

Creating a donut polygon

a follow up from my previous post.   This one shows the syntax on how to create a donut polygon from coordinates. Note the donut ring coordinates are given in counterclockwise order while the outer polygon ring is clockwise

import arcpy
from arcpy import env
env.overwriteOutput = True
coords = [
          [[0,0],[0,1],[1,1],[1,0],[0,0],
          [0.25,0.25], [0.25,0.75],[0.75,0.75],[0.75,0.25],[0.25,0.25]
         ]]

pnt = arcpy.Point()
array = arcpy.Array()
features = []
for a_feature in coords:
  for xy in a_feature:
    pnt.X = xy[0]
    pnt.Y = xy[1]
    array.add(pnt)
  array.add(array.getObject(0))
  polygon = arcpy.Polygon(array)
  array.removeAll()
  features.append(polygon)
arcpy.CopyFeatures_management(features, "c:/temp/x_shape.shp")

No comments:

Post a Comment