Make sure PostGIS is >= 1.5

Raise an AssertionError when postgis is not >= 1.5.
stable
David Decotigny 2010-09-11 15:27:38 +02:00
rodzic a3286243a2
commit b46e66b7cc
2 zmienionych plików z 37 dodań i 0 usunięć

Wyświetl plik

@ -0,0 +1,22 @@
[datasource]
host=localhost
user=maposmatic
password=mysecurepasswd
dbname=maposmatic
[rendering]
# List of available stylesheets, each needs to be described by an eponymous
# configuration section in this file.
available_stylesheets: stylesheet_osm1, stylesheet_osm2
# The default Mapnik stylesheet.
[stylesheet_osm1]
name: Default
description: The default OSM style
path: /path/to/mapnik-osm/osm.xml
# Another stylesheet
[stylesheet_osm2]
name: AnotherOne
description: Another OSM Stylesheet
path: /path/to/another/osm.xml

Wyświetl plik

@ -244,6 +244,9 @@ class OCitySMap:
# (which loads the unicode extensions for psycopg2)
db.set_client_encoding('utf8')
# Make sure the DB is correctly installed
self._verify_db(db)
try:
timeout = int(self._parser.get('datasource', 'request_timeout'))
except (ConfigParser.NoOptionError, ValueError):
@ -253,6 +256,18 @@ class OCitySMap:
self.__db = db
return self.__db
def _verify_db(self, db):
"""Make sure the PostGIS DB is compatible with us."""
cursor = db.cursor()
cursor.execute("""
SELECT ST_AsText(ST_LongestLine(
'POINT(100 100)'::geometry,
'LINESTRING(20 80, 98 190, 110 180, 50 75 )'::geometry)
) As lline;
""")
assert cursor.fetchall()[0][0] == "LINESTRING(100 100,98 190)", \
LOG.fatal("PostGIS >= 1.5 required for correct operation !")
def _set_request_timeout(self, db, timeout_minutes=15):
"""Sets the PostgreSQL request timeout to avoid long-running queries on
the database."""