AnsweredAssumed Answered

need help creating multipart polygon output using arcpy

Question asked by efisher16 on Mar 14, 2017
Latest reply on Mar 15, 2017 by efisher16

Hi all,

 

I am working on a script that transforms the vertex coordinates of input multi-part polygon shapefiles and outputs these transformed coordinate values into new multi-part polygons.  When I run the script, I am able to generate an identical shapefile to the original (but with transformed coordinate values), but none of the individual features remain.  I've tried to debug the code myself by observing the format of my main array that is fed into the arcpy.Polygon object and compared these results against arrays from working script examples provided by ESRI.  I don't see any difference, but clearly something is not right.  I was hoping someone could have a look below and recommend a solution.  Here's the code:

 

import arcpy
import math

 

infc = "C:\\testing\\fortesting.shp"

 

def transform(pntX,pntY):
    global Calc_north
    global Calc_east
    global Calc_elev

 

    start_north = -3770671.323
    start_east = -72160.677
    end_north = -3770648.576
    end_east = -72151.373

 

    delta_n = start_north - end_north
    delta_e = end_east - start_east
    angle = math.degrees(math.atan(delta_n/delta_e))

 

    deltaY = pntX*(math.sin(math.radians(angle)))
    deltaX = pntX*(math.cos(math.radians(angle)))

 

    Calc_north = start_north - deltaY
    Calc_east = deltaX + start_east
    Calc_elev = pntY

 

array = arcpy.Array()

 

# Enter for loop for each feature
for row in arcpy.da.SearchCursor(infc, ["OID@", "SHAPE@"]):
    # Print the current multipoint's ID
    print("Feature {}:".format(row[0]))
    # Step through each part of the feature
    for part in row[1]:
        # Step through each vertex in the part
        sub_array = arcpy.Array()
        for pnt in part:
            # Print x,y coordinates of current point
            transform(pnt.X,pnt.Y)
            #print pnt.X, pnt.Y, Calc_east, Calc_north, Calc_elev
            new_pnt = arcpy.Point(Calc_east, Calc_north)
            sub_array.add(new_pnt)
        sub_array.add(sub_array.getObject(0))
        array.add(sub_array)
        del sub_array
multi_Part_Polygon = arcpy.Polygon(array, arcpy.SpatialReference(102484), True)
arcpy.CopyFeatures_management(multi_Part_Polygon,"C:\\testing\\test18.shp")

Outcomes