From: Sandro Santilli <strk@keybit.net>
Date: Wed, 21 Oct 2015 14:17:10 +0000 (+0000)
Subject: Support for Puntal output in topology.AsTopoJSON
X-Git-Tag: 2.3.0beta1~414
X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9e61f28d4da6db7985272a4d7fa7950560e50fe6;p=postgis

Support for Puntal output in topology.AsTopoJSON

Closes #3343

git-svn-id: http://svn.osgeo.org/postgis/trunk@14298 b70326c6-7e19-0410-871a-916f4a2858ee
---

diff --git a/doc/extras_topology.xml b/doc/extras_topology.xml
index 45fc82c4a..1482f3f44 100644
--- a/doc/extras_topology.xml
+++ b/doc/extras_topology.xml
@@ -3266,11 +3266,16 @@ in the "edgeMapTable" table.
     </note>
 
 		<para>
-A full TopoJSON document will be need to contain, in addition to the snippets returned by this function, the actual arcs plus some headers. See the <ulink url="http://github.com/mbostock/topojson/wiki/Specification">TopoJSON specification</ulink>.
+A full TopoJSON document will be need to contain, in
+addition to the snippets returned by this function,
+the actual arcs plus some headers. See the <ulink
+url="http://github.com/mbostock/topojson-specification/blob/master/README.md"
+>TopoJSON specification</ulink>.
 		</para>
               
                 <!-- use this format if new function -->
                 <para>Availability: 2.1.0 </para>
+                <para>Enhanced: 2.2.1 added support for puntal inputs</para>
 			</refsection>
 		
 		
diff --git a/topology/sql/export/TopoJSON.sql.in b/topology/sql/export/TopoJSON.sql.in
index 847875cfe..4d331634e 100644
--- a/topology/sql/export/TopoJSON.sql.in
+++ b/topology/sql/export/TopoJSON.sql.in
@@ -22,6 +22,9 @@
 --
 -- text AsTopoJSON(TopoGeometry, edgeMapTable)
 --
+-- Format specification here:
+-- http://github.com/mbostock/topojson-specification/blob/master/README.md
+--
 -- }{
 CREATE OR REPLACE FUNCTION topology.AsTopoJSON(tg topology.TopoGeometry, edgeMapTable regclass)
   RETURNS text AS
@@ -56,12 +59,12 @@ BEGIN
   SELECT name FROM topology.topology into toponame
               WHERE id = tg.topology_id;
 
-  -- Puntual TopoGeometry
+  -- TODO: implement scale ?
+
+  -- Puntal TopoGeometry, simply delegate to AsGeoJSON
   IF tg.type = 1 THEN
-    -- TODO: implement scale ?
-    --json := ST_AsGeoJSON(topology.Geometry(tg));
-    --return json;
-    RAISE EXCEPTION 'TopoJSON export does not support puntual objects';
+    json := ST_AsGeoJSON(topology.Geometry(tg));
+    return json;
   ELSIF tg.type = 2 THEN -- lineal
 
     FOR rec IN SELECT (ST_Dump(topology.Geometry(tg))).geom
diff --git a/topology/test/regress/topojson.sql b/topology/test/regress/topojson.sql
index 82d7675b1..5f154b060 100644
--- a/topology/test/regress/topojson.sql
+++ b/topology/test/regress/topojson.sql
@@ -92,5 +92,10 @@ SELECT 'A3-vanilla', feature_name, topology.AsTopoJSON(feature, null)
  WHERE feature_name IN ('P6')
  ORDER BY feature_name;
 
+SELECT 'P1-vanilla', feature_name, topology.AsTopoJSON(feature, null)
+ FROM features.traffic_signs
+ WHERE feature_name IN ('S2')
+ ORDER BY feature_name;
+
 SELECT topology.DropTopology('city_data');
 DROP SCHEMA features CASCADE;
diff --git a/topology/test/regress/topojson_expected b/topology/test/regress/topojson_expected
index cd597712d..0b1901193 100644
--- a/topology/test/regress/topojson_expected
+++ b/topology/test/regress/topojson_expected
@@ -49,4 +49,5 @@ E33
 E34
 E35
 A3-vanilla|P6|{ "type": "MultiPolygon", "arcs": [[[-33],[30,25],[1]],[[-34],[34]]]}
+P1-vanilla|S2|{"type":"MultiPoint","coordinates":[[35,14]]}
 Topology 'city_data' dropped