Changeset 3056 for inundation/geospatial_data
- Timestamp:
- Jun 2, 2006, 3:10:48 PM (19 years ago)
- Location:
- inundation/geospatial_data
- Files:
-
- 2 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):
Note: See TracChangeset
for help on using the changeset viewer.