mirror of
https://github.com/django/django.git
synced 2025-07-04 01:39:20 +00:00
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
This commit is contained in:
parent
8f644283ee
commit
179a2c45c3
@ -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
|
||||
|
@ -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):
|
||||
|
Loading…
x
Reference in New Issue
Block a user