Create fishnet in iterative model

3715
15
07-19-2011 11:52 AM
deleted-user-qQeebl6UEQjh
New Contributor
I wonder if anyone has any ideas on the following.

I am using Create Fishnet in an iterative model. The goal being to flip through all features in a feature class and create a fishnet from the bounding coordinates of each individual feature. Fishnet is fed from a feature layer denoted with the %n% keyword but the extents data does not update. The result is the same grid being created over and over again. Is there any way to ensure that the extents are being updated?
Reply
0 Kudos
15 Replies
deleted-user-qQeebl6UEQjh
New Contributor
Well I gave up on out of the box and came up with the script below to create fishnets. I am hoping to keep this as an iterative model where this script is passed the current %n% value from the model. Can anyone suggest how/if it is possible to pass the %n% value into a script using sys.argv[]? Using 9.2. Thanks.

# Import system modules
import sys, string, os, arcgisscripting

# Create the geoprocessor object
gp = arcgisscripting.create()
gp.overwriteOutput = 1

# Set workspace
gp.Workspace = "C:/CollapseTestModel.gdb"
myNet = "C:/CollapseTestModel.gdb/Net03"
myTemplate = "C:/CollapseTestModel.gdb/SelectBody__0"

dsc=gp.describe(myTemplate)

extents = dsc.Extent
print extent

gp.CreateFishnet_management(myNet,extents[0:17] + " " + extents[18:34],extents[0:17] + " 53", 0.000045, 0.000045, 50, 50, "#", "NO_LABELS", myTemplate)

print gp.GetMessages()
Reply
0 Kudos
TrevorSelf
New Contributor II
I wonder if anyone has any ideas on the following.

I am using Create Fishnet in an iterative model. The goal being to flip through all features in a feature class and create a fishnet from the bounding coordinates of each individual feature. Fishnet is fed from a feature layer denoted with the %n% keyword but the extents data does not update. The result is the same grid being created over and over again. Is there any way to ensure that the extents are being updated?


I am having this same problem! It appears, by looking through the log, that the extent is set before the file that sets the extent is fed into the fishnet tool. I'm thinking about trying to get the corners of the extent with minimum bounding geometry and feature vertices to point tools, but it might add several steps to the model.
Reply
0 Kudos
DanLee
by Esri Regular Contributor
Esri Regular Contributor
Perhaps before Create Fishnet you can use Copy Features to copy a selected feature to a feature class or an in_memory feature class (if you don't need to save it); and then feed this feature class to the Template extent. I think this would make the extent update in each iteration.
Reply
0 Kudos
TrevorSelf
New Contributor II
Dan,
Thanks for replying so quickly. I have tried this suggestion exactly. I have a separate model to iterate through a feature class and copy out individual features into their own feature classes, but the create fishnet tool ends up just creating many fishnets on top of each other (one for each feature in the geodatabase). When checking through the log, as the feature classes iterate, they are input into each iteration in the create fishnet tool, but the extents never update to the extents of each feature class
Reply
0 Kudos
NobbirAhmed
Esri Regular Contributor
The whole thing can be done in Python. Here is a sample code (not tested on 9.2):

import arcgisscripting

gp = arcgisscripting.create()
gp.overwriteOutput = 1

# input hard-coded but you can make it a script tool parameter to make it an interactive input.
in_fc = r"C:\temp\f.gdb\curvepoly"  # this polygon feature class has several polygons.

rows = gp.SearchCursor(in_fc)
row = rows.Next()

while row:
    feat = row.shape
    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

    out_fc = r"C:\temp\f.gdb\fishnetall_" + str(row.OBJECTID)

    result = gp.CreateFishnet_management(out_fc, orig, yaxis, "0", "0", "5", "8", opp_corner)
    print(gp.GetMessages())

    row = rows.Next()

del row, rows

Reply
0 Kudos
DanLee
by Esri Regular Contributor
Esri Regular Contributor
Dan,
Thanks for replying so quickly. I have tried this suggestion exactly. I have a separate model to iterate through a feature class and copy out individual features into their own feature classes, but the create fishnet tool ends up just creating many fishnets on top of each other (one for each feature in the geodatabase). When checking through the log, as the feature classes iterate, they are input into each iteration in the create fishnet tool, but the extents never update to the extents of each feature class


Thank you for letting me know. We have investigated this issue; there is indeed a bug in the tool that affects the extent update in iteration. If you can, please submit a change/fix request to Esri Support; we might get to it a bit quicker.

There is no easy workaround. Hope you can use the script Nobbir provided to get through the process.  Sorry about the inconvenience.
Reply
0 Kudos
DanLee
by Esri Regular Contributor
Esri Regular Contributor
Hi Señor and Trevor,

It's been a while; we will be looking into enhancements for the Create Fishnet tool. Both of you needed fishnets for individual features; could you describe why you want a fishnet per feature? What is the application/story?  Your use cases would help us understand the requirements and provide the right solutions.

If you have any additional criteria about creating fishnet, please let me know. I appreciate your time and input.

Thanks a lot!
Reply
0 Kudos
ClemensHabsburg-Lothringen
New Contributor
Thank you for letting me know. We have investigated this issue; there is indeed a bug in the tool that affects the extent update in iteration. If you can, please submit a change/fix request to Esri Support; we might get to it a bit quicker.

There is no easy workaround. Hope you can use the script Nobbir provided to get through the process.  Sorry about the inconvenience.


Could you already solve this problem? Or is there another way to workaround?
Thanks
Reply
0 Kudos
NobbirAhmed
Esri Regular Contributor
We haven't made any changes to the tool. This tool won't work the way you want in ModelBuilder. There is a plan to create a new similar tool - but there is no tentative time-frame yet.

Have you tried my Python script? This may be the only workaround comes to my mind.
Reply
0 Kudos