How to use an iterator to set the 'Template Extent' for the CREATE FISHNET tool?

275
1
11-15-2012 02:29 AM
MarkZweifler
New Contributor II
I have a base "fishnet" polygon grid. I attempted to create a model that iterates over each cell in that base fishnet grid and subdivide that cell with the Create Fishnet tool into a new feature class.

I expected that I simply would need to set the output from my iterate feature iterator  as the 'Template Extent' parameter for the Create Fishnet tool. However, while I can see the name of this iterator output model variable in the drop-down list for the 'Template Extent' parameter;  the name does not have the blue Model Variable icon. And more importantly, the template extent does not update at each model iteration. 
Is there a way that I can make my model recognize aan iteration output as a template extent?  ( see screenshot below)

[ATTACH=CONFIG]19323[/ATTACH]
0 Kudos
1 Reply
JamesCrandall
MVP Frequent Contributor
I have a base "fishnet" polygon grid. I attempted to create a model that iterates over each cell in that base fishnet grid and subdivide that cell with the Create Fishnet tool into a new feature class.

I expected that I simply would need to set the output from my iterate feature iterator  as the 'Template Extent' parameter for the Create Fishnet tool. However, while I can see the name of this iterator output model variable in the drop-down list for the 'Template Extent' parameter;  the name does not have the blue Model Variable icon. And more importantly, the template extent does not update at each model iteration. 
Is there a way that I can make my model recognize aan iteration output as a template extent?  ( see screenshot below)

[ATTACH=CONFIG]19323[/ATTACH]


Mark,

I know you are looking for a model solution here, but can you implement this with just straight-up Python code?  I had a need for doing this same thing and came up with the code below (it is pulled from a larger script/process, but I peiced it together as best I could and it does work on a 9x9 grid example). 

You will need to alter the inputLocation and inputFC variables, add the cellHeight and Width you want the output grids to be and it should just work.

also: this is for ArcGIS 9.3.1, but again it should just work in newer versions.



import arcgisscripting
gp = arcgisscripting.create(9.3)

#you will need to modify these two parameters for your situation.  This is an ex of a pgdb FeatureClass
inputLocation = "\\\\C:\Scratch.mdb"
inputFC = inputLocation + "\\exGRID"

# Open a search cursor on a feature class 
rows = gp.searchcursor(inputFC)
row = rows.Next()
i = 1
while row:
   
   gp.AddMessage("Attempting to process polgyon " + str(i))
  
  #Get the shape field
   shape = row.shape
      
  #Get the extent object
   extent = shape.extent

   outputName = "Fishnet_" + str(i)
   outFC = inputLocation + "\\" + outputName
  
  #Get the origin (lowerLeft) and y-axis (upperLeft) properties of the polygon
   ll = extent.lowerleft
   ul = extent.upperleft
   ur = extent.upperright
   
   originXY = str(ll.x) + " " + str(ll.y)
   yaxisXY = str(ul.x) + " " + str(ul.y)
   
   opp_corner = str(ur.x) + " " + str(ur.y)

   
   gp.AddMessage("LowerLeft (x,y): %f, %f" % (ll.x, ll.y))
   gp.AddMessage("UpperLeft (x,y): %f, %f" % (ul.x, ul.y))
   
   gp.AddMessage("XMin: %f" % (extent.xmin))
   gp.AddMessage("YMin: %f" % (extent.ymin))
   gp.AddMessage("XMax: %f" % (extent.xmax))
   gp.AddMessage("YMax: %f" % (extent.ymax))
   
   
   #keep the cell width/height set to zero as it will use the opp_corner to figure it out
   cellWidth = 0
   cellHeight = 0
   
   #plug in the #rows/#cols you want the output grids to contain 
   nrows = 10
   ncols = 10
   
   gp.CreateFishnet_management(outFC, originXY, yaxisXY, cellWidth, cellHeight, nrows, ncols, opp_corner)
   
   gp.AddMessage("Created " + outputName)
   
   i = i + 1
   row = rows.Next()
0 Kudos