I have a feature class of line-based ellipses generated by the Table to Ellipse tool that looks like this:
What I want is polygons of the individual ellipses, however tools like Feature to Polygon will create a polygon for every intersection.

My solution to this right now is a Search Cursor in Python that makes a layer from each line ellipse and then runs the Feature to Polygon tool on that layer. This is extremely slow and means I have a feature dataset with hundreds (soon to be thousands) of individual polygon feature classes in it instead of one file.

I saw from this question that there is a Python package, Shapely, that might run much faster than the arcpy tool in a loop. I can't believe, however, that there isn't some way to do this in ArcGIS. Can anyone think of a better solution?

I think the best approach will be to try and generate elliptical polygons at the outset by cursoring through the same table you input to Table To Ellipse.
–
PolyGeo♦Jul 19 '13 at 21:15

I agree. I am at a loss, however, as to how to do that. The Table to Ellipse tool does not have the option to make polygons, and I don't have a table of vertices, the table has a center point, a major axis, a minor axis, and an azimuth.
–
AlmaThomJul 19 '13 at 21:43

My code below not working? I can comment it more if desired.
–
PaulJul 19 '13 at 21:50

I would appreciate that, Paul. I think the problem is that I didn't mention I am working out of a GDB and some of the code might need tweaking, unfortunately I am not sure what part.
–
AlmaThomJul 19 '13 at 21:54

1

As an aside, your problem of having a "feature dataset with hundreds (soon to be thousands) of individual polygon feature classes" should be easy to resolve by using Append to bring them back into a single feature class.
–
PolyGeo♦Jul 20 '13 at 1:07

1 Answer
1

Instead of using Feature to Polygon multiple times, you could use your SearchCursor to read the vertices of each ellipse and then create a polygon from the vertices.

shpin = "Feature class"
shpout = "output polygon FC"
#Get number of features in input.
entries = int(arcpy.GetCount_management(shpin).getOutput(0))
#Get name of OID field.
oid = [str(x.name) for x in arcpy.ListFields(shpin, "*", "OID")][0]
array = arcpy.Array()
polyvert = []
#Starting at 1 and running to entries +1, because Python ranges start at 0;
#FC OID starts at 1. This can be changed to "for i in xrange(entries):" for a shapefile
for i in xrange(1,entries+1):
#Use where_clause to loop over each feature in feature class.
#explode_to_points is used to get coordinates of all vertices in ellipse.
vertices = [row[0].firstPoint for row in arcpy.da.SearchCursor(shpin,
"SHAPE@", '"{0}"={1}'.format(oid, i), explode_to_points=True)]
#Use list comprehension to add vertices individually to array.
[array.add(x) for x in vertices] #Add point objects to array.
#Create polygon from point array and append to list.
polyvert.append(arcpy.Polygon(array))
array.removeAll() #Remove data for next loop.
arcpy.CopyFeatures_management(polyvert, shpout) #Convert polygon array to shapefile
#Define same projection as input.
arcpy.DefineProjection_management(shpout, arcpy.Describe(input).spatialReference)

If you don't need to maintain highly accurate output polygons, I recommend that you run generalize on your input before proceeding. I made a test shapefile of 25 ellipses with major,minor axes of 50,150. Each ellipse had over 21,000 vertices. Run time was 61 seconds. Using generalize set to 1 inch, the vertice count was reduced to 70 and run time was .71 seconds. The file size was also reduced from 7.8MB to 55KB.

If you are running this on thousands of ellipses that are expansive, run time can easily approach a few hours and you'll end up with a potentially very large output. Granted, if you are making ellipses in the first place, you probably want highly accurate (and vertex-dense) output polygons.

When I run this, vertices is empty which causes an error. I'm not too familiar with this code so I'm not entirely sure how to go about debugging it.
–
AlmaThomJul 19 '13 at 20:19

Are you running out of a GDB? the OID name and syntax of SQL where clause changes slightly depending on if the input is a shapefile/feature class. My code was written to operate on a shapefile.
–
PaulJul 19 '13 at 20:20