PostGIS  2.3.6-r@@SVN_REVISION@@
static void test_gbox_utils ( void  )
static

Definition at line 1416 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().

1417 {
1418  LWGEOM *lwg;
1419  GBOX gbox;
1420  double a1, a2;
1421  SPHEROID s;
1422  POINT2D pt;
1423 
1424  /* Init to WGS84 */
1426 
1427  gbox.flags = gflags(0, 0, 1);
1428 
1429  /* One-degree square by equator */
1430  lwg = lwgeom_from_wkt("POLYGON((1 20,1 21,2 21,2 20,1 20))", LW_PARSER_CHECK_NONE);
1431  lwgeom_calculate_gbox_geodetic(lwg, &gbox);
1432  a1 = gbox_angular_width(&gbox);
1433  a2 = gbox_angular_height(&gbox);
1434  CU_ASSERT_DOUBLE_EQUAL(a1, 0.0177951, 0.0000001);
1435  CU_ASSERT_DOUBLE_EQUAL(a2, 0.017764, 0.0000001);
1436  lwgeom_free(lwg);
1437 
1438  /* One-degree square *across* antimeridian */
1439  lwg = lwgeom_from_wkt("POLYGON((179.5 2,179.5 1,-179.5 1,-179.5 2,179.5 2))", LW_PARSER_CHECK_NONE);
1440  lwgeom_calculate_gbox_geodetic(lwg, &gbox);
1441  a1 = gbox_angular_width(&gbox);
1442  a2 = gbox_angular_height(&gbox);
1443  //printf("a1=%g a2=%g\n", a1, a2);
1444  CU_ASSERT_DOUBLE_EQUAL(a1, 0.0174613, 0.0000001);
1445  CU_ASSERT_DOUBLE_EQUAL(a2, 0.0174553, 0.0000001);
1446  lwgeom_free(lwg);
1447 
1448  /* One-degree square *across* antimeridian */
1449  lwg = lwgeom_from_wkt("POLYGON((178.5 2,178.5 1,-179.5 1,-179.5 2,178.5 2))", LW_PARSER_CHECK_NONE);
1450  lwgeom_calculate_gbox_geodetic(lwg, &gbox);
1451  gbox_centroid(&gbox, &pt);
1452  //printf("POINT(%g %g)\n", pt.x, pt.y);
1453  CU_ASSERT_DOUBLE_EQUAL(pt.x, 179.5, 0.0001);
1454  CU_ASSERT_DOUBLE_EQUAL(pt.y, 1.50024, 0.0001);
1455  lwgeom_free(lwg);
1456 
1457 }
int lwgeom_calculate_gbox_geodetic(const LWGEOM *geom, GBOX *gbox)
Calculate the geodetic bounding box for an LWGEOM.
Definition: lwgeodetic.c:2626
void spheroid_init(SPHEROID *s, double a, double b)
Initialize a spheroid object for use in geodetic functions.
Definition: lwspheroid.c:39
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1063
int gbox_centroid(const GBOX *gbox, POINT2D *out)
Computes the average(ish) center of the box and returns success.
Definition: lwgeodetic.c:258
#define WGS84_MINOR_AXIS
Definition: liblwgeom.h:129
LWGEOM * lwgeom_from_wkt(const char *wkt, const char check)
Definition: lwin_wkt.c:904
#define LW_PARSER_CHECK_NONE
Definition: liblwgeom.h:1985
double x
Definition: liblwgeom.h:327
double y
Definition: liblwgeom.h:327
char * s
Definition: cu_in_wkt.c:23
uint8_t flags
Definition: liblwgeom.h:290
uint8_t gflags(int hasz, int hasm, int geodetic)
Construct a new flags char.
Definition: g_util.c:145
#define WGS84_MAJOR_AXIS
Definition: liblwgeom.h:127
double gbox_angular_height(const GBOX *gbox)
GBOX utility functions to figure out coverage/location on the globe.
Definition: lwgeodetic.c:179
double gbox_angular_width(const GBOX *gbox)
Returns the angular width (longitudinal span) of the box in radians.
Definition: lwgeodetic.c:206

Here is the call graph for this function:

Here is the caller graph for this function: