2

I am working to create a polygon from UTM coordinates. The script I am using fails with a "must be a sequence, not float" error:

Traceback (most recent call last):
  File "F:/sample/clipTiles.py", line 104, in <module>
    arcpy.Array([arcpy.Point(*coords) for coords in feature])))
TypeError: type object argument after * must be a sequence, not float

I have been working off the ArcGIS Polygon help section. My UTM coordinates are generated earlier in a script and take the following form:

[[734855.5142000001, 4744379.424500001], [740607.6685000001, 4744379.424500001], [740607.6685000001, 4736862.1753], [734855.5142000001, 4736862.1753]]

These are the min/max point pairs of a custom bounding box I need to convert to polygon.


                # feature_info eventually takes the following form: [[734855.5142000001, 4744379.424500001], [740607.6685000001, 4744379.424500001], [740607.6685000001, 4736862.1753], [734855.5142000001, 4736862.1753]]
                feature_info = [[xmin, ymax], [xmax,ymax], [xmax, ymin], [xmin, ymin]]

                # A list that will hold each of the Polygon objects
                features = []

                for feature in feature_info:
                    # Create a Polygon object based on the array of points
                    # Append to the list of Polygon objects
                    features.append(
                        arcpy.Polygon(
                            arcpy.Array([arcpy.Point(*coords) for coords in feature])))

                # Persist a copy of the Polyline objects using CopyFeatures
                outshp = os.path.join(outws, row[2] + "_shp")
                arcpy.CopyFeatures_management(features, outshp)

How can I write these UTM coordinates to a polygon featureclass?

1 Answer 1

3

I do it this way by creating an Array of Point objects that form a line that closes back on itself, and then creating a Polygon object from that Array:

# feature_info eventually takes the following form: [[734855.5142000001, 4744379.424500001], [740607.6685000001, 4744379.424500001], [740607.6685000001, 4736862.1753], [734855.5142000001, 4736862.1753]]
feature_info = [(xmin, ymax), (xmax,ymax), (xmax, ymin), (xmin, ymin)]

lineArray = arcpy.Array()

for x,y in feature_info:
    lineArray.add(arcpy.Point(x,y))
lineArray.add(lineArray.getObject(0))
polygon = arcpy.Polygon(lineArray)

# Persist a copy of the Polyline objects using CopyFeatures
outshp = os.path.join(outws, row[2] + "_shp")
arcpy.CopyFeatures_management(polygon, outshp)

I suspect that lists and tuples can be used interchangeably in my first line so try:

feature_info = [[xmin, ymax], [xmax,ymax], [xmax, ymin], [xmin, ymin]]

If it complains about requiring a tuple then create a new empty list and append into it by iterating your list of lists, using the tuple function to "freeze" each one, into a list of tuples.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.