Patch introducing shapestore registry
Jan-Oliver Wagner
jan at intevation.de
Fri May 13 09:15:39 CEST 2005
On Fri, May 13, 2005 at 09:14:44AM +0200, Jan-Oliver Wagner wrote:
> attached is a patch that introduces a simple shapestore
> registry.
now it is.
--
Jan-Oliver Wagner http://intevation.de/~jan/
Intevation GmbH http://intevation.de/
Kolab Konsortium http://kolab-konsortium.de/
FreeGIS http://freegis.org/
-------------- next part --------------
Index: data.py
===================================================================
RCS file: /thubanrepository/thuban/Thuban/Model/data.py,v
retrieving revision 1.16
diff -u -3 -p -r1.16 data.py
--- data.py 27 Apr 2005 11:04:56 -0000 1.16
+++ data.py 13 May 2005 07:07:08 -0000
@@ -112,6 +112,29 @@ class ShapeTable(transientdb.AutoTransie
"""Return a tuple containing the shapestore"""
return (self.store(),)
+
+class ShapeStoreRegistry:
+
+ def __init__(self):
+ self._registry = []
+
+ def __nonzero__(self):
+ return len(self._registry) <> 0
+
+ def __iter__(self):
+ return iter(self._registry)
+
+ def add(self, shapetype, clazz):
+ self._registry.append( (shapetype, clazz ) )
+
+ def findClass(self, shapetype):
+ for i in self._registry:
+ if i[0] == shapetype:
+ return i[1]
+ return None
+
+shapestore_registry = ShapeStoreRegistry()
+
# XXX: (this statement should be kept in mind when re-engeneering)
#
# From a desing POV it was wrong to distinguish between table and
@@ -295,6 +318,9 @@ class ShapefileStore(FileShapeStore):
def Shape(self, index):
"""Return the shape with index index"""
return ShapefileShape(self.shapefile, index)
+
+# Add the type supported by ShapefileStore.
+shapestore_registry.add("shapefile", ShapefileStore)
class DerivedShapeStore:
Index: load.py
===================================================================
RCS file: /thubanrepository/thuban/Thuban/Model/load.py,v
retrieving revision 1.55
diff -u -3 -p -r1.55 load.py
--- load.py 6 May 2005 14:17:03 -0000 1.55
+++ load.py 13 May 2005 07:07:08 -0000
@@ -14,7 +14,8 @@ Parser for thuban session files.
__version__ = "$Revision: 1.55 $"
-import string, os
+import os
+from string import atoi
import xml.sax
import xml.sax.handler
@@ -35,7 +36,8 @@ from Thuban.Model.range import Range
from Thuban.Model.classification import Classification, \
ClassGroupDefault, ClassGroupSingleton, ClassGroupRange, ClassGroupMap, \
ClassGroupProperties
-from Thuban.Model.data import DerivedShapeStore, ShapefileStore
+from Thuban.Model.data import DerivedShapeStore, ShapefileStore, \
+ shapestore_registry
from Thuban.Model.table import DBFTable
from Thuban.Model.transientdb import TransientJoinedTable
@@ -64,14 +66,14 @@ def parse_color(color):
Color may be either 'None' or of the form '#RRGGBB' in the usual
HTML color notation
"""
- color = string.strip(color)
+ color = color.strip()
if color == "None":
result = Transparent
elif color[0] == '#':
if len(color) == 7:
- r = string.atoi(color[1:3], 16) / 255.0
- g = string.atoi(color[3:5], 16) / 255.0
- b = string.atoi(color[5:7], 16) / 255.0
+ r = atoi(color[1:3], 16) / 255.0
+ g = atoi(color[3:5], 16) / 255.0
+ b = atoi(color[5:7], 16) / 255.0
result = Color(r, g, b)
else:
raise ValueError(_("Invalid hexadecimal color specification %s")
@@ -378,9 +380,18 @@ class SessionLoader(XMLReader):
ID = attrs["id"]
filename = attrs["filename"]
filetype = attrs["filetype"]
- if filetype != "shapefile":
+ clazz = shapestore_registry.findClass(filetype)
+ if clazz is None:
raise LoadError("shapesource filetype %r not supported" % filetype)
- self.idmap[ID] = self.open_shapefile(filename)
+
+ # TODO: We should better separate the task of finding the correct path
+ # and of loading a shape store. E.g. something like this:
+ # filename = fix_filename_path(filename)
+
+ if clazz == ShapefileStore:
+ self.idmap[ID] = self.open_shapefile(filename)
+ else:
+ self.idmap[ID] = clazz(self.theSession, filename)
def start_derivedshapesource(self, name, qname, attrs):
attrs = self.check_attrs(name, attrs,
Index: session.py
===================================================================
RCS file: /thubanrepository/thuban/Thuban/Model/session.py,v
retrieving revision 1.28
diff -u -3 -p -r1.28 session.py
--- session.py 11 Mar 2004 21:04:30 -0000 1.28
+++ session.py 13 May 2005 07:07:08 -0000
@@ -303,8 +303,13 @@ class Session(TitledObject, Modifiable):
The session only holds a weak reference to the shapestore, so it
will automatically be removed from the session when the last
reference goes away.
+
+ If shapestore is None, this will be ignored.
+
+ Returns: its shapestore parameter.
"""
- self._add_shapestore(shapestore)
+ if shapestore is not None:
+ self._add_shapestore(shapestore)
return shapestore
def TransientDB(self):
More information about the Thuban-devel
mailing list
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)