I'm trying to implement a fairly straightforward multiprocessing script that takes every polygon in a shapefile, tessellates into a grid, takes the center points of each grid square, and then clips the points by the original feature (since the tessellation generates a minimum bounding rectangle). The tessellation feature class is never created so next step (FeatureToPoint) fails. I don't understand - can someone help?
Even if I comment out all the arcpy commands except GenerateTessellation, the output is never actually created.
import multiprocessing
import os
import time
import arcpy
startTime = time.time()
basedir = r"C:\Users\Jay\Documents\ArcGIS\Projects\DataPrep"
scratchGDB = 'C:\\Jay\\data\data.gdb'
output = os.path.join(basedir, "grids.gdb")
features = os.path.join(basedir,"features.shp")
def multifunction(ft):
import arcpy
name = ft[0]
extent = ft[1].extent
print('Working on {}'.format(name))
fl = arcpy.management.MakeFeatureLayer(features, "{}fl".format(name), where_clause=f"Name='{name}'")
gdb = os.path.join(basedir, "{}.gdb".format(name))
arcpy.management.CreateFileGDB(basedir, "{}.gdb".format(name))
output=os.path.join(gdb, "{}grid".format(name))
grid = arcpy.management.GenerateTessellation(output, Extent=extent, Shape_Type="SQUARE", Size="900 SquareMeters")
print('tellessation')
pointgrid = arcpy.management.FeatureToPoint(grid, os.path.join(scratchGDB, "{}pointgrid".format(apt)))
arcpy.analysis.Clip(pointgrid, fl, os.path.join(output, f"{apt}Points"))
arcpy.management.Delete(fl)
arcpy.management.Delete(grid)
arcpy.management.Delete(pointgrid)
def main():
processList = [feature for feature in arcpy.da.SearchCursor(features, ['Name', 'SHAPE@'])]
pool = multiprocessing.Pool(1)
pool.map(multifunction, processList[0:10])
pool.close()
pool.join()
if __name__ == "__main__":
print("Running")
main()
executionTime = (time.time() - startTime)
print('Execution time in seconds: ' + str(executionTime))