Changeset 3051
- Timestamp:
- Jun 2, 2006, 12:33:16 PM (18 years ago)
- Location:
- inundation
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/geospatial_data/geospatial_data.py
r2955 r3051 692 692 else: 693 693 points = ensure_numeric(points, Float) 694 695 694 if geo_reference is None: 696 695 geo = None #Geo_reference() -
inundation/pmesh/mesh_interface.py
r3042 r3051 8 8 from utilities.numerical_tools import ensure_numeric 9 9 from Numeric import Float 10 from utilities.polygon import inside_polygon 10 11 11 12 # This is due to pmesh being a package and a module and … … 69 70 # converted to relative coordinates (I think). How can we simplify this? 70 71 # 72 #FIXME (DSG-DSG) this code does not take into account geo-referencing 71 73 #if interior_regions is not None: 72 # from utilities.polygon import inside_polygon 73 # 74 # for interior_polygon, res in interior_regions: 75 # indices = inside_polygon(interior_polygon, bounding_polygon, 76 # closed = True, verbose = False) 77 # 78 # if len(indices) <> len(interior_polygon): 79 # msg = 'Interior polygon %s is outside bounding polygon: %s'\ 80 # %(str(interior_polygon), str(bounding_polygon)) 81 # raise msg 74 75 # for interior_polygon, res in interior_regions: 76 # indices = inside_polygon(interior_polygon, bounding_polygon, 77 # closed = True, verbose = False) 78 79 # if len(indices) <> len(interior_polygon): 80 # msg = 'Interior polygon %s is outside bounding polygon: %s'\ 81 # %(str(interior_polygon), str(bounding_polygon)) 82 # raise msg 82 83 83 84 -
inundation/utilities/polygon.py
r2955 r3051 14 14 from math import sqrt 15 15 from utilities.numerical_tools import ensure_numeric 16 16 from geospatial_data.geospatial_data import ensure_absolute 17 17 18 18 def point_on_line(x, y, x0, y0, x1, y1): … … 43 43 44 44 45 def inside_polygon(points, polygon, closed = True, verbose = False): 45 def inside_polygon(points, polygon, closed = True, verbose = False, 46 points_geo_ref=None, polygon_geo_ref=None): 46 47 """Determine points inside a polygon 47 48 … … 56 57 57 58 try: 58 points = ensure_ numeric(points, Float)59 points = ensure_absolute(points, geo_reference=points_geo_ref) 59 60 except NameError, e: 60 61 raise NameError, e … … 64 65 65 66 try: 66 polygon = ensure_ numeric(polygon, Float)67 polygon = ensure_absolute(polygon, geo_reference=polygon_geo_ref) 67 68 except NameError, e: 68 69 raise NameError, e … … 70 71 msg = 'Polygon %s could not be converted to Numeric array' %(str(polygon)) 71 72 raise msg 72 73 74 73 75 74 if len(points.shape) == 1: -
inundation/utilities/test_polygon.py
r2912 r3051 7 7 8 8 from polygon import * 9 9 from coordinate_transforms.geo_reference import Geo_reference 10 10 11 11 def test_function(x, y): … … 624 624 os.remove('test1.png') 625 625 os.remove('test2.png') 626 626 627 628 def test_inside_polygon_geo_ref(self): 629 630 631 #Simplest case: Polygon is the unit square 632 polygon_absolute = [[0,0], [1,0], [1,1], [0,1]] 633 poly_geo_ref = Geo_reference(57,100,100) 634 polygon = poly_geo_ref.change_points_geo_ref(polygon_absolute) 635 636 points_absolute = (0.5, 0.5) 637 points_geo_ref = Geo_reference(57,78,-56) 638 points = points_geo_ref.change_points_geo_ref(points_absolute) 639 640 assert inside_polygon( points_absolute, polygon_absolute) 641 642 points_inside = inside_polygon( points, polygon, 643 polygon_geo_ref=poly_geo_ref, 644 points_geo_ref=points_geo_ref) 645 #print "points_inside",points_inside 646 #assert 1 == len(inside_polygon( points, polygon, 647 # polygon_geo_ref=poly_geo_ref, 648 # points_geo_ref=points_geo_ref)) 649 assert not inside_polygon( (0.5, 1.5), polygon, 650 polygon_geo_ref= poly_geo_ref ) 651 assert not inside_polygon( (0.5, -0.5), polygon, 652 polygon_geo_ref= poly_geo_ref ) 653 assert not inside_polygon( (-0.5, 0.5), polygon, 654 polygon_geo_ref= poly_geo_ref ) 655 assert not inside_polygon( (1.5, 0.5), polygon, 656 polygon_geo_ref= poly_geo_ref ) 627 657 #------------------------------------------------------------- 628 658 if __name__ == "__main__": 629 659 suite = unittest.makeSuite(Test_Polygon,'test') 660 #suite = unittest.makeSuite(Test_Polygon,'test_inside_polygon_geo_ref') 630 661 runner = unittest.TextTestRunner() 631 662 runner.run(suite)
Note: See TracChangeset
for help on using the changeset viewer.