Changeset 6132


Ignore:
Timestamp:
Jan 9, 2009, 4:10:11 PM (16 years ago)
Author:
ole
Message:

Check for duplicate polygon ids in csv2polygon

File:
1 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/shallow_water/data_manager.py

    r6130 r6132  
    10941094
    10951095    # Loop through entries and compose polygons
     1096    past_ids = {}
     1097    last_id = None
    10961098    for i, id in enumerate(X['id']):
     1099
     1100        # Check for duplicate polygons
     1101        if id in past_ids:
     1102            msg = 'Polygon %s was duplicated in line %d' % (id, i)
     1103            raise Exception, msg
    10971104       
    10981105        if id not in polygons:
     
    11011108            if values is not None:
    11021109                values[id] = X[value_name][i]
     1110
     1111            # Keep track of previous polygon ids
     1112            if last_id is not None:
     1113                past_ids[last_id] = i
    11031114           
    11041115        # Append this point to current polygon
     
    11071118           
    11081119        # Check that value is the same across each polygon
    1109         assert values[id] == X[value_name][i]
     1120        msg = 'Values must be the same across each polygon.'
     1121        msg += 'I got %s in line %d but it should have been %s' % (X[value_name][i], i, values[id])
     1122        assert values[id] == X[value_name][i], msg
     1123
     1124        last_id = id
    11101125       
    11111126    return polygons, values
Note: See TracChangeset for help on using the changeset viewer.