Ignore:
Timestamp:
Feb 28, 2008, 10:43:58 AM (16 years ago)
Author:
ole
Message:

Decimated polygon test file to remove potentially licensed data.
Fiddled with code.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/utilities/polygon.py

    r4882 r5086  
    55
    66
    7 try:
    8     from scipy import Float, Int, zeros, ones, array, concatenate, reshape, dot
    9 except:
    10     #print 'Could not find scipy - using Numeric'
    11     from Numeric import Float, Int, zeros, ones, array, concatenate, reshape, dot
     7#try:
     8#    from scipy import Float, Int, zeros, ones, array, concatenate, reshape, dot
     9#except:
     10#    #print 'Could not find scipy - using Numeric'
     11
     12from Numeric import Float, Int, zeros, ones, array, concatenate, reshape, dot
    1213
    1314
     
    337338
    338339def plot_polygons(polygons_points, style=None,
    339                          figname=None, label=None, verbose=False):
     340                  figname=None, label=None, verbose=False):
    340341   
    341342    """ Take list of polygons and plot.
     
    572573
    573574
     575def write_polygon(polygon, filename=None):
     576    """Write polygon to csv file.
     577       There will be exactly two numbers, easting and northing,
     578       in each line separated by a comma.
     579       
     580       No header.   
     581    """
     582
     583    fid = open(filename, 'w')
     584    for point in polygon:
     585        fid.write('%f, %f\n' %point)
     586    fid.close()
     587   
     588
    574589def populate_polygon(polygon, number_of_points, seed=None, exclude=None):
    575590    """Populate given polygon with uniformly distributed points.
     
    595610    points = []
    596611
    597     #Find outer extent of polygon
     612    # Find outer extent of polygon
    598613    max_x = min_x = polygon[0][0]
    599614    max_y = min_y = polygon[0][1]
     
    722737
    723738
     739def decimate_polygon(polygon, factor=10):
     740    """Reduce number of points in polygon by the specified
     741    factor (default=10, hence the name of the function) such that
     742    the extrema in both axes are preserved.
     743
     744    Return reduced polygon
     745    """
     746
     747    # FIXME(Ole): This doesn't work at present,
     748    # but it isn't critical either
     749
     750    # Find outer extent of polygon
     751    num_polygon = ensure_numeric(polygon)
     752    max_x = max(num_polygon[:,0])
     753    max_y = max(num_polygon[:,1])
     754    min_x = min(num_polygon[:,0])
     755    min_y = min(num_polygon[:,1])       
     756
     757    # Keep only some points making sure extrema are kept
     758    reduced_polygon = []   
     759    for i, point in enumerate(polygon):
     760        x = point[0]
     761        y = point[1]       
     762        if x in [min_x, max_x] and y in [min_y, max_y]:
     763            # Keep
     764            reduced_polygon.append(point)
     765        else:
     766            if len(reduced_polygon)*factor < i:
     767                reduced_polygon.append(point)               
     768
     769    return reduced_polygon
     770
    724771##############################################
    725772#Initialise module
Note: See TracChangeset for help on using the changeset viewer.