Changeset 3149


Ignore:
Timestamp:
Jun 13, 2006, 4:33:40 PM (18 years ago)
Author:
duncan
Message:

made geospatial.set_geo_reference more flexible.

Location:
inundation/geospatial_data
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • inundation/geospatial_data/geospatial_data.py

    r3056 r3149  
    9898
    9999        self.set_verbose(verbose)
    100 
     100        self.geo_reference=None #create the attribute
    101101        if file_name is None:
    102102            if delimiter is not None:
     
    165165        from coordinate_transforms.geo_reference import Geo_reference
    166166
    167 
    168167        if geo_reference is None:
    169             self.geo_reference = Geo_reference() # Use default
    170         elif isinstance(geo_reference, Geo_reference):
    171             self.geo_reference = geo_reference
    172         else:
     168            geo_reference = Geo_reference() # Use default
     169        if not isinstance(geo_reference, Geo_reference):
    173170            msg = 'Argument geo_reference must be a valid Geo_reference \n'
    174171            msg += 'object or None.'
    175172            raise msg
     173
     174        # if a geo ref already exists, change the point data to
     175        # represent the new geo-ref
     176        if  self.geo_reference is not None:
     177            #print "self.geo_reference",self.geo_reference
     178            #print "geo_reference",geo_reference
     179            #FIXME: Maybe put out a warning here...
     180            self.data_points = geo_reference.change_points_geo_ref \
     181                               (self.data_points,
     182                                self.geo_reference)
     183           
     184        self.geo_reference = geo_reference
    176185
    177186
  • inundation/geospatial_data/test_geospatial_data.py

    r3056 r3149  
    113113            raise 'Should have raised exception'
    114114
    115 
     115    def test_set_geo_reference(self):
     116        points_ab = [[12.5,34.7],[-4.5,-60.0]]
     117        x_p = -10
     118        y_p = -40
     119        geo_ref = Geo_reference(56, x_p, y_p)
     120        points_rel = geo_ref.change_points_geo_ref(points_ab)
     121        spatial = Geospatial_data(points_rel)
     122        # since the geo_ref wasn't set
     123        assert not allclose( points_ab, spatial.get_data_points(absolute=True))
     124       
     125        spatial = Geospatial_data(points_rel, geo_reference=geo_ref)
     126        assert allclose( points_ab, spatial.get_data_points(absolute=True))
     127       
     128        x_p = 10
     129        y_p = 400
     130        new_geo_ref = Geo_reference(56, x_p, y_p)
     131        spatial.set_geo_reference(new_geo_ref)
     132        assert allclose( points_ab, spatial.get_data_points(absolute=True))
     133       
     134       
     135       
    116136    def test_conversions_to_points_dict(self):
    117137        """test conversions to points_dict
     
    11701190
    11711191if __name__ == "__main__":
    1172     #suite = unittest.makeSuite(Test_Geospatial_data, 'test_check_geo_reference1')
     1192    #suite = unittest.makeSuite(Test_Geospatial_data, 'test_set_geo_reference')
    11731193    suite = unittest.makeSuite(Test_Geospatial_data, 'test')
    11741194    runner = unittest.TextTestRunner()
Note: See TracChangeset for help on using the changeset viewer.