Changeset 9343 for trunk/anuga_work


Ignore:
Timestamp:
Sep 22, 2014, 11:15:38 AM (11 years ago)
Author:
davies
Message:

Fixing bug in bounding polygon shapefile routine

Location:
trunk/anuga_work/development/gareth/template_scenarios/tsunami/tsunami3/scripts
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/anuga_work/development/gareth/template_scenarios/tsunami/tsunami3/scripts/user_functions.py

    r9341 r9343  
    9494        {boundary_line_and_tags[0][1]: range(len(bounding_polygon) - 1)}
    9595
     96    # Treat the case of a 'closed' polygon with first point == last point
     97    # by dropping the last point
     98    if bounding_polygon[0] == bounding_polygon[-1]:
     99        bounding_polygon = [bounding_polygon[k] for k in range(len(bounding_polygon)-1)]
     100
    96101    for i in range(boundary_segnum - 1):
     102        # Loop over all the 'other' boundary segments, and find the line which
     103        # starts at the end point of bounding_polygon
    97104
    98         # Find the line which starts at the end point of bounding_polygon
     105        found_match = False # Flag for error if no matching segments found
    99106
    100107        for j in range(boundary_segnum):
    101108            blj = boundary_line_and_tags[j][0]
    102109            if blj[0] == bounding_polygon[-1]:
     110
     111                found_match = True
    103112
    104113                # Append all but the first point of blj to bounding_polygon
     
    112121
    113122                if i == boundary_segnum - 2:
     123                    # The first and last points should match
     124                    if bounding_polygon[0] != bounding_polygon[-1]:
     125                        msg = 'The first and last points of the bounding ' + \
     126                              'polygon are not identical'
     127                        raise ValueError(msg)
     128                   
     129                    # Remove the last point
    114130                    bounding_polygon = [bounding_polygon[k] for k in
    115131                                        range(len(bounding_polygon) - 1)]
     
    127143                else:
    128144                    boundary_tags[key] = new_tags
     145                # Finish the j loop
     146                break
     147        # Check that a 'match' was found for every 'i' iteration
     148        if not found_match:
     149            raise Exception, 'Did not find a match'
    129150
    130151    return (bounding_polygon, boundary_tags)
Note: See TracChangeset for help on using the changeset viewer.