]> granicus.if.org Git - postgis/commitdiff
AsGML(TopoGeometry): allow specifying a prefix for topology element identifiers,...
authorSandro Santilli <strk@keybit.net>
Thu, 27 Jan 2011 20:35:23 +0000 (20:35 +0000)
committerSandro Santilli <strk@keybit.net>
Thu, 27 Jan 2011 20:35:23 +0000 (20:35 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@6744 b70326c6-7e19-0410-871a-916f4a2858ee

topology/sql/gml.sql
topology/test/regress/gml.sql
topology/test/regress/gml_expected

index 6c42a8ecd1a2621e9bd79f17525dcf68308c594a..3e97982ffac30cdefabf0416f6010dc8c478e679 100644 (file)
 --{
 --
 -- INTERNAL FUNCTION
--- text _AsGMLNode(id, point, nsprefix, precision, options)
+-- text _AsGMLNode(id, point, nsprefix, precision, options, idprefix)
 --
 -- }{
-CREATE OR REPLACE FUNCTION topology._AsGMLNode(int, geometry, text, int, int)
+CREATE OR REPLACE FUNCTION topology._AsGMLNode(int, geometry, text, int, int,
+  text)
   RETURNS text
 AS
 $$
@@ -40,6 +41,7 @@ DECLARE
   nsprefix text;
   precision ALIAS FOR $4;
   options ALIAS FOR $5;
+  idprefix ALIAS FOR $6;
   gml text;
 BEGIN
 
@@ -52,7 +54,8 @@ BEGIN
     END IF;
   END IF;
 
-  gml := '<' || nsprefix || 'Node ' || nsprefix || 'id="N' || id || '"';
+  gml := '<' || nsprefix || 'Node ' || nsprefix
+    || 'id="' || idprefix || 'N' || id || '"';
   IF point IS NOT NULL THEN
     gml = gml || '>'
               || '<' || nsprefix || 'pointProperty>'
@@ -66,16 +69,16 @@ BEGIN
 END
 $$
 LANGUAGE 'plpgsql';
---} _AsGMLNode(id, point, nsprefix, precision, options)
+--} _AsGMLNode(id, point, nsprefix, precision, options, idprefix)
 
 --{
 --
 -- INTERNAL FUNCTION
 -- text _AsGMLEdge(edge_id, start_node, end_node, line, visitedTable,
---                 nsprefix, precision, options)
+--                 nsprefix, precision, options, idprefix)
 --
 -- }{
-CREATE OR REPLACE FUNCTION topology._AsGMLEdge(int, int, int, geometry, regclass, text, int, int)
+CREATE OR REPLACE FUNCTION topology._AsGMLEdge(int, int, int, geometry, regclass, text, int, int, text)
   RETURNS text
 AS
 $$
@@ -90,6 +93,7 @@ DECLARE
   nsprefix text;
   precision ALIAS FOR $7;
   options ALIAS FOR $8;
+  idprefix ALIAS FOR $9;
   gml text;
 BEGIN
 
@@ -102,7 +106,8 @@ BEGIN
     END IF;
   END IF;
 
-  gml := '<' || nsprefix || 'Edge ' || nsprefix || 'id="E' || edge_id || '">';
+  gml := '<' || nsprefix || 'Edge ' || nsprefix
+    || 'id="' || idprefix || 'E' || edge_id || '">';
 
   -- Start node
   gml = gml || '<' || nsprefix || 'directedNode orientation="-"';
@@ -114,7 +119,7 @@ BEGIN
             || ' WHERE element_type = 1 AND element_id = '
             || start_node LIMIT 1 INTO visited;
     IF visited IS NOT NULL THEN
-      gml = gml || ' xlink:href="#N' || start_node || '" />';
+      gml = gml || ' xlink:href="#' || idprefix || 'N' || start_node || '" />';
     ELSE
       -- Mark as visited 
       EXECUTE 'INSERT INTO ' || visitedTable::text
@@ -125,7 +130,7 @@ BEGIN
   IF visited IS NULL THEN
     gml = gml || '>';
     gml = gml || topology._AsGMLNode(start_node, NULL, nsprefix_in,
-                                     precision, options);
+                                     precision, options, idprefix);
     gml = gml || '</' || nsprefix || 'directedNode>';
   END IF;
 
@@ -139,7 +144,7 @@ BEGIN
             || ' WHERE element_type = 1 AND element_id = '
             || end_node LIMIT 1 INTO visited;
     IF visited IS NOT NULL THEN
-      gml = gml || ' xlink:href="#N' || end_node || '" />';
+      gml = gml || ' xlink:href="#' || idprefix || 'N' || end_node || '" />';
     ELSE
       -- Mark as visited 
       EXECUTE 'INSERT INTO ' || visitedTable::text
@@ -150,7 +155,7 @@ BEGIN
   IF visited IS NULL THEN
     gml = gml || '>';
     gml = gml || topology._AsGMLNode(end_node, NULL, nsprefix_in,
-                                     precision, options);
+                                     precision, options, idprefix);
     gml = gml || '</' || nsprefix || 'directedNode>';
   END IF;
 
@@ -166,17 +171,17 @@ BEGIN
 END
 $$
 LANGUAGE 'plpgsql';
---} _AsGMLEdge(id, start_node, end_node, line, visitedTable, nsprefix, precision, options)
+--} _AsGMLEdge(id, start_node, end_node, line, visitedTable, nsprefix, precision, options, idprefix)
 
 --{
 --
 -- API FUNCTION
 --
--- text AsGML(TopoGeometry, nsprefix, precision, options, visitedTable)
+-- text AsGML(TopoGeometry, nsprefix, precision, options, visitedTable, idprefix)
 --
 -- }{
 CREATE OR REPLACE FUNCTION topology.AsGML(topology.TopoGeometry,
-    text, int, int, regclass)
+    text, int, int, regclass, text)
   RETURNS text
 AS
 $$
@@ -190,6 +195,7 @@ DECLARE
   options int;
   visitedTable ALIAS FOR $5;
   visited bool;
+  idprefix ALIAS FOR $6;
   toponame text;
   gml text;
   sql text;
@@ -240,7 +246,7 @@ BEGIN
                 || ' WHERE element_type = 1 AND element_id = '
                 || rec.element_id LIMIT 1 INTO visited;
         IF visited IS NOT NULL THEN
-          gml = gml || ' xlink:href="#N' || rec.element_id || '" />';
+          gml = gml || ' xlink:href="#' || idprefix || 'N' || rec.element_id || '" />';
           CONTINUE;
         ELSE
           -- Mark as visited 
@@ -250,7 +256,7 @@ BEGIN
         END IF;
       END IF;
       gml = gml || '>';
-      gml = gml || topology._AsGMLNode(rec.element_id, rec.geom, nsprefix_in, precision, options);
+      gml = gml || topology._AsGMLNode(rec.element_id, rec.geom, nsprefix_in, precision, options, idprefix);
       gml = gml || '</' || nsprefix || 'directedNode>';
     END LOOP;
     gml = gml || '</' || nsprefix || 'TopoPoint>';
@@ -292,7 +298,7 @@ BEGIN
             || rec2.edge_id LIMIT 1 INTO visited;
           IF visited THEN
             -- Use xlink:href if visited
-            gml = gml || ' xlink:href="#E' || rec2.edge_id || '" />';
+            gml = gml || ' xlink:href="#' || idprefix || 'E' || rec2.edge_id || '" />';
             CONTINUE;
           ELSE
             -- Mark as visited otherwise
@@ -311,7 +317,7 @@ BEGIN
                                         rec2.end_node, rec2.geom,
                                         visitedTable,
                                         nsprefix_in, precision,
-                                        options);
+                                        options, idprefix);
 
 
         gml = gml || '</' || nsprefix || 'directedEdge>';
@@ -376,7 +382,7 @@ BEGIN
             || rec2.edge_id LIMIT 1 INTO visited;
           IF visited THEN
             -- Use xlink:href if visited
-            gml = gml || ' xlink:href="#E' || rec2.edge_id || '" />';
+            gml = gml || ' xlink:href="#' || idprefix || 'E' || rec2.edge_id || '" />';
             CONTINUE;
           ELSE
             -- Mark as visited otherwise
@@ -394,7 +400,7 @@ BEGIN
                                         rec2.end_node, rec2.geom,
                                         visitedTable,
                                         nsprefix_in,
-                                        precision, options);
+                                        precision, options, idprefix);
         gml = gml || '</' || nsprefix || 'directedEdge>';
 
       END LOOP;
@@ -416,7 +422,22 @@ BEGIN
 END
 $$
 LANGUAGE 'plpgsql';
---} AsGML(TopoGeometry, nsprefix, precision, options, visitedTable)
+--} AsGML(TopoGeometry, nsprefix, precision, options, visitedTable, idprefix)
+
+--{
+--
+-- API FUNCTION 
+--
+-- text AsGML(TopoGeometry, nsprefix, precision, options, visitedTable)
+--
+-- }{
+CREATE OR REPLACE FUNCTION topology.AsGML(topology.TopoGeometry, text, int, int, regclass)
+  RETURNS text AS
+$$
+ SELECT topology.AsGML($1, $2, $3, $4, $5, '');
+$$ LANGUAGE 'sql';
+-- } AsGML(TopoGeometry, nsprefix, precision, options)
+
 
 --{
 --
index 693df670885081da9dd277799caa3215147961f3..76c2b04a69b6ac8aa0f2bc50dd922380c14acebc 100644 (file)
@@ -156,6 +156,13 @@ SELECT feature_name||'-visited', topology.AsGML(feature,
 
 -- TODO: we'd need to query a street taking E14 and E13, to find E14 visited ..
 
+-- Test custom identifier prefix
+-- P3 visits (E18),(E17),E8,E15,E16,E14
+--           (N10),(N13),(N18),N19,N12,N11
+SELECT feature_name||'-visited-idprefix', topology.AsGML(feature,
+       '', 15, 2, 'visited'::regclass, 'cd-') FROM features.land_parcels
+       WHERE feature_name IN ('P3');
+
 --- } Visited table bookkeeping
 
 SELECT topology.DropTopology('city_data');
index 2900e783904f81803fea2aa53b42cf7ee701cd43..aeb7a8fbbf09036cff87a0303053569b582d2a95 100644 (file)
@@ -55,4 +55,5 @@ S3-visited|<TopoPoint><directedNode xlink:href="#N6" /></TopoPoint>
 R1-visited|<TopoCurve><directedEdge><Edge id="E9"><directedNode orientation="-"><Node id="N15"/></directedNode><directedNode xlink:href="#N14" /><curveProperty><Curve srsName="EPSG:4326"><segments><LineStringSegment><posList>9 14 21 14</posList></LineStringSegment></segments></Curve></curveProperty></Edge></directedEdge><directedEdge orientation="-"><Edge id="E10"><directedNode orientation="-"><Node id="N13"/></directedNode><directedNode xlink:href="#N14" /><curveProperty><Curve srsName="EPSG:4326"><segments><LineStringSegment><posList>35 14 21 14</posList></LineStringSegment></segments></Curve></curveProperty></Edge></directedEdge></TopoCurve>
 P2-visited|<TopoSurface><directedFace><Face><directedEdge orientation="-"><Edge id="E18"><directedNode orientation="-"><Node id="N10"/></directedNode><directedNode xlink:href="#N13" /><curveProperty><Curve srsName="EPSG:4326"><segments><LineStringSegment><posList>35 6 35 14</posList></LineStringSegment></segments></Curve></curveProperty></Edge></directedEdge><directedEdge orientation="-"><Edge id="E13"><directedNode orientation="-" xlink:href="#N9" /><directedNode xlink:href="#N10" /><curveProperty><Curve srsName="EPSG:4326"><segments><LineStringSegment><posList>21 6 35 6</posList></LineStringSegment></segments></Curve></curveProperty></Edge></directedEdge><directedEdge xlink:href="#E20" /><directedEdge xlink:href="#E19" /><directedEdge><Edge id="E7"><directedNode orientation="-" xlink:href="#N17" /><directedNode><Node id="N18"/></directedNode><curveProperty><Curve srsName="EPSG:4326"><segments><LineStringSegment><posList>21 22 35 22</posList></LineStringSegment></segments></Curve></curveProperty></Edge></directedEdge><directedEdge orientation="-"><Edge id="E17"><directedNode orientation="-" xlink:href="#N13" /><directedNode xlink:href="#N18" /><curveProperty><Curve srsName="EPSG:4326"><segments><LineStringSegment><posList>35 14 35 22</posList></LineStringSegment></segments></Curve></curveProperty></Edge></directedEdge></Face></directedFace></TopoSurface>
 P1-visited|<TopoSurface><directedFace><Face><directedEdge orientation="-"><Edge id="E20"><directedNode orientation="-"><Node id="N9"/></directedNode><directedNode xlink:href="#N14" /><curveProperty><Curve srsName="EPSG:4326"><segments><LineStringSegment><posList>21 6 21 14</posList></LineStringSegment></segments></Curve></curveProperty></Edge></directedEdge><directedEdge orientation="-"><Edge id="E12"><directedNode orientation="-"><Node id="N8"/></directedNode><directedNode xlink:href="#N9" /><curveProperty><Curve srsName="EPSG:4326"><segments><LineStringSegment><posList>9 6 21 6</posList></LineStringSegment></segments></Curve></curveProperty></Edge></directedEdge><directedEdge><Edge id="E22"><directedNode orientation="-" xlink:href="#N8" /><directedNode xlink:href="#N15" /><curveProperty><Curve srsName="EPSG:4326"><segments><LineStringSegment><posList>9 6 9 14</posList></LineStringSegment></segments></Curve></curveProperty></Edge></directedEdge><directedEdge><Edge id="E21"><directedNode orientation="-" xlink:href="#N15" /><directedNode><Node id="N16"/></directedNode><curveProperty><Curve srsName="EPSG:4326"><segments><LineStringSegment><posList>9 14 9 22</posList></LineStringSegment></segments></Curve></curveProperty></Edge></directedEdge><directedEdge><Edge id="E6"><directedNode orientation="-" xlink:href="#N16" /><directedNode><Node id="N17"/></directedNode><curveProperty><Curve srsName="EPSG:4326"><segments><LineStringSegment><posList>9 22 21 22</posList></LineStringSegment></segments></Curve></curveProperty></Edge></directedEdge><directedEdge orientation="-"><Edge id="E19"><directedNode orientation="-" xlink:href="#N14" /><directedNode xlink:href="#N17" /><curveProperty><Curve srsName="EPSG:4326"><segments><LineStringSegment><posList>21 14 21 22</posList></LineStringSegment></segments></Curve></curveProperty></Edge></directedEdge></Face></directedFace></TopoSurface>
+P3-visited-idprefix|<TopoSurface><directedFace><Face><directedEdge orientation="-"><Edge id="cd-E16"><directedNode orientation="-"><Node id="cd-N11"/></directedNode><directedNode><Node id="cd-N12"/></directedNode><curveProperty><Curve srsName="EPSG:4326"><segments><LineStringSegment><posList>47 6 47 14</posList></LineStringSegment></segments></Curve></curveProperty></Edge></directedEdge><directedEdge orientation="-"><Edge id="cd-E14"><directedNode orientation="-" xlink:href="#cd-N10" /><directedNode xlink:href="#cd-N11" /><curveProperty><Curve srsName="EPSG:4326"><segments><LineStringSegment><posList>35 6 47 6</posList></LineStringSegment></segments></Curve></curveProperty></Edge></directedEdge><directedEdge xlink:href="#cd-E18" /><directedEdge xlink:href="#cd-E17" /><directedEdge><Edge id="cd-E8"><directedNode orientation="-" xlink:href="#cd-N18" /><directedNode><Node id="cd-N19"/></directedNode><curveProperty><Curve srsName="EPSG:4326"><segments><LineStringSegment><posList>35 22 47 22</posList></LineStringSegment></segments></Curve></curveProperty></Edge></directedEdge><directedEdge orientation="-"><Edge id="cd-E15"><directedNode orientation="-" xlink:href="#cd-N12" /><directedNode xlink:href="#cd-N19" /><curveProperty><Curve srsName="EPSG:4326"><segments><LineStringSegment><posList>47 14 47 22</posList></LineStringSegment></segments></Curve></curveProperty></Edge></directedEdge></Face></directedFace></TopoSurface>
 Topology 'city_data' dropped