Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to assign numbers to a certain types of building and I need to use field calculator. I tried many different versions of this and I still cant find whats wrong. Could you tell me where do I make a mistake?

![Printscreen]1

share|improve this question
    
obyv column is a short type... I tried float (among others) but didnt help. – Robert Spal Oct 27 '15 at 12:09
9  
Looks like a script for VB instead of Python, perhaps check the parser for VB Script? – Joseph Oct 27 '15 at 12:12
    
Thanks a lot! Artwork21s code worked. – Robert Spal Oct 28 '15 at 15:42
    
Artwork 21 has answered this but just for your info (and sanity) write your field calculator expressions in a text editor that supports python syntax highlighting. Notepad++ or similar. It will greatly decrease frustration - the field calculator is such an unfriendly tool. – kingmi Nov 4 '15 at 11:24
    
Yep, I just found out how unfriendly it is. I will use notepad next time. Thanks – Robert Spal Nov 5 '15 at 11:52
up vote 7 down vote accepted

Your python syntax is not correct, try:

def myFunc(typ, oby):
  if typ == 'D':
    return 'Z'
  else: return '25'

function call:

myFunc(!TYP!, !obyy!)
share|improve this answer

Here is a working if/then statement in VBS.

For your code, I would think something like this:

Dim result
if [TYP] = "D" then
     result = "Z"
else result = "25"
end if

And:

obyv = result
share|improve this answer

Looks like you used "=" rather than "==".

def countRows(rowcount): 
    import arcpy 
    if %rowcount% == 0: 
        return "false" 
    else: 
        return "true"
share|improve this answer
    
There is no need to import arcpy and I think doing so would make this run very slowly. – PolyGeo Nov 4 '15 at 10:50

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.