Changeset 2489


Ignore:
Timestamp:
Mar 7, 2006, 11:33:08 AM (18 years ago)
Author:
nick
Message:

Geospatial_data addition finished

Location:
inundation/geospatial_data
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • inundation/geospatial_data/geospatial_data.py

    r2472 r2489  
    88
    99from Numeric import concatenate
     10
     11from coordinate_transforms.geo_reference import Geo_reference
    1012       
    1113class Geospatial_data:
     
    8587            self.geo_reference = geo_reference
    8688        else:
    87             msg = 'Argument geo_reference must be a valid Geo_reference \
    88                     object or None.'
     89            msg = 'Argument geo_reference must be a valid Geo_reference \n'
     90            msg += 'object or None.'
    8991            raise msg
    9092
     
    134136        """
    135137
    136         a_points = self.get_data_points()
    137         b_points = other.get_data_points()
    138        
    139         a_attribute_keys = self.attributes.keys()
    140         b_attribute_keys = other.attributes.keys()
    141        
     138        # sets xll and yll as the smallest from self and other
     139        if self.geo_reference.xllcorner <= other.geo_reference.xllcorner:
     140            xll = self.geo_reference.xllcorner
     141        else:
     142            xll = other.geo_reference.xllcorner
     143
     144        if self.geo_reference.yllcorner <= other.geo_reference.yllcorner:
     145            yll = self.geo_reference.yllcorner
     146        else:
     147            yll = other.geo_reference.yllcorner
     148
     149        # find objects zone and checks if the same
    142150        geo_ref1 = self.get_geo_reference()
    143151        zone1 = geo_ref1.get_zone()
     
    146154        zone2 = geo_ref2.get_zone()
    147155       
    148         if zone1 == zone2:  # and some more checks to add
    149            
    150             c_points = concatenate((a_points, b_points), axis = 0)
     156        geo_ref = Geo_reference(zone1, xll, yll)
     157       
     158        if zone1 == zone2: 
     159            a_rel_points = self.get_data_points()
     160            b_rel_points = other.get_data_points()
     161           
     162            # subtracts xll and yll from self's and other's
     163            # reletive data point and concatenates
     164            c_points = concatenate((a_rel_points-[xll, yll],
     165                                    b_rel_points-[xll, yll]), axis = 0)
     166
    151167            new_dictionary = {}
    152168            for x in self.attributes.keys():
    153169                if other.attributes.has_key(x):
    154170
    155                     attrib_a = self.attributes[x]
    156                     attrib_b = other.attributes[x]
    157                     new_dictionary[x] = concatenate((attrib_a, attrib_b))
     171                    a_attrib = self.attributes[x]
     172                    b_attrib = other.attributes[x]
     173                    new_dictionary[x] = concatenate((a_attrib, b_attrib))
    158174
    159175                else:
    160176                    msg = 'Both geospatial_data objects must have the same \n'
    161 #                    msg += 'attributes to allow addition.'
     177                    msg += 'attributes to allow addition.'
    162178                    raise msg
    163179 
    164             return Geospatial_data(c_points, new_dictionary)
     180            return Geospatial_data(c_points, new_dictionary, geo_ref)
    165181           
    166182        else:
     
    168184            ZONE to allow addition.'
    169185            raise msg
    170 
    171 
    172 #        else:
    173 #            print 'zones are not the same'
    174            
    175        
    176 
    177    
    178      
    179        
     186     
    180187
    181188
  • inundation/geospatial_data/test_geospatial_data.py

    r2473 r2489  
    208208                                              [1.0, 2.1], [3.0, 5.3]])
    209209       
    210     def xtest_add1 (self):
     210    def test_add1 (self):
    211211        """
    212212        difference in Geo_reference resolved
     
    228228        assert allclose(G.get_geo_reference().get_xllcorner(), 0.1)
    229229        assert allclose(G.get_geo_reference().get_yllcorner(), 2.0)
    230         assert allclose(G.get_data_points(), [[2.0, 4.1], [4.0, 7.3], [5.1, 9.3], [6.1, 6.3]])                             
     230#        print 'G data points=', G.get_data_points()
     231        assert allclose(G.get_data_points(), [[2.0, 4.1], [4.0, 7.3], [5.1, 9.1], [6.1, 6.3]])                             
    231232
    232233    def xtest_create_from_file(self):
Note: See TracChangeset for help on using the changeset viewer.