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

Legend:
Removed from v.2102  
changed lines
  Added in v.2472

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26