Skip to content

Commit

Permalink
use QgsDataSourceURI to parse postgres connection string in mapserver…
Browse files Browse the repository at this point in the history
… export (fixes #1107)

git-svn-id: http://svn.osgeo.org/qgis/trunk@9783 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Dec 13, 2008
1 parent 0360d75 commit cefa3e9
Showing 1 changed file with 7 additions and 38 deletions.
45 changes: 7 additions & 38 deletions python/plugins/mapserver_export/ms_export.py
Expand Up @@ -25,6 +25,7 @@
import os
from string import *
from xml.dom import minidom, Node
from qgis.core import *

# symbol map
qgisSymbols = {'hard:circle' : 'CIRCLE',
Expand Down Expand Up @@ -234,39 +235,6 @@ def writeWebSection(self):
self.outFile.write(" FOOTER '" + self.footer + "'\n")
self.outFile.write(" END\n\n")

def parsePostgisConnection( self, dataString ):
pg = {}
pg['host'] = 'localhost'
pg['dbname'] = 'gisdata'
pg['user'] = ''
pg['password'] = ''
pg['table'] = ''
pg['geom'] = 'the_geom'


whereCondition = dataString.split("sql")[1][1:]
cmp = dataString.split("sql")[0].split(" ")

for c in cmp:
if c[:1] == "(":
pg['geom'] = c[1:][:-1]
else:
kvp = c.split("=")
if (len(kvp) >= 2):
pg[kvp[0]] = kvp[1]

connString = 'host=' + pg['host'] + " user=" + pg['user']

if (len(pg['password'].replace("\'", "")) > 0):
connString += " password=" + pg['password'].replace("'", "")

connString += " dbname=" + pg['dbname']

dataString = pg['geom'] + " FROM " + pg['table'].replace("\"", "")
filterString = whereCondition.replace("\"", "")
return (connString, dataString, filterString)


# Write the map layers - we have to defer writing to disk so we
# can invert the order of the layes, since they are opposite in QGIS
# compared to mapserver
Expand Down Expand Up @@ -321,13 +289,14 @@ def writeMapLayers(self):

if providerString == 'postgres':
# it's a postgis layer
(pgConnString, sqlData, sqlFilter) = self.parsePostgisConnection(dataString)
uri = QgsDataSourceURI(dataString)

layer_def += " CONNECTIONTYPE postgis\n"
layer_def += " CONNECTION \"" + pgConnString + "\"\n"
layer_def += " DATA \"" + sqlData + "\"\n"
layer_def += " CONNECTION \"" + uri.connectionInfo() + "\"\n"
layer_def += " DATA '\"" + uri.geometryColumn() + "\" FROM " + uri.quotedTablename() + "'\n"
# don't write the filter keyword if there isn't one
if sqlFilter:
layer_def += " FILTER \"" + sqlFilter + "\"\n"
if uri.sql() != "":
layer_def += " FILTER ( " + uri.sql() + " )\n"

elif providerString == 'wms' and lyr.getAttribute("type").encode('utf-8').upper() == 'RASTER':
# it's a WMS layer
Expand Down

0 comments on commit cefa3e9

Please sign in to comment.