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 want to label the source files for a unified shapefile, and there are three respective columns for each. If there is no value in the column, there is no data from that source; if there is a value in multiple columns, it is from multiple sources (and therein lies the problem). I have written the following for use in the Codeblock in field calculator:

def srcfind (grcode,grcode2,lur):
 if lur == 'Parks and Recreational' and grcode == 0 and grcode2 == 0:
  return 'dmti'
 elif lur == 'Parks and Recreational' and grcode > 0 and grcode2 > 0: 
  if grcode <> 0 and grcode2 <> 0:
   return 'dmti, land cover, clutter'
  elif grcode == 0 and grcode2 > 0:
   return 'dmti and land cover'
  elif grcode > 0 and grcode2 == 0:
   return 'dmti and clutter'
 elif lur <> 'Parks and Recreational' and grcode > 0 and grcode2 == 0:
  return 'clutter'
 elif lur <> 'Parks and Recreational' and grcode == 0 and grcode2 > 0:
  return 'land cover'
 elif lur <> 'Parks and Recreational' and grcode > 0 and grcode2 > 0:
  return 'clutter and land cover' 

The first 'if' works correctly; even the 'dmti, land cover, clutter' category works correctly; and the last three elifs work correctly, it's just the middle part to determine 'dmti and land cover' and 'dmti and clutter' which don't work, resulting in the field being labelled 'land cover' or 'clutter' (depending on which column has a value).

Essentially, how do I fix this?

The image below is the attribute table with the variables labelled. You can see that it doesn't work for the conditions I mentioned.

The attribute table

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

I only analyzed your first record, to see why it didn't go through:

Lur = Parks and Recreational' grcode = 0 grcode2 = 15

You have two main if statements for the Lur = 'Park and Recreational':

if lur == 'Parks and Recreational' and grcode == 0 and grcode2 == 0:

elif lur == 'Parks and Recreational' and grcode > 0 and grcode2 > 0:

Which none of the conditions will be satisfied for the above record.

I would try using the below, which will at least make suitable for the top record:

def srcfind (grcode,grcode2,lur):
 if lur == 'Parks and Recreational' and grcode == 0 and grcode2 == 0:
  return 'dmti'
 elif lur == 'Parks and Recreational': 
  if grcode <> 0 and grcode2 <> 0:
   return 'dmti, land cover, clutter'
  elif grcode == 0 and grcode2 > 0:
   return 'dmti and land cover'
  elif grcode > 0 and grcode2 == 0:
   return 'dmti and clutter'
 elif lur <> 'Parks and Recreational' and grcode > 0 and grcode2 == 0:
  return 'clutter'
 elif lur <> 'Parks and Recreational' and grcode == 0 and grcode2 > 0:
  return 'land cover'
 elif lur <> 'Parks and Recreational' and grcode > 0 and grcode2 > 0:
  return 'clutter and land cover' 
share|improve this answer
1  
thanks, that worked a charm. I'm still kind of new to Python so I guess it's a rookie mistake. –  Emily Apr 17 '12 at 19:54
add 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.