summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Bronn <jbronn@gmail.com>2007-07-24 03:20:42 +0000
committerJustin Bronn <jbronn@gmail.com>2007-07-24 03:20:42 +0000
commit179a2c45c3381249cb5daa4b888df7cfa4b4c12c (patch)
treedcddbabe5197989f563368c48e6ecdbe7bb0136a
parent8f644283ee8e5ffc5693b1409f7753429e665fbc (diff)
gis: gdal: fixed area function, place field pointer within class, integer and float fields return None when empty.
git-svn-id: http://code.djangoproject.com/svn/django/branches/gis@5754 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/contrib/gis/gdal/field.py16
-rw-r--r--django/contrib/gis/gdal/geometries.py11
2 files changed, 14 insertions, 13 deletions
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):