/[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 2105 by bh, Thu Mar 11 21:04:30 2004 UTC revision 2106 by bh, Fri Mar 12 12:59:33 2004 UTC
# Line 514  class PostGISShapeStore(PostGISTable): Line 514  class PostGISShapeStore(PostGISTable):
514          self.quoted_geo_col = quote_identifier(self.geometry_column)          self.quoted_geo_col = quote_identifier(self.geometry_column)
515    
516      def _fetch_table_information(self):      def _fetch_table_information(self):
517          """Extend inherited method to retrieve the SRID"""          """Extend inherited method to retrieve the SRID and shape type"""
518          PostGISTable._fetch_table_information(self)          PostGISTable._fetch_table_information(self)
519    
520            # First, try to get it from the geometry_columns table.
521          cursor = self.db.cursor()          cursor = self.db.cursor()
522          cursor.execute("SELECT srid FROM geometry_columns"          cursor.execute("SELECT srid, type FROM geometry_columns"
523                         " WHERE f_table_name = %s AND f_geometry_column=%s",                         " WHERE f_table_name = %s AND f_geometry_column=%s",
524                         (self.tablename, self.geometry_column))                         (self.tablename, self.geometry_column))
525          self.srid = cursor.fetchone()[0]          row = cursor.fetchone()
526            if row is not None:
527                self.srid = row[0]
528                self.shape_type = shapetype_map.get(row[1])
529                return
530    
531            # The table is probably really a view and thus not in
532            # geometry_columns.  Use a different approach
533            cursor = self.db.cursor()
534            cursor.execute("SELECT DISTINCT SRID(%s) FROM %s;" %
535                           (quote_identifier(self.geometry_column),
536                            self.tablename))
537            row = cursor.fetchone()
538            if row is not None:
539                self.srid = row[0]
540                # Try to see whether there's another one
541                row = cursor.fetchone()
542                if row is not None:
543                    # There are at least two different srids.  We don't
544                    # support that
545                    self.srid = None
546    
547            cursor = self.db.cursor()
548            cursor.execute("SELECT DISTINCT GeometryType(%s) FROM %s;"
549                           % (quote_identifier(self.geometry_column),
550                              self.tablename))
551            row = cursor.fetchone()
552            if row is not None:
553                self.shape_type = shapetype_map.get(row[0])
554                # Try to see whether there's another one
555                row = cursor.fetchone()
556                if row is not None:
557                    # There are at least two different srids.  We don't
558                    # support that
559                    self.shape_type = None
560    
561      def _create_col_from_description(self, index, description):      def _create_col_from_description(self, index, description):
562          """Extend the inherited method to find geometry columns          """Extend the inherited method to find geometry columns
# Line 574  class PostGISShapeStore(PostGISTable): Line 610  class PostGISShapeStore(PostGISTable):
610    
611      def ShapeType(self):      def ShapeType(self):
612          """Return the type of the shapes in the shapestore."""          """Return the type of the shapes in the shapestore."""
613          cursor = self.db.cursor()          return self.shape_type
         cursor.execute("SELECT type FROM geometry_columns WHERE"  
                        " f_table_name=%s AND f_geometry_column=%s",  
                        (self.tablename, self.geometry_column))  
         result = cursor.fetchone()[0]  
         cursor.close()  
         return shapetype_map[result]  
614    
615      def RawShapeFormat(self):      def RawShapeFormat(self):
616          """Return the raw data format of the shape data.          """Return the raw data format of the shape data.

Legend:
Removed from v.2105  
changed lines
  Added in v.2106

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26