1 from django.core.management.base import BaseCommand, AppCommand
2 from django.db import connection, transaction
3 import os
4
6 help = "Installs a cleangeometry function in postgres required for processing incoming geometries."
7
9 path = os.path.abspath(os.path.join(__file__, '../../../sql/cleangeometry.sql'))
10
11 sql = open(path,'r').read()
12
13
14 sql = sql.replace('%','%%')
15
16 cursor = connection.cursor()
17 cursor.db.enter_transaction_management()
18
19 cursor.execute(sql)
20 print cursor.statusmessage
21 print "TESTING"
22
23 cursor.execute("select cleangeometry(st_geomfromewkt('SRID=4326;POLYGON ((30 10, 10 20, 20 40, 40 40, 30 10))'))")
24 assert cursor.fetchall() == [('0103000020E610000001000000050000000000000000003E4000000000000024400000000000002440000000000000344000000000000034400000000000004440000000000000444000000000000044400000000000003E400000000000002440',)]
25 cursor.db.commit()
26 cursor.db.leave_transaction_management()
27 print "CLEANGEOMETRY function installed successfully"
28