Permalink
Browse files

gis: added GEOSGeometry, a ctypes wrapper for the GEOS library, provi…

…ding:

  (1) an interface with the GEOS C API, using only python and ctypes (can be accessed w/get_GEOM_geos)
  (2) independence from the GEOS Python SWIG module that is deprecated and no longer maintained
  (3) portability, currently works on both Linux and Win32 platforms


git-svn-id: http://code.djangoproject.com/svn/django/branches/gis@5008 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent fdbbd65 commit 39f9d48e4e60a1d82a16f831f3c6153ac21f9148 @jbronn jbronn committed Apr 16, 2007
@@ -1,5 +1,5 @@
# GEOS Routines
-from django.contrib.gis.geos import hex_to_wkt, centroid, area
+from django.contrib.gis.geos import GEOSGeometry, hex_to_wkt, centroid, area
# Until model subclassing is a possibility, a mixin class is used to add
# the necessary functions that may be contributed for geographic objects.
@@ -8,6 +8,10 @@ class GeoMixin:
# A subclass of Model is specifically needed so that these geographic
# routines are present for instantiations of the models.
+ def _get_GEOM_geos(self, field):
+ "Gets a GEOS Python object for the geometry."
+ return GEOSGeometry(getattr(self, field.attname), 'hex')
+
def _get_GEOM_wkt(self, field):
"Gets the WKT of the geometry."
hex = getattr(self, field.attname)
@@ -19,6 +23,7 @@ def _get_GEOM_centroid(self, field):
return centroid(hex)
def _get_GEOM_area(self, field):
+ "Gets the area of the geometry, in projected units."
hex = getattr(self, field.attname)
return area(hex)
@@ -4,6 +4,9 @@
# The GeoManager
from django.contrib.gis.db.models.manager import GeoManager
+# The GeoQ object
+from django.contrib.gis.db.models.query import GeoQ
+
# The various PostGIS/OpenGIS enabled fields.
from django.contrib.gis.db.models.fields import \
GeometryField, PointField, LineStringField, PolygonField, \
@@ -60,6 +60,7 @@ def contribute_to_class(self, cls, name):
super(GeometryField, self).contribute_to_class(cls, name)
# Adding the WKT accessor function for geometry
+ setattr(cls, 'get_%s_geos' % self.name, curry(cls._get_GEOM_geos, field=self))
setattr(cls, 'get_%s_wkt' % self.name, curry(cls._get_GEOM_wkt, field=self))
setattr(cls, 'get_%s_centroid' % self.name, curry(cls._get_GEOM_centroid, field=self))
setattr(cls, 'get_%s_area' % self.name, curry(cls._get_GEOM_area, field=self))
@@ -1,4 +1,4 @@
-from django.db.models.query import Q, QNot, QuerySet
+from django.db.models.query import Q, QuerySet
from django.contrib.gis.db.models.postgis import parse_lookup
import operator
Oops, something went wrong.

0 comments on commit 39f9d48

Please sign in to comment.