Changeset 3614


Ignore:
Timestamp:
Sep 18, 2006, 1:32:48 PM (18 years ago)
Author:
ole
Message:

Updated and tested new convert_from_latlon_to_utm

Location:
anuga_core/source/anuga/coordinate_transforms
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/coordinate_transforms/geo_reference.py

    r3514 r3614  
    237237            other.zone = self.zone           
    238238        else:   
    239             msg = 'Both geospatial_data objects must be in the same \
    240             ZONE to allow reconciliation. I got zone %d and %d'\
    241             %(self.zone, other.zone)
     239            msg = 'Both geospatial_data objects must be in the same '+\
     240                  'ZONE to allow reconciliation. I got zone %d and %d'\
     241                  %(self.zone, other.zone)
    242242            raise ANUGAError, msg
    243243   
  • anuga_core/source/anuga/coordinate_transforms/redfearn.py

    r3613 r3614  
    163163
    164164
    165 # FIXME (Ole)
    166 def convert_points_from_latlon_to_utm(latitudes, longitudes,
     165
     166def convert_points_from_latlon_to_utm(points,
    167167                                      false_easting=None,
    168168                                      false_northing=None):
    169     """Wrapper
    170     """
    171    
    172     return convert_lats_longs(latitudes,
    173                               longitudes,
    174                               false_easting,
    175                               false_northing)
    176 
    177    
    178 
     169    """Convert a list of points given in latitude and longitude to UTM
     170
     171
     172    Input
     173
     174    points: list of points given in decimal degrees (latitude, longitude)
     175    false_easting (optional)
     176    false_northing (optional)
     177
     178    Output
     179
     180    zone:   UTM zone for converted points
     181    points: List of converted points
     182
     183
     184    Notes
     185
     186    Assume the false_easting and false_northing are the same for each list.
     187    If points end up belonging to different UTM zones, an ANUGAerror is thrown.
     188
     189   
     190   
     191    """
     192
     193    old_geo = Geo_reference()   
     194    utm_points = []
     195    for point in points:
     196        zone, easting, northing = redfearn(float(point[0]),
     197                                           float(point[1]),
     198                                           false_easting=false_easting,
     199                                           false_northing=false_northing)
     200
     201        new_geo = Geo_reference(zone)
     202        old_geo.reconcile_zones(new_geo)
     203       
     204        utm_points.append([easting, northing])
     205
     206
     207    return old_geo.get_zone(), utm_points
     208
     209
     210   
     211
     212
     213# FIXME (Ole): Is this not supersedede by the above?
    179214def convert_lats_longs(latitudes,
    180215                       longitudes,
  • anuga_core/source/anuga/coordinate_transforms/test_redfearn.py

    r3514 r3614  
    164164        self.failUnless(zone == 56,
    165165                        'Bad zone error!')
     166       
    166167    def test_convert_lats_longs2(self):
    167168
     
    180181        lats = [lat_gong, lat_2]
    181182        longs = [lon_gong, lon_2]
     183       
    182184        try:
    183185            zone, points = convert_lats_longs(lats, longs)
     
    185187            pass
    186188        else:
    187             self.failUnless(0 ==1,
    188                         'Error not thrown error!')
     189            self.failUnless(False,
     190                            'Error not thrown error!')
    189191           
    190192    def test_convert_lats_longs3(self):
     
    208210            pass
    209211        else:
    210             self.failUnless(0 ==1,
    211                         'Error not thrown error!')
     212            self.failUnless(False,
     213                            'Error not thrown error!')
     214
     215    # Similar test for alternative interface       
     216    def test_convert_latlon_to_UTM1(self):
     217
     218        #Site Name:    GDA-MGA: (UTM with GRS80 ellipsoid)
     219        #Zone:   56   
     220        #Easting:  222908.705  Northing: 6233785.284
     221        #Latitude:   -34  0 ' 0.00000 ''  Longitude: 150  0 ' 0.00000 ''
     222        #Grid Convergence:  -1  40 ' 43.13 ''  Point Scale: 1.00054660
     223
     224        lat_gong = degminsec2decimal_degrees(-34,30,0.)
     225        lon_gong = degminsec2decimal_degrees(150,55,0.)
     226       
     227        lat_2 = degminsec2decimal_degrees(-34,00,0.)
     228        lon_2 = degminsec2decimal_degrees(150,00,0.)
     229       
     230        points = [[lat_gong, lon_gong], [lat_2, lon_2]]
     231        zone, points = convert_points_from_latlon_to_utm(points)
     232
     233        assert allclose(points[0][0], 308728.009)
     234        assert allclose(points[0][1], 6180432.601)
     235        assert allclose(points[1][0],  222908.705)
     236        assert allclose(points[1][1], 6233785.284)
     237        self.failUnless(zone == 56,
     238                        'Bad zone error!')
     239
     240    def test_convert_latlon_to_UTM2(self):       
     241
     242        #Site Name:    GDA-MGA: (UTM with GRS80 ellipsoid)
     243        #Zone:   56   
     244        #Easting:  222908.705  Northing: 6233785.284
     245        #Latitude:   -34  0 ' 0.00000 ''  Longitude: 150  0 ' 0.00000 ''
     246        #Grid Convergence:  -1  40 ' 43.13 ''  Point Scale: 1.00054660
     247
     248        lat_gong = degminsec2decimal_degrees(-34,30,0.)
     249        lon_gong = degminsec2decimal_degrees(150,55,0.)
     250       
     251        lat_2 = degminsec2decimal_degrees(34,00,0.)
     252        lon_2 = degminsec2decimal_degrees(100,00,0.)
     253
     254        points = [[lat_gong, lon_gong], [lat_2, lon_2]]
     255
     256        try:
     257            zone, points = convert_points_from_latlon_to_utm(points)           
     258        except ANUGAError:
     259            pass
     260        else:
     261            self.fail('Error not thrown error!')
     262
     263    def test_convert_latlon_to_UTM3(self):           
     264
     265        #Site Name:    GDA-MGA: (UTM with GRS80 ellipsoid)
     266        #Zone:   56   
     267        #Easting:  222908.705  Northing: 6233785.284
     268        #Latitude:   -34  0 ' 0.00000 ''  Longitude: 150  0 ' 0.00000 ''
     269        #Grid Convergence:  -1  40 ' 43.13 ''  Point Scale: 1.00054660
     270
     271        lat_gong = "-34.5"
     272        lon_gong = "150.916666667"
     273        lat_2 = degminsec2decimal_degrees(34,00,0.)
     274        lon_2 = degminsec2decimal_degrees(100,00,0.)
     275
     276        points = [[lat_gong, lon_gong], [lat_2, lon_2]]
     277
     278        try:
     279            zone, points = convert_points_from_latlon_to_utm(points)                       
     280        except ANUGAError:
     281            pass
     282        else:
     283            self.fail('Error not thrown error!')
     284
     285           
    212286#-------------------------------------------------------------
    213287if __name__ == "__main__":
Note: See TracChangeset for help on using the changeset viewer.