Ignore:
Timestamp:
Mar 24, 2006, 6:07:58 PM (18 years ago)
Author:
ole
Message:

Duncan and Ole refactoring and dealing with georeferencing

File:
1 edited

Legend:

Unmodified
Added
Removed
  • inundation/coordinate_transforms/geo_reference.py

    r2593 r2594  
    77
    88import types, sys
    9 from Numeric import array,Float,ArrayType
     9from Numeric import array,Float,ArrayType,reshape
     10from utilities.numerical_tools import ensure_numeric
    1011
    1112DEFAULT_ZONE = sys.maxint
     
    131132        If the points do not have a geo ref, assume 'absolute' values
    132133        """
     134
     135        # FIXME: Use ensure_numeric
    133136       
    134137        is_list = False
    135138        if type(points) == types.ListType:
    136139            is_list = True
    137             if len(points)>0 and type(points[0]) not in [types.ListType,types.TupleType]:
    138                 #a single point is being passed.  make it a list of lists
    139                 points = [points]
    140         elif type(points) == ArrayType:
    141             if len(points.shape) == 1:
    142                 points = [points]
    143        
    144         # FIXME: currently untested
    145         # Always returns a list of lists
    146         if points_geo_ref is self:
    147             return points       
    148            
    149         #convert into array
    150         points = array(points).astype(Float)
    151         #add point geo ref to points
    152         if not points_geo_ref is None:
    153             points[:,0] += points_geo_ref.xllcorner
    154             points[:,1] += points_geo_ref.yllcorner
    155        
    156         #subtract primary geo ref from points
    157         points[:,0] -= self.xllcorner
    158         points[:,1] -= self.yllcorner
     140
     141        points = ensure_numeric(points)
     142        if len(points.shape) == 1:
     143            #One point has been passed
     144            msg = 'Single point must have two elements'
     145            assert len(points) == 2, msg
     146            points = reshape(points, (1,2))
     147
     148           
     149        if points_geo_ref is not self:
     150            #add point geo ref to points
     151            if not points_geo_ref is None:
     152                points[:,0] += points_geo_ref.xllcorner
     153                points[:,1] += points_geo_ref.yllcorner
     154       
     155            #subtract primary geo ref from points
     156            points[:,0] -= self.xllcorner
     157            points[:,1] -= self.yllcorner
     158
     159           
    159160        if is_list:
    160161            points = points.tolist()
     162           
    161163        return points
     164   
    162165   
    163166    def get_absolute(self, points):
     
    188191        return points
    189192
     193
     194    def reconcile_zones(self, other):
     195
     196        if self.zone == other.zone or self.zone == DEFAULT_ZONE and other.zone == DEFAULT_ZONE:
     197            pass
     198        elif self.zone == DEFAULT_ZONE:
     199            self.zone = other.zone
     200        elif other.zone == DEFAULT_ZONE:
     201            other.zone = self.zone           
     202        else:   
     203            msg = 'Both geospatial_data objects must be in the same \
     204            ZONE to allow reconciliation. I got zone %d and %d' %(self.zone, other.zone)
     205            raise msg
    190206   
    191207    #def easting_northing2geo_reffed_point(self, x, y):
Note: See TracChangeset for help on using the changeset viewer.