bh: thuban/test test_postgis_db.py, 1.13, 1.13.2.1 postgissupport.py, 1.7, 1.7.2.1
cvs@intevation.de
cvs at intevation.de
Thu Dec 16 20:17:53 CET 2004
Author: bh
Update of /thubanrepository/thuban/test
In directory doto:/tmp/cvs-serv29760/test
Modified Files:
Tag: thuban-1-0-branch
test_postgis_db.py postgissupport.py
Log Message:
Add support for PostGIS tables with LINESTRING geomentries.
Fixes RT#2299
* Thuban/Model/postgisdb.py (shapetype_map): Add LINESTRING
* test/postgissupport.py
(PostgreSQLServer.get_default_static_data_db): Rename the "roads"
table to "roads-multi" because it now uses MULTILINESTRING
geometries and introduce a new "roads" table that uses LINESTRING
(coords_to_multilinestring): Make the doc string more precise
(coords_to_linestring): New. Create a LINESTRING WKT
representatin
(wkt_converter): Add coords_to_linestring
(upload_shapefile): Rephrase the doc-string a bit.
* test/test_postgis_db.py (TestPostGISShapestoreArc)
(LineStringTests)
(TestPostGISShapestoreLineString)
(TestPostGISShapestoreMultiLineString): Split
TestPostGISShapestoreArc into a base class LineStringTests and two
derived classes TestPostGISShapestoreLineString for LINESTRING
geometries and TestPostGISShapestoreMultiLineString for
MULTILINESTRING geometries. Most test methods are in the base
class with the exception of tests that explicitly check the raw
format.
Index: test_postgis_db.py
===================================================================
RCS file: /thubanrepository/thuban/test/test_postgis_db.py,v
retrieving revision 1.13
retrieving revision 1.13.2.1
diff -u -d -r1.13 -r1.13.2.1
--- test_postgis_db.py 11 Feb 2004 09:05:40 -0000 1.13
+++ test_postgis_db.py 16 Dec 2004 19:17:51 -0000 1.13.2.1
@@ -572,14 +572,12 @@
-class TestPostGISShapestoreArc(PostGISStaticTests):
+class LineStringTests:
- """Tests for PostGISShapeStore objects with MULTILINESTRING data"""
+ """Tests shared by the LINESTRING and MULTILINESTRING tests.
- def setUp(self):
- """Extend inherited method to set self.table to a PostGISShapeStore"""
- PostGISStaticTests.setUp(self)
- self.store = PostGISShapeStore(self.db, "roads")
+ The tests are the same because they are based on the same data.
+ """
def test_shape_type(self):
"""Test PostGISShapeStore.ShapeType() with ARC shapes"""
@@ -605,17 +603,43 @@
[[(-15.0821743011474, 66.2773818969726),
(-15.0263500213623, 66.2733917236328)]])
- def test_shape_raw_data(self):
- """Test PostGISShapeStore.Shape(i).RawData() with ARC shapes"""
- self.assertEquals(self.store.Shape(32).RawData(),
- "MULTILINESTRING((-15.0821743011475 66.2773818969727,"
- "-15.0263500213623 66.2733917236328))")
-
def test_shapes_in_region(self):
"""Test PostGISShapeStore.ShapesInRegion() with ARC shapes"""
shapes = self.store.ShapesInRegion((-24.0, 64.5, -23.5, 65.0))
self.assertEquals([s.ShapeID() for s in shapes], [573, 581, 613])
+
+class TestPostGISShapestoreLineString(LineStringTests, PostGISStaticTests):
+
+ """Tests for PostGISShapeStore objects with LINESTRING data"""
+
+ def setUp(self):
+ """Extend inherited method to set self.table to a PostGISShapeStore"""
+ PostGISStaticTests.setUp(self)
+ self.store = PostGISShapeStore(self.db, "roads")
+
+ def test_shape_raw_data(self):
+ """Test PostGISShapeStore.Shape(i).RawData() with ARC shapes"""
+ self.assertEquals(self.store.Shape(32).RawData(),
+ "LINESTRING(-15.0821743011475 66.2773818969727,"
+ "-15.0263500213623 66.2733917236328)")
+
+
+class TestPostGISShapestoreMultiLineString(LineStringTests,
+ PostGISStaticTests):
+
+ """Tests for PostGISShapeStore objects with MULTILINESTRING data"""
+
+ def setUp(self):
+ """Extend inherited method to set self.table to a PostGISShapeStore"""
+ PostGISStaticTests.setUp(self)
+ self.store = PostGISShapeStore(self.db, "roads_multi")
+
+ def test_shape_raw_data(self):
+ """Test PostGISShapeStore.Shape(i).RawData() with ARC shapes"""
+ self.assertEquals(self.store.Shape(32).RawData(),
+ "MULTILINESTRING((-15.0821743011475 66.2773818969727,"
+ "-15.0263500213623 66.2733917236328))")
class PolygonTests:
Index: postgissupport.py
===================================================================
RCS file: /thubanrepository/thuban/test/postgissupport.py,v
retrieving revision 1.7
retrieving revision 1.7.2.1
diff -u -d -r1.7 -r1.7.2.1
--- postgissupport.py 10 Feb 2004 15:51:57 -0000 1.7
+++ postgissupport.py 16 Dec 2004 19:17:51 -0000 1.7.2.1
@@ -243,15 +243,21 @@
[("gid_offset", 1000)]),
("political", os.path.join("..", "Data", "iceland",
"political.shp")),
- ("roads", os.path.join("..", "Data", "iceland",
+ ("roads_multi", os.path.join("..", "Data", "iceland",
"roads-line.shp")),
+ # same as roads-multi but using LINESTRING instead of
+ # MULTILINESTRING
+ ("roads", os.path.join("..", "Data", "iceland",
+ "roads-line.shp"),
+ [("force_wkt_type", "LINESTRING")]),
+
# The polygon data as a MULTIPOLYGON geometry type
("political_multi", os.path.join("..", "Data", "iceland",
"political.shp"),
[("force_wkt_type", "MULTIPOLYGON")]),
- # Copy of landmarks but using an srid
+ # Copy of landmarks but using an srid != -1
("landmarks_srid", os.path.join("..", "Data", "iceland",
"cultural_landmark-point.shp"),
[("gid_offset", 1000),
@@ -551,8 +557,14 @@
poly.append(", ".join(["%r %r" % p for p in ring]))
return "POLYGON((%s))" % "), (".join(poly)
+def coords_to_linestring(coords):
+ """Return string with a LINESTRING WKT representation of coords"""
+ if len(coords) > 1:
+ raise ValueError("A LINESTRING can only have one arc")
+ return "LINESTRING(%s)" % ", ".join(["%r %r" % p for p in coords[0]])
+
def coords_to_multilinestring(coords):
- """Return string with a WKT representation of the arc in coords"""
+ """Return string with a MULTILINESTRING WKT representation of coords"""
poly = []
for ring in coords:
poly.append(", ".join(["%r %r" % p for p in ring]))
@@ -567,6 +579,7 @@
wkt_converter = {
"POINT": coords_to_point,
+ "LINESTRING": coords_to_linestring,
"MULTILINESTRING": coords_to_multilinestring,
"POLYGON": coords_to_polygon,
"MULTIPOLYGON": coords_to_multipolygon,
@@ -585,9 +598,9 @@
tablename -- The name of the table to create and into which the data
is to be inserted
- force_wkt_type -- If given the real WKT geometry type to use instead
- of the default that would be chosen based on the type of
- the shapefile
+ force_wkt_type -- If given and not None, this is used as the WKT
+ geometry type to use instead of the default that would
+ be chosen based on the type of the shapefile
gid_offset -- A number to add to the shapeid to get the value for
the gid column (default 0)
More information about the Thuban-devel
mailing list
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)