PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ test_tree_circ_distance()

static void test_tree_circ_distance ( void  )
static

Definition at line 175 of file cu_tree.c.

176 {
177  LWGEOM *lwg1, *lwg2;
178  CIRC_NODE *c1, *c2;
179  SPHEROID s;
180  double d1, d2, d3, d4, e1, e2;
181  double threshold = 0.0;
182 
183  spheroid_init(&s, 1.0, 1.0);
184 
185  /* Ticket #4223 */
186  /* tall skinny rectangle */
187  lwg1 = lwgeom_from_wkt("POLYGON((58.5112113206308 0,58.5112113200772 0.000901937525203378,58.511300910044 0.000901937636668872,58.5113009105976 0,58.5112113206308 0))", LW_PARSER_CHECK_NONE);
188  /* square box 5m to left */
189  lwg2 = lwgeom_from_wkt("POLYGON((58.5111665256017 0.000270581240841207,58.5111665255629 0.000360774987788249,58.5110769356128 0.000360774943200728,58.5110769356515 0.000270581207400566,58.5111665256017 0.000270581240841207))", LW_PARSER_CHECK_NONE);
190  c1 = lwgeom_calculate_circ_tree(lwg1);
191  c2 = lwgeom_calculate_circ_tree(lwg2);
192  d1 = circ_tree_distance_tree(c1, c2, &s, threshold);
193  d2 = lwgeom_distance_spheroid(lwg1, lwg2, &s, threshold);
194  e1 = d1 * WGS84_RADIUS;
195  e2 = d2 * WGS84_RADIUS;
196  // printf("d1 = %g d2 = %g\n", d1, d2);
197  // printf("e1 = %g e2 = %g\n", e1, e2);
198  // printf("polygon a\n");
199  // circ_tree_print(c1, 0);
200  // printf("polygon b\n");
201  // circ_tree_print(c2, 0);
202  circ_tree_free(c1);
203  circ_tree_free(c2);
204  lwgeom_free(lwg1);
205  lwgeom_free(lwg2);
206  CU_ASSERT_DOUBLE_EQUAL(e1, e2, 0.0001);
207 
208 
209  /* Ticket #1958 */
210  lwg1 = lwgeom_from_wkt("LINESTRING(22.88333 41.96667,21.32667 42.13667)", LW_PARSER_CHECK_NONE);
211  lwg2 = lwgeom_from_wkt("POLYGON((22.94472 41.34667,22.87528 41.99028,22.87389 41.98472,22.87472 41.98333,22.94472 41.34667))", LW_PARSER_CHECK_NONE);
212  c1 = lwgeom_calculate_circ_tree(lwg1);
213  c2 = lwgeom_calculate_circ_tree(lwg2);
214  d1 = circ_tree_distance_tree(c1, c2, &s, threshold);
215  d2 = lwgeom_distance_spheroid(lwg1, lwg2, &s, threshold);
216 // printf("d1 = %g d2 = %g\n", d1 * WGS84_RADIUS, d2 * WGS84_RADIUS);
217 // printf("line\n");
218 // circ_tree_print(c1, 0);
219 // printf("poly\n");
220 // circ_tree_print(c2, 0);
221  circ_tree_free(c1);
222  circ_tree_free(c2);
223  lwgeom_free(lwg1);
224  lwgeom_free(lwg2);
225  CU_ASSERT_DOUBLE_EQUAL(d1, d2, 0.0000001);
226 
227  /* Ticket #1951 */
228  lwg1 = lwgeom_from_wkt("LINESTRING(0 0, 0 0)", LW_PARSER_CHECK_NONE);
229  lwg2 = lwgeom_from_wkt("POINT(0.1 0.1)", LW_PARSER_CHECK_NONE);
230  c1 = lwgeom_calculate_circ_tree(lwg1);
231  c2 = lwgeom_calculate_circ_tree(lwg2);
232  d1 = circ_tree_distance_tree(c1, c2, &s, threshold);
233  d2 = lwgeom_distance_spheroid(lwg1, lwg2, &s, threshold);
234  circ_tree_free(c1);
235  circ_tree_free(c2);
236  lwgeom_free(lwg1);
237  lwgeom_free(lwg2);
238  CU_ASSERT_DOUBLE_EQUAL(d1, d2, 0.00001);
239 
240  lwg1 = lwgeom_from_wkt("LINESTRING(-1 -1,0 -1,1 -1,1 0,1 1,0 0,-1 1,-1 0,-1 -1)", LW_PARSER_CHECK_NONE);
241  lwg2 = lwgeom_from_wkt("POINT(-2 0)", LW_PARSER_CHECK_NONE);
242  c1 = lwgeom_calculate_circ_tree(lwg1);
243  c2 = lwgeom_calculate_circ_tree(lwg2);
244  d1 = circ_tree_distance_tree(c1, c2, &s, threshold);
245  d2 = lwgeom_distance_spheroid(lwg1, lwg2, &s, threshold);
246  circ_tree_free(c1);
247  circ_tree_free(c2);
248  lwgeom_free(lwg1);
249  lwgeom_free(lwg2);
250  CU_ASSERT_DOUBLE_EQUAL(d1, d2, 0.00001);
251 
252  lwg1 = lwgeom_from_wkt("LINESTRING(-1 -1,0 -1,1 -1,1 0,1 1,0 0,-1 1,-1 0,-1 -1)", LW_PARSER_CHECK_NONE);
253  lwg2 = lwgeom_from_wkt("POINT(2 2)", LW_PARSER_CHECK_NONE);
254  c1 = lwgeom_calculate_circ_tree(lwg1);
255  c2 = lwgeom_calculate_circ_tree(lwg2);
256  d1 = circ_tree_distance_tree(c1, c2, &s, threshold);
257  d2 = lwgeom_distance_spheroid(lwg1, lwg2, &s, threshold);
258  circ_tree_free(c1);
259  circ_tree_free(c2);
260  lwgeom_free(lwg1);
261  lwgeom_free(lwg2);
262  CU_ASSERT_DOUBLE_EQUAL(d1, d2, 0.00001);
263 
264  lwg1 = lwgeom_from_wkt("LINESTRING(-1 -1,0 -1,1 -1,1 0,1 1,0 0,-1 1,-1 0,-1 -1)", LW_PARSER_CHECK_NONE);
265  lwg2 = lwgeom_from_wkt("POINT(1 1)", LW_PARSER_CHECK_NONE);
266  c1 = lwgeom_calculate_circ_tree(lwg1);
267  c2 = lwgeom_calculate_circ_tree(lwg2);
268  d1 = circ_tree_distance_tree(c1, c2, &s, threshold);
269  d2 = lwgeom_distance_spheroid(lwg1, lwg2, &s, threshold);
270  circ_tree_free(c1);
271  circ_tree_free(c2);
272  lwgeom_free(lwg1);
273  lwgeom_free(lwg2);
274  CU_ASSERT_DOUBLE_EQUAL(d1, d2, 0.00001);
275 
276  lwg1 = lwgeom_from_wkt("LINESTRING(-1 -1,0 -1,1 -1,1 0,1 1,0 0,-1 1,-1 0,-1 -1)", LW_PARSER_CHECK_NONE);
277  lwg2 = lwgeom_from_wkt("POINT(1 0.5)", LW_PARSER_CHECK_NONE);
278  c1 = lwgeom_calculate_circ_tree(lwg1);
279  c2 = lwgeom_calculate_circ_tree(lwg2);
280  d1 = circ_tree_distance_tree(c1, c2, &s, threshold);
281  d2 = lwgeom_distance_spheroid(lwg1, lwg2, &s, threshold);
282 // printf("distance_tree %g\n", distance_tree);
283 // printf("distance_geom %g\n", distance_geom);
284 // circ_tree_print(cline, 0);
285 // circ_tree_print(cpoint, 0);
286  circ_tree_free(c1);
287  circ_tree_free(c2);
288  lwgeom_free(lwg1);
289  lwgeom_free(lwg2);
290  CU_ASSERT_DOUBLE_EQUAL(d1, d2, 0.00001);
291 
292 
293  /* Ticket #2351 */
294  lwg1 = lwgeom_from_wkt("LINESTRING(149.386990599235 -26.3567415843982,149.386990599247 -26.3567415843965)", LW_PARSER_CHECK_NONE);
295  lwg2 = lwgeom_from_wkt("POINT(149.386990599235 -26.3567415843982)", LW_PARSER_CHECK_NONE);
296  c1 = lwgeom_calculate_circ_tree(lwg1);
297  c2 = lwgeom_calculate_circ_tree(lwg2);
298  d1 = circ_tree_distance_tree(c1, c2, &s, threshold);
299  d2 = lwgeom_distance_spheroid(lwg1, lwg2, &s, threshold);
300 // printf("d1 = %g d2 = %g\n", d1 * WGS84_RADIUS, d2 * WGS84_RADIUS);
301 // printf("line\n");
302 // circ_tree_print(c1, 0);
303 // printf("point\n");
304 // circ_tree_print(c2, 0);
305  circ_tree_free(c1);
306  circ_tree_free(c2);
307  lwgeom_free(lwg1);
308  lwgeom_free(lwg2);
309  CU_ASSERT_DOUBLE_EQUAL(d1, d2, 0.0000001);
310 
311  /* Ticket #2634 */
312  lwg1 = lwgeom_from_wkt("MULTIPOINT (-10 40,-10 65,10 40,10 65,30 40,30 65,50 40,50 65)", LW_PARSER_CHECK_NONE);
313  lwg2 = lwgeom_from_wkt("POLYGON((-9.1111111 40,-9.14954053919354 39.6098193559677,-9.26335203497743 39.2346331352698,-9.44817187539491 38.8888595339608,-9.6968975376269 38.5857864376269,-9.99997063396079 38.3370607753949,-10.3457442352698 38.1522409349774,-10.7209304559677 38.0384294391935,-11.1111111 38,-11.5012917440323 38.0384294391935,-11.8764779647302 38.1522409349774,-12.2222515660392 38.3370607753949,-12.5253246623731 38.5857864376269,-12.7740503246051 38.8888595339608,-12.9588701650226 39.2346331352698,-13.0726816608065 39.6098193559677,-13.1111111 40,-13.0726816608065 40.3901806440322,-12.9588701650226 40.7653668647302,-12.7740503246051 41.1111404660392,-12.5253246623731 41.4142135623731,-12.2222515660392 41.6629392246051,-11.8764779647302 41.8477590650226,-11.5012917440323 41.9615705608065,-11.1111111 42,-10.7209304559678 41.9615705608065,-10.3457442352698 41.8477590650226,-9.9999706339608 41.6629392246051,-9.69689753762691 41.4142135623731,-9.44817187539491 41.1111404660392,-9.26335203497743 40.7653668647302,-9.14954053919354 40.3901806440323,-9.1111111 40))", LW_PARSER_CHECK_NONE);
314  c1 = lwgeom_calculate_circ_tree(lwg1);
315  c2 = lwgeom_calculate_circ_tree(lwg2);
316  d1 = circ_tree_distance_tree(c1, c2, &s, threshold);
317  d2 = lwgeom_distance_spheroid(lwg1, lwg2, &s, threshold);
318 // printf("d1 = %g d2 = %g\n", d1 * WGS84_RADIUS, d2 * WGS84_RADIUS);
319 // printf("multipoint\n");
320 // circ_tree_print(c1, 0);
321 // printf("polygon\n");
322 // circ_tree_print(c2, 0);
323  circ_tree_free(c1);
324  circ_tree_free(c2);
325  lwgeom_free(lwg1);
326  lwgeom_free(lwg2);
327  CU_ASSERT_DOUBLE_EQUAL(d1, d2, 0.0000001);
328 
329  /* Ticket #2634 */
330  lwg1 = lwgeom_from_wkt("MULTIPOINT Z (-10 40 1,-10 65 1,10 40 1,10 65 1,30 40 1,30 65 1,50 40 1,50 65 1,-10 40 2,-10 65 2,10 40 2,10 65 2,30 40 2,30 65 2,50 40 2,50 65 2,-10 40 3,-10 65 3,10 40 3,10 65 3,30 40 3,30 65 3,50 40 3,50 65 3)", LW_PARSER_CHECK_NONE);
331  lwg2 = lwgeom_from_wkt("MULTIPOLYGON(((-9.1111111 40,-9.14954053919354 39.6098193559677,-9.26335203497743 39.2346331352698,-9.44817187539491 38.8888595339608,-9.6968975376269 38.5857864376269,-9.99997063396079 38.3370607753949,-10.3457442352698 38.1522409349774,-10.7209304559677 38.0384294391935,-11.1111111 38,-11.5012917440323 38.0384294391935,-11.8764779647302 38.1522409349774,-12.2222515660392 38.3370607753949,-12.5253246623731 38.5857864376269,-12.7740503246051 38.8888595339608,-12.9588701650226 39.2346331352698,-13.0726816608065 39.6098193559677,-13.1111111 40,-13.0726816608065 40.3901806440322,-12.9588701650226 40.7653668647302,-12.7740503246051 41.1111404660392,-12.5253246623731 41.4142135623731,-12.2222515660392 41.6629392246051,-11.8764779647302 41.8477590650226,-11.5012917440323 41.9615705608065,-11.1111111 42,-10.7209304559678 41.9615705608065,-10.3457442352698 41.8477590650226,-9.9999706339608 41.6629392246051,-9.69689753762691 41.4142135623731,-9.44817187539491 41.1111404660392,-9.26335203497743 40.7653668647302,-9.14954053919354 40.3901806440323,-9.1111111 40)))", LW_PARSER_CHECK_NONE);
332  c1 = lwgeom_calculate_circ_tree(lwg1);
333  c2 = lwgeom_calculate_circ_tree(lwg2);
334 // printf("\n");
335 // circ_tree_print(c1, 0);
336 // printf("\n");
337 // circ_tree_print(c2, 0);
338 // printf("\n");
339  d1 = lwgeom_distance_spheroid(lwg1, lwg2, &s, threshold);
340  d2 = circ_tree_distance_tree(c1, c2, &s, threshold);
341  d3 = circ_tree_distance_tree(c1, c2, &s, threshold);
342  d4 = circ_tree_distance_tree(c1, c2, &s, threshold);
343 // printf("\n d1-no-tree %20.20g\n d2 %20.20g\n d3 %20.20g\n d4 %20.20g\n", d1, d2, d3, d4);
344  circ_tree_free(c1);
345  circ_tree_free(c2);
346  lwgeom_free(lwg1);
347  lwgeom_free(lwg2);
348  CU_ASSERT_DOUBLE_EQUAL(d1, d2, 0.00000001);
349  CU_ASSERT_DOUBLE_EQUAL(d1, d3, 0.00000001);
350  CU_ASSERT_DOUBLE_EQUAL(d1, d4, 0.00000001);
351 
352 }
char * s
Definition: cu_in_wkt.c:23
double lwgeom_distance_spheroid(const LWGEOM *lwgeom1, const LWGEOM *lwgeom2, const SPHEROID *spheroid, double tolerance)
Calculate the geodetic distance from lwgeom1 to lwgeom2 on the spheroid.
Definition: lwgeodetic.c:2187
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1144
#define LW_PARSER_CHECK_NONE
Definition: liblwgeom.h:2005
#define WGS84_RADIUS
Definition: liblwgeom.h:131
void spheroid_init(SPHEROID *s, double a, double b)
Initialize a spheroid object for use in geodetic functions.
Definition: lwspheroid.c:39
LWGEOM * lwgeom_from_wkt(const char *wkt, const char check)
Definition: lwin_wkt.c:904
double circ_tree_distance_tree(const CIRC_NODE *n1, const CIRC_NODE *n2, const SPHEROID *spheroid, double threshold)
void circ_tree_free(CIRC_NODE *node)
Recurse from top of node tree and free all children.
CIRC_NODE * lwgeom_calculate_circ_tree(const LWGEOM *lwgeom)
Note that p1 and p2 are pointers into an independent POINTARRAY, do not free them.

References circ_tree_distance_tree(), circ_tree_free(), LW_PARSER_CHECK_NONE, lwgeom_calculate_circ_tree(), lwgeom_distance_spheroid(), lwgeom_free(), lwgeom_from_wkt(), s, spheroid_init(), and WGS84_RADIUS.

Referenced by tree_suite_setup().

Here is the call graph for this function:
Here is the caller graph for this function: