Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I don't know exactly if there is a tool for this or a maybe a python script could be more suitable. I want to compare string elements from a field (POI_NAME) with another string element in another field (ROTULO). Find attached an screenshot.

My goal, AT LEAST, is to have a YES/NO matching, but It could be fantastic having a % of matching. Do anyone know anything about?

enter image description here

I tried something like this:

Python code

But it doesn't work.

After editing the code, to:

New code

We can see that it does not working well (BECAUSE IT HAS SPECIAL CHARS AND SPACES):

enter image description here

share|improve this question
add comment

1 Answer 1

up vote 3 down vote accepted

First of all, you should compare your string in a case insensitive way. EDIT: I also add .strip() in case you have blank spaces in your string.

POI_name.lower().strip() == ROTULO.lower().strip()

Because Python is case sensitive and ROTULO is in capital letter

For further comparison, this is more a Python question. For instance, have a look at this post an SO, which uses pylevenshtein

EDIT: I've tried this (from Wikibooks), and it worked nicely (the larger the value, the more different are the words

def lev(a, b):
    if not a: return len(b)
    if not b: return len(a)
    return min(lev(a[1:], b[1:])+(a[0] != b[0]), lev(a[1:], b)+1, lev(a, b[1:])+1) 
share|improve this answer
    
I looked up for this issue you mentioned @radouxju, but still doesn't working. –  juasmilla May 12 at 9:38
    
@juasmilla "doesn't work" is far less helpful to people trying to help you than if you can say what is not working e.g. it gives an error, and what that precise error message is; or it updates the wrong rows; or it does not update all the rows; or it did not update any rows; etc; etc –  PolyGeo May 12 at 9:46
    
Sorry you we're right. I forgot to edit my first question with this new income. Editing...just a sec. –  juasmilla May 12 at 9:48
2  
I've tested my code and it worked with me. Is it possible that you have special characters or spaces ? Maybe you could try to compare the length of the field values (len(!POI_name!)-len(!ROTULO!) ) for debugging. –  radouxju May 12 at 10:05
    
@radouxju as you said, I've found special chars and spaces... so this is not as simple as I thought.I'll have a look to the post you mentioned (pylevenshtein) but, unfortunatelly, I do not really know if could use its code in ArcGIS 10 field calculator. –  juasmilla May 12 at 10:29
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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