1

I am trying to write a script partially in ArcGIS ModelBuilder and adding an if statement on my own.

It uses the Feature Compare tool in arcgis and I want to use the result.getOutput in an If statement so that if it is true then run a process - in this case a copy features.

The big picture here is to compare two features and if there are differences in them then truncate and update.

I need help with the If statement or alternative. I don't think I'm getting result.getOutput value to pass to the if statement and then run the if. Can anyone see where this might be incorrect?

# -*- coding: utf-8 -*-
# --------------------------------------------------------------------------    -
# compare_test1.py
# Created on: 2015-11-03 14:06:44.00000
#   (generated by ArcGIS/ModelBuilder)
# Description: 
# ---------------------------------------------------------------------------

# Import arcpy module
import arcpy


# Local variables:
TONGIS_PARKING = "Database Connections\\ESRI10PUB GIS_VIEWER WAREHOUSE.sde\\TONGIS.PARKING"
TONGIS_PARKING__2_ = "Database Connections\\ESRI10PUB GIS_VIEWER WAREHOUSE.sde\\TONGIS.PARKING"
test = ""
PARKING_CopyFeatures = "G:\\Projects 10\\Corporate Services\\Information Technology\\Default.gdb\\PARKING_CopyFeatures"

# Process: Feature Compare
result = arcpy.FeatureCompare_management(TONGIS_PARKING, TONGIS_PARKING__2_, "GLOBALID", "ALL", "", "0.00001 Unknown", "0", "0", "", "", "NO_CONTINUE_COMPARE", test)
changes = result.getOutput(1)
#print "Comparision Result is: " + changes
change = str(changes)
if change == "True":
    # Process: Copy Features
    arcpy.CopyFeatures_management(TONGIS_PARKING__2_, PARKING_CopyFeatures, "", "0", "0", "0")   
5
  • Is it a typo that your if statement is not using change?
    – Paul
    Commented Nov 23, 2015 at 16:43
  • Yes, I corrected it in my question.
    – Scott
    Commented Nov 23, 2015 at 18:25
  • 2
    check if result.getOutput(1) is actually "True" or True (there's a difference).
    – Paul H
    Commented Nov 23, 2015 at 18:26
  • For boolean True/False you should not include the quotation marks as you elude to @Paul H
    – Jeff May
    Commented Nov 23, 2015 at 19:34
  • @JeffMay, personally, I wouldn't put it past arcpy to return a string, though.
    – Paul H
    Commented Nov 23, 2015 at 19:55

1 Answer 1

2

This is a case sensitivity issue. getOutput(1) on the Result object returned by Feature Compare will be 'true' or 'false' (not 'True' or 'False', or True or False).

Note: getOutput(n) always returns a string (for any geoprocessing tool).

0

Your Answer

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

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