Changeset 2890
- Timestamp:
- May 17, 2006, 12:10:51 PM (18 years ago)
- Location:
- inundation/geospatial_data
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/geospatial_data/geospatial_data.py
r2889 r2890 1023 1023 G.export_points_file(results_file) 1024 1024 1025 def point_info2absolute_array(point, mesh_origin = None): 1025 # ' 1026 def ensure_absolute(points, geo_reference = None): 1026 1027 """ 1027 1028 This function inputs several formats and 1028 outputs one format. - 1029 """ 1030 pass 1031 1029 outputs one format. - a numeric array of absolute points. 1030 1031 Inputed formats are; 1032 points: List or numeric array of coordinate pairs [xi, eta] of 1033 points or geospatial object 1034 1035 mesh_origin: A geo_reference object or 3-tuples consisting of 1036 UTM zone, easting and northing. 1037 If specified vertex coordinates are assumed to be 1038 relative to their respective origins. 1039 """ 1040 if isinstance(points,Geospatial_data): 1041 points = points.get_data_points( \ 1042 absolute = True) 1043 msg = "Use a Geospatial_data object or a mesh origin. Not both." 1044 assert geo_reference == None, msg 1045 1046 else: 1047 points = ensure_numeric(points, Float) 1048 1049 if geo_reference is None: 1050 geo = None #Geo_reference() 1051 else: 1052 if isinstance(geo_reference, Geo_reference): 1053 geo = geo_reference 1054 else: 1055 geo = Geo_reference(geo_reference[0], 1056 geo_reference[1], 1057 geo_reference[2]) 1058 points = geo.get_absolute(points) 1059 return points 1032 1060 1033 1061 -
inundation/geospatial_data/test_geospatial_data.py
r2698 r2890 950 950 os.remove(results_file) 951 951 952 953 952 953 def test_ensure_absolute(self): 954 points = [[2.0, 0.0],[1.0, 1.0], 955 [2.0, 0.0],[2.0, 2.0], 956 [1.0, 3.0],[2.0, 2.0]] 957 new_points = ensure_absolute(points) 958 959 assert allclose(new_points, points) 960 961 points = array([[2.0, 0.0],[1.0, 1.0], 962 [2.0, 0.0],[2.0, 2.0], 963 [1.0, 3.0],[2.0, 2.0]]) 964 new_points = ensure_absolute(points) 965 966 assert allclose(new_points, points) 967 968 ab_points = array([[2.0, 0.0],[1.0, 1.0], 969 [2.0, 0.0],[2.0, 2.0], 970 [1.0, 3.0],[2.0, 2.0]]) 971 972 mesh_origin = (56, 290000, 618000) #zone, easting, northing 973 974 data_points = zeros((ab_points.shape), Float) 975 #Shift datapoints according to new origins 976 for k in range(len(ab_points)): 977 data_points[k][0] = ab_points[k][0] - mesh_origin[1] 978 data_points[k][1] = ab_points[k][1] - mesh_origin[2] 979 #print "data_points",data_points 980 new_points = ensure_absolute(data_points, 981 geo_reference = mesh_origin) 982 #print "new_points",new_points 983 #print "ab_points",ab_points 984 985 assert allclose(new_points, ab_points) 986 987 geo = Geo_reference(56,67,-56) 988 989 data_points = geo.change_points_geo_ref(ab_points) 990 new_points = ensure_absolute(data_points, 991 geo_reference = geo) 992 #print "new_points",new_points 993 #print "ab_points",ab_points 994 995 assert allclose(new_points, ab_points) 996 997 998 geo_reference = Geo_reference(56, 100, 200) 999 ab_points = [[1.0, 2.1], [3.0, 5.3]] 1000 points = geo_reference.change_points_geo_ref(ab_points) 1001 attributes = [2, 4] 1002 #print "geo in points", points 1003 G = Geospatial_data(points, attributes, 1004 geo_reference = geo_reference) 1005 1006 new_points = ensure_absolute(G) 1007 #print "new_points",new_points 1008 #print "ab_points",ab_points 1009 1010 assert allclose(new_points, ab_points) 1011 954 1012 if __name__ == "__main__": 955 #suite = unittest.makeSuite(Test_Geospatial_data, 'test_ create_from_pts_file_with_geo')1013 #suite = unittest.makeSuite(Test_Geospatial_data, 'test_ensure_absolute') 956 1014 suite = unittest.makeSuite(Test_Geospatial_data, 'test') 957 1015 runner = unittest.TextTestRunner()
Note: See TracChangeset
for help on using the changeset viewer.