]> granicus.if.org Git - postgis/commitdiff
Allow adding points at precision distance with TopoGeo_addPoint
authorSandro Santilli <strk@keybit.net>
Wed, 6 Mar 2013 15:20:48 +0000 (15:20 +0000)
committerSandro Santilli <strk@keybit.net>
Wed, 6 Mar 2013 15:20:48 +0000 (15:20 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@11149 b70326c6-7e19-0410-871a-916f4a2858ee

topology/sql/populate.sql.in.c
topology/test/regress/topogeo_addpoint.sql
topology/test/regress/topogeo_addpoint_expected

index 4b0d1970e80efa1e95b7f6731d2ed1f0a080a625..1e2e3119d2e07705c7925c4fe4bc4aed0bfd01c7 100644 (file)
@@ -706,13 +706,15 @@ BEGIN
   -- Get tolerance, if 0 was given
   tol := COALESCE( NULLIF(tolerance, 0), topology._st_mintolerance(atopology, apoint) );
 
-  -- 1. Check if any existing node falls within tolerance
+  -- 1. Check if any existing node is closer than the given precision
   --    and if so pick the closest
   sql := 'SELECT a.node_id FROM ' 
     || quote_ident(atopology) 
     || '.node as a WHERE ST_DWithin(a.geom,'
     || quote_literal(apoint::text) || '::geometry,'
-    || tol || ') ORDER BY ST_Distance('
+    || tol || ') AND ST_Distance('
+    || quote_literal(apoint::text)
+    || '::geometry, a.geom) < ' || tol || ' ORDER BY ST_Distance('
     || quote_literal(apoint::text)
     || '::geometry, a.geom) LIMIT 1;';
 #ifdef POSTGIS_TOPOLOGY_DEBUG
index 5275ff535d4713da276ebefbb700c8a2be06f11a..99cd81f96f17b515fcf96e9261a5f30f65f8cbea 100644 (file)
@@ -46,6 +46,11 @@ SELECT 'E', n.edge_id, n.start_node, n.end_node
     OR n.end_node > m.max
 ORDER BY n.edge_id;
 
+-- Test precision
+SELECT 'prec1', 'N' || topogeo_addpoint('city_data', 'POINT(39 26)', 2);
+SELECT 'prec2', 'N' || topogeo_addpoint('city_data', 'POINT(39 26)', 1);
+SELECT 'prec3', 'N' || topogeo_addpoint('city_data', 'POINT(36 26)', 1);
+
 SELECT DropTopology('city_data');
 
 -- See http://trac.osgeo.org/postgis/ticket/2033
@@ -54,3 +59,4 @@ SELECT 'tt2033', 'E' || topogeo_addlinestring('t', 'LINESTRING(0 0 0,0 1 0,0 2 1
 SELECT 'tt2033', 'N' || topogeo_addpoint('t', 'POINT(0.2 1 1)', 0.5);
 SELECT 'tt2033', 'NC', node_id, ST_AsText(geom) FROM t.node ORDER BY node_id;
 SELECT 'tt2033.end' || DropTopology('t');
+
index af6e614de2b4da6fbed450d872ab347db901d10b..ce32d19ae25964d5bc676d961196f39d350fbf7f 100644 (file)
@@ -19,6 +19,9 @@ N|24|3|POINT(16 18)
 N|25||POINT(26 30)
 E|2|2|25
 E|27|25|2
+prec1|N23
+prec2|N26
+prec3|N27
 Topology 'city_data' dropped
 tt2033.start|t
 tt2033|E1