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

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

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

revision 1417 by bh, Tue Jul 15 08:43:53 2003 UTC revision 1843 by bh, Tue Oct 21 10:49:38 2003 UTC
# Line 26  from Thuban.Model.table import DBFTable, Line 26  from Thuban.Model.table import DBFTable,
26  from Thuban.Model.data import DerivedShapeStore, ShapefileStore  from Thuban.Model.data import DerivedShapeStore, ShapefileStore
27    
28  from Thuban.Model.xmlwriter import XMLWriter  from Thuban.Model.xmlwriter import XMLWriter
29    from postgisdb import PostGISConnection, PostGISShapeStore
30    
31  def relative_filename(dir, filename):  def relative_filename(dir, filename):
32      """Return a filename relative to dir for the absolute file name absname.      """Return a filename relative to dir for the absolute file name absname.
# Line 105  class SessionSaver(XMLWriter): Line 106  class SessionSaver(XMLWriter):
106      def write(self, file_or_filename):      def write(self, file_or_filename):
107          XMLWriter.write(self, file_or_filename)          XMLWriter.write(self, file_or_filename)
108    
109          self.write_header("session", "thuban-0.9.dtd")          self.write_header("session", "thuban-1.0.dtd")
110          self.write_session(self.session)          self.write_session(self.session)
111          self.close()          self.close()
112    
# Line 132  class SessionSaver(XMLWriter): Line 133  class SessionSaver(XMLWriter):
133              attrs["xmlns:" + name] = uri              attrs["xmlns:" + name] = uri
134          # default name space          # default name space
135          attrs["xmlns"] = \          attrs["xmlns"] = \
136                 "http://thuban.intevation.org/dtds/thuban-0.9-dev.dtd"                 "http://thuban.intevation.org/dtds/thuban-1.0-dev.dtd"
137          self.open_element("session", attrs)          self.open_element("session", attrs)
138            self.write_db_connections(session)
139          self.write_data_containers(session)          self.write_data_containers(session)
140          for map in session.Maps():          for map in session.Maps():
141              self.write_map(map)              self.write_map(map)
142          self.close_element("session")          self.close_element("session")
143    
144        def write_db_connections(self, session):
145            for conn in session.DBConnections():
146                if isinstance(conn, PostGISConnection):
147                    self.write_element("dbconnection",
148                                       {"id": self.define_id(conn),
149                                        "dbtype": "postgis",
150                                        "host": conn.host,
151                                        "port": conn.port,
152                                        "user": conn.user,
153                                        "dbname": conn.dbname})
154                else:
155                    raise ValueError("Can't handle db connection %r" % conn)
156    
157      def write_data_containers(self, session):      def write_data_containers(self, session):
158          containers = sort_data_stores(session.DataContainers())          containers = sort_data_stores(session.DataContainers())
159          for container in containers:          for container in containers:
# Line 166  class SessionSaver(XMLWriter): Line 181  class SessionSaver(XMLWriter):
181                                     {"id": idvalue,                                     {"id": idvalue,
182                                      "shapesource": self.get_id(shapesource),                                      "shapesource": self.get_id(shapesource),
183                                      "table": self.get_id(table)})                                      "table": self.get_id(table)})
184                elif isinstance(container, PostGISShapeStore):
185                    conn = container.DBConnection()
186                    self.write_element("dbshapesource",
187                                       {"id": idvalue,
188                                        "dbconn": self.get_id(conn),
189                                        "tablename": container.TableName()})
190              elif isinstance(container, DBFTable):              elif isinstance(container, DBFTable):
191                  filename = relative_filename(self.dir, container.FileName())                  filename = relative_filename(self.dir, container.FileName())
192                  self.write_element("filetable",                  self.write_element("filetable",
# Line 208  class SessionSaver(XMLWriter): Line 229  class SessionSaver(XMLWriter):
229          """Write the projection.          """Write the projection.
230          """          """
231          if projection and len(projection.params) > 0:          if projection and len(projection.params) > 0:
232              self.open_element("projection", {"name": projection.GetName()})              attrs = {"name": projection.GetName()}
233                epsg = projection.EPSGCode()
234                if epsg is not None:
235                    attrs["epsg"] = epsg
236                self.open_element("projection", attrs)
237              for param in projection.params:              for param in projection.params:
238                  self.write_element('parameter value="%s"' %                  self.write_element('parameter value="%s"' %
239                                     self.encode(param))                                     self.encode(param))
# Line 254  class SessionSaver(XMLWriter): Line 279  class SessionSaver(XMLWriter):
279    
280          lc = layer.GetClassification()          lc = layer.GetClassification()
281    
282          field = lc.GetField()          field = layer.GetClassificationColumn()
283    
284          #          #
285          # there isn't a classification of anything so do nothing          # there isn't a classification of anything so do nothing
286          #          #
287          if field is None: return          if field is None: return
288    
289          attrs["field"] = field          attrs["field"] = field
290          attrs["field_type"] = str(lc.GetFieldType())          attrs["field_type"] = str(layer.GetFieldType(field))
291          self.open_element("classification", attrs)          self.open_element("classification", attrs)
292    
293          for g in lc:          for g in lc:
# Line 270  class SessionSaver(XMLWriter): Line 295  class SessionSaver(XMLWriter):
295                  open_el  = 'clnull label="%s"' % self.encode(g.GetLabel())                  open_el  = 'clnull label="%s"' % self.encode(g.GetLabel())
296                  close_el = 'clnull'                  close_el = 'clnull'
297              elif isinstance(g, ClassGroupSingleton):              elif isinstance(g, ClassGroupSingleton):
298                  if lc.GetFieldType() == FIELDTYPE_STRING:                  if layer.GetFieldType(field) == FIELDTYPE_STRING:
299                      value = self.encode(g.GetValue())                      value = self.encode(g.GetValue())
300                  else:                  else:
301                      value = str(g.GetValue())                      value = str(g.GetValue())

Legend:
Removed from v.1417  
changed lines
  Added in v.1843

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26