2

I'm trying to dissolve polygon features from different layers by their FID. If two polygons have the same FID the result should be one single polygon. Maybe this drawing will help to make clear what I'm trying to get: enter image description here

Here's how I was going to proceed: First I performed a Union of the two layers joining only the FIDs. Thus I got a new layer with an attribute table containing two fields (called FID_Layer1 and FID_Layer2) with the initial FID of each layer and the value -1 if the polygon is from the respective other layer. Then I tried to add a new field combining those two fields but erasing the negative values and replacing them with the actual value. Based on this field I am going to perform a Dissolve hoping that it will give me the results I want. In order to get the new field on which to perform the Dissolve I wrote a script in Python:

def FID_Union(inValue):
if !FID_Layer1! < 0:
    return !FID_Layer2!
else:
    return !FID_Layer1!

However, this doesn't work. The error message tells me that there's a syntax error in Line 2 but I can't figure out what's wrong.

So can anybody tell me what I have to change in the script to make it work? Or is there another (easier) way to dissolve the polygons from different layers? I'd be happy about any suggestions.

  • 1
    My guess would be that everything after def FID_Union(inValue): has to be indented. This might not solve your problem completely but it's a start :) – Joseph Sep 18 '15 at 10:48
2

As @Joseph pointed out, you need to indent after your "def" statement. However, you will get another error because you can't get the values from other fields if they have not been passed to the function within the codeblock.

On another note, you are defining a function variable "inValue" but not doing anything with it.

I would therefore write your above code (in the codeblock) as:

def FID_Union(inValue1, inValue2):
    if inValue1 < 0:
        return invalue2
    else:
        return invalue1

Then you can enter the following in the calculation box:

FID_Union(!FID_Layer1!,!FID_Layer2!)

Your input fields will be assigned to the variables in the function and you will get one of the values returned base on your "if" condition.

enter image description here

  • No problem - glad to hear it! – Ali Sep 18 '15 at 15:52

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.