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

Definition at line 1281 of file cu_geodetic.c.

References GBOX::flags, gflags(), LW_PARSER_CHECK_NONE, lwgeom_area_sphere(), lwgeom_area_spheroid(), lwgeom_calculate_gbox_geodetic(), lwgeom_free(), lwgeom_from_wkt(), s, spheroid_init(), WGS84_MAJOR_AXIS, and WGS84_MINOR_AXIS.

Referenced by geodetic_suite_setup().

1282 {
1283  LWGEOM *lwg;
1284  GBOX gbox;
1285  double a1, a2;
1286  SPHEROID s;
1287 
1288  /* Init to WGS84 */
1290 
1291  gbox.flags = gflags(0, 0, 1);
1292 
1293  /* Medford lot test polygon */
1294  lwg = lwgeom_from_wkt("POLYGON((-122.848227067007 42.5007249610493,-122.848309475585 42.5007179884263,-122.848327688675 42.500835880696,-122.848245279942 42.5008428533324,-122.848227067007 42.5007249610493))", LW_PARSER_CHECK_NONE);
1295  lwgeom_calculate_gbox_geodetic(lwg, &gbox);
1296  a1 = lwgeom_area_sphere(lwg, &s);
1297  a2 = lwgeom_area_spheroid(lwg, &s);
1298  //printf("\nsphere: %.12g\nspheroid: %.12g\n", a1, a2);
1299  CU_ASSERT_DOUBLE_EQUAL(a1, 89.7127703297, 0.1); /* sphere */
1300  CU_ASSERT_DOUBLE_EQUAL(a2, 89.8684316032, 0.1); /* spheroid */
1301  lwgeom_free(lwg);
1302 
1303  /* Big-ass polygon */
1304  lwg = lwgeom_from_wkt("POLYGON((-2 3, -2 4, -1 4, -1 3, -2 3))", LW_PARSER_CHECK_NONE);
1305  lwgeom_calculate_gbox_geodetic(lwg, &gbox);
1306  a1 = lwgeom_area_sphere(lwg, &s);
1307  a2 = lwgeom_area_spheroid(lwg, &s);
1308  //printf("\nsphere: %.12g\nspheroid: %.12g\n", a1, a2);
1309  CU_ASSERT_DOUBLE_EQUAL(a1, 12341436880.1, 10.0); /* sphere */
1310  CU_ASSERT_DOUBLE_EQUAL(a2, 12286574431.9, 10.0); /* spheroid */
1311  lwgeom_free(lwg);
1312 
1313  /* One-degree square */
1314  lwg = lwgeom_from_wkt("POLYGON((8.5 2,8.5 1,9.5 1,9.5 2,8.5 2))", LW_PARSER_CHECK_NONE);
1315  lwgeom_calculate_gbox_geodetic(lwg, &gbox);
1316  a1 = lwgeom_area_sphere(lwg, &s);
1317  a2 = lwgeom_area_spheroid(lwg, &s);
1318  //printf("\nsphere: %.12g\nspheroid: %.12g\n", a1, a2);
1319  CU_ASSERT_DOUBLE_EQUAL(a1, 12360265021.1, 10.0); /* sphere */
1320  CU_ASSERT_DOUBLE_EQUAL(a2, 12304814950.073, 100.0); /* spheroid */
1321  lwgeom_free(lwg);
1322 
1323  /* One-degree square *near* dateline */
1324  lwg = lwgeom_from_wkt("POLYGON((179.5 2,179.5 1,178.5 1,178.5 2,179.5 2))", LW_PARSER_CHECK_NONE);
1325  lwgeom_calculate_gbox_geodetic(lwg, &gbox);
1326  a1 = lwgeom_area_sphere(lwg, &s);
1327  a2 = lwgeom_area_spheroid(lwg, &s);
1328  //printf("\nsphere: %.12g\nspheroid: %.12g\n", a1, a2);
1329  CU_ASSERT_DOUBLE_EQUAL(a1, 12360265021.1, 10.0); /* sphere */
1330  CU_ASSERT_DOUBLE_EQUAL(a2, 12304814950.073, 100.0); /* spheroid */
1331  lwgeom_free(lwg);
1332 
1333  /* One-degree square *across* dateline */
1334  lwg = lwgeom_from_wkt("POLYGON((179.5 2,179.5 1,-179.5 1,-179.5 2,179.5 2))", LW_PARSER_CHECK_NONE);
1335  lwgeom_calculate_gbox_geodetic(lwg, &gbox);
1336  a1 = lwgeom_area_sphere(lwg, &s);
1337  a2 = lwgeom_area_spheroid(lwg, &s);
1338  //printf("\nsphere: %.12g\nspheroid: %.12g\n", a1, a2);
1339  CU_ASSERT_DOUBLE_EQUAL(a1, 12360265021.3679, 10.0); /* sphere */
1340  CU_ASSERT_DOUBLE_EQUAL(a2, 12304814950.073, 100.0); /* spheroid */
1341  lwgeom_free(lwg);
1342 }
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
#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
char * s
Definition: cu_in_wkt.c:24
double lwgeom_area_sphere(const LWGEOM *lwgeom, const SPHEROID *spheroid)
Calculate the geodetic area of a lwgeom on the sphere.
Definition: lwgeodetic.c:1924
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 lwgeom_area_spheroid(const LWGEOM *lwgeom, const SPHEROID *spheroid)
Calculate the geodetic area of a lwgeom on the spheroid.
Definition: lwspheroid.c:513

Here is the call graph for this function:

Here is the caller graph for this function: