Select to view content in your preferred language

ArcPy Circle Function

275
2
05-30-2024 11:33 AM
YahyaMasri
Emerging Contributor

I am trying to create inset maps using ArcPy and I want them to be circles, but I don't know how to create a circular function the same way a rectangle function was up on the GraphicElement Documentation.

This is the code for a rectangle that was on the documentation: 

def MakeRec_LL(llx, lly, w, h):

xyRecList = [[llx, lly], [llx, lly+h], [llx+w,lly+h], [llx+w,lly], [llx,lly]]

xyRecList = [[1,1],[1, 2], [2.75, 2], [2.75, 1], [1, 1]]

array = arcpy.Array([arcpy.Point(*coords) for coords in xyRecList])

rec = arcpy.Polygon(array)

return rec

 

p = arcpy.mp.ArcGISProject('CURRENT')

#Create a layout

lyt = p.createLayout(6, 3, 'INCH', 'New Layout with Rectangles')

 

Does anyone know how to replicate this process, but for circles instead?

0 Kudos
2 Replies
RhettZufelt
MVP Notable Contributor

Not sure about layouts, but You can use the arcpy.analysis.buffer function to create circular polygons using a point and radius.

R_

0 Kudos
DanPatterson
MVP Esteemed Contributor
def _circle(radius=100, clockwise=True, theta=1, xc=0.0, yc=0.0):
    """Produce a circle/ellipse depending on parameters.

    Requires
    --------
    `radius` : number
        in projected units
    `clockwise` : boolean
        True for clockwise (outer rings), False for counter-clockwise
        (for inner rings)
    `theta` : number
        Angle spacing. If theta=1, angles between -180 to 180, are returned
        in 1 degree increments. The endpoint is excluded.

    Returns:
    -------
      list of coordinates for the circle/ellipse

    Notes:
    ------
     You can also use np.linspace if you want to specify point numbers.
     np.linspace(start, stop, num=50, endpoint=True, retstep=False)
     np.linspace(-180, 180, num=720, endpoint=True, retstep=False)
    """
    import numpy as np
    if clockwise:
        angles = np.deg2rad(np.arange(180.0, -180.0-theta, step=-theta))
    else:
        angles = np.deg2rad(np.arange(-180.0, 180.0+theta, step=theta))
    x_s = radius*np.cos(angles)            # X values
    y_s = radius*np.sin(angles) * scale    # Y values
    pnts = np.c_[x_s, y_s]
    pnts = pnts + [xc, yc]
    return pnts

Then feed the points into

array = arcpy.Array([arcpy.Point(*coords) for coords in pnts])
rec = arcpy.Polygon(array)  # or Polyline

... sort of retired...