AnsweredAssumed Answered

Arcpy (2.6) modify multiparts polygon vertice xy vlaue

Question asked by soo2csc on Aug 30, 2016
Latest reply on Sep 5, 2016 by soo2csc

Dear all,

 

I am using python2.6 (together with arcgis 10.0) and try to modify the vertice xy values for multiple parts polygon using the following scripts, no error thrown but the vertice xy value not changed. Please help to advice what is wrong in my script:

 

 

def modify(f, n):
     s = '%.12f' % f
     i, p, d = s.partition('.')
     return '.'.join([i, (d+'0'*n)[:n]])

import arcpy
import logging
from arcpy import env

env.workspace = r"C:\modifyTest"
infc = "testing.mdb/donutTesting1"
desc = arcpy.Describe(infc)
shapefieldname = desc.ShapeFieldName
my_field = "SHAPE"
rows = arcpy.UpdateCursor(infc)
for row in rows:
     feat = row.getValue(shapefieldname)
     arr_pol = arcpy.Array()
     partnum = 0
     if feat.isMultipart == True:
          for part in feat:
               parts = []
               arr_parts = arcpy.Array()

               while partnum < feat.partCount:
                    part = feat.getPart(partnum)
                    pnt = part.next()
                    while pnt:
                         X_value = modify( pnt.X , 2)
                         Y_value = modify( pnt.Y , 2)
                         pnt.X= X_value
                         pnt.Y= Y_value
                         #print pnt.X, pnt.Y
                         parts.append([X_value, Y_value])
                         XYPoint = arcpy.Point(X_value, Y_value)
                         arr_parts.add(XYPoint)
                         arr_pol.add(arr_parts)

                         pnt = part.next()
                         if pnt is None:
                              pnt = part.next()
                              if pnt:
                                   X_value = modify( pnt.X , 2)
                                   Y_value = modify( pnt.Y , 2)
                                   pnt.X= X_value
                                   pnt.Y= Y_value
                                   parts.append([X_value, Y_value])
                                   XYPoint = arcpy.Point(X_value, Y_value)
                                   arr_parts.add(XYPoint)
                                   arr_pol.add(arr_parts)
                    partnum += 1
              print parts
      polygon = arcpy.Polygon(arr_pol)
      row.setValue(my_field,polygon)
      rows.updateRow(row)

Attachments

Outcomes