PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ test_spheroid_area()

static void test_spheroid_area ( void  )
static

Definition at line 1341 of file cu_geodetic.c.

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

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().

Here is the call graph for this function:
Here is the caller graph for this function: