split circle into 6 equal parts

2570
2
09-06-2011 01:21 PM
JinMa
by
New Contributor II
I have a circle polygon feature class.  How do I split each circle into six equal parts.

any idea or code is highly appreciated.

Thanks
Tags (2)
0 Kudos
2 Replies
MarcNakleh
New Contributor III
Interesting question! I'm sure people with more experience might be able to help you a bit more.

My first thought would be to run through each row using arcpy.SearchCursor, and collect:

  • Shape Area

  • Centroid Position

I believe both of these are available as properties inside the Shape Field.

Once you have those, you can find the Circle's radius by using Python's Math Module:
import math
radius = math.sqrt(area / math.pi)

Then, you could use arcpy.Polyline to construct a feature for each circle that includes 5 lines whose first node is on the centroid and whose length is a little more than the radius, at angles of 60, 120, 180, 240 and 300.

It's probably not the quickest way, but it should get the job done. I hope this helps!
0 Kudos
AlexeyTereshenkov
Regular Contributor III
import arcpy, math

arcpy.env.overwriteOutput = True
arcpy.env.workspace = r"C:\GIS\Temp\test.gdb"
tempworkspace = arcpy.env.workspace
in_poly_fc = r"C:\GIS\Temp\test.gdb\CirclesFeatureClass"
clip_lines_fc = r"ClipLines"
sum_lines_fc = r"SumClipLines"

#converting an existing fc with circles to Geometry objects
geometries = arcpy.CopyFeatures_management(in_poly_fc,arcpy.Geometry())

for feature in geometries:
    #obtaining a centroid of the circle centroid via Geometry class attribute
    centroid_Point = feature.trueCentroid
    centroid_xy = []

    #obtaining XY coordinates of the centroid via Point class attribute
    centroid_xy.append(centroid_Point.X)
    centroid_xy.append(centroid_Point.Y)

    #obtaining the radius
    #have to add a small overhead value to make sure the radius end point will overshoot the polygon
    #otherwise may get undershooting lines which depends on the precision of the coordinates
    #and XY tolerance of the source data
    radius = math.sqrt(feature.area / math.pi) + 1

    #supply the list of angles for bearing
    bearing_angles = [0,60,120,180,240,300,360]

    #creating bearing angles table and adding fields
    bearing_table = arcpy.CreateTable_management(tempworkspace,"BearingDataTable")
    arcpy.AddField_management(bearing_table,"Xcoord","Double")
    arcpy.AddField_management(bearing_table,"Ycoord","Double")
    arcpy.AddField_management(bearing_table,"Bearing","Double")
    arcpy.AddField_management(bearing_table,"Distance","Double")

    #inserting all required lines constructed from centroid with the radius and bearing angle
    with arcpy.da.InsertCursor(bearing_table,["Xcoord","Ycoord","Bearing","Distance"]) as ins_cursor:
        for bearing_angle in bearing_angles:
            ins_cursor.insertRow((centroid_xy[0],centroid_xy[1],bearing_angle,radius))
    del ins_cursor

    #projected coordinate system used for output lines feature classes generated
    project_coordsys = """PROJCS['NAD_1927_StatePlane_Alabama_East_FIPS_0101',GEOGCS['GCS_North_American_1927',
    DATUM['D_North_American_1927',SPHEROID['Clarke_1866',6378206.4,294.9786982]],PRIMEM['Greenwich',0.0],
    UNIT['Degree',0.0174532925199433]],PROJECTION['Transverse_Mercator'],PARAMETER['False_Easting',500000.0],
    PARAMETER['False_Northing',0.0],PARAMETER['Central_Meridian',-85.83333333333333],
    PARAMETER['Scale_Factor',0.99996],PARAMETER['Latitude_Of_Origin',30.5],
    UNIT['Foot_US',0.3048006096012192]];-17948200 -43887100 3048,00609601219;
    -100000 10000;-100000 10000;3,28083333333333E-03;0,001;0,001;IsHighPrecision"""

    arcpy.BearingDistanceToLine_management(bearing_table,clip_lines_fc,"Xcoord","Ycoord",
                                           "Distance","Feet","Bearing",spatial_reference=project_coordsys)
    #adding each circle's 8 lines in iteration to the sum output line feature class
    arcpy.Append_management(clip_lines_fc,sum_lines_fc,"NO_TEST")

    #deleting temp feature classes to avoid locking issues at next iteration
    arcpy.Delete_management(bearing_table)
    arcpy.Delete_management(clip_lines_fc)

#cutting each circle in the polygon feature class by using the lines obtained earlier
arcpy.FeatureToPolygon_management([in_poly_fc,sum_lines_fc],"Quadrants","#","ATTRIBUTES","#")
0 Kudos