Changeset 3054


Ignore:
Timestamp:
Jun 2, 2006, 3:02:36 PM (18 years ago)
Author:
duncan
Message:

removing geo-ref from inside_polygon

Location:
inundation/utilities
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • inundation/utilities/polygon.py

    r3052 r3054  
    4343
    4444
    45 def is_inside_polygon(point, polygon, closed=True, verbose=False,
    46                       points_geo_ref=None, polygon_geo_ref=None):
     45def is_inside_polygon(point, polygon, closed=True, verbose=False):
    4746    """Determine if one point is inside a polygon
    4847
     
    5049    """
    5150
    52     indices = inside_polygon(point, polygon, closed, verbose,
    53                              points_geo_ref, polygon_geo_ref)
     51    indices = inside_polygon(point, polygon, closed, verbose)
    5452
    5553    if indices.shape[0] == 1:
     
    6260   
    6361
    64 def inside_polygon(points, polygon, closed=True, verbose=False,
    65                    points_geo_ref=None, polygon_geo_ref=None):
     62def inside_polygon(points, polygon, closed=True, verbose=False):
    6663    """Determine points inside a polygon
    6764
     
    7168
    7269       See separate_points_by_polygon for documentation
     70
     71       points and polygon can be a geospatial instance,
     72       a list or a numeric array
    7373    """
    7474
     
    7676
    7777    try:
    78         points = ensure_absolute(points, geo_reference=points_geo_ref)
     78        points = ensure_absolute(points)
    7979    except NameError, e:
    8080        raise NameError, e
     
    8484
    8585    try:
    86         polygon = ensure_absolute(polygon, geo_reference=polygon_geo_ref)
     86        polygon = ensure_absolute(polygon)
    8787    except NameError, e:
    8888        raise NameError, e
  • inundation/utilities/test_polygon.py

    r3052 r3054  
    55from Numeric import zeros, array, allclose
    66from math import sqrt, pi
     7from utilities.numerical_tools import ensure_numeric
    78
    89from polygon import *
    910from coordinate_transforms.geo_reference import Geo_reference
     11from geospatial_data.geospatial_data import Geospatial_data
    1012
    1113def test_function(x, y):
     
    631633
    632634       
    633     def test_inside_polygon_geo_ref(self):
     635    def test_inside_polygon_geospatial(self):
     636
     637
     638        polygon_absolute = [[0,0], [1,0], [1,1], [0,1]]
     639        poly_geo_ref = Geo_reference(57,100,100)
     640       
     641
    634642
    635643
     
    638646        poly_geo_ref = Geo_reference(57,100,100)
    639647        polygon = poly_geo_ref.change_points_geo_ref(polygon_absolute)
    640 
     648        poly_spatial = Geospatial_data(polygon,
     649                                       geo_reference=poly_geo_ref)
     650       
    641651        points_absolute = (0.5, 0.5)
    642652        points_geo_ref = Geo_reference(57,78,-56)
    643653        points = points_geo_ref.change_points_geo_ref(points_absolute)
     654        points_spatial = Geospatial_data(points,
     655                                         geo_reference=points_geo_ref)
     656       
     657        assert is_inside_polygon(points_absolute, polygon_absolute)
     658        assert is_inside_polygon(ensure_numeric(points_absolute),
     659                                 ensure_numeric(polygon_absolute))
     660        assert is_inside_polygon(points_absolute, poly_spatial)
     661        assert is_inside_polygon(points_spatial, poly_spatial)
     662        assert is_inside_polygon(points_spatial, polygon_absolute)
    644663
    645664        assert is_inside_polygon(points_absolute, polygon_absolute)
    646665       
    647         points_inside = inside_polygon(points, polygon,
    648                                polygon_geo_ref=poly_geo_ref,
    649                                points_geo_ref=points_geo_ref)
    650         #print "points_inside",points_inside
    651         #assert 1 == len(inside_polygon( points, polygon,
    652         #                       polygon_geo_ref=poly_geo_ref,
    653         #                       points_geo_ref=points_geo_ref))
    654         assert not is_inside_polygon((0.5, 1.5), polygon,
    655                                      polygon_geo_ref=poly_geo_ref )
    656         assert not is_inside_polygon((0.5, -0.5), polygon,
    657                                      polygon_geo_ref=poly_geo_ref )
    658         assert not is_inside_polygon((-0.5, 0.5), polygon,
    659                                      polygon_geo_ref=poly_geo_ref )
    660         assert not is_inside_polygon((1.5, 0.5), polygon,
    661                                      polygon_geo_ref=poly_geo_ref )
     666       
    662667#-------------------------------------------------------------
    663668if __name__ == "__main__":
Note: See TracChangeset for help on using the changeset viewer.