2

So I have 490 point fc's in a single directory with uniform spatial features, field names/datatypes. I'm trying to figure out how to consecutively input the first seven fc's into the merge tool, create a new merged fc, and then iterate the model until 70 new merged fc's are created.

I know how to iterate single fc's as input into a tool, but not multiple features per x number of iterations.

I have some code below that uses list, an array, and a count system that does what i need for another GP operation. How can I translate this into modelbuilder's variables/methods? I am using modelbuilder because I was having trouble mapping fields for merge in python

try:
 # Create list of rasters
 rasters = arcpy.ListRasters("*", "tif")
 rastersCount = len(rasters)
 counter = 0
 weekNum = 1
 while counter < rastersCount:
 #collect 7 consecutive rasters
 weekRasters = []
 for i in range(counter,(counter+7)):
 weekRasters.append(rasters[i])
 # Execute CellStatistics (one can use list of rasters directly here)
 outCellStatistics = CellStatistics(weekRasters, "SUM", "NODATA")
 # Save the output
 outRasterName = "week_"+ str(weekNum)
 outCellStatistics.save("D:/dailyrainfall/nueces_dailyrainfall_rasterized/" + outRasterName )
 counter += 7
 weekNum += 1
except:
 # If an error occurred while running a tool, then print the messages.
 print arcpy.GetMessages()

Using ArcGIS 10 (ArcInfo) SP4 with all extensions

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Apr 22, 2012 at 7:37

2 Answers 2

2

I'm not sure you can transfer that type of logic to modelbuilder. But are you aware that you can wire up a script to a model builder tool? Why bother with any thing else as you have the framework of logic in your existing script (it just needs tweaking)? Once you add your script as a "tool script" it looks and behaves like any other geoprocessing tool.

answered Apr 22, 2012 at 8:32
2
  • the only reason i'm using modelbuilder is because I was having trouble mapping fields for merge in python Commented Apr 22, 2012 at 20:26
  • 2
    There's no mention of that issue in the original question. Would it be possible for you to re-phrase your question to more accurately describe what you are trying to do, please? For example, your code does not mention Merge so my preference would be to see some that does. Commented Apr 23, 2012 at 0:02
2

I couldn't get it to work with modelbuilder, but spent a few days modifying the code provided in the original post. Although this code isn't complex, it is for some without much experience. I hope others can profit by the time I spent crunching away.

#----------------------------------------------------------------
# merge 7 consecutive feature classes, sum one field, 
# sort the summed field ascending, and delete identical features
#
# 4/29/2012
#----------------------------------------------------------------
import arcpy
from arcpy import env
# Set workspace
env.workspace = "C:/nueces_dailyrainfall_sorted/2009/2nd/"
# Allow overwrites
arcpy.env.overwriteOutput = True
try:
 # Create list of feature classes
 fcs = arcpy.ListFeatureClasses()
 fcsCount = len(fcs)
 counter = 0
 weekNum = 1
 while counter < fcsCount:
 #collect 7 consecutive feature classes
 weekFeatures = []
 for i in range(counter,(counter+7)):
 weekFeatures.append(fcs[i])
 # local variables
 path = "C:/nueces_dailyrainfall_sorted/2009/2nd/" 
 outFeatureName = "week_"+ str(weekNum)
 outStatsTable = "week_"+ str(weekNum)+ "_summary"
 caseField = "Id"
 joinField = "Id"
 statsFields = [["Globvalue", "SUM"]]
 identField = ["Id"]
 # Execute Merge
 arcpy.Merge_management(weekFeatures, outFeatureName)
 # Execute Summary Statistics
 arcpy.Statistics_analysis(path+outFeatureName+".shp", path+outStatsTable+".dbf", statsFields, joinField)
 # Execute Join Field
 arcpy.JoinField_management(path+outFeatureName+".shp", joinField, path+outStatsTable+".dbf", joinField)
 # Sort by Sum_Globalvalue Ascending
 arcpy.Sort_management(path+outFeatureName+".shp", path+outFeatureName+"_sorted"+".shp", "Id ASCENDING", "UR")
 # Delete identical
 arcpy.DeleteIdentical_management(path+outFeatureName+"_sorted"+".shp", identField)
 counter += 7
 weekNum += 1
except:
 # If an error occurred while running a tool, then print the messages.
 print arcpy.GetMessages()
answered Apr 29, 2012 at 17:17

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.