import arcpy from arcpy import env env.workspace = r"C:\TIFFs" env.overwriteOutput = 1 list = [] #append each raster to a list lstFCs = arcpy.ListFeatureClasses("*") for fc in lstFCs: list.append(fc) #iterate through each raster lstRasters = arcpy.ListRasters("*") for raster in lstRasters: for n in list: #find the fishnet shapefile by checking if the raster name is in the shapefile name if raster.split(".")[0] in n: rows = arcpy.SearchCursor(n) for row in rows: FID = row.FID #create a feature layer for each polygon in the fishnet shapefile arcpy.MakeFeatureLayer_management(n, "FC_lyr", "FID = " + str(FID)) #clip the raster by each polygon, and output a new TIFF to another directory arcpy.Clip_management(raster, "#", r"C:\TIFFs\Clip" + "\\" + raster + "_clip_" + str(FID) + ".tif", "FC_lyr", "256", "ClippingGeometry") print "Finished"
# only import arcpy - don't use arcgisscripting/gp at 10.ximport arcpyfrom arcpy import envarcpy.env.overwriteOutput = True ## 1env.workspace = r"X:\mohammadi\finalmunichGIS\fishnet4500\fishnet4500plus.gdb"def sendmsg (msg): print msg arcpy.AddMessage(msg)fcList = arcpy.ListFeatureClasses("","Polygon","")for fc in fcList: env.workspace = r"X:\mohammadi\finalmunichGIS\fishnet4500\fishnet4500plus.gdb" lyrFC = "lyrFC" sendmsg (fc) # in_fc is your polygon feature class in_fc = fc arcpy.MakeFeatureLayer_management(in_fc,lyrFC) # in_tif is your input in_raster = r"X:\mohammadi\finalmunichGIS\Testdatenoriginaldata\munich_subset.tif" # output location outPath = r"X:\mohammadi\finalmunichGIS\clip0ffishnet9000\lastclip" # get list of object ids objIDs = [] objIDField = arcpy.Describe(lyrFC).OIDFieldName rows = arcpy.SearchCursor(lyrFC) row = rows.next() while row: objIDs.append(row.getValue(objIDField)) row = rows.next() del row, rows # temp polygons copyFC = r"X:\mohammadi\finalmunichGIS\test.gdb\fc_parent1_1c" # one by one clip raster to polygons arcpy.env.workspace = outPath for objID in objIDs: where = "{0} = {1}".format(objIDField,objID) arcpy.SelectLayerByAttribute_management(lyrFC,"NEW_SELECTION",where) arcpy.CopyFeatures_management(lyrFC,copyFC) ext = arcpy.Describe(copyFC).Extent extString = "{0} {1} {2} {3}".format(ext.xmin, ext.ymin, ext.xmax, ext.ymax) out_raster = "{0}_clip{1}.tif".format(in_fc, objID) arcpy.Clip_management(in_raster, extString, out_raster, copyFC) print arcpy.GetMessages(0) arcpy.Delete_management(copyFC) arcpy.Delete_management(lyrFC)
for objID in objIDs: where = "{1} = {0}".format(objIDField,objID) arcpy.SelectLayerByAttribute_management(lyrFC,"NEW_SELECTION",where) arcpy.CopyFeatures_management(lyrFC,copyFC) ext = arcpy.Describe(copyFC).Extent extString = "{0} {1} {2} {3}".format(ext.xmin, ext.ymin, ext.xmax, ext.ymax) out_raster = "{0}_clip{1}.tif".format(in_fc, objID) arcpy.Clip_management(in_raster, extString, out_raster, copyFC) print arcpy.GetMessages(0)
# only import arcpy - don't use arcgisscripting/gp at 10.ximport arcpyfrom arcpy import envarcpy.env.overwriteOutput = True ## 1env.workspace = r"X:\mohammadi\finalmunichGIS\fishnet4500\fishnet4500.gdb"# in_fc is your polygon feature class#in_fc = r"X:\mohammadi\finalmunichGIS\fishnet4500" fcList = arcpy.ListFeatureClasses("","Polygon","")for fc in fcList: lyrFC = "lyrFC" # in_fc is your polygon feature class in_fc = fc # in_tif is your input in_raster = r"X:\mohammadi\finalmunichGIS\Testdatenoriginaldata\munich_subset.tif" # output location outPath = r"X:\mohammadi\finalmunichGIS\lastclip" arcpy.MakeFeatureLayer_management(in_fc,lyrFC) # get list of object ids objIDs = [] objIDField = arcpy.Describe(lyrFC).OIDFieldName rows = arcpy.SearchCursor(lyrFC) row = rows.next() while row: objIDs.append(row.getValue(objIDField)) row = rows.next() del row, rows # temp polygons copyFC = r"X:\mohammadi\finalmunichGIS\test.gdb\test" # one by one clip raster to polygons arcpy.env.workspace= outPath for objID in objIDs: where = "{1} = {0}".format(objIDField,objID) arcpy.SelectLayerByAttribute_management(lyrFC,"NEW_SELECTION",where) arcpy.CopyFeatures_management(lyrFC,copyFC) ext = arcpy.Describe(copyFC).Extent extString = "{0} {1} {2} {3}".format(ext.xmin, ext.ymin, ext.xmax, ext.ymax) out_raster = "{0}_clip{1}.tif".format(in_fc, objID) arcpy.Clip_management(in_raster, extString, out_raster, copyFC) print arcpy.GetMessages(0) arcpy.Delete_management(copyFC)
# only import arcpy - don't use arcgisscripting/gp at 10.ximport arcpyfrom arcpy import envarcpy.env.overwriteOutput = True ## 1env.workspace = r"X:\mohammadi\finalmunichGIS\munich.gdb"# in_fc is your polygon feature classin_fc = r"X:\mohammadi\finalmunichGIS\fishnet4500" fcList = arcpy.ListFeatureClasses("","Polygon","")for fc in fcList: lyrFC = "lyrFC" # in_fc is your polygon feature class in_fc = fc # in_tif is your input in_raster = r"X:\mohammadi\finalmunichGIS\Testdatenoriginaldata\munich_subset.tif" # output location outPath = r"X:\mohammadi\finalmunichGIS\lastclip" arcpy.MakeFeatureLayer_management(in_fc,lyrFC) # get list of object ids objIDs = [] objIDField = arcpy.Describe(lyrFC).OIDFieldName rows = arcpy.SearchCursor(lyrFC) row = rows.next() while row: objIDs.append(row.getValue(objIDField)) row = rows.next() del row, rows # temp polygons copyFC = r"X:\mohammadi\finalmunichGIS\test.gdb\fc_parent1_1c" # one by one clip raster to polygons arcpy.env.workspace= outPath for objID in objIDs: where = "{0} = {1}".format(objIDField,objID) arcpy.SelectLayerByAttribute_management(lyrFC,"NEW_SELECTION",where) arcpy.CopyFeatures_management(lyrFC,copyFC) ext = arcpy.Describe(copyFC).Extent extString = "{0} {1} {2} {3}".format(ext.xmin, ext.ymin, ext.xmax, ext.ymax) out_raster = "{0}_clip{1}.tif".format(in_fc, objID) arcpy.Clip_management(in_raster, extString, out_raster, copyFC) print arcpy.GetMessages(0) arcpy.Delete_management(copyFC)
import arcpy from arcpy import env env.workspace = r"X:\mohammadi\finalmunichGIS\clip0ffishnet9000\clip" lstRasters = arcpy.ListRasters("*", "TIF") for raster in lstRasters: xmin = arcpy.Describe(raster).extent.XMin ymin = arcpy.Describe(raster).extent.YMin xmax = arcpy.Describe(raster).extent.XMax ymax = arcpy.Describe(raster).extent.YMax ymin2 = arcpy.Describe(raster).extent.YMin + 10 arcpy.CreateFishnet_management("fishnet_" + raster[:-4] + ".shp", str(xmin) + " " + str(ymin), str(xmin) + " " + str(ymin2), "0","0","2","2", str(xmax) + " " + str(ymax), "NO_LABELS", "#","POLYGON") print "Finished"
#import arcpy and arcgisscriptingimport arcgisscriptinggp = arcgisscripting.create(9.3)gp.overwriteOutput = 1import arcpy# Set the current workspacegp.env.workspace = r"X:\mohammadi\finalmunichGIS\clip0ffishnet9000\clip"# Get and print a list of GRIDs from the workspacerasters = arcpy.ListRasters("*", "TIF")for raster in rasters: print(raster)# input hard-coded but you can make it a script tool parameter to make it an interactive input.#in_fc = r"X:\mohammadi\finalmunichGIS\clip0ffishnet9000\clip" # this polygon feature class has several polygons.rows = gp.SearchCursor(rasters)row = rows.Next()while row: feat = row.raster ext = feat.extent orig = str(ext.xmin) + " " + str(ext.ymin) yaxis = str(ext.xmin) + " " + str(ext.ymin + 100.00) opp_corner = str(ext.xmax) + " " + str(ext.ymax) print orig, yaxis, opp_corneroutPath = r"X:\mohammadi\finalmunichGIS\fishnet4500\4500.shp"+ str(row.OBJECTID)result = gp.CreateFishnet_management(outPath, orig, yaxis, "0", "0", "2", "2", opp_corner,"NO_LABELS","#","POLYGON") print(gp.GetMessages()) row = rows.Next()del row, rows
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.