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

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

1336 {
1337  LWGEOM *lwg;
1338  GBOX gbox;
1339  double a1, a2;
1340  SPHEROID s;
1341 
1342  /* Init to WGS84 */
1344 
1345  gbox.flags = gflags(0, 0, 1);
1346 
1347  /* Medford lot test polygon */
1348  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);
1349  lwgeom_calculate_gbox_geodetic(lwg, &gbox);
1350  /* sphere: Planimeter -E -p 20 -e $WGS84_SPHERE -r --input-string \
1351  "42.5007249610493 -122.848227067007;42.5007179884263 -122.848309475585;"\
1352  "42.500835880696 -122.848327688675;42.5008428533324 -122.848245279942" */
1353  a1 = lwgeom_area_sphere(lwg, &s);
1354  CU_ASSERT_DOUBLE_EQUAL(a1, 89.721147136698008, 0.1);
1355  /* spheroid: Planimeter -E -p 20 -r --input-string \
1356  "42.5007249610493 -122.848227067007;42.5007179884263 -122.848309475585;"\
1357  "42.500835880696 -122.848327688675;42.5008428533324 -122.848245279942" */
1358  a2 = lwgeom_area_spheroid(lwg, &s);
1359  CU_ASSERT_DOUBLE_EQUAL(a2, 89.868413479309585, 0.1);
1360  lwgeom_free(lwg);
1361 
1362  /* Big-ass polygon */
1363  lwg = lwgeom_from_wkt("POLYGON((-2 3, -2 4, -1 4, -1 3, -2 3))", LW_PARSER_CHECK_NONE);
1364  lwgeom_calculate_gbox_geodetic(lwg, &gbox);
1365  /* sphere: Planimeter -E -p 20 -e $WGS84_SPHERE -r --input-string "3 -2;4 -2;4 -1;3 -1" */
1366  a1 = lwgeom_area_sphere(lwg, &s);
1367  CU_ASSERT_DOUBLE_EQUAL(a1, 12341436880.106982993974659, 0.1);
1368  /* spheroid: Planimeter -E -p 20 -r --input-string "3 -2;4 -2;4 -1;3 -1" */
1369 #if PROJ_GEODESIC
1370  // printf("XXXXX %d\n", PJ_VERSION);
1371  a2 = lwgeom_area_spheroid(lwg, &s);
1372  CU_ASSERT_DOUBLE_EQUAL(a2, 12286884908.946891319597874, 0.1);
1373 #endif
1374  lwgeom_free(lwg);
1375 
1376  /* One-degree square */
1377  lwg = lwgeom_from_wkt("POLYGON((8.5 2,8.5 1,9.5 1,9.5 2,8.5 2))", LW_PARSER_CHECK_NONE);
1378  lwgeom_calculate_gbox_geodetic(lwg, &gbox);
1379  /* sphere: Planimeter -E -p 20 -e $WGS84_SPHERE --input-string "2 8.5;1 8.5;1 9.5;2 9.5" */
1380  a1 = lwgeom_area_sphere(lwg, &s);
1381  CU_ASSERT_DOUBLE_EQUAL(a1, 12360265021.368023059138681, 0.1);
1382  /* spheroid: Planimeter -E -p 20 --input-string "2 8.5;1 8.5;1 9.5;2 9.5" */
1383 #if PROJ_GEODESIC
1384  a2 = lwgeom_area_spheroid(lwg, &s);
1385  CU_ASSERT_DOUBLE_EQUAL(a2, 12305128751.042900673161556, 0.1);
1386 #endif
1387  lwgeom_free(lwg);
1388 
1389  /* One-degree square *near* the antimeridian */
1390  lwg = lwgeom_from_wkt("POLYGON((179.5 2,179.5 1,178.5 1,178.5 2,179.5 2))", LW_PARSER_CHECK_NONE);
1391  lwgeom_calculate_gbox_geodetic(lwg, &gbox);
1392  /* sphere: Planimeter -E -p 20 -e $WGS84_SPHERE -r --input-string "2 179.5;1 179.5;1 178.5;2 178.5" */
1393  a1 = lwgeom_area_sphere(lwg, &s);
1394  CU_ASSERT_DOUBLE_EQUAL(a1, 12360265021.368023059138681, 0.1);
1395  /* spheroid: Planimeter -E -p 20 -r --input-string "2 179.5;1 179.5;1 178.5;2 178.5" */
1396 #if PROJ_GEODESIC
1397  a2 = lwgeom_area_spheroid(lwg, &s);
1398  CU_ASSERT_DOUBLE_EQUAL(a2, 12305128751.042900673161556, 0.1);
1399 #endif
1400  lwgeom_free(lwg);
1401 
1402  /* One-degree square *across* the antimeridian */
1403  lwg = lwgeom_from_wkt("POLYGON((179.5 2,179.5 1,-179.5 1,-179.5 2,179.5 2))", LW_PARSER_CHECK_NONE);
1404  lwgeom_calculate_gbox_geodetic(lwg, &gbox);
1405  /* sphere: Planimeter -E -p 20 -e $WGS84_SPHERE --input-string "2 179.5;1 179.5;1 -179.5;2 -179.5" */
1406  a1 = lwgeom_area_sphere(lwg, &s);
1407  CU_ASSERT_DOUBLE_EQUAL(a1, 12360265021.368023059138681, 0.1);
1408  /* spheroid: Planimeter -E -p 20 --input-string "2 179.5;1 179.5;1 -179.5;2 -179.5" */
1409 #if PROJ_GEODESIC
1410  a2 = lwgeom_area_spheroid(lwg, &s);
1411  CU_ASSERT_DOUBLE_EQUAL(a2, 12305128751.042900673161556, 0.1);
1412 #endif
1413  lwgeom_free(lwg);
1414 }
int lwgeom_calculate_gbox_geodetic(const LWGEOM *geom, GBOX *gbox)
Calculate the geodetic bounding box for an LWGEOM.
Definition: lwgeodetic.c:2615
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
#define WGS84_MINOR_AXIS
Definition: liblwgeom.h:115
LWGEOM * lwgeom_from_wkt(const char *wkt, const char check)
Definition: lwin_wkt.c:890
#define LW_PARSER_CHECK_NONE
Definition: liblwgeom.h:1869
char * s
Definition: cu_in_wkt.c:23
double lwgeom_area_sphere(const LWGEOM *lwgeom, const SPHEROID *spheroid)
Calculate the geodetic area of a lwgeom on the sphere.
Definition: lwgeodetic.c:1927
uint8_t flags
Definition: liblwgeom.h:275
uint8_t gflags(int hasz, int hasm, int geodetic)
Construct a new flags char.
Definition: g_util.c:130
#define WGS84_MAJOR_AXIS
Definition: liblwgeom.h:113
double lwgeom_area_spheroid(const LWGEOM *lwgeom, const SPHEROID *spheroid)
Calculate the geodetic area of a lwgeom on the spheroid.
Definition: lwspheroid.c:628

Here is the call graph for this function:

Here is the caller graph for this function: