2
This utility module is for obtaining information about the PostGIS
5
See PostGIS docs at Ch. 6.2.1 for more information on these functions.
9
def _get_postgis_func(func):
10
"Helper routine for calling PostGIS functions and returning their result."
11
from django.db import connection
12
cursor = connection.cursor()
13
cursor.execute('SELECT %s()' % func)
14
row = cursor.fetchone()
18
### PostGIS management functions ###
19
def postgis_geos_version():
20
"Returns the version of the GEOS library used with PostGIS."
21
return _get_postgis_func('postgis_geos_version')
23
def postgis_lib_version():
24
"Returns the version number of the PostGIS library used with PostgreSQL."
25
return _get_postgis_func('postgis_lib_version')
27
def postgis_proj_version():
28
"Returns the version of the PROJ.4 library used with PostGIS."
29
return _get_postgis_func('postgis_proj_version')
31
def postgis_version():
32
"Returns PostGIS version number and compile-time options."
33
return _get_postgis_func('postgis_version')
35
def postgis_full_version():
36
"Returns PostGIS version number and compile-time options."
37
return _get_postgis_func('postgis_full_version')
39
### Routines for parsing output of management functions. ###
40
version_regex = re.compile('^(?P<major>\d)\.(?P<minor1>\d)\.(?P<minor2>\d+)')
41
def postgis_version_tuple():
42
"Returns the PostGIS version as a tuple."
44
# Getting the PostGIS version
45
version = postgis_lib_version()
46
m = version_regex.match(version)
48
major = int(m.group('major'))
49
minor1 = int(m.group('minor1'))
50
minor2 = int(m.group('minor2'))
52
raise Exception('Could not parse PostGIS version string: %s' % version)
54
return (version, major, minor1, minor2)