Ignore:
Timestamp:
Apr 4, 2006, 3:49:42 PM (18 years ago)
Author:
duncan
Message:

Adding ability to remove points outside of the mesh when interpolating

File:
1 edited

Legend:

Unmodified
Added
Removed
  • inundation/utilities/polygon.py

    r2633 r2655  
    127127                                                verbose=verbose)
    128128
     129   
    129130    if one_point:
    130131        return count != 1
     
    135136        else:
    136137            return indices[count:][::-1]  #return reversed
     138       
     139
     140def in_and_outside_polygon(points, polygon, closed = True, verbose = False):
     141    """Determine points inside and outside a polygon
     142
     143       See separate_points_by_polygon for documentation
     144
     145       Returns an array of points inside and an array of points outside the polygon
     146    """
     147
     148    if verbose: print 'Checking input to outside_polygon'
     149    try:
     150        points = ensure_numeric(points, Float)
     151    except NameError, e:
     152        raise NameError, e
     153    except:
     154        msg = 'Points could not be converted to Numeric array'
     155        raise msg
     156
     157    try:
     158        polygon = ensure_numeric(polygon, Float)
     159    except NameError, e:
     160        raise NameError, e
     161    except:
     162        msg = 'Polygon could not be converted to Numeric array'
     163        raise msg
     164
     165
     166
     167    if len(points.shape) == 1:
     168        one_point = True
     169        points = reshape(points, (1,2))
     170    else:
     171        one_point = False
     172
     173    indices, count = separate_points_by_polygon(points, polygon,
     174                                                closed=closed,
     175                                                verbose=verbose)
     176    # Returns an array of points inside and an array of points outside
     177    # the polygon
     178 
     179    if count == len(indices):
     180        # No points are outside
     181        return indices[:count],[]
     182    else:
     183        return  indices[:count], indices[count:][::-1]  #return reversed
    137184
    138185
Note: See TracChangeset for help on using the changeset viewer.