Changeset 3297


Ignore:
Timestamp:
Jul 10, 2006, 4:22:33 PM (17 years ago)
Author:
duncan
Message:

in geospatial_data.py let data_points be lats and longs

Location:
inundation/geospatial_data
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • inundation/geospatial_data/geospatial_data.py

    r3280 r3297  
    2323                 latitudes = None,
    2424                 longitudes = None,
     25                 points_are_lats_longs = False,
    2526                 verbose = False):
    2627
     
    105106                raise ValueError, msg
    106107            file_name = None
    107             if latitudes is not None or longitudes is not None:
     108            if latitudes is not None or longitudes is not None or \
     109                   points_are_lats_longs:
    108110                data_points, geo_reference =  \
    109111                             self._set_using_lat_long(latitudes=latitudes,
    110                                                   longitudes=longitudes,
    111                                                   geo_reference=geo_reference,
    112                                                   data_points=data_points)
     112                                  longitudes=longitudes,
     113                                  geo_reference=geo_reference,
     114                                  data_points=data_points,
     115                                  points_are_lats_longs=points_are_lats_longs)
    113116            self.check_data_points(data_points)
    114117            self.set_attributes(attributes)
     
    202205                            longitudes,
    203206                            geo_reference,
    204                             data_points):
     207                            data_points,
     208                            points_are_lats_longs):
    205209        if geo_reference is not None:
    206210            msg = """A georeference is specified yet latitude and longitude are also specified!"""
    207211            raise ValueError, msg
    208          
    209         if data_points is not None:
     212        if data_points is not None and not points_are_lats_longs:
    210213            msg = """Data points are specified yet latitude and longitude are also specified!"""
     214            raise ValueError, msg
     215       
     216        if points_are_lats_longs:
     217            if data_points is None:
     218                msg = """Data points are not specified !"""
     219                raise ValueError, msg
     220            lats_longs = ensure_numeric(data_points)
     221            latitudes = lats_longs[:,0:1]
     222            longitudes = lats_longs[:,1:]
     223           
     224        if latitudes is None and longitudes is None:
     225            msg = """Latitudes and Longitudes are not."""
    211226            raise ValueError, msg
    212227       
     
    216231       
    217232        if longitudes is None:
    218             msg = """latitudes are specified yet longitudes aren't!"""
     233            msg = """Latitudes are specified yet longitudes aren't!"""
    219234            raise ValueError, msg
    220235       
  • inundation/geospatial_data/test_geospatial_data.py

    r3292 r3297  
    13021302        else:
    13031303            self.failUnless(0 ==1,  'Error not thrown error!')
    1304            
     1304
     1305    def test_lat_long2(self):
     1306        lat_gong = degminsec2decimal_degrees(-34,30,0.)
     1307        lon_gong = degminsec2decimal_degrees(150,55,0.)
     1308       
     1309        lat_2 = degminsec2decimal_degrees(-34,00,0.)
     1310        lon_2 = degminsec2decimal_degrees(150,00,0.)
     1311       
     1312        points = [[lat_gong, lon_gong], [lat_2, lon_2]]
     1313        gsd = Geospatial_data(data_points=points, points_are_lats_longs=True)
     1314
     1315        points = gsd.get_data_points(absolute=True)
     1316       
     1317        assert allclose(points[0][0], 308728.009)
     1318        assert allclose(points[0][1], 6180432.601)
     1319        assert allclose(points[1][0],  222908.705)
     1320        assert allclose(points[1][1], 6233785.284)
     1321        self.failUnless(gsd.get_geo_reference().get_zone() == 56,
     1322                        'Bad zone error!')
     1323
     1324        try:
     1325            results = Geospatial_data(points_are_lats_longs=True)
     1326        except ValueError:
     1327            pass
     1328        else:
     1329            self.failUnless(0 ==1,  'Error not thrown error!')
     1330
    13051331if __name__ == "__main__":
    13061332
Note: See TracChangeset for help on using the changeset viewer.