Django

Code

Changeset 5754

Show
Ignore:
Timestamp:
07/23/07 22:20:42 (1 year ago)
Author:
jbronn
Message:

gis: gdal: fixed area function, place field pointer within class, integer and float fields return None when empty.

Files:

Legend:

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

    r5749 r5754  
    1111    "A class that wraps an OGR Field, needs to be instantiated from a Feature object." 
    1212 
    13     _fld = 0 # Initially NULL 
    14  
    1513    #### Python 'magic' routines #### 
    1614    def __init__(self, fld, val=''): 
    1715        "Needs a C pointer (Python integer in ctypes) in order to initialize." 
     16        self._fld = 0 # Initially NULL 
     17 
    1818        if not fld: 
    1919            raise OGRException, 'Cannot create OGR Field, invalid pointer given.' 
     
    5252            return int(self._val) 
    5353        except ValueError: 
    54             return 0 
    55      
     54            return None 
    5655class OFTIntegerList(Field): pass 
     56 
    5757class OFTReal(Field): 
    5858    @property 
    5959    def value(self): 
    6060        "Returns a float contained in this field." 
    61  
    6261        try: 
    6362            return float(self._val) 
    6463        except ValueError: 
    65             #FIXME: 0?  None? 
    66             return 0 
     64            return None 
     65class OFTRealList(Field): pass 
    6766 
    68          
    69  
    70 class OFTRealList(Field): pass 
    7167class OFTString(Field): pass 
    7268class OFTStringList(Field): pass 
  • django/branches/gis/django/contrib/gis/gdal/geometries.py

    r5749 r5754  
    5656# The OGR_G_* routines are relevant here. 
    5757 
    58 #### ctypes prototypes #### 
     58#### ctypes prototypes for functions that return double values #### 
    5959def pnt_func(f): 
    6060    "For accessing point information." 
     
    6262    f.argtypes = [c_void_p, c_int] 
    6363    return f 
     64# GetX, GetY, GetZ all return doubles. 
    6465getx = pnt_func(lgdal.OGR_G_GetX) 
    6566gety = pnt_func(lgdal.OGR_G_GetY) 
    6667getz = pnt_func(lgdal.OGR_G_GetZ) 
     68 
     69# GetArea returns a double. 
     70get_area = lgdal.OGR_G_GetArea 
     71get_area.restype = c_double 
     72get_area.argtypes = [c_void_p] 
    6773 
    6874#### OGRGeometry Class #### 
     
    212218    def area(self): 
    213219        "Returns the area for a LinearRing, Polygon, or MultiPolygon; 0 otherwise." 
    214         a = lgdal.OGR_G_GetArea(self._g) 
    215         return a.value 
     220        return get_area(self._g) 
    216221 
    217222    @property