~ubuntu-branches/ubuntu/quantal/python-django/quantal-security

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Chris Lamb
  • Date: 2010-05-21 07:52:55 UTC
  • mfrom: (1.3.6 upstream)
  • mto: This revision was merged to the branch mainline in revision 28.
  • Revision ID: james.westby@ubuntu.com-20100521075255-ii78v1dyfmyu3uzx
Tags: upstream-1.2
ImportĀ upstreamĀ versionĀ 1.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
from ctypes import c_char_p, c_int, c_size_t, c_ubyte, c_uint, POINTER
2
 
from django.contrib.gis.geos.libgeos import lgeos, CS_PTR, GEOM_PTR, PREPGEOM_PTR, GEOS_PREPARE
 
2
from django.contrib.gis.geos.libgeos import CS_PTR, GEOM_PTR, PREPGEOM_PTR, GEOS_PREPARE
3
3
from django.contrib.gis.geos.prototypes.errcheck import \
4
4
    check_geom, check_minus_one, check_sized_string, check_string, check_zero
 
5
from django.contrib.gis.geos.prototypes.threadsafe import GEOSFunc
5
6
 
6
7
# This is the return type used by binary output (WKB, HEX) routines.
7
8
c_uchar_p = POINTER(c_ubyte)
63
64
### ctypes prototypes ###
64
65
 
65
66
# Deprecated creation routines from WKB, HEX, WKT
66
 
from_hex = bin_constructor(lgeos.GEOSGeomFromHEX_buf)
67
 
from_wkb = bin_constructor(lgeos.GEOSGeomFromWKB_buf)
68
 
from_wkt = geom_output(lgeos.GEOSGeomFromWKT, [c_char_p])
 
67
from_hex = bin_constructor(GEOSFunc('GEOSGeomFromHEX_buf'))
 
68
from_wkb = bin_constructor(GEOSFunc('GEOSGeomFromWKB_buf'))
 
69
from_wkt = geom_output(GEOSFunc('GEOSGeomFromWKT'), [c_char_p])
69
70
 
70
 
# Output routines
71
 
to_hex = bin_output(lgeos.GEOSGeomToHEX_buf)
72
 
to_wkb = bin_output(lgeos.GEOSGeomToWKB_buf)
73
 
to_wkt = string_from_geom(lgeos.GEOSGeomToWKT)
 
71
# Deprecated output routines
 
72
to_hex = bin_output(GEOSFunc('GEOSGeomToHEX_buf'))
 
73
to_wkb = bin_output(GEOSFunc('GEOSGeomToWKB_buf'))
 
74
to_wkt = string_from_geom(GEOSFunc('GEOSGeomToWKT'))
74
75
 
75
76
# The GEOS geometry type, typeid, num_coordites and number of geometries
76
 
geos_normalize = int_from_geom(lgeos.GEOSNormalize)
77
 
geos_type = string_from_geom(lgeos.GEOSGeomType)
78
 
geos_typeid = int_from_geom(lgeos.GEOSGeomTypeId)
79
 
get_dims = int_from_geom(lgeos.GEOSGeom_getDimensions, zero=True)
80
 
get_num_coords = int_from_geom(lgeos.GEOSGetNumCoordinates)
81
 
get_num_geoms = int_from_geom(lgeos.GEOSGetNumGeometries)
 
77
geos_normalize = int_from_geom(GEOSFunc('GEOSNormalize'))
 
78
geos_type = string_from_geom(GEOSFunc('GEOSGeomType'))
 
79
geos_typeid = int_from_geom(GEOSFunc('GEOSGeomTypeId'))
 
80
get_dims = int_from_geom(GEOSFunc('GEOSGeom_getDimensions'), zero=True)
 
81
get_num_coords = int_from_geom(GEOSFunc('GEOSGetNumCoordinates'))
 
82
get_num_geoms = int_from_geom(GEOSFunc('GEOSGetNumGeometries'))
82
83
 
83
84
# Geometry creation factories
84
 
create_point = geom_output(lgeos.GEOSGeom_createPoint, [CS_PTR])
85
 
create_linestring = geom_output(lgeos.GEOSGeom_createLineString, [CS_PTR])
86
 
create_linearring = geom_output(lgeos.GEOSGeom_createLinearRing, [CS_PTR])
 
85
create_point = geom_output(GEOSFunc('GEOSGeom_createPoint'), [CS_PTR])
 
86
create_linestring = geom_output(GEOSFunc('GEOSGeom_createLineString'), [CS_PTR])
 
87
create_linearring = geom_output(GEOSFunc('GEOSGeom_createLinearRing'), [CS_PTR])
87
88
 
88
89
# Polygon and collection creation routines are special and will not
89
90
# have their argument types defined.
90
 
create_polygon = geom_output(lgeos.GEOSGeom_createPolygon, None)
91
 
create_collection = geom_output(lgeos.GEOSGeom_createCollection, None)
 
91
create_polygon = geom_output(GEOSFunc('GEOSGeom_createPolygon'), None)
 
92
create_collection = geom_output(GEOSFunc('GEOSGeom_createCollection'), None)
92
93
 
93
94
# Ring routines
94
 
get_extring = geom_output(lgeos.GEOSGetExteriorRing, [GEOM_PTR])
95
 
get_intring = geom_index(lgeos.GEOSGetInteriorRingN)
96
 
get_nrings = int_from_geom(lgeos.GEOSGetNumInteriorRings)
 
95
get_extring = geom_output(GEOSFunc('GEOSGetExteriorRing'), [GEOM_PTR])
 
96
get_intring = geom_index(GEOSFunc('GEOSGetInteriorRingN'))
 
97
get_nrings = int_from_geom(GEOSFunc('GEOSGetNumInteriorRings'))
97
98
 
98
99
# Collection Routines
99
 
get_geomn = geom_index(lgeos.GEOSGetGeometryN)
 
100
get_geomn = geom_index(GEOSFunc('GEOSGetGeometryN'))
100
101
 
101
102
# Cloning
102
 
geom_clone = lgeos.GEOSGeom_clone
 
103
geom_clone = GEOSFunc('GEOSGeom_clone')
103
104
geom_clone.argtypes = [GEOM_PTR]
104
105
geom_clone.restype = GEOM_PTR
105
106
 
106
107
# Destruction routine.
107
 
destroy_geom = lgeos.GEOSGeom_destroy
 
108
destroy_geom = GEOSFunc('GEOSGeom_destroy')
108
109
destroy_geom.argtypes = [GEOM_PTR]
109
110
destroy_geom.restype = None
110
111
 
111
112
# SRID routines
112
 
geos_get_srid = lgeos.GEOSGetSRID
 
113
geos_get_srid = GEOSFunc('GEOSGetSRID')
113
114
geos_get_srid.argtypes = [GEOM_PTR]
114
115
geos_get_srid.restype = c_int
115
116
 
116
 
geos_set_srid = lgeos.GEOSSetSRID
 
117
geos_set_srid = GEOSFunc('GEOSSetSRID')
117
118
geos_set_srid.argtypes = [GEOM_PTR, c_int]
118
119
geos_set_srid.restype = None