Saturday 31 October 2015

geometry - Faster equivalent of arcpy distanceTo method


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.



Avenue:


theView = av.GetActiveDoc
Catchments=theView.GetActiveThemes.Get(0)

aTab=Catchments.getFtab
shpFld=aTab.findField("Shape")
feat=aTab.ReturnValue(shpFld,0)
outLine=feat.AsPolyLine
pC=feat.ReturnCenter

aTime0=date.now
for each i in (0..10000)
d=outLine.Distance(pC)
end

msgbox.info ((Date.Now-aTime0).AsSeconds.asstring,"")

enter image description here



Python:


import arcpy, time
infc=r'C:\Temp\theme1.shp'
with arcpy.da.SearchCursor(infc,("FID","Shape@")) as cursor:
for i,feat in cursor:
break

outline=feat.boundary()
pC=feat.centroid

start = time.time()
for i in range(10000):
d=outline.distanceTo(pC)

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





No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...