Changeset 3054 for inundation
- Timestamp:
- Jun 2, 2006, 3:02:36 PM (19 years ago)
- Location:
- inundation/utilities
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/utilities/polygon.py
r3052 r3054 43 43 44 44 45 def is_inside_polygon(point, polygon, closed=True, verbose=False, 46 points_geo_ref=None, polygon_geo_ref=None): 45 def is_inside_polygon(point, polygon, closed=True, verbose=False): 47 46 """Determine if one point is inside a polygon 48 47 … … 50 49 """ 51 50 52 indices = inside_polygon(point, polygon, closed, verbose, 53 points_geo_ref, polygon_geo_ref) 51 indices = inside_polygon(point, polygon, closed, verbose) 54 52 55 53 if indices.shape[0] == 1: … … 62 60 63 61 64 def inside_polygon(points, polygon, closed=True, verbose=False, 65 points_geo_ref=None, polygon_geo_ref=None): 62 def inside_polygon(points, polygon, closed=True, verbose=False): 66 63 """Determine points inside a polygon 67 64 … … 71 68 72 69 See separate_points_by_polygon for documentation 70 71 points and polygon can be a geospatial instance, 72 a list or a numeric array 73 73 """ 74 74 … … 76 76 77 77 try: 78 points = ensure_absolute(points , geo_reference=points_geo_ref)78 points = ensure_absolute(points) 79 79 except NameError, e: 80 80 raise NameError, e … … 84 84 85 85 try: 86 polygon = ensure_absolute(polygon , geo_reference=polygon_geo_ref)86 polygon = ensure_absolute(polygon) 87 87 except NameError, e: 88 88 raise NameError, e -
inundation/utilities/test_polygon.py
r3052 r3054 5 5 from Numeric import zeros, array, allclose 6 6 from math import sqrt, pi 7 from utilities.numerical_tools import ensure_numeric 7 8 8 9 from polygon import * 9 10 from coordinate_transforms.geo_reference import Geo_reference 11 from geospatial_data.geospatial_data import Geospatial_data 10 12 11 13 def test_function(x, y): … … 631 633 632 634 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 634 642 635 643 … … 638 646 poly_geo_ref = Geo_reference(57,100,100) 639 647 polygon = poly_geo_ref.change_points_geo_ref(polygon_absolute) 640 648 poly_spatial = Geospatial_data(polygon, 649 geo_reference=poly_geo_ref) 650 641 651 points_absolute = (0.5, 0.5) 642 652 points_geo_ref = Geo_reference(57,78,-56) 643 653 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) 644 663 645 664 assert is_inside_polygon(points_absolute, polygon_absolute) 646 665 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 662 667 #------------------------------------------------------------- 663 668 if __name__ == "__main__":
Note: See TracChangeset
for help on using the changeset viewer.