4

I've made a simple model in ModelBuilder, ArcGIS 10.1. The model take a file in gdb, select two consecutive years, and calculate the near distances between the actual and previous year. As the near distance values are attached to attribute table of the "input file", I want to export the feature with attached attributes to another geodatabase, and export my attribute table to .csv.

The model seems to work fine when I run it manually for every couple of years (years 2005-2009: 2005-2006, 2006-2007, 2007-2008, 2008-2009). However, when I run it as a batch process, my output results are all the same and contains all years, not only the selected ones.

How can I correctly export the final outputs per year? I tried to alter the name of Output Feature Class to bb_%n% following this post: Unexpected result using ModelBuilder in batch?, however it does not to seems to influence my output.

My ModelBuilder: enter image description here

and my Batch process:

enter image description here

Python snippet:

# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------------
# near_distance.py
# Created on: 2017-04-11 10:46:59.00000
#   (generated by ArcGIS/ModelBuilder)
# Usage: near_distance <Actual_year> <Previous_year> <Output_Feature_Class__BB_per_year_> <a1> 
# Description: 
# identify old and new year
# 
# measure neirest neighbor distance

# ---------------------------------------------------------------------------

# Set the necessary product code
# import arcinfo


# Import arcpy module
import arcpy

# Load required toolboxes
arcpy.ImportToolbox("C:/Users/maria/UEL/Projects/2017_wind_beetle_from_aerial/Ferencik/analyzed_data/export_attributeTable.tbx")

# Script arguments
Actual_year = arcpy.GetParameterAsText(0)
if Actual_year == '#' or not Actual_year:
    Actual_year = "\"year\" = 2006" # provide a default value if unspecified

Previous_year = arcpy.GetParameterAsText(1)
if Previous_year == '#' or not Previous_year:
    Previous_year = "\"year\" = 2005" # provide a default value if unspecified

Output_Feature_Class__BB_per_year_ = arcpy.GetParameterAsText(2)
if Output_Feature_Class__BB_per_year_ == '#' or not Output_Feature_Class__BB_per_year_:
    Output_Feature_Class__BB_per_year_ = "a1" # provide a default value if unspecified

a1 = arcpy.GetParameterAsText(3)
if a1 == '#' or not a1:
    a1 = "C:\\Users\\maria\\UEL\\Projects\\2017_wind_beetle_from_aerial\\Ferencik\\analyzed_data\\near_distance.gdb\\a1" # provide a default value if unspecified

# Local variables:
bb_integer = "C:\\Users\\maria\\UEL\\Projects\\2017_wind_beetle_from_aerial\\Ferencik\\analyzed_data\\BB_corrected_by_location.gdb\\bb_integer"
BB_n = Previous_year
Actual_year_completed = BB_n
BB_n_1 = Actual_year
Output_geodatabase = "C:\\Users\\maria\\UEL\\Projects\\2017_wind_beetle_from_aerial\\Ferencik\\analyzed_data\\near_distance.gdb"
t__Name__csv = "C:\\Users\\maria\\UEL\\Projects\\2017_wind_beetle_from_aerial\\Ferencik\\output_data\\Results\\near_distance2\\t_%Name%.csv"

# Process: Select (2)
arcpy.Select_analysis(bb_integer, BB_n_1, Actual_year)

# Process: Select
arcpy.Select_analysis(bb_integer, BB_n, Previous_year)

# Process: Near
arcpy.Near_analysis(BB_n_1, "C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select", "", "NO_LOCATION", "NO_ANGLE")

# Process: Feature Class to Feature Class
arcpy.FeatureClassToFeatureClass_conversion(Actual_year_completed, Output_geodatabase, Output_Feature_Class__BB_per_year_, "", "FID_bb_15 \"FID_bb_15\" true true false 4 Long 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,FID_bb_15,-1,-1;FID_aoifin \"FID_aoifin\" true true false 4 Long 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,FID_aoifin,-1,-1;FID_aoi \"FID_aoi\" true true false 4 Long 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,FID_aoi,-1,-1;FID_clean_2011 \"FID_clean_2011\" true true false 4 Long 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,FID_clean_2011,-1,-1;Id \"Id\" true true false 4 Long 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,Id,-1,-1;FID_all_2015_true \"FID_all_2015_true\" true true false 4 Long 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,FID_all_2015_true,-1,-1;Id_1 \"Id\" true true false 4 Long 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,Id_1,-1,-1;FID_all_2015_false \"FID_all_2015_false\" true true false 4 Long 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,FID_all_2015_false,-1,-1;Id_12 \"Id\" true true false 4 Long 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,Id_12,-1,-1;FID_all_2013_false \"FID_all_2013_false\" true true false 4 Long 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,FID_all_2013_false,-1,-1;Id_12_13 \"Id\" true true false 4 Long 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,Id_12_13,-1,-1;FID_all_2011_infra \"FID_all_2011_infra\" true true false 4 Long 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,FID_all_2011_infra,-1,-1;Id_12_13_14 \"Id\" true true false 4 Long 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,Id_12_13_14,-1,-1;FID_all_2009_infra \"FID_all_2009_infra\" true true false 4 Long 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,FID_all_2009_infra,-1,-1;Id_12_13_14_15 \"Id\" true true false 4 Long 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,Id_12_13_14_15,-1,-1;FID_all_2008_infr \"FID_all_2008_infr\" true true false 4 Long 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,FID_all_2008_infr,-1,-1;Id_12_13_14_15_16 \"Id\" true true false 4 Long 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,Id_12_13_14_15_16,-1,-1;FID_all_2008_farba \"FID_all_2008_farba\" true true false 4 Long 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,FID_all_2008_farba,-1,-1;Id_12_13_14_15_16_17 \"Id\" true true false 4 Long 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,Id_12_13_14_15_16_17,-1,-1;FID_all_2005_farba \"FID_all_2005_farba\" true true false 4 Long 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,FID_all_2005_farba,-1,-1;Id_12_13_14_15_16_17_18 \"Id\" true true false 4 Long 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,Id_12_13_14_15_16_17_18,-1,-1;FID_mlc03 \"FID_mlc03\" true true false 4 Long 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,FID_mlc03,-1,-1;ID_12_13_14_15_16_17_18_19 \"ID\" true true false 8 Double 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,ID_12_13_14_15_16_17_18_19,-1,-1;GRIDCODE \"GRIDCODE\" true true false 8 Double 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,GRIDCODE,-1,-1;FID_zonacia_2016_navrh \"FID_zonacia_2016_navrh\" true true false 4 Long 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,FID_zonacia_2016_navrh,-1,-1;OBJECTID_1 \"OBJECTID\" true true false 8 Double 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,OBJECTID_1,-1,-1;ZONA \"ZONA\" true true false 3 Text 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,ZONA,-1,-1;Nazov_zony \"Nazov_zony\" true true false 70 Text 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,Nazov_zony,-1,-1;Zona_OP \"Zona_OP\" true true false 40 Text 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,Zona_OP,-1,-1;SOP \"SOP\" true true false 4 Long 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,SOP,-1,-1;Shape_Leng \"Shape_Leng\" true true false 8 Double 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,Shape_Leng,-1,-1;FID_forest_cleaned_from_1997_JPRL \"FID_forest_cleaned_from_1997_JPRL\" true true false 4 Long 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,FID_forest_cleaned_from_1997_JPRL,-1,-1;Id_12_13_14_15_16_17_18_19_20 \"Id\" true true false 4 Long 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,Id_12_13_14_15_16_17_18_19_20,-1,-1;FID_zonacia_2016_navrh_1 \"FID_zonacia_2016_navrh_1\" true true false 4 Long 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,FID_zonacia_2016_navrh_1,-1,-1;OBJECTID_12 \"OBJECTID\" true true false 8 Double 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,OBJECTID_12,-1,-1;ZONA_1 \"ZONA\" true true false 3 Text 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,ZONA_1,-1,-1;Nazov_zony_1 \"Nazov_zony\" true true false 70 Text 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,Nazov_zony_1,-1,-1;Zona_OP_1 \"Zona_OP\" true true false 40 Text 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,Zona_OP_1,-1,-1;SOP_1 \"SOP\" true true false 4 Long 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,SOP_1,-1,-1;Shape_Leng_1 \"Shape_Leng\" true true false 8 Double 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,Shape_Leng_1,-1,-1;year \"year\" true true false 4 Long 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,year,-1,-1;FID_bb_11 \"FID_bb_11\" true true false 4 Long 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,FID_bb_11,-1,-1;FID_bb_13 \"FID_bb_13\" true true false 4 Long 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,FID_bb_13,-1,-1;FID_bb_09 \"FID_bb_09\" true true false 4 Long 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,FID_bb_09,-1,-1;FID_bb_08 \"FID_bb_08\" true true false 4 Long 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,FID_bb_08,-1,-1;FID_bb_07 \"FID_bb_07\" true true false 4 Long 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,FID_bb_07,-1,-1;FID_bb_06 \"FID_bb_06\" true true false 4 Long 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,FID_bb_06,-1,-1;FID_bb_05 \"FID_bb_05\" true true false 4 Long 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,FID_bb_05,-1,-1;ORIG_FID \"ORIG_FID\" true true false 4 Long 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,ORIG_FID,-1,-1;Shape_Length \"Shape_Length\" true true true 8 Double 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,Shape_Length,-1,-1;Shape_Area \"Shape_Area\" true true true 8 Double 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,Shape_Area,-1,-1;Shape_length_1 \"Shape_length_1\" true true false 0 Double 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,Shape_length_1,-1,-1;Shape_area_1 \"Shape_area_1\" true true false 0 Double 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,Shape_area_1,-1,-1;NEAR_FID \"NEAR_FID\" true true false 0 Long 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,NEAR_FID,-1,-1;NEAR_DIST \"NEAR_DIST\" true true false 0 Double 0 0 ,First,#,C:\\Users\\maria\\Documents\\ArcGIS\\Default.gdb\\bb_integer_Select1,NEAR_DIST,-1,-1", "")

# Process: exportTable2
arcpy.gp.toolbox = "C:/Users/maria/UEL/Projects/2017_wind_beetle_from_aerial/Ferencik/analyzed_data/export_attributeTable.tbx";
# Warning: the toolbox C:/Users/maria/UEL/Projects/2017_wind_beetle_from_aerial/Ferencik/analyzed_data/export_attributeTable.tbx DOES NOT have an alias. 
# Please assign this toolbox an alias to avoid tool name collisions
# And replace arcpy.gp.exportTable2(...) with arcpy.exportTable2_ALIAS(...)
arcpy.gp.exportTable2(Output_geodatabase, t__Name__csv)
  • 1
    Perhaps review gis.stackexchange.com/questions/36891/… What you are seeing may or may not be another manifestation of the same thing. – PolyGeo Apr 7 '17 at 10:21
  • Hmmm... yes, probably I'll need to figure out how to apply iterators to count years in my model... – maycca Apr 7 '17 at 18:17
  • 1
    Could you upload your model somewhere, or export it to a Python snippet and post it? – GISGe Apr 10 '17 at 9:20
  • yes, I have updated my question, and attached the generated python snippet – maycca Apr 11 '17 at 8:50
  • 1
    I think you'll get further by not exporting a model as a Python script. I would instead start a new script, then run each step in your model from its tool dialog, and use Copy As Python Snippet in the Geoprocessing | Results window, to copy then paste it into your script. – PolyGeo Apr 17 '17 at 5:55
2

When you run ModelBuilder in batch mode, it doesn't process all the inputs in series, but in parallel. To get the model to run in series, you need an iterator. Iterate Row Selection will be perfect.

  • Create a data table containing all that information you feed into the batch command
  • Set that table as a parameter instead of Previous Year or Actual Year
  • Insert a "Clear Selection" step either as the first step inside the iterator, or the last. It's part of the "Select Layer" tool
  • Run Model

Since your model works when it's run once, this should get everything working properly.

  • Oh, and make sure that the name of the answer file is in the input file, too. That way you won't wind up trying to overwrite the same file, which can cause the whole thing to stop working. – P.T. Curran May 8 '17 at 21:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.