[Qgis-developer] more than one geometry column

Stefanie Tellex stefie10 at media.mit.edu
Thu Nov 6 16:44:19 EST 2008


Hi,

I wanted to have more than one geometry column in a layer.  This patch
changes QgsPostgresProvider so that it handles geometry columns that
aren't the primary column by reading and writing them as WKT.  So it
looks like a string attributes to clients, but clients can convert it to
a geometry value by using fromWKT.

It's against revision 9563.

Stefanie

-------------- next part --------------
Index: qgis/qgis_unstable/src/providers/postgres/qgspostgresprovider.cpp
===================================================================
--- qgis.orig/qgis_unstable/src/providers/postgres/qgspostgresprovider.cpp	2008-11-06 14:30:29.000000000 -0500
+++ qgis/qgis_unstable/src/providers/postgres/qgspostgresprovider.cpp	2008-11-06 16:37:54.000000000 -0500
@@ -46,7 +46,6 @@
 #include "qgspostgisbox3d.h"
 #include "qgslogger.h"
 #include "qgslogger.h"
-
 const QString POSTGRES_KEY = "postgres";
 const QString POSTGRES_DESCRIPTION = "PostgreSQL/PostGIS data provider";
 
@@ -424,6 +423,10 @@
       {
         query += QString( ",boolout(%1)" ).arg( quotedIdentifier( fieldname ) );
       }
+      else if ( type == "geometry")
+      {
+	query += QString(",AsText(%1)").arg(quotedIdentifier(fieldname));
+      }
       else
       {
         query += "," + quotedIdentifier( fieldname ) + "::text";
@@ -826,6 +829,7 @@
                   fieldTypeName == "bpchar" ||
                   fieldTypeName == "varchar" ||
                   fieldTypeName == "bool" ||
+                  fieldTypeName == "geometry" ||
                   fieldTypeName == "money" ||
                   fieldTypeName.startsWith( "time" ) ||
                   fieldTypeName.startsWith( "date" ) )
@@ -1787,6 +1791,7 @@
 
       insert += "," + quotedIdentifier( fieldname );
 
+
       QString defVal = defaultValue( it.key() ).toString();
 
       if ( i == flist.size() )
@@ -1804,7 +1809,11 @@
         }
         else
         {
-          values += "," + quotedValue( it->toString() );
+	  if (fit->typeName() == "geometry") {
+	    values += ",GeomFromText(" + quotedValue(it->toString()) + ")";
+	  } else {
+	    values += "," + quotedValue( it->toString() );
+	  }
         }
       }
       else



More information about the Qgis-developer mailing list