Possible solution using rasters:
- Split total extent using fishnet
- Set environment cell size
- a) start with first tile, i.e. n = 1
- b) Convert polygons and points to raster
- Calculate zonal statistics (points grid = zones, polygons grid =
- Count number of records in statistics table. If less than count of
points, reduce cell size and go to b), otherwise transfer data from
statistics table to points table, proceed with next tile, i.e. n+=1
go to a)
I tested the script below using 2.4 million points and the same number of polygons. I used fishnet equal 5*5 tiles. It means that about 100 thousands points were processed at a time.
This is a snapshot of result window:
I tried spatial join on the same datasets and when it get to 5%, I cancelled it. By this time tool was running for 8 minutes.
This means that with truly massive datasets (few millions), raster approach could greatly reduce processing time.
Note that I used raster to create my points and polygons, i.e. tested polygons were the most basic squares. I expect the advantage of raster approach can be even greater with more complex shapes. I could of reduce processing time further, by using fishnet with less tiles, but didn't want to risk in_memory space corruption.
import arcpy, time, os
from arcpy import env
from arcpy.sa import ZonalStatisticsAsTable as ZS
for n,tile in enumerate(tiles):
arcpy.AddMessage("Processing tile no %i out of %i" %(n+1,len(tiles)))
env.cellSize = cSize
outZSaT = ZS(pointsGrid, "Value",polygonsGrid,stats,"DATA", "MINIMUM")
arcpy.AddMessage("Updating lookup ....")
arcpy.SetProgressor("step", "", 0, nPoints)
with arcpy.da.SearchCursor(stats,("Value","MIN")) as cursor:
for v,m in cursor:
arcpy.AddMessage("Processed %i points" %nTot)
arcpy.AddMessage("Transferring results ...")
arcpy.SetProgressor("step", "", 0, nTot)
with arcpy.da.UpdateCursor(points,("pointid","PGONID")) as cursor:
for row in cursor:
arcpy.AddMessage("Total time %i sec" %int(time.time()-t0))