TitlePages

Friday 12 December 2014

How to check for condition in Geoprocessing Service or Model Builder

How to check for if/else conditions in Geoprocessing Service


TOOL USED:  
Arc python and Script tool
Python script will be deployed in the ARC Toolbox to create the Conversion Tool 

WORKING OF THE TOOL:
Script tool is created in the ArcMap and the required input & Output Parameter are set. The script tool source is set to the custom python code present in an Python file(.py)
Out motive is to use check for the count of a features in an feature class and performing an conditional Execution

PROCEDURE:
  • Open ArcMap 10.0+ 
  • Create your own Geometric Network or Open your Existing Geometric Network
  • Add your Geometric network to the Table of contents in the ArcMap as Shown Below


·         Create a new Model in your myToolBox .Right Click on MyToolBox > New > Model.Following window will appear on the Screen 







  •    Add your desired feature class to the Model. (Right Click on any empty space and select ADD DATA  and select your feature class in the object browser)
  • ·         Add Get Count and Calculate value Model from the System Toolbox Connect the model as shown below 






  • ·         Now open calculate value Model and in the Expression Textbox call the function Calculate(%RowCount%)
  • ·         Here %RowCount% will act as an Inline Variable and Compiler automatically replace the %RowCount% with the value of the rowcount field
  • ·         At the Code block defined the function Calculate as

def calculate(row):
if row>0:
return true
else:
return false
  • ·         Make the return Data type as Boolean
  • ·         The output Boolean can be set as a precondition for any model. So that the Model  get executes only when the output of calculate value is true






No comments: