Select to view content in your preferred language

How to write geometries that are perfect circles?

5985
8
Jump to solution
04-29-2014 04:42 AM
NickJacob
Deactivated User
Hello!

Is anyone out there familiar with writing geometries that are perfect circles (..err should I say arcs?).  In one of my scripts I deconstruct, then reconstruct polygon features point by point.  It appears that some of my features are perfectly round and only contain two points.  So far, I've experimented quite a bit in Arc's Python Window and I've read ESRI's online help here:

http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//002z0000001v000000

...but still stuck.  Is there a trick to writing perfectly round polygon features that I'm missing?  If anyone out there has any advice it'd be greatly appreciated.

Please note that I'm restricted to ArcGIS for Desktop 10.0 and Python 2.6.  Thanks!

- Nick
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
ChrisSnyder
Honored Contributor
Are you interested in a "true curve" circle or a "densified" circle? The former will have two verticies (the start/end nodes) and a mathematical equation that describes the line that connects the nodes. The densified circle will have a whole bunch of verticies that in sum approximate a circle.

Here's some code that might help....
pntGeom = arcpy.PointGeometry(arcpy.Point(2000, 2000)) #substitute your centroid x/y coordinates circleGeom = pntGeom.buffer(100) #substitute the distance from your circles verticies to the centroid arcpy.CopyFeatures_management(circleGeom, r"C:\temp\test.gdb\test) # copying to a GDB will preserve the "true curve" geometry arcpy.CopyFeatures_management(circleGeom, r"C:\temp\test.shp) # copying to a .shp will force densification

View solution in original post

0 Kudos
8 Replies
JoshuaChisholm
Frequent Contributor
Hello Nick,

Would it be possible in your workflow to create a point file and then use the buffer tool?

Edit: Never mind, that is still not a perfect circle.

Edit 2: I'm not sure if it is actually possible to create a perfect circle in a Shapefile. I think feature classes in geodatabases will accept perfect circles.
0 Kudos
NickJacob
Deactivated User
Thanks for responding Josh!

I'm more interested in how to write a circular geometry from scratch using only two point points.  I guess it doesn't necessarily need to be a perfect circle.
0 Kudos
ChrisSnyder
Honored Contributor
pntGeom = arcpy.PointGeometry(arcpy.Point(2000, 2500))
circleGeom = pntGeom.buffer(100)
0 Kudos
ChrisSnyder
Honored Contributor
Are you interested in a "true curve" circle or a "densified" circle? The former will have two verticies (the start/end nodes) and a mathematical equation that describes the line that connects the nodes. The densified circle will have a whole bunch of verticies that in sum approximate a circle.

Here's some code that might help....
pntGeom = arcpy.PointGeometry(arcpy.Point(2000, 2000)) #substitute your centroid x/y coordinates circleGeom = pntGeom.buffer(100) #substitute the distance from your circles verticies to the centroid arcpy.CopyFeatures_management(circleGeom, r"C:\temp\test.gdb\test) # copying to a GDB will preserve the "true curve" geometry arcpy.CopyFeatures_management(circleGeom, r"C:\temp\test.shp) # copying to a .shp will force densification
0 Kudos
NickJacob
Deactivated User
Thank you Chris!!

I would have never thought of that, but your code makes perfect sense.  Let me ask you this - is it possible to read that kind of information from a 'true curve' circle using a search cursor?  I've experimented in the Python Window a little bit but wasn't able to find a object with that .buffer attribute.

Thanks again for your help!
- Nick
0 Kudos
RichardFairhurst
MVP Alum
Unless something has changed in the latest versions of ArcMap, Python geometries cannot access true curve information and destroy it, since you can only access the vertices of the geometry and it assumes straight lines exist between them.  .Net applications can access true curves information through the geometry interfaces it provides.
0 Kudos
MattEiben
Deactivated User
Another somewhat brute force method I found here http://gis.stackexchange.com/questions/5574/how-to-create-a-circle-in-arcpy uses a little trigonometry to make your circle.  It's not technically a true circle though, it's actually 100 lines.

import math, arcpy

def circle_poly(x,y,r): 
    for i in range(100):
        ang = float(i)/100 * math.pi * 2
        yield (x + r * math.cos(ang), y + r * math.sin(ang) )

pointArray = arcpy.Array()
for (x,y) in circle_poly(-121.4543,43.972,100):
    pointArray.add(arcpy.Point(x,y))

circlePolygon = arcpy.Polygon(pointArray, arcpy.SpatialReference(4326))

outFC = arcpy.CreateFeatureclass_management("in_memory","circle","POLYGON")
arcpy.DefineProjection_management(outFC, arcpy.SpatialReference(4326))
cursor = arcpy.da.InsertCursor(outFC, ["SHAPE@"])
cursor.insertRow([circlePolygon])

del cursor
del circlePolygon
del pointArray


Chris's solution is definitely the way to go, but I found this method interesting anyways.
0 Kudos
ChrisSnyder
Honored Contributor
is it possible to read that kind of information from a 'true curve' circle using a search cursor


As far as I know, you cannot access the "equation" for true curves via Python.

Interestingly enough, I noted that (assuming you are using the code from my example above):

>>> circleGeom.getPart(0) #will yield
<Array [<Point (2000.0, 2100.0, #, #)>, <Point (2000.0, 2100.0, #, #)>]>

But...

>>> circleGeom.JSON #(or .WKT) will yield all the densified verticies...
u'{"rings":[[[2000,2100],[2003.1099862269837,2099.9516282291988],[2006.216963743148,2099.8065597133595],[2009.3179267484072,2099.564934796902],[2012.4098752613259,2099.2269872363277],[2015.4898180214084,2098.7930439740758],[2018.5547753829494,2098.2635248222264],[2021.6017821976484,2097.6389420563605],[2024.6278906832001,2096.9198999199666],[2027.6301732750831,2096.1070940398727],[2030.6057254587888,2095.201310753273].....


A somewhat related topic: http://forums.arcgis.com/threads/49557-True-Curves-True-Evil
0 Kudos