#import arcpy and arcgisscripting
import arcgisscripting
gp = arcgisscripting.create(9.3)
gp.overwriteOutput = 1
import arcpy
# Set the current workspace
gp.env.workspace = r"X:\mohammadi\finalmunichGIS\clip0ffishnet9000\clip"
# Get and print a list of GRIDs from the workspace
rasters = 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_corner
outPath = 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
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"
# only import arcpy - don't use arcgisscripting/gp at 10.x
import arcpy
from arcpy import env
arcpy.env.overwriteOutput = True ## 1
env.workspace = r"X:\mohammadi\finalmunichGIS\munich.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\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)
# only import arcpy - don't use arcgisscripting/gp at 10.x
import arcpy
from arcpy import env
arcpy.env.overwriteOutput = True ## 1
env.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)
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)