Changeset 3056 for inundation
- Timestamp:
- Jun 2, 2006, 3:10:48 PM (19 years ago)
- Location:
- inundation
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/geospatial_data/geospatial_data.py
r3051 r3056 704 704 return points 705 705 706 706 707 def ensure_geospatial(points, geo_reference = None): 708 """ 709 This function inputs several formats and 710 outputs one format. - a geospatial_data instance. 711 712 Inputed formats are; 713 points: List or numeric array of coordinate pairs [xi, eta] of 714 points or geospatial object 715 716 mesh_origin: A geo_reference object or 3-tuples consisting of 717 UTM zone, easting and northing. 718 If specified vertex coordinates are assumed to be 719 relative to their respective origins. 720 """ 721 if isinstance(points,Geospatial_data): 722 #points = points.get_data_points( \ 723 # absolute = True) 724 msg = "Use a Geospatial_data object or a mesh origin. Not both." 725 assert geo_reference == None, msg 726 727 else: 728 points = ensure_numeric(points, Float) 729 if geo_reference is None: 730 geo = None #Geo_reference() 731 else: 732 if isinstance(geo_reference, Geo_reference): 733 geo = geo_reference 734 else: 735 geo = Geo_reference(geo_reference[0], 736 geo_reference[1], 737 geo_reference[2]) 738 points = Geospatial_data(data_points=points, geo_reference=geo) 739 #points = geo.get_absolute(points) 740 return points 741 -
inundation/geospatial_data/test_geospatial_data.py
r2996 r3056 990 990 991 991 assert allclose(new_points, ab_points) 992 993 994 def test_ensure_geospatial(self): 995 points = [[2.0, 0.0],[1.0, 1.0], 996 [2.0, 0.0],[2.0, 2.0], 997 [1.0, 3.0],[2.0, 2.0]] 998 new_points = ensure_absolute(points) 999 1000 assert allclose(new_points, points) 1001 1002 points = array([[2.0, 0.0],[1.0, 1.0], 1003 [2.0, 0.0],[2.0, 2.0], 1004 [1.0, 3.0],[2.0, 2.0]]) 1005 new_points = ensure_absolute(points) 1006 1007 assert allclose(new_points, points) 1008 1009 ab_points = array([[2.0, 0.0],[1.0, 1.0], 1010 [2.0, 0.0],[2.0, 2.0], 1011 [1.0, 3.0],[2.0, 2.0]]) 1012 1013 mesh_origin = (56, 290000, 618000) #zone, easting, northing 1014 1015 data_points = zeros((ab_points.shape), Float) 1016 #Shift datapoints according to new origins 1017 for k in range(len(ab_points)): 1018 data_points[k][0] = ab_points[k][0] - mesh_origin[1] 1019 data_points[k][1] = ab_points[k][1] - mesh_origin[2] 1020 #print "data_points",data_points 1021 new_geospatial = ensure_geospatial(data_points, 1022 geo_reference=mesh_origin) 1023 new_points = new_geospatial.get_data_points(absolute=True) 1024 #print "new_points",new_points 1025 #print "ab_points",ab_points 1026 1027 assert allclose(new_points, ab_points) 1028 1029 geo = Geo_reference(56,67,-56) 1030 1031 data_points = geo.change_points_geo_ref(ab_points) 1032 new_geospatial = ensure_geospatial(data_points, 1033 geo_reference=geo) 1034 new_points = new_geospatial.get_data_points(absolute=True) 1035 #print "new_points",new_points 1036 #print "ab_points",ab_points 1037 1038 assert allclose(new_points, ab_points) 1039 1040 1041 geo_reference = Geo_reference(56, 100, 200) 1042 ab_points = [[1.0, 2.1], [3.0, 5.3]] 1043 points = geo_reference.change_points_geo_ref(ab_points) 1044 attributes = [2, 4] 1045 #print "geo in points", points 1046 G = Geospatial_data(points, attributes, 1047 geo_reference=geo_reference) 1048 1049 new_geospatial = ensure_geospatial(G) 1050 new_points = new_geospatial.get_data_points(absolute=True) 1051 #print "new_points",new_points 1052 #print "ab_points",ab_points 1053 1054 assert allclose(new_points, ab_points) 992 1055 993 1056 def test_isinstance(self): -
inundation/pmesh/mesh_interface.py
r3051 r3056 17 17 from mesh import Mesh 18 18 19 import exceptions 20 class PolygonError(exceptions.Exception): pass 19 21 20 22 def create_mesh_from_regions(bounding_polygon, … … 44 46 45 47 poly_geo_reference is the geo_reference of the polygons. 48 The bounding polygon and the interior polygons 46 49 If none, assume absolute. Please pass one though, since absolute 47 50 references have a zone. … … 61 64 # To do make maximum_triangle_area optional? 62 65 # check the segment indexes - throw an error if they are out of bounds 63 # 66 #(DSG) Yes! 67 64 68 #In addition I reckon the polygons could be of class Geospatial_data 65 69 #(DSG) Yes! 66 70 67 71 # First check that interior polygons are fully contained in bounding polygon 68 69 # FIXME (Ole): This causes the tests to fail because coordinates have been 70 # converted to relative coordinates (I think). How can we simplify this? 71 # 72 #FIXME (DSG-DSG) this code does not take into account geo-referencing 73 #if interior_regions is not None: 72 #Note, Both poly's have the same geo_ref, therefore don't take into account 73 # geo_ref 74 if interior_regions is not None: 74 75 75 #for interior_polygon, res in interior_regions:76 #indices = inside_polygon(interior_polygon, bounding_polygon,77 #closed = True, verbose = False)76 for interior_polygon, res in interior_regions: 77 indices = inside_polygon(interior_polygon, bounding_polygon, 78 closed = True, verbose = False) 78 79 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 # raisemsg80 if len(indices) <> len(interior_polygon): 81 msg = 'Interior polygon %s is outside bounding polygon: %s'\ 82 %(str(interior_polygon), str(bounding_polygon)) 83 raise PolygonError, msg 83 84 84 85 -
inundation/pmesh/test_mesh_interface.py
r3052 r3056 113 113 114 114 # These are the absolute values 115 min_x = 10116 min_y = 88115 min_x = -10 116 min_y = -88 117 117 polygon_absolute = [[min_x,min_y],[1000,100],[1000,1000],[100,1000]] 118 118 … … 170 170 171 171 # These are the absolute values 172 min_x = 10173 min_y = 88172 min_x = -10 173 min_y = -88 174 174 polygon = [[min_x,min_y],[1000,100],[1000,1000],[100,1000]] 175 175 … … 221 221 'FAILED!') 222 222 223 def NOT_IMPLEMEMTED_test_create_mesh_from_regions_interior_regions(self):223 def test_create_mesh_from_regions_interior_regions(self): 224 224 ### Test that create_mesh_from_regions fails when an interior region is 225 225 ### outside bounding polygon. … … 301 301 suite = unittest.makeSuite(TestCase,'test') 302 302 #suite = unittest.makeSuite(meshTestCase,'test_asciiFile') 303 runner = unittest.TextTestRunner( verbosity=2) #verbosity=2)303 runner = unittest.TextTestRunner() #verbosity=2) 304 304 runner.run(suite) 305 305
Note: See TracChangeset
for help on using the changeset viewer.