Changeset 3280 for inundation
- Timestamp:
- Jul 5, 2006, 5:17:40 PM (18 years ago)
- Location:
- inundation
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/coordinate_transforms/redfearn.py
r2253 r3280 2 2 3 3 """ 4 from coordinate_transforms.geo_reference import Geo_reference, DEFAULT_ZONE 4 5 5 6 def degminsec2decimal_degrees(dd,mm,ss): … … 159 160 160 161 return zone, easting, northing 162 163 def convert_lats_longs(latitudes, 164 longitudes, 165 false_easting=None, 166 false_northing=None): 167 """ 168 Redfearn a list of latitudes and longitudes. 169 170 Assume the false_easting and false_northing are the same for each list. 171 172 Note, if a zone turns out to be different, an ANUGAerror is thrown. 173 """ 174 # Using geo_ref so there is only one point in the code where zones 175 # are checked. 176 old_geo = Geo_reference() 177 points = [] 178 179 for lat, long in map(None, latitudes, longitudes,): 180 zone, easting, northing = redfearn(lat, 181 long, 182 false_easting=false_easting, 183 false_northing=false_northing) 184 new_geo = Geo_reference(zone) 185 old_geo.reconcile_zones(new_geo) 186 #print "old_geo.get_zone()", old_geo.get_zone() 187 points.append([easting, northing]) 188 189 return old_geo.get_zone(), points -
inundation/coordinate_transforms/test_redfearn.py
r2253 r3280 7 7 8 8 import unittest 9 from redfearn import *10 9 from Numeric import allclose 11 10 11 from redfearn import * 12 from utilities.anuga_exceptions import ANUGAError 12 13 13 14 #------------------------------------------------------------- … … 139 140 # #assert allclose(northing, 6181725.1724276) 140 141 142 def test_convert_lats_longs(self): 141 143 144 #Site Name: GDA-MGA: (UTM with GRS80 ellipsoid) 145 #Zone: 56 146 #Easting: 222908.705 Northing: 6233785.284 147 #Latitude: -34 0 ' 0.00000 '' Longitude: 150 0 ' 0.00000 '' 148 #Grid Convergence: -1 40 ' 43.13 '' Point Scale: 1.00054660 149 150 lat_gong = degminsec2decimal_degrees(-34,30,0.) 151 lon_gong = degminsec2decimal_degrees(150,55,0.) 152 153 lat_2 = degminsec2decimal_degrees(-34,00,0.) 154 lon_2 = degminsec2decimal_degrees(150,00,0.) 155 156 lats = [lat_gong, lat_2] 157 longs = [lon_gong, lon_2] 158 zone, points = convert_lats_longs(lats, longs) 159 160 assert allclose(points[0][0], 308728.009) 161 assert allclose(points[0][1], 6180432.601) 162 assert allclose(points[1][0], 222908.705) 163 assert allclose(points[1][1], 6233785.284) 164 self.failUnless(zone == 56, 165 'Bad zone error!') 166 def test_convert_lats_longs2(self): 167 168 #Site Name: GDA-MGA: (UTM with GRS80 ellipsoid) 169 #Zone: 56 170 #Easting: 222908.705 Northing: 6233785.284 171 #Latitude: -34 0 ' 0.00000 '' Longitude: 150 0 ' 0.00000 '' 172 #Grid Convergence: -1 40 ' 43.13 '' Point Scale: 1.00054660 173 174 lat_gong = degminsec2decimal_degrees(-34,30,0.) 175 lon_gong = degminsec2decimal_degrees(150,55,0.) 176 177 lat_2 = degminsec2decimal_degrees(34,00,0.) 178 lon_2 = degminsec2decimal_degrees(100,00,0.) 179 180 lats = [lat_gong, lat_2] 181 longs = [lon_gong, lon_2] 182 try: 183 zone, points = convert_lats_longs(lats, longs) 184 except ANUGAError: 185 pass 186 else: 187 self.failUnless(0 ==1, 188 'Error not thrown error!') 142 189 143 190 #------------------------------------------------------------- -
inundation/geospatial_data/geospatial_data.py
r3266 r3280 4 4 """ 5 5 6 from os import access, F_OK, R_OK 7 from Numeric import concatenate, array, Float, shape 6 8 7 9 from utilities.numerical_tools import ensure_numeric 8 9 from Numeric import concatenate, array, Float, shape10 11 10 from coordinate_transforms.geo_reference import Geo_reference, TitleError 12 13 from os import access, F_OK, R_OK 11 from coordinate_transforms.redfearn import convert_lats_longs 12 14 13 15 14 class Geospatial_data: … … 22 21 file_name = None, 23 22 delimiter = None, 23 latitudes = None, 24 longitudes = None, 24 25 verbose = False): 25 26 … … 104 105 raise ValueError, msg 105 106 file_name = None 107 if latitudes is not None or longitudes is not None: 108 data_points, geo_reference = \ 109 self._set_using_lat_long(latitudes=latitudes, 110 longitudes=longitudes, 111 geo_reference=geo_reference, 112 data_points=data_points) 106 113 self.check_data_points(data_points) 107 114 self.set_attributes(attributes) … … 191 198 verbose = False 192 199 200 def _set_using_lat_long(self, 201 latitudes, 202 longitudes, 203 geo_reference, 204 data_points): 205 if geo_reference is not None: 206 msg = """A georeference is specified yet latitude and longitude are also specified!""" 207 raise ValueError, msg 208 209 if data_points is not None: 210 msg = """Data points are specified yet latitude and longitude are also specified!""" 211 raise ValueError, msg 212 213 if latitudes is None: 214 msg = """Longitudes are specified yet latitudes aren't!""" 215 raise ValueError, msg 216 217 if longitudes is None: 218 msg = """latitudes are specified yet longitudes aren't!""" 219 raise ValueError, msg 220 221 zone, data_points = convert_lats_longs(latitudes, longitudes) 222 223 return data_points, Geo_reference(zone=zone) 224 193 225 def get_geo_reference(self): 194 226 return self.geo_reference -
inundation/geospatial_data/test_geospatial_data.py
r3266 r3280 9 9 10 10 from geospatial_data import * 11 12 11 from coordinate_transforms.geo_reference import Geo_reference, TitleError 12 from coordinate_transforms.redfearn import degminsec2decimal_degrees 13 13 14 14 15 class Test_Geospatial_data(unittest.TestCase): … … 1247 1248 1248 1249 1250 1251 def test_lat_long(self): 1252 lat_gong = degminsec2decimal_degrees(-34,30,0.) 1253 lon_gong = degminsec2decimal_degrees(150,55,0.) 1254 1255 lat_2 = degminsec2decimal_degrees(-34,00,0.) 1256 lon_2 = degminsec2decimal_degrees(150,00,0.) 1257 1258 lats = [lat_gong, lat_2] 1259 longs = [lon_gong, lon_2] 1260 gsd = Geospatial_data(latitudes=lats, longitudes=longs) 1261 1262 points = gsd.get_data_points(absolute=True) 1263 1264 assert allclose(points[0][0], 308728.009) 1265 assert allclose(points[0][1], 6180432.601) 1266 assert allclose(points[1][0], 222908.705) 1267 assert allclose(points[1][1], 6233785.284) 1268 self.failUnless(gsd.get_geo_reference().get_zone() == 56, 1269 'Bad zone error!') 1270 1271 try: 1272 results = Geospatial_data(latitudes=lats) 1273 except ValueError: 1274 pass 1275 else: 1276 self.failUnless(0 ==1, 1277 'Error not thrown error!') 1278 try: 1279 results = Geospatial_data(latitudes=lats) 1280 except ValueError: 1281 pass 1282 else: 1283 self.failUnless(0 ==1, 1284 'Error not thrown error!') 1285 try: 1286 results = Geospatial_data(longitudes=lats) 1287 except ValueError: 1288 pass 1289 else: 1290 self.failUnless(0 ==1, 1291 'Error not thrown error!') 1292 try: 1293 results = Geospatial_data(latitudes=lats, longitudes=longs, 1294 geo_reference="p") 1295 except ValueError: 1296 pass 1297 else: 1298 self.failUnless(0 ==1, 1299 'Error not thrown error!') 1300 1301 try: 1302 results = Geospatial_data(latitudes=lats, longitudes=longs, 1303 data_points=12) 1304 except ValueError: 1305 pass 1306 else: 1307 self.failUnless(0 ==1, 1308 'Error not thrown error!') 1309 1249 1310 if __name__ == "__main__": 1250 1311 1251 #suite = unittest.makeSuite(Test_Geospatial_data, 'test_ isinstance')1312 #suite = unittest.makeSuite(Test_Geospatial_data, 'test_lat_long') 1252 1313 suite = unittest.makeSuite(Test_Geospatial_data, 'test') 1253 1314 runner = unittest.TextTestRunner()
Note: See TracChangeset
for help on using the changeset viewer.