~ubuntu-branches/ubuntu/jaunty/python-django/jaunty

« back to all changes in this revision

Viewing changes to django/contrib/gis/geos/prototypes/misc.py

  • Committer: Bazaar Package Importer
  • Author(s): Scott James Remnant, Eddy Mulyono
  • Date: 2008-09-16 12:18:47 UTC
  • mfrom: (1.1.5 upstream) (4.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080916121847-mg225rg5mnsdqzr0
Tags: 1.0-1ubuntu1
* Merge from Debian (LP: #264191), remaining changes:
  - Run test suite on build.

[Eddy Mulyono]
* Update patch to workaround network test case failures.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"""
 
2
 This module is for the miscellaneous GEOS routines, particularly the
 
3
 ones that return the area, distance, and length.
 
4
"""
 
5
from ctypes import c_int, c_double, POINTER
 
6
from django.contrib.gis.geos.libgeos import lgeos, GEOM_PTR
 
7
from django.contrib.gis.geos.prototypes.errcheck import check_dbl
 
8
 
 
9
### ctypes generator function ###
 
10
def dbl_from_geom(func, num_geom=1):
 
11
    """
 
12
    Argument is a Geometry, return type is double that is passed
 
13
    in by reference as the last argument.
 
14
    """
 
15
    argtypes = [GEOM_PTR for i in xrange(num_geom)]
 
16
    argtypes += [POINTER(c_double)]
 
17
    func.argtypes = argtypes
 
18
    func.restype = c_int # Status code returned
 
19
    func.errcheck = check_dbl
 
20
    return func
 
21
 
 
22
### ctypes prototypes ###
 
23
 
 
24
# Area, distance, and length prototypes.
 
25
geos_area = dbl_from_geom(lgeos.GEOSArea)
 
26
geos_distance = dbl_from_geom(lgeos.GEOSDistance, num_geom=2)
 
27
geos_length = dbl_from_geom(lgeos.GEOSLength)