I want to delete all points inside a polygon layer:
import arcpy
import time
arcpy.env.workspace = r"E:\DensityMaps\DensityMapsTest1.gdb"
arcpy.env.overwriteOutput = True
start_time = time.time()
arcpy.Erase_analysis("Test_Points_Project", "Europe_coastline_NoLakesRivers", "PointsPolyErase1")
print "Erase ended "+("--- %s seconds ---" % (time.time() - start_time))
This lasts 36,9 seconds
Then I read this post saying that the process can be dramatically optimized using in_memory. I give it a try:
import arcpy
import time
arcpy.env.overwriteOutput = True
start_time = time.time()
#Copy points to in_memory
inFeature = r"E:\DensityMaps\DensityMapsTest1.gdb\Test_Points_Project"
memoryFeature = "in_memory\PointsMemory"
arcpy.CopyFeatures_management(inFeature, memoryFeature)
#Erase points that are inside polygons
arcpy.Erase_analysis(memoryFeature, r"E:\DensityMaps\DensityMapsTest1.gdb\Europe_coastline_NoLakesRivers", "PointsMemory")
#Copy points back to directory
arcpy.CopyFeatures_management("PointsMemory", r"E:\DensityMaps\DensityMapsTest1.gdb\PointsPolyErase")
print "Erase ended "+("--- %s seconds ---" % (time.time() - start_time))
This lasts 38.4 seconds, 1,5 seconds slower than the previous script. I am obviously doing something wrong. Very wrong.
It's very important to make the process faster because the original point file contains 22 millions points (1,5 GB). If I don't manage to do it fast the operation can last about 24 hours.
Here are the files if you want to test