[QGIS Commit] r9783 - trunk/qgis/python/plugins/mapserver_export

svn_qgis at osgeo.org svn_qgis at osgeo.org
Sat Dec 13 09:43:34 EST 2008


Author: jef
Date: 2008-12-13 09:43:34 -0500 (Sat, 13 Dec 2008)
New Revision: 9783

Modified:
   trunk/qgis/python/plugins/mapserver_export/ms_export.py
Log:
use QgsDataSourceURI to parse postgres connection string in mapserver export (fixes #1107)

Modified: trunk/qgis/python/plugins/mapserver_export/ms_export.py
===================================================================
--- trunk/qgis/python/plugins/mapserver_export/ms_export.py	2008-12-13 13:19:26 UTC (rev 9782)
+++ trunk/qgis/python/plugins/mapserver_export/ms_export.py	2008-12-13 14:43:34 UTC (rev 9783)
@@ -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',
@@ -234,39 +235,6 @@
       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
@@ -321,13 +289,14 @@
 
       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 



More information about the QGIS-commit mailing list