Django

Code

Changeset 5008

Show
Ignore:
Timestamp:
04/15/07 22:43:53 (2 years ago)
Author:
jbronn
Message:

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

(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

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/gis/django/contrib/gis/db/models/fields/__init__.py

    r4884 r5008  
    6161 
    6262        # Adding the WKT accessor function for geometry 
     63        setattr(cls, 'get_%s_geos' % self.name, curry(cls._get_GEOM_geos, field=self)) 
    6364        setattr(cls, 'get_%s_wkt' % self.name, curry(cls._get_GEOM_wkt, field=self)) 
    6465        setattr(cls, 'get_%s_centroid' % self.name, curry(cls._get_GEOM_centroid, field=self)) 
  • django/branches/gis/django/contrib/gis/db/models/GeoMixin.py

    r4884 r5008  
    11# GEOS Routines 
    2 from django.contrib.gis.geos import hex_to_wkt, centroid, area 
     2from django.contrib.gis.geos import GEOSGeometry, hex_to_wkt, centroid, area 
    33 
    44# Until model subclassing is a possibility, a mixin class is used to add 
     
    99    # A subclass of Model is specifically needed so that these geographic 
    1010    # routines are present for instantiations of the models. 
     11    def _get_GEOM_geos(self, field): 
     12        "Gets a GEOS Python object for the geometry." 
     13        return GEOSGeometry(getattr(self, field.attname), 'hex') 
     14 
    1115    def _get_GEOM_wkt(self, field): 
    1216        "Gets the WKT of the geometry." 
     
    2024     
    2125    def _get_GEOM_area(self, field): 
     26        "Gets the area of the geometry, in projected units." 
    2227        hex = getattr(self, field.attname) 
    2328        return area(hex) 
  • django/branches/gis/django/contrib/gis/db/models/__init__.py

    r4884 r5008  
    44# The GeoManager 
    55from django.contrib.gis.db.models.manager import GeoManager 
     6 
     7# The GeoQ object 
     8from django.contrib.gis.db.models.query import GeoQ 
    69 
    710# The various PostGIS/OpenGIS enabled fields. 
  • django/branches/gis/django/contrib/gis/db/models/query.py

    r4884 r5008  
    1 from django.db.models.query import Q, QNot, QuerySet 
     1from django.db.models.query import Q, QuerySet 
    22from django.contrib.gis.db.models.postgis import parse_lookup 
    33import operator 
  • django/branches/gis/django/contrib/gis/geos/__init__.py

    r4882 r5008  
    1 from geos import geomFromWKT, geomToWKT, geomFromHEX, geomToHEX 
     1from GEOSGeometry import GEOSGeometry, GEOSException 
    22 
    33def hex_to_wkt(hex): 
    4     "Converts EWKBHEX into WKT." 
    5     return geomToWKT(geomFromHEX(hex)) 
     4    "Converts HEXEWKB into WKT." 
     5    return GEOSGeometry(hex, 'hex').wkt 
    66 
    77def wkt_to_hex(wkt): 
    8     "Converts WKT into EWKBHEX." 
    9     return geomToHEX(geomFromWKT(wkt)) 
     8    "Converts WKT into HEXEWKB." 
     9    return GEOSGeometry(wkt, 'wkt').hex 
    1010 
    11 def centroid(hex): 
    12     "Returns the centroid of the geometry (given in EWKBHEX)." 
    13     center = (geomFromHEX(hex)).getCentroid() 
    14     return geomToWKT(center) 
     11def centroid(input, geom_type='hex'): 
     12    "Returns the centroid of the geometry (given in HEXEWKB)." 
     13    return GEOSGeometry(input, geom_type).centroid.wkt 
    1514 
    16 def area(hex): 
    17     "Returns the area of the geometry (given in EWKBHEX)." 
    18     return (geomFromHEX(hex)).area() 
     15def area(input, geom_type='hex'): 
     16    "Returns the area of the geometry (given in HEXEWKB)." 
     17    return GEOSGeometry(input, geom_type).area 
    1918