Django

Code

Changeset 6707

Show
Ignore:
Timestamp:
11/20/07 09:10:20 (8 months ago)
Author:
jbronn
Message:

gis: gdal: Fixed memory leak introduced in the refactor caused by unnecessary cloning of SpatialReference? objects from Features; fixed windows-compatibility issues (no error code returned by some destruction routines by windows libraries); OFTDate/Time fields return None if invalid date is encountered (thanks tlp).

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/gis/django/contrib/gis/gdal/feature.py

    r6686 r6707  
    3434 
    3535    def __getitem__(self, index): 
    36         "Gets the Field at the specified index." 
     36        """ 
     37        Gets the Field object at the specified index, which may be either 
     38        an integer or the Field's string label.  Note that the Field object 
     39        is not the field's _value_ -- use the `get` method instead to  
     40        retrieve the value (e.g. an integer) instead of a Field instance. 
     41        """ 
    3742        if isinstance(index, basestring): 
    3843            i = self.index(index) 
     
    8792        # Retrieving the geometry pointer for the feature. 
    8893        geom_ptr = get_feat_geom_ref(self._ptr) 
     94        return OGRGeometry(clone_geom(geom_ptr)) 
    8995 
    90         # Attempting to retrieve the Spatial Reference for the geometry. 
    91         try: 
    92             srs_ptr = get_geom_srs(geom_ptr) 
    93             srs = SpatialReference(clone_srs(srs_ptr))  
    94         except OGRException: 
    95             srs = None 
    96         # Geometry is cloned so the feature isn't invalidated.  
    97         return OGRGeometry(clone_geom(geom_ptr), srs) 
    98      
    9996    @property 
    10097    def geom_type(self): 
     
    106103        """ 
    107104        Returns the value of the field, instead of an instance of the Field 
    108         object.  May take a string of the field name or a Field object as 
    109         parameters. 
     105        object.  May take a string of the field name or a Field object as 
     106        parameters. 
    110107        """ 
    111108        field_name = getattr(field, 'name', field) 
  • django/branches/gis/django/contrib/gis/gdal/field.py

    r6686 r6707  
    129129        "Returns a Python `date` object for the OFTDate field." 
    130130        yy, mm, dd, hh, mn, ss, tz = self.as_datetime() 
    131         return date(yy.value, mm.value, dd.value) 
     131        try: 
     132            return date(yy.value, mm.value, dd.value) 
     133        except ValueError: 
     134            return None 
    132135 
    133136class OFTDateTime(Field): 
     
    140143        #  The `tz` variable has values of: 0=unknown, 1=localtime (ambiguous),  
    141144        #  100=GMT, 104=GMT+1, 80=GMT-5, etc. 
    142         return datetime(yy.value, mm.value, dd.value, hh.value, mn.value, ss.value) 
     145        try: 
     146            return datetime(yy.value, mm.value, dd.value, hh.value, mn.value, ss.value) 
     147        except ValueError: 
     148            return None 
    143149 
    144150class OFTTime(Field): 
     
    147153        "Returns a Python `time` object for this OFTTime field." 
    148154        yy, mm, dd, hh, mn, ss, tz = self.as_datetime() 
    149         return time(hh.value, mn.value, ss.value) 
     155        try: 
     156            return time(hh.value, mn.value, ss.value) 
     157        except ValueError: 
     158            return None 
    150159 
    151160# List fields are also just subclasses 
  • django/branches/gis/django/contrib/gis/gdal/libgdal.py

    r6686 r6707  
    77    # Windows NT shared library 
    88    lib_name = 'libgdal-1.dll' 
     9    errcheck_flag = False 
    910elif os.name == 'posix': 
    1011    platform = os.uname()[0] 
     
    1516        # Attempting to use .so extension for all other platforms. 
    1617        lib_name = 'libgdal.so' 
     18    errcheck_flag = True 
    1719else: 
    1820    raise OGRException('Unsupported OS "%s"' % os.name) 
  • django/branches/gis/django/contrib/gis/gdal/prototypes/ds.py

    r6686 r6707  
    66from ctypes import c_char_p, c_int, c_long, c_void_p, POINTER 
    77from django.contrib.gis.gdal.envelope import OGREnvelope 
    8 from django.contrib.gis.gdal.libgdal import lgdal 
     8from django.contrib.gis.gdal.libgdal import lgdal, errcheck_flag 
    99from django.contrib.gis.gdal.prototypes.generation import \ 
    1010    const_string_output, double_output, geom_output, int_output, \ 
     
    4848### Feature Routines ### 
    4949clone_feature = voidptr_output(lgdal.OGR_F_Clone, [c_void_p]) 
    50 destroy_feature = void_output(lgdal.OGR_F_Destroy, [c_void_p]
     50destroy_feature = void_output(lgdal.OGR_F_Destroy, [c_void_p], errcheck=errcheck_flag
    5151feature_equal = int_output(lgdal.OGR_F_Equal, [c_void_p, c_void_p]) 
    5252get_feat_geom_ref = geom_output(lgdal.OGR_F_GetGeometryRef, [c_void_p]) 
  • django/branches/gis/django/contrib/gis/gdal/prototypes/geom.py

    r6686 r6707  
    11from ctypes import c_char, c_char_p, c_double, c_int, c_ubyte, c_void_p, POINTER 
    22from django.contrib.gis.gdal.envelope import OGREnvelope 
    3 from django.contrib.gis.gdal.libgdal import lgdal 
     3from django.contrib.gis.gdal.libgdal import lgdal, errcheck_flag 
    44from django.contrib.gis.gdal.prototypes.errcheck import check_bool, check_envelope 
    55from django.contrib.gis.gdal.prototypes.generation import \ 
     
    7373get_point_count = int_output(lgdal.OGR_G_GetPointCount, [c_void_p]) 
    7474get_point = void_output(lgdal.OGR_G_GetPoint, [c_void_p, c_int, POINTER(c_double), POINTER(c_double), POINTER(c_double)], errcheck=False) 
    75 geom_close_rings = void_output(lgdal.OGR_G_CloseRings, [c_void_p]
     75geom_close_rings = void_output(lgdal.OGR_G_CloseRings, [c_void_p], errcheck=errcheck_flag
    7676 
    7777# Topology routines. 
  • django/branches/gis/django/contrib/gis/gdal/prototypes/srs.py

    r6686 r6707  
    11from ctypes import c_char_p, c_int, c_void_p, POINTER 
    2 from django.contrib.gis.gdal.libgdal import lgdal 
     2from django.contrib.gis.gdal.libgdal import lgdal, errcheck_flag 
    33from django.contrib.gis.gdal.prototypes.generation import \ 
    44    const_string_output, double_output, int_output, \ 
     
    2323clone_srs = srs_output(lgdal.OSRClone, [c_void_p]) 
    2424new_srs = srs_output(lgdal.OSRNewSpatialReference, [c_char_p]) 
    25 release_srs = void_output(lgdal.OSRRelease, [c_void_p]) 
    26 srs_validate = void_output(lgdal.OSRValidate, [c_void_p], errcheck=True) 
     25release_srs = void_output(lgdal.OSRRelease, [c_void_p], errcheck=errcheck_flag) 
     26destroy_srs = void_output(lgdal.OSRDestroySpatialReference, [c_void_p], errcheck=errcheck_flag) 
     27srs_validate = void_output(lgdal.OSRValidate, [c_void_p]) 
    2728 
    2829# Getting the semi_major, semi_minor, and flattening functions. 
     
    6869# Coordinate transformation 
    6970new_ct= srs_output(lgdal.OCTNewCoordinateTransformation, [c_void_p, c_void_p]) 
    70 destroy_ct = void_output(lgdal.OCTDestroyCoordinateTransformation, [c_void_p]
     71destroy_ct = void_output(lgdal.OCTDestroyCoordinateTransformation, [c_void_p], errcheck=errcheck_flag