0

I'm working with NLCD raster data to make a canopy layer across the US. I have a loop set up to where I will clip a section of my massive woodland layer to one degree blocks.

Sometimes only parts of an area are getting clipped, leaving giant gaps in the data.

I patched this together by hand in an earlier stage but turns out my dissolve tool doesn't want to work at such a large scale so I'm cutting my stuff up again to run through a Dissolve loop.

I would loathe making an even smaller grid set, but that's on my table to try. But I just can't figure out why Clip isn't working properly.

import arcpy, os, sys, shutil, time
import arcpy.cartography as CA

arcpy.env.overwriteOutput = 1
start = time.time()

#********DATA AND PATHS********
curr_dir = os.getcwd()
print(curr_dir)


#INPUT Directories
input = os.path.join(curr_dir, 'Input.gdb')
woodland_data = os.path.join(input, 'dissolve_me')#These are the projected input
grids = os.path.join(curr_dir, 'Grids.gdb')#These are the exploded grid files

#PROCESSING Directories
scratch = os.path.join(curr_dir, 'scratch.gdb')#clipped woodland features here
scratch_fc = os.path.join(scratch, 'clipped_')#clipped fc name

#OUTPUT Directories
woodland = os.path.join(curr_dir, 'Final.gdb')#Smoothed output goes here
dissolve_fc = os.path.join(woodland, 'dissolved_')#smoothed fc name
fail_gdb = os.path.join(curr_dir, 'Failed.gdb')#Tile to re-run gets dumped in here
failed_tiles = os.path.join(fail_gdb, 'failed_')

arcpy.env.workspace = (grids)
fcs = arcpy.ListFeatureClasses()


def clip_polygon():

    for tile in fcs:
        print(tile)

        try:
            arcpy.Clip_analysis(woodland_data, tile, (scratch_fc + tile), "")
            print(tile + ' Woodland clipped')
        except:
           # arcpy.FeatureClassToFeatureClass_conversion(tile, failed_tiles, (tile + 'failed'))
           # arcpy.CopyFeatures_management(tile, failed_tiles)
            print(tile + ' FAILED')
        else:
            print('moving on to next tile.....')
            continue


if __name__ == '__main__':

   clip_polygon()

end = time.time()
print(end - start)

1 Answers1

0

What size are the tiles you're trying to clip to? Does this error or just not function? (I've had issues with memory errors specifically with dissolving large data and feature classes) Look at this post https://gis.stackexchange.com/questions/239390/dissolve-multiple-shapefiles-so-that-touching-polygons-become-one-gdal-ogr
I would try the option 5 using Eliminate tool. You may need to iterate over a few times to reduce the number of polygons. I would try geopandas - WAY better than ESRI in my opinion! Look at the solution on this post. Dissolve Overlapping Polygons (with GDAL/OGR) while keeping non-connected results distinct