PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ test_tree_circ_distance()

static void test_tree_circ_distance ( void  )
static

Definition at line 175 of file cu_tree.c.

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, and spheroid_init().

Referenced by tree_suite_setup().

176 {
177  LWGEOM *lwg1, *lwg2;
178  CIRC_NODE *c1, *c2;
179  SPHEROID s;
180  double d1, d2, d3, d4;
181  double threshold = 0.0;
182 
183  spheroid_init(&s, 1.0, 1.0);
184 
185  /* Ticket #1958 */
186  lwg1 = lwgeom_from_wkt("LINESTRING(22.88333 41.96667,21.32667 42.13667)", LW_PARSER_CHECK_NONE);
187  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);
188  c1 = lwgeom_calculate_circ_tree(lwg1);
189  c2 = lwgeom_calculate_circ_tree(lwg2);
190  d1 = circ_tree_distance_tree(c1, c2, &s, threshold);
191  d2 = lwgeom_distance_spheroid(lwg1, lwg2, &s, threshold);
192 // printf("d1 = %g d2 = %g\n", d1 * WGS84_RADIUS, d2 * WGS84_RADIUS);
193 // printf("line\n");
194 // circ_tree_print(c1, 0);
195 // printf("poly\n");
196 // circ_tree_print(c2, 0);
197  circ_tree_free(c1);
198  circ_tree_free(c2);
199  lwgeom_free(lwg1);
200  lwgeom_free(lwg2);
201  CU_ASSERT_DOUBLE_EQUAL(d1, d2, 0.0000001);
202 
203  /* Ticket #1951 */
204  lwg1 = lwgeom_from_wkt("LINESTRING(0 0, 0 0)", LW_PARSER_CHECK_NONE);
205  lwg2 = lwgeom_from_wkt("POINT(0.1 0.1)", LW_PARSER_CHECK_NONE);
206  c1 = lwgeom_calculate_circ_tree(lwg1);
207  c2 = lwgeom_calculate_circ_tree(lwg2);
208  d1 = circ_tree_distance_tree(c1, c2, &s, threshold);
209  d2 = lwgeom_distance_spheroid(lwg1, lwg2, &s, threshold);
210  circ_tree_free(c1);
211  circ_tree_free(c2);
212  lwgeom_free(lwg1);
213  lwgeom_free(lwg2);
214  CU_ASSERT_DOUBLE_EQUAL(d1, d2, 0.00001);
215 
216  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);
217  lwg2 = lwgeom_from_wkt("POINT(-2 0)", LW_PARSER_CHECK_NONE);
218  c1 = lwgeom_calculate_circ_tree(lwg1);
219  c2 = lwgeom_calculate_circ_tree(lwg2);
220  d1 = circ_tree_distance_tree(c1, c2, &s, threshold);
221  d2 = lwgeom_distance_spheroid(lwg1, lwg2, &s, threshold);
222  circ_tree_free(c1);
223  circ_tree_free(c2);
224  lwgeom_free(lwg1);
225  lwgeom_free(lwg2);
226  CU_ASSERT_DOUBLE_EQUAL(d1, d2, 0.00001);
227 
228  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);
229  lwg2 = lwgeom_from_wkt("POINT(2 2)", 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(1 1)", 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(1 0.5)", 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 // printf("distance_tree %g\n", distance_tree);
259 // printf("distance_geom %g\n", distance_geom);
260 // circ_tree_print(cline, 0);
261 // circ_tree_print(cpoint, 0);
262  circ_tree_free(c1);
263  circ_tree_free(c2);
264  lwgeom_free(lwg1);
265  lwgeom_free(lwg2);
266  CU_ASSERT_DOUBLE_EQUAL(d1, d2, 0.00001);
267 
268 
269  /* Ticket #2351 */
270  lwg1 = lwgeom_from_wkt("LINESTRING(149.386990599235 -26.3567415843982,149.386990599247 -26.3567415843965)", LW_PARSER_CHECK_NONE);
271  lwg2 = lwgeom_from_wkt("POINT(149.386990599235 -26.3567415843982)", LW_PARSER_CHECK_NONE);
272  c1 = lwgeom_calculate_circ_tree(lwg1);
273  c2 = lwgeom_calculate_circ_tree(lwg2);
274  d1 = circ_tree_distance_tree(c1, c2, &s, threshold);
275  d2 = lwgeom_distance_spheroid(lwg1, lwg2, &s, threshold);
276 // printf("d1 = %g d2 = %g\n", d1 * WGS84_RADIUS, d2 * WGS84_RADIUS);
277 // printf("line\n");
278 // circ_tree_print(c1, 0);
279 // printf("point\n");
280 // circ_tree_print(c2, 0);
281  circ_tree_free(c1);
282  circ_tree_free(c2);
283  lwgeom_free(lwg1);
284  lwgeom_free(lwg2);
285  CU_ASSERT_DOUBLE_EQUAL(d1, d2, 0.0000001);
286 
287  /* Ticket #2634 */
288  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);
289  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);
290  c1 = lwgeom_calculate_circ_tree(lwg1);
291  c2 = lwgeom_calculate_circ_tree(lwg2);
292  d1 = circ_tree_distance_tree(c1, c2, &s, threshold);
293  d2 = lwgeom_distance_spheroid(lwg1, lwg2, &s, threshold);
294 // printf("d1 = %g d2 = %g\n", d1 * WGS84_RADIUS, d2 * WGS84_RADIUS);
295 // printf("multipoint\n");
296 // circ_tree_print(c1, 0);
297 // printf("polygon\n");
298 // circ_tree_print(c2, 0);
299  circ_tree_free(c1);
300  circ_tree_free(c2);
301  lwgeom_free(lwg1);
302  lwgeom_free(lwg2);
303  CU_ASSERT_DOUBLE_EQUAL(d1, d2, 0.0000001);
304 
305  /* Ticket #2634 */
306  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);
307  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);
308  c1 = lwgeom_calculate_circ_tree(lwg1);
309  c2 = lwgeom_calculate_circ_tree(lwg2);
310 // printf("\n");
311 // circ_tree_print(c1, 0);
312 // printf("\n");
313 // circ_tree_print(c2, 0);
314 // printf("\n");
315  d1 = lwgeom_distance_spheroid(lwg1, lwg2, &s, threshold);
316  d2 = circ_tree_distance_tree(c1, c2, &s, threshold);
317  d3 = circ_tree_distance_tree(c1, c2, &s, threshold);
318  d4 = circ_tree_distance_tree(c1, c2, &s, threshold);
319 // printf("\n d1-no-tree %20.20g\n d2 %20.20g\n d3 %20.20g\n d4 %20.20g\n", d1, d2, d3, d4);
320  circ_tree_free(c1);
321  circ_tree_free(c2);
322  lwgeom_free(lwg1);
323  lwgeom_free(lwg2);
324  CU_ASSERT_DOUBLE_EQUAL(d1, d2, 0.00000001);
325  CU_ASSERT_DOUBLE_EQUAL(d1, d3, 0.00000001);
326  CU_ASSERT_DOUBLE_EQUAL(d1, d4, 0.00000001);
327 
328 }
Note that p1 and p2 are pointers into an independent POINTARRAY, do not free them.
void spheroid_init(SPHEROID *s, double a, double b)
Initialize a spheroid object for use in geodetic functions.
Definition: lwspheroid.c:25
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1050
double circ_tree_distance_tree(const CIRC_NODE *n1, const CIRC_NODE *n2, const SPHEROID *spheroid, double threshold)
LWGEOM * lwgeom_from_wkt(const char *wkt, const char check)
Definition: lwin_wkt.c:890
CIRC_NODE * lwgeom_calculate_circ_tree(const LWGEOM *lwgeom)
#define LW_PARSER_CHECK_NONE
Definition: liblwgeom.h:1869
char * s
Definition: cu_in_wkt.c:23
void circ_tree_free(CIRC_NODE *node)
Recurse from top of node tree and free all children.
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:2081
Here is the call graph for this function:
Here is the caller graph for this function: