/[thuban]/branches/WIP-pyshapelib-bramz/Thuban/Model/postgisdb.py
ViewVC logotype

Diff of /branches/WIP-pyshapelib-bramz/Thuban/Model/postgisdb.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1946 by bh, Thu Nov 13 18:56:41 2003 UTC revision 2057 by bh, Tue Feb 10 15:51:57 2004 UTC
# Line 1  Line 1 
1  # Copyright (C) 2003 by Intevation GmbH  # Copyright (C) 2003, 2004 by Intevation GmbH
2  # Authors:  # Authors:
3  # Martin Mueller <[email protected]>  # Martin Mueller <[email protected]>
4  # Bernhard Herzog <[email protected]>  # Bernhard Herzog <[email protected]>
# Line 41  def quote_identifier(ident): Line 41  def quote_identifier(ident):
41      """Return a quoted version of the identifier ident.      """Return a quoted version of the identifier ident.
42    
43      The return value is a string that can be put directly into an SQL      The return value is a string that can be put directly into an SQL
44      statement. The quoted identifier is surrounded by double quotes and      statement.  The quoted identifier is surrounded by double quotes and
45      any double quotes alread in the input value are converted to two      any double quotes already in the input value are converted to two
46      double quotes. Examples:      double quotes.  Examples:
47    
48      >>> quote_identifier("abc\"def")      >>> quote_identifier("abc\"def")
49      '"abc""def"'      '"abc""def"'
# Line 115  class PostGISConnection: Line 115  class PostGISConnection:
115          return ("postgis://%(user)s@%(host)s:%(port)s/%(dbname)s"          return ("postgis://%(user)s@%(host)s:%(port)s/%(dbname)s"
116                  % self.__dict__)                  % self.__dict__)
117    
118        def MatchesParameters(self, parameters):
119            """Return whether the connection matches the dictionary of parameters
120    
121            Return whether instatiating the connection with the given
122            parameters would establish essentially the same connection as
123            self. The connection is essentially the same if the same
124            database (identified by host, port and databasename) is accessed
125            as the same user.
126            """
127            return (parameters["host"] == self.host
128                    and parameters["port"] == self.port
129                    and parameters["dbname"] == self.dbname
130                    and parameters["user"] == self.user)
131    
132      def Close(self):      def Close(self):
133          """Close the database connection"""          """Close the database connection"""
134          self.connection.close()          self.connection.close()
# Line 367  class PostGISShapeStore(PostGISTable): Line 381  class PostGISShapeStore(PostGISTable):
381    
382      """Shapestore interface to a table in a PostGIS database"""      """Shapestore interface to a table in a PostGIS database"""
383    
384        def _fetch_table_information(self):
385            """Extend inherited method to retrieve the SRID"""
386            PostGISTable._fetch_table_information(self)
387            cursor = self.db.cursor()
388            cursor.execute("SELECT srid FROM geometry_columns"
389                           " WHERE f_table_name = %s", (self.tablename,))
390            self.srid = cursor.fetchone()[0]
391    
392      def Table(self):      def Table(self):
393          """Return self since a PostGISShapeStore is its own table."""          """Return self since a PostGISShapeStore is its own table."""
394          return self          return self
# Line 411  class PostGISShapeStore(PostGISTable): Line 433  class PostGISShapeStore(PostGISTable):
433              cursor.execute("SELECT extent(%s) FROM %s;"              cursor.execute("SELECT extent(%s) FROM %s;"
434                             % (self.quoted_geo_col, self.quoted_tablename))                             % (self.quoted_geo_col, self.quoted_tablename))
435              result = cursor.fetchone()              result = cursor.fetchone()
436              if result:              if result[0]:
437                  (minx, miny), (maxx, maxy) \                  (minx, miny), (maxx, maxy) \
438                        = wellknowntext.parse_wkt_thuban(result[0])[0]                        = wellknowntext.parse_wkt_thuban(result[0])[0]
439                  return (minx, miny, maxx, maxy)                  return (minx, miny, maxx, maxy)
# Line 446  class PostGISShapeStore(PostGISTable): Line 468  class PostGISShapeStore(PostGISTable):
468                     left, bottom))                     left, bottom))
469          cursor = self.db.cursor()          cursor = self.db.cursor()
470          cursor.execute("SELECT gid, AsText(%s) FROM %s"          cursor.execute("SELECT gid, AsText(%s) FROM %s"
471                       " WHERE %s && GeometryFromText('%s', -1) ORDER BY gid"                       " WHERE %s && GeometryFromText('%s', %d) ORDER BY gid"
472                         % (self.quoted_geo_col, self.quoted_tablename,                         % (self.quoted_geo_col, self.quoted_tablename,
473                            self.quoted_geo_col, geom))                            self.quoted_geo_col, geom, self.srid))
474          while 1:          while 1:
475              result = cursor.fetchone()              result = cursor.fetchone()
476              if result is None:              if result is None:

Legend:
Removed from v.1946  
changed lines
  Added in v.2057

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26