[Featureserver] Postgis datasource schema implementation

Walter Lorenzetti lorenzetti at faunalia.it
Fri Jan 11 11:27:49 EST 2008


Christopher Schmidt ha scritto:
> Can you turn this into a diff? (Checkout FeatureServer, copy in your
> file, and then 'svn diff'.) I don't have any way to review your changes
> as a new file.
>
>   
this is better?

===================================================================
--- trunk/featureserver/FeatureServer/DataSource/PostGIS.py    
(revisione 414)
+++ trunk/featureserver/FeatureServer/DataSource/PostGIS.py     (copia
locale)
@@ -1,5 +1,5 @@
 __author__  = "MetaCarta"
-__copyright__ = "Copyright (c) 2006-2008 MetaCarta"
+__copyright__ = "Copyright (c) 2006-2007 MetaCarta"
 __license__ = "Clear BSD"
 __version__ = "$Id$"

@@ -24,9 +24,10 @@
        FeatureServer."""
     wkt_linestring_match = re.compile(r'\(([^()]+)\)')

-    def __init__(self, name, srid = 4326, fid = "ogc_fid", geometry =
"the_geom", order = "", writable = True, **args):
+    def __init__(self, name, srid = 4326, schema = "public", fid =
"ogc_fid", geometry = "the_geom", order = "", writable = True, **args):
         DataSource.__init__(self, name, **args)
-        self.table      = args["layer"]
+        self.schema     = schema
+       self.table      = args["layer"]
         self.fid_col    = fid
         self.geom_col   = geometry
         self.order      = order
@@ -127,14 +128,14 @@
         return {"type": geomtype, "coordinates": coords}

     def id_sequence (self):
-        return self.table + "_" + self.fid_col + "_seq"
+        return self.schema + "." + self.table + "_" + self.fid_col + "_seq"

     def create (self, action):
         feature = action.feature
         columns = ", ".join(self.column_names(feature)+[self.geom_col])
         values = ",
".join(self.value_formats(feature)+["SetSRID('%s'::geometry, %s) " %
(self.to_wkt(feature.geometry), self.srid)])
-        sql = "INSERT INTO \"%s\" (%s) VALUES (%s)" % (
-                                        self.table, columns, values)
+        sql = "INSERT INTO \"%s\".\"%s\" (%s) VALUES (%s)" % (
+                                        self.schema, self.table,
columns, values)
         cursor = self.db.cursor()
         cursor.execute(str(sql), self.feature_values(feature))
         cursor.execute("SELECT currval('%s');" % self.id_sequence())
@@ -146,16 +147,16 @@
     def update (self, action):
         feature = action.feature
         predicates = ", ".join( self.feature_predicates(feature) )
-        sql = "UPDATE \"%s\" SET %s WHERE %s = %d" % (
-                    self.table, predicates, self.fid_col, action.id )
+        sql = "UPDATE \"%s\".\"%s\" SET %s WHERE %s = %d" % (
+                    self.schema, self.table, predicates, self.fid_col,
action.id )
         cursor = self.db.cursor()
         cursor.execute(str(sql), self.feature_values(feature))
         self.db.commit()
         return self.select(action)

     def delete (self, action):
-        sql = "DELETE FROM \"%s\" WHERE %s = %%(%s)d" % (
-                    self.table, self.fid_col, self.fid_col )
+        sql = "DELETE FROM \"%s\".\"%s\" WHERE %s = %%(%s)d" % (
+                    self.schema, self.table, self.fid_col, self.fid_col )
         cursor = self.db.cursor()
         cursor.execute(str(sql), {self.fid_col: action.id})
         return []
@@ -164,8 +165,8 @@
         cursor = self.db.cursor()

         if action.id:
-            sql = "SELECT AsText(%s) as fs_text_geom, * FROM \"%s\"
WHERE %s = %%(%s)d" % (
-                    self.geom_col, self.table, self.fid_col, self.fid_col )
+            sql = "SELECT AsText(%s) as fs_text_geom, * FROM
\"%s\".\"%s\" WHERE %s = %%(%s)d" % (
+                    self.geom_col, self.schema, self.table,
self.fid_col, self.fid_col )
             try:
                 cursor.execute(str(sql)% {self.fid_col: action.id})
             except:
@@ -183,7 +184,7 @@
                 filters.append( "%s && SetSRID('BOX3D(%f %f,%f
%f)'::box3d, %s) and intersects(%s, SetSRID('BOX3D(%f %f,%f %f)'::box3d,
%s))" % (
                                         (self.geom_col,) +
tuple(action.bbox) + (self.srid,) + (self.geom_col,) +
(tuple(action.bbox) + (self.srid,))))

-            sql = "SELECT AsText(%s) as fs_text_geom, * FROM \"%s\"" %
(self.geom_col, self.table)
+            sql = "SELECT AsText(%s) as fs_text_geom, * FROM
\"%s\".\"%s\"" % (self.geom_col, self.schema, self.table)
             if filters:
                 sql += " WHERE " + " AND ".join(filters)
             if self.order:

Bye
Walter

-- 
Please no  .doc, .xls, .ppt, .dwg:
https://www.faunalia.it/dokuwiki/doku.php?id=public:OpenFormats

Walter Lorenzetti
email+jabber: lorenzetti at faunalia.it
www.faunalia.it
Cell: (+39) 347-6597931  Tel+Fax: (+39) 0587-213742
Piazza Garibaldi 5 - 56025 Pontedera (PI), Italy




More information about the Featureserver mailing list