Skip navigation
All People > Dan_Patterson > Py... blog > 2017 > February

Circling the point

Posted by Dan_Patterson Champion Feb 21, 2017

Again, points and directions have arisen.  This time, this post ... ,there was a need to place points within a polygon for geocoding based on compass directions.  The simplest solution turns out to be to create a centroid, then generate points about it at some distance and angle.


So the solution can be approached using search cursors, but as usual, I like numpy since you can vectorize most operations.  The code below, reads in the centroid points of an input polygon theme (r"...\fishnet_label.shp") which in this case was the centroids of a fishnet since they are easy to create.  From there, the steps are simple:


  • convert the input point file to an array (FeatureClassToNumPyArray
  • collect the point coordinates that fall on a circle at a distance and angle from the centroid (_circle def)
  • stack the points and convert back to a point file (Numpyarraytofeatureclass)


Of course, you can put in the angles in the table, provide, sub-identifiers and even the compass representation in text form.  The points can also be created with random angles and distances with little code modification.  A couple of examples are below, followed by the code.  See Darren's example in the link for a cursor approach.


points around circle .... points around circle 2


And the code

: if north angle is needed, you can use this to convert
:    ang = np.mod((450.0 - ang), 360.)

import numpy as np
import arcpy

def _circle(radius=10, theta=22.5, xc=0.0, yc=0.0):
    """Produce points around a circle.
    :  radius - distance from centre
    :  theta - either a single value to form angles about a circle or
    :        - a list or tuple of the desired angles

    if isinstance(theta, (list, tuple)):
        angles = np.deg2rad(np.array(theta))
        angles = np.deg2rad(np.arange(180.0, -180.0-theta, step=-theta))
    x_s = radius*np.cos(angles) + xc    # X values
    y_s = radius*np.sin(angles) + yc    # Y values
    pnts = np.c_[x_s, y_s]
    return pnts

# --------------------------------------------------------------------
if __name__ == '__main__':
    """produce some points around a centroid at angles and distances"""

    inFC = r"C:\Data\points\fishnet_label.shp"
    outFC = r"C:\Data\points\pnts2.shp"
    radius = 2
    theta = 22.5  # or a list like... theta = [0, 90, 180, 270]
    a = arcpy.da.FeatureClassToNumPyArray(inFC, ["SHAPE@X", "SHAPE@Y"])
    b = [_circle(radius, theta, a['SHAPE@X'][i], a['SHAPE@Y'][i])
         for i in range(len(a))]
    c = np.vstack(b)
    c.dtype = a.dtype
    arcpy.da.NumPyArrayToFeatureClass(c, outFC, c.dtype.names)


See other posts about circles and related things.

circles sectors rings buffers and the n-gons

New ... Now that python 3.x is 8 years old, it became obvious that Continuum would update their package distribution

I have just started playing with doing non Arc*ish stuff for now since only the 3.4 distribution is officially supported in ArcGIS PRO.  I was pleasantly surprised to see one of my old-time favourite IDEs back ... Pythonwin ... by Mark Hammond.


Mix a little Spyder, 'win and Jupyter across multiple screens working on separate things and they all behaved nice.

I will post more as I find it... but for now, here are they are... (pycharm and others will join the play group when I have time).


anaconda for python 3.6


And a closer look at Spyder

Check it out and compare anaconda package documentation



Yes... version 2.0.0 is now here.  check ... for more information 

It is part of the new distribution and enables you to work with the 'classic' style (sic status quo) or the new style.