2

I'm trying to make tool of change detection between two polygons layers by fields of initial state and final state. Everything is working except attribute selection, I would like user could choose whether areals with no change include or exclude from calculations. I create new layer by intersection, then I want to compare values in field of initial state with values in field of final state and exclude areals without change.

# select areals without no change
if change == "Exclude":
    where_clause = '"' + field_initial + '" <> ' + "'" + field_final + "'"
    arcpy.Select_analysis(output_fc, output_select2, where_clause)

output_fc is layer created by intersection.

It creates new layer, but with all objects, it makes no selection at all, I would like to get same result as when I use attribute selection in ArcMAP. I tried to do it in python window, also in tool, there is no error in expression but no selection.

enter image description here

  • What data type are the fields that you are comparing? – Pura Vida Apr 26 '16 at 12:41
  • Data type is string, values are codes of category, for example 21310 (string not number) ... it is code of land cover category. – zubro Apr 26 '16 at 12:46
  • 1
    I think you have your quotes mixed up on the 2nd field in the where clause. You use single quotes instead of double quotes. Try this: where_clause = '"' + field_initial + '" <> ' + '"' + field_final + '"' – Pura Vida Apr 26 '16 at 12:56
2

You've swapped usage of quotes in your Python snippet. Instead of passing in a quoted field name, you've supplied a string literal, ie "KOD5" <> 'KOD5_1'.

You need to change the quoting so that the second field name is quoted with double quotes instead:

# select areals without no change
if change == "Exclude":
    where_clause = '"' + field_initial + '" <> "' + field_final + '"'
    arcpy.Select_analysis(output_fc, output_select2, where_clause)

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.