Ignore:
Timestamp:
Sep 4, 2008, 5:22:08 PM (16 years ago)
Author:
ole
Message:

Run time - flow through cross section and some refactoring + clean up

File:
1 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/geospatial_data/geospatial_data.py

    r5729 r5730  
    228228        self.attributes = attributes   
    229229
     230    #def set_geo_reference(self, geo_reference):
     231    #    # FIXME (Ole): Backwards compatibility - deprecate
     232    #    self.setgeo_reference(geo_reference)
    230233
    231234    def set_geo_reference(self, geo_reference):
    232         """
    233         Set's the georeference of geospatial.
    234         It can also be used to change the georeference
     235        """Set the georeference of geospatial data.
     236       
     237        It can also be used to change the georeference and will ensure that
     238        the absolute coordinate values are unchanged.
    235239        """
    236240        from anuga.coordinate_transforms.geo_reference import Geo_reference
    237241
    238242        if geo_reference is None:
    239             geo_reference = Geo_reference() # Use default
     243            # Use default - points are in absolute coordinates
     244            geo_reference = Geo_reference()
     245           
     246        # Allow for tuple (zone, xllcorner, yllcorner)   
    240247        geo_reference = ensure_geo_reference(geo_reference)
     248       
    241249        if not isinstance(geo_reference, Geo_reference):
     250            # FIXME (Ole): This exception will be raised if geo_reference is None
    242251            msg = 'Argument geo_reference must be a valid Geo_reference \n'
    243252            msg += 'object or None.'
    244253            raise msg
    245254
    246         # if a geo ref already exists, change the point data to
    247         # represent the new geo-ref
     255        # If a geo_reference already exists, change the point data according to
     256        # the new geo reference
    248257        if  self.geo_reference is not None:
    249             #FIXME: Maybe put out a warning here...
    250             self.data_points = self.get_data_points \
    251                                (geo_reference=geo_reference)
     258            self.data_points = self.get_data_points(geo_reference=geo_reference)
    252259           
    253260        self.geo_reference = geo_reference
     
    376383            lats_longs = []
    377384            for point in self.get_data_points(True):
    378                 ### UTMtoLL(northing, easting, zone,
     385           
     386                # UTMtoLL(northing, easting, zone,
    379387                lat_calced, long_calced = UTMtoLL(point[1],point[0],
    380388                                                  zone, isSouthHemisphere)
    381389                lats_longs.append((lat_calced, long_calced)) # to hash
    382390            return lats_longs
     391           
    383392        if absolute is True and geo_reference is None:
    384393            return self.geo_reference.get_absolute(self.data_points)
     
    388397                                self.geo_reference)
    389398        else:
     399            # If absolute is False
    390400            return self.data_points
    391401
     
    13151325           
    13161326def ensure_absolute(points, geo_reference=None):
    1317     """
     1327    """Ensure that points are in absolute coordinates.
     1328   
    13181329    This function inputs several formats and
    13191330    outputs one format. - a numeric array of absolute points.
    13201331
    1321     Inputed formats are;
    1322     points: List or numeric array of coordinate pairs [xi, eta] of
     1332    Input formats are;
     1333      points: List or numeric array of coordinate pairs [xi, eta] of
    13231334              points or geospatial object or points file name
    13241335
     
    13281339                 relative to their respective origins.
    13291340    """
    1330     if isinstance(points,type('')):
    1331         #It's a string
    1332         #assume it is a point file
    1333         points = Geospatial_data(file_name = points)
    1334        
    1335     if isinstance(points,Geospatial_data):
    1336         points = points.get_data_points( \
    1337                 absolute = True)
    1338         msg = "Use a Geospatial_data object or a mesh origin. Not both."
     1341
     1342    # Input check
     1343    if isinstance(points, basestring):
     1344        #It's a string - assume it is a point file
     1345        points = Geospatial_data(file_name=points)
     1346       
     1347    if isinstance(points, Geospatial_data):
     1348        points = points.get_data_points(absolute=True)
     1349        msg = 'Use a Geospatial_data object or a mesh origin. Not both.'
    13391350        assert geo_reference == None, msg
    1340            
    13411351    else:
    13421352        points = ensure_numeric(points, Float)
     1353       
     1354    # Sort of geo_reference and convert points
    13431355    if geo_reference is None:
    13441356        geo = None #Geo_reference()
     
    13511363                                geo_reference[2])
    13521364        points = geo.get_absolute(points)
     1365       
     1366    # Return   
    13531367    return points
    13541368     
     
    13681382                 relative to their respective origins.
    13691383    """
    1370     if isinstance(points,Geospatial_data):
     1384   
     1385    # Input check
     1386    if isinstance(points, Geospatial_data):
    13711387        msg = "Use a Geospatial_data object or a mesh origin. Not both."
    1372         assert geo_reference == None, msg
     1388        assert geo_reference is None, msg
    13731389        return points   
    13741390    else:
     1391        # List or numeric array of absolute points
    13751392        points = ensure_numeric(points, Float)
     1393
     1394    # Sort out geo reference   
    13761395    if geo_reference is None:
    13771396        geo = None
     
    13831402                                geo_reference[1],
    13841403                                geo_reference[2])
     1404                               
     1405    # Create Geospatial_data object with appropriate geo reference and return                           
    13851406    points = Geospatial_data(data_points=points, geo_reference=geo)       
    13861407    return points
Note: See TracChangeset for help on using the changeset viewer.