diff --git a/django/contrib/gis/gdal/field.py b/django/contrib/gis/gdal/field.py index 338a886b03..e2ed6d8297 100644 --- a/django/contrib/gis/gdal/field.py +++ b/django/contrib/gis/gdal/field.py @@ -10,11 +10,11 @@ from django.contrib.gis.gdal.error import OGRException class Field(object): "A class that wraps an OGR Field, needs to be instantiated from a Feature object." - _fld = 0 # Initially NULL - #### Python 'magic' routines #### def __init__(self, fld, val=''): "Needs a C pointer (Python integer in ctypes) in order to initialize." + self._fld = 0 # Initially NULL + if not fld: raise OGRException, 'Cannot create OGR Field, invalid pointer given.' self._fld = fld @@ -51,23 +51,19 @@ class OFTInteger(Field): try: return int(self._val) except ValueError: - return 0 - + return None class OFTIntegerList(Field): pass + class OFTReal(Field): @property def value(self): "Returns a float contained in this field." - try: return float(self._val) except ValueError: - #FIXME: 0? None? - return 0 - - - + return None class OFTRealList(Field): pass + class OFTString(Field): pass class OFTStringList(Field): pass class OFTWideString(Field): pass diff --git a/django/contrib/gis/gdal/geometries.py b/django/contrib/gis/gdal/geometries.py index 355ba4580a..cbf4b39efc 100644 --- a/django/contrib/gis/gdal/geometries.py +++ b/django/contrib/gis/gdal/geometries.py @@ -55,16 +55,22 @@ from django.contrib.gis.gdal.srs import SpatialReference, CoordTransform # # The OGR_G_* routines are relevant here. -#### ctypes prototypes #### +#### ctypes prototypes for functions that return double values #### def pnt_func(f): "For accessing point information." f.restype = c_double f.argtypes = [c_void_p, c_int] return f +# GetX, GetY, GetZ all return doubles. getx = pnt_func(lgdal.OGR_G_GetX) gety = pnt_func(lgdal.OGR_G_GetY) getz = pnt_func(lgdal.OGR_G_GetZ) +# GetArea returns a double. +get_area = lgdal.OGR_G_GetArea +get_area.restype = c_double +get_area.argtypes = [c_void_p] + #### OGRGeometry Class #### class OGRGeometryIndexError(OGRException, KeyError): """This exception is raised when an invalid index is encountered, and has @@ -211,8 +217,7 @@ class OGRGeometry(object): @property def area(self): "Returns the area for a LinearRing, Polygon, or MultiPolygon; 0 otherwise." - a = lgdal.OGR_G_GetArea(self._g) - return a.value + return get_area(self._g) @property def envelope(self):