Scenario: You need to automate the operation, crop the grid's range to a vector, and then crop the vector grid. Using the arcpy implementation, the code is as follows:
Import arcpy arcpy.env.workspace = ' F:/dl_data/mass_buildings/test/sat ' rasters = arcpy. Listrasters ("*", "tiff") Output_workspace = "f:/dl_data/mass_buildings/test/map_corr/ras/" for ras in rasters:img = a rcpy. Raster (RAS) ext = img.extent Array = arcpy. Array () Array.add (ext.upperleft) array.add (ext.upperright) array.add (ext.lowerright) Array.add (ext.lower left) polygon = arcpy. Polygon (array) fname = str (img) fname = Fname.split ('. ') [0] clip_in_name = ' tmp/' +fname+ ' _clip_in.shp ' clip_out_name = ' tmp/' +fname+ ' _clip_out.shp ' label_out_name ' tmp/' +fname[:8]+ ' _r ' xy_tolerance = 0 arcpy. Copyfeatures_management (Polygon, clip_in_name) arcpy. Clip_analysis ("F:\DL_DATA\mass_buildings\massachusetts-buildings_corrected.shp", Clip_in_name, Clip_out_name, Xy_ Tolerance) Arcpy.env.extent = ext arcpy. Polygontoraster_conversion (clip_out_name, ' AA ', Label_out_name, "Cell_center", "NONE", 1) arcpy. Rastertootherformat_conversion (Label_out_name, Output_workspace, ' TIFF ') print fname+ ' Done '