PostGIS  2.1.10dev-r@@SVN_REVISION@@
static void test_gbox_utils ( void  )
static

Definition at line 1344 of file cu_geodetic.c.

References GBOX::flags, gbox_angular_height(), gbox_angular_width(), gbox_centroid(), gflags(), LW_PARSER_CHECK_NONE, lwgeom_calculate_gbox_geodetic(), lwgeom_free(), lwgeom_from_wkt(), s, spheroid_init(), WGS84_MAJOR_AXIS, WGS84_MINOR_AXIS, POINT2D::x, and POINT2D::y.

Referenced by geodetic_suite_setup().

1345 {
1346  LWGEOM *lwg;
1347  GBOX gbox;
1348  double a1, a2;
1349  SPHEROID s;
1350  POINT2D pt;
1351 
1352  /* Init to WGS84 */
1354 
1355  gbox.flags = gflags(0, 0, 1);
1356 
1357  /* One-degree square by equator */
1358  lwg = lwgeom_from_wkt("POLYGON((1 20,1 21,2 21,2 20,1 20))", LW_PARSER_CHECK_NONE);
1359  lwgeom_calculate_gbox_geodetic(lwg, &gbox);
1360  a1 = gbox_angular_width(&gbox);
1361  a2 = gbox_angular_height(&gbox);
1362  CU_ASSERT_DOUBLE_EQUAL(a1, 0.0177951, 0.0000001);
1363  CU_ASSERT_DOUBLE_EQUAL(a2, 0.017764, 0.0000001);
1364  lwgeom_free(lwg);
1365 
1366  /* One-degree square *across* dateline */
1367  lwg = lwgeom_from_wkt("POLYGON((179.5 2,179.5 1,-179.5 1,-179.5 2,179.5 2))", LW_PARSER_CHECK_NONE);
1368  lwgeom_calculate_gbox_geodetic(lwg, &gbox);
1369  a1 = gbox_angular_width(&gbox);
1370  a2 = gbox_angular_height(&gbox);
1371  //printf("a1=%g a2=%g\n", a1, a2);
1372  CU_ASSERT_DOUBLE_EQUAL(a1, 0.0174613, 0.0000001);
1373  CU_ASSERT_DOUBLE_EQUAL(a2, 0.0174553, 0.0000001);
1374  lwgeom_free(lwg);
1375 
1376  /* One-degree square *across* dateline */
1377  lwg = lwgeom_from_wkt("POLYGON((178.5 2,178.5 1,-179.5 1,-179.5 2,178.5 2))", LW_PARSER_CHECK_NONE);
1378  lwgeom_calculate_gbox_geodetic(lwg, &gbox);
1379  gbox_centroid(&gbox, &pt);
1380  //printf("POINT(%g %g)\n", pt.x, pt.y);
1381  CU_ASSERT_DOUBLE_EQUAL(pt.x, 179.5, 0.0001);
1382  CU_ASSERT_DOUBLE_EQUAL(pt.y, 1.50024, 0.0001);
1383  lwgeom_free(lwg);
1384 
1385 }
int lwgeom_calculate_gbox_geodetic(const LWGEOM *geom, GBOX *gbox)
Calculate the geodetic bounding box for an LWGEOM.
Definition: lwgeodetic.c:2612
void spheroid_init(SPHEROID *s, double a, double b)
Initialize a spheroid object for use in geodetic functions.
Definition: lwspheroid.c:20
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1006
int gbox_centroid(const GBOX *gbox, POINT2D *out)
Computes the average(ish) center of the box and returns success.
Definition: lwgeodetic.c:244
#define WGS84_MINOR_AXIS
Definition: liblwgeom.h:97
LWGEOM * lwgeom_from_wkt(const char *wkt, const char check)
Definition: lwin_wkt.c:844
#define LW_PARSER_CHECK_NONE
Definition: liblwgeom.h:1706
double x
Definition: liblwgeom.h:284
double y
Definition: liblwgeom.h:284
char * s
Definition: cu_in_wkt.c:24
uint8_t flags
Definition: liblwgeom.h:247
uint8_t gflags(int hasz, int hasm, int geodetic)
Construct a new flags char.
Definition: g_util.c:131
#define WGS84_MAJOR_AXIS
Definition: liblwgeom.h:95
double gbox_angular_height(const GBOX *gbox)
GBOX utility functions to figure out coverage/location on the globe.
Definition: lwgeodetic.c:165
double gbox_angular_width(const GBOX *gbox)
Returns the angular width (longitudinal span) of the box in radians.
Definition: lwgeodetic.c:192

Here is the call graph for this function:

Here is the caller graph for this function: