/[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 1340 by jonathan, Tue Jul 1 16:10:25 2003 UTC revision 1843 by bh, Tue Oct 21 10:49:38 2003 UTC
# Line 22  from Thuban.Model.layer import Layer, Ra Line 22  from Thuban.Model.layer import Layer, Ra
22  from Thuban.Model.classification import \  from Thuban.Model.classification import \
23      ClassGroupDefault, ClassGroupSingleton, ClassGroupRange, ClassGroupMap      ClassGroupDefault, ClassGroupSingleton, ClassGroupRange, ClassGroupMap
24  from Thuban.Model.transientdb import AutoTransientTable, TransientJoinedTable  from Thuban.Model.transientdb import AutoTransientTable, TransientJoinedTable
25  from Thuban.Model.table import DBFTable  from Thuban.Model.table import DBFTable, FIELDTYPE_STRING
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.8.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.8.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 183  class SessionSaver(XMLWriter): Line 204  class SessionSaver(XMLWriter):
204                                      "right": self.get_id(right),                                      "right": self.get_id(right),
205                                      "rightcolumn": right_field,                                      "rightcolumn": right_field,
206                                      "left": self.get_id(left),                                      "left": self.get_id(left),
207                                      "leftcolumn": left_field})                                      "leftcolumn": left_field,
208                                        "jointype": container.JoinType()})
209              else:              else:
210                  raise ValueError("Can't handle container %r" % container)                  raise ValueError("Can't handle container %r" % container)
211    
# Line 207  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 253  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:
294              if isinstance(g, ClassGroupDefault):              if isinstance(g, ClassGroupDefault):
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 layer.GetFieldType(field) == FIELDTYPE_STRING:
299                        value = self.encode(g.GetValue())
300                    else:
301                        value = str(g.GetValue())
302                  open_el  = 'clpoint label="%s" value="%s"' \                  open_el  = 'clpoint label="%s" value="%s"' \
303                             % (self.encode(g.GetLabel()), str(g.GetValue()))                             % (self.encode(g.GetLabel()), value)
304                  close_el = 'clpoint'                  close_el = 'clpoint'
305              elif isinstance(g, ClassGroupRange):              elif isinstance(g, ClassGroupRange):
306                  open_el  = 'clrange label="%s" range="%s"' \                  open_el  = 'clrange label="%s" range="%s"' \

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26