Unfortunately arcpy distanceTo method is painfully slow. When speed is crucial, I am still using Avenue to work around it, but it is getting harder to transfer ArcView 3 to newer computers.

As requested by @PolyGeo code snippets tested on polygon made of 3250 vertices.



theView = av.GetActiveDoc

for each i in (0..10000)
msgbox.info ((Date.Now-aTime0).AsSeconds.asstring,"")

enter image description here



import arcpy, time
with arcpy.da.SearchCursor(infc,("FID","Shape@")) as cursor:
    for i,feat in cursor:

start = time.time()
for i in range(10000):

end = time.time()
arcpy.AddMessage(end - start)
  • Executing: Script3 centres Start Time: Fri Jul 28 19:32:08 2017
  • Running script Script3...
  • 83.7339999675751
  • Completed script Script3...


Note that last 5 lines are doing exactly the same thing, calculatiog distance from polygon centroid to it's boundary. As one can see arcpy function is far behind out of date Avenue.

So, does anybody aware of python module that works significantly faster, please

  • 3
    @FelixIP, I feel your pain. The arcpy.Geometry objects are very expensive to create and operate. I'd go for the Near GP tool for calculating the matrix of plain distances between two feature classes (which you can pre-create if needed using other GP tools). Or do you need to operate on each vertex of the polygon as if it is an individual geometry object? The thing is that running GP tools will be faster in general than using arcpy.Geometry objects. Jul 28, 2017 at 7:53
  • @AlexTereshenkov it is about this nice idea blog.mapbox.com/… that I implemented in both languages, but slow handling of geometries in arcpy makes ArcGIS version almost useless. I am not sure that using tools can help in this case
    – FelixIP
    Jul 28, 2017 at 8:08
  • 3
    @FelixIP, I see. I'd still recommend prototyping getting the centroids of your features (through a GP tool) into an in_memory feature class and then run the Near GP tool. I promise it will be much faster than arcpy.Geometry, but I am not sure whether it will beat Avenue ;) Jul 28, 2017 at 8:24
  • 1
    Alex's suggestion is what I would try first. If you need much more speed I'd suggest using PostGIS for these sorts of distance queries.
    – Alexander
    Jul 28, 2017 at 9:22
  • @Alex Tereshenko I did a quick test: replaced distance calculation inside loop by spatial join (closest) between list of point geometries to outline, output to in memory feature class. It took 7 seconnds to complete. Massive acceleration. If you post your suggestion as an answer, I'll gladly accept it
    – FelixIP
    Jul 30, 2017 at 9:59


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.