Working with Numpy Arrays

2187
1
12-26-2012 07:28 PM
MichaelMarkieta
New Contributor III
I have a numpy array like so:

import numpy as np

np.array([('1', [[0.0, 0.0], [1.0, 0.0], [0.30901699437494745, 0.95105651629515353], [-0.80901699437494734, 0.58778525229247325], [-0.80901699437494756, -0.58778525229247303], [0.0, 0.0]]),
       ('2', [[0.0, 0.0], [-0.80901699437494756, -0.58778525229247303], [0.30901699437494723, -0.95105651629515364], [1.0, -2.4492935982947064e-16], [1.0, 0.0], [0.0, 0.0]])], 
       dtype=[('UniqueID', 'S4'), ('XY', '<f8', (6, 2))])


I want to convert this array into a feature class using the 10.1 arcpy.da.NumPyArrayToFeatureClass function. However, feeding this array into the arcpy function gives me two points at (0,0), representing the first coordinate pairs in UniqueID 1 and 2.

Any thoughts on what might be the problem? Each UniqueID relates to a tuple of coordinate pairs that should be connected to form a closed polygon (last point is the same as the first point).
Tags (2)
0 Kudos
1 Reply
CarlSunderman
Occasional Contributor
This is basically taken exactly from the help, without using numpy
import arcpy

# A list of features and coordinate pairs
#
coordList = [[[0.0, 0.0], [1.0, 0.0], [0.30901699437494745, 0.95105651629515353], [-0.80901699437494734, 0.58778525229247325], [-0.80901699437494756, -0.58778525229247303], [0.0, 0.0]],
       [[0.0, 0.0], [-0.80901699437494756, -0.58778525229247303], [0.30901699437494723, -0.95105651629515364], [1.0, -2.4492935982947064], [1.0, 0.0], [0.0, 0.0]]]


# Create empty Point and Array objects
#
point = arcpy.Point()
array = arcpy.Array()

# A list that will hold each of the polygon objects 
# 
featureList = []

for feature in coordList:
    # For each coordinate pair, set the x,y properties and add to the 
    #  Array object.
    #
    for coordPair in feature:
        point.X = coordPair[0]
        point.Y = coordPair[1]
        array.add(point)

    # Create a polygon object based on the array of points
    #
    polygon = arcpy.Polygon(array)

    # Clear the array for future use
    #
    array.removeAll()

    # Append to the list of polygon objects
    #
    featureList.append(polygon)

# Create a copy of the polygon objects, by using featureList as input to 
#  the CopyFeatures tool.
#
arcpy.CopyFeatures_management(featureList, "C:/outputFOlder/PolygonArray")
0 Kudos