Friday 25 December 2015

Testing point in polygon overlay performance of Intersect, Spatial Join and Near in ArcGIS for Desktop?


In answers and comments to Select points within a polygon and update attributes I think it is being suggested that Spatial Join (Analysis) and/or Near (Analysis) may be faster than Intersect (Analysis) for performing a point in polygon overlay to transfer polygon attributes onto the points that intersect them.


This surprised me because I have always expected that Intersect might be a bit quicker than Spatial Join, and I think it would be quite a lot quicker than Near. Unfortunately, I do not have an Advanced level license of ArcGIS for Desktop so I cannot performance test Near.


Does anyone have a reproducible test that indicates Near and/or Spatial Join being faster than Intersect?



I am going to provide as an answer my test on Intersect vs Spatial Join where I create a 10x10 fishnet of polygons and a 100x100 fishnet of points covering the same extent (0,0,10,10) and then perform a vanilla Intersect and a vanilla Spatial Join (INTERSECT) of the two.



Answer



My quick testing, using ArcGIS 10.2.2 for Desktop on Windows 7 SP1, indicates that Intersect is faster than Spatial Join.


This test, run from IDLE:


import arcpy,time

if not arcpy.Exists(r"C:\temp\test.gdb"):
arcpy.CreateFileGDB_management(r"C:\temp","test.gdb")
if arcpy.Exists(r"C:\temp\test.gdb\fnPoly100"):
arcpy.Delete_management(r"C:\temp\test.gdb\fnPoly100")

if arcpy.Exists(r"C:\temp\test.gdb\fnPoly10000"):
arcpy.Delete_management(r"C:\temp\test.gdb\fnPoly10000")
if arcpy.Exists(r"C:\temp\test.gdb\fnPoint10000"):
arcpy.Delete_management(r"C:\temp\test.gdb\fnPoint10000")
arcpy.CreateFishnet_management("C:/temp/test.gdb/fnPoly100","0 0","0 1","1","1","10","10","#","NO_LABELS","#","POLYGON")
arcpy.CreateFishnet_management("C:/temp/test.gdb/fnPoly10000","0 0","0 1","0.1","0.1","100","100","#","LABELS","#","POLYGON")
arcpy.Delete_management(r"C:\temp\test.gdb\fnPoly10000")
arcpy.Rename_management("C:/temp/test.gdb/fnPoly10000_label","C:/temp/test.gdb/fnPoint10000","FeatureClass")



if arcpy.Exists(r"C:\temp\test.gdb\SpatialJoinResult"):
arcpy.Delete_management(r"C:\temp\test.gdb\SpatialJoinResult")
start = time.clock()
arcpy.SpatialJoin_analysis("C:/temp/test.gdb/fnPoint10000","C:/temp/test.gdb/fnPoly100",
"C:/temp/test.gdb/SpatialJoinResult",
"JOIN_ONE_TO_ONE","KEEP_ALL",
"""Shape_Length "Shape_Length" false true true 8 Double 0 0 ,First,#,C:/temp/test.gdb/fnPoly100,Shape_Length,-1,-1;Shape_Area "Shape_Area" false true true 8 Double 0 0 ,First,#,C:/temp/test.gdb/fnPoly100,Shape_Area,-1,-1""",
"INTERSECT","#","#")
elapsed = (time.clock() - start)
print("Spatial Join took " + str(elapsed) + " seconds")


if arcpy.Exists(r"C:\temp\test.gdb\IntersectResult"):
arcpy.Delete_management(r"C:\temp\test.gdb\IntersectResult")
start = time.clock()
arcpy.Intersect_analysis("C:/temp/test.gdb/fnPoint10000 #;C:/temp/test.gdb/fnPoly100 #",
"C:/temp/test.gdb/IntersectResult","ALL","#","INPUT")
elapsed = (time.clock() - start)
print("Intersect took " + str(elapsed) + " seconds")

yielded these results:




Spatial Join took 3.13998451416 seconds


Intersect took 2.3185308145 seconds



I ran my test with the Intersect first a few times, and then the Spatial Join first a few times, and Intersect was always the winner on this data.


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...