PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ test_lwgeom_distance_sphere()

static void test_lwgeom_distance_sphere ( void  )
static

Definition at line 1177 of file cu_geodetic.c.

References SPHEROID::a, SPHEROID::b, LW_PARSER_CHECK_NONE, lwgeom_distance_spheroid(), lwgeom_free(), lwgeom_from_hexwkb(), lwgeom_from_wkt(), SPHEROID::radius, s, and spheroid_init().

Referenced by geodetic_suite_setup().

1178 {
1179  LWGEOM *lwg1, *lwg2;
1180  double d;
1181  SPHEROID s;
1182 
1183  /* Init and force spherical */
1184  spheroid_init(&s, 6378137.0, 6356752.314245179498);
1185  s.a = s.b = s.radius;
1186 
1187  /* Line/line distance, 1 degree apart */
1188  lwg1 = lwgeom_from_wkt("LINESTRING(-30 10, -20 5, -10 3, 0 1)", LW_PARSER_CHECK_NONE);
1189  lwg2 = lwgeom_from_wkt("LINESTRING(-10 -5, -5 0, 5 0, 10 -5)", LW_PARSER_CHECK_NONE);
1190  d = lwgeom_distance_spheroid(lwg1, lwg2, &s, 0.0);
1191  CU_ASSERT_DOUBLE_EQUAL(d, s.radius * M_PI / 180.0, 0.00001);
1192  lwgeom_free(lwg1);
1193  lwgeom_free(lwg2);
1194 
1195  /* Line/line distance, crossing, 0.0 apart */
1196  lwg1 = lwgeom_from_wkt("LINESTRING(-30 10, -20 5, -10 3, 0 1)", LW_PARSER_CHECK_NONE);
1197  lwg2 = lwgeom_from_wkt("LINESTRING(-10 -5, -5 20, 5 0, 10 -5)", LW_PARSER_CHECK_NONE);
1198  d = lwgeom_distance_spheroid(lwg1, lwg2, &s, 0.0);
1199  CU_ASSERT_DOUBLE_EQUAL(d, 0.0, 0.00001);
1200  lwgeom_free(lwg1);
1201  lwgeom_free(lwg2);
1202 
1203  /* Line/point distance, 1 degree apart */
1204  lwg1 = lwgeom_from_wkt("POINT(-4 1)", LW_PARSER_CHECK_NONE);
1205  lwg2 = lwgeom_from_wkt("LINESTRING(-10 -5, -5 0, 5 0, 10 -5)", LW_PARSER_CHECK_NONE);
1206  d = lwgeom_distance_spheroid(lwg1, lwg2, &s, 0.0);
1207  CU_ASSERT_DOUBLE_EQUAL(d, s.radius * M_PI / 180.0, 0.00001);
1208  lwgeom_free(lwg1);
1209  lwgeom_free(lwg2);
1210 
1211  lwg1 = lwgeom_from_wkt("POINT(-4 1)", LW_PARSER_CHECK_NONE);
1212  lwg2 = lwgeom_from_wkt("POINT(-4 -1)", LW_PARSER_CHECK_NONE);
1213  d = lwgeom_distance_spheroid(lwg1, lwg2, &s, 0.0);
1214  CU_ASSERT_DOUBLE_EQUAL(d, s.radius * M_PI / 90.0, 0.00001);
1215  lwgeom_free(lwg1);
1216  lwgeom_free(lwg2);
1217 
1218  /* Poly/point distance, point inside polygon, 0.0 apart */
1219  lwg1 = lwgeom_from_wkt("POLYGON((-4 1, -3 5, 1 2, 1.5 -5, -4 1))", LW_PARSER_CHECK_NONE);
1220  lwg2 = lwgeom_from_wkt("POINT(-1 -1)", LW_PARSER_CHECK_NONE);
1221  d = lwgeom_distance_spheroid(lwg1, lwg2, &s, 0.0);
1222  CU_ASSERT_DOUBLE_EQUAL(d, 0.0, 0.00001);
1223  lwgeom_free(lwg1);
1224  lwgeom_free(lwg2);
1225 
1226  /* Poly/point distance, point inside polygon hole, 1 degree apart */
1227  lwg1 = lwgeom_from_wkt("POLYGON((-4 -4, -4 4, 4 4, 4 -4, -4 -4), (-2 -2, -2 2, 2 2, 2 -2, -2 -2))", LW_PARSER_CHECK_NONE);
1228  lwg2 = lwgeom_from_wkt("POINT(-1 -1)", LW_PARSER_CHECK_NONE);
1229  d = lwgeom_distance_spheroid(lwg1, lwg2, &s, 0.0);
1230  CU_ASSERT_DOUBLE_EQUAL(d, 111178.142466, 0.1);
1231  lwgeom_free(lwg1);
1232  lwgeom_free(lwg2);
1233 
1234  /* Poly/point distance, point on hole boundary, 0.0 apart */
1235  lwg1 = lwgeom_from_wkt("POLYGON((-4 -4, -4 4, 4 4, 4 -4, -4 -4), (-2 -2, -2 2, 2 2, 2 -2, -2 -2))", LW_PARSER_CHECK_NONE);
1236  lwg2 = lwgeom_from_wkt("POINT(2 2)", LW_PARSER_CHECK_NONE);
1237  d = lwgeom_distance_spheroid(lwg1, lwg2, &s, 0.0);
1238  CU_ASSERT_DOUBLE_EQUAL(d, 0.0, 0.00001);
1239  lwgeom_free(lwg1);
1240  lwgeom_free(lwg2);
1241 
1242  /* Medford test case #1 */
1243  lwg1 = lwgeom_from_hexwkb("0105000020E610000001000000010200000002000000EF7B8779C7BD5EC0FD20D94B852845400E539C62B9BD5EC0F0A5BE767C284540", LW_PARSER_CHECK_NONE);
1244  lwg2 = lwgeom_from_hexwkb("0106000020E61000000100000001030000000100000007000000280EC3FB8CCA5EC0A5CDC747233C45402787C8F58CCA5EC0659EA2761E3C45400CED58DF8FCA5EC0C37FAE6E1E3C4540AE97B8E08FCA5EC00346F58B1F3C4540250359FD8ECA5EC05460628E1F3C45403738F4018FCA5EC05DC84042233C4540280EC3FB8CCA5EC0A5CDC747233C4540", LW_PARSER_CHECK_NONE);
1245  d = lwgeom_distance_spheroid(lwg1, lwg2, &s, 0.0);
1246  CU_ASSERT_DOUBLE_EQUAL(d, 23630.8003, 0.1);
1247  lwgeom_free(lwg1);
1248  lwgeom_free(lwg2);
1249 
1250  /* Ticket #2351 */
1251  lwg1 = lwgeom_from_wkt("LINESTRING(149.386990599235 -26.3567415843982,149.386990599247 -26.3567415843965)", LW_PARSER_CHECK_NONE);
1252  lwg2 = lwgeom_from_wkt("POINT(149.386990599235 -26.3567415843982)", LW_PARSER_CHECK_NONE);
1253  d = lwgeom_distance_spheroid(lwg1, lwg2, &s, 0.0);
1254  CU_ASSERT_DOUBLE_EQUAL(d, 0.0, 0.00001);
1255  lwgeom_free(lwg1);
1256  lwgeom_free(lwg2);
1257 
1258  /* Ticket #2638, no "M" */
1259  lwg1 = lwgeom_from_wkt("LINESTRING (-41.0821 50.3036,50 -41)", LW_PARSER_CHECK_NONE);
1260  lwg2 = lwgeom_from_wkt("POLYGON((0 0,10 0,10 10,0 10,0 0),(5 5,7 5,7 7,5 7,5 5))", LW_PARSER_CHECK_NONE);
1261  d = lwgeom_distance_spheroid(lwg1, lwg2, &s, 0.0);
1262  CU_ASSERT_DOUBLE_EQUAL(d, 0.0, 0.00001);
1263  lwgeom_free(lwg1);
1264  lwgeom_free(lwg2);
1265 
1266  /* Ticket #2638, with "M" */
1267  lwg1 = lwgeom_from_wkt("LINESTRING M (-41.0821 50.3036 1,50 -41 1)", LW_PARSER_CHECK_NONE);
1268  lwg2 = lwgeom_from_wkt("POLYGON M ((0 0 2,10 0 1,10 10 -2,0 10 -5,0 0 -5),(5 5 6,7 5 6,7 7 6,5 7 10,5 5 -2))", LW_PARSER_CHECK_NONE);
1269  d = lwgeom_distance_spheroid(lwg1, lwg2, &s, 0.0);
1270  CU_ASSERT_DOUBLE_EQUAL(d, 0.0, 0.00001);
1271  lwgeom_free(lwg1);
1272  lwgeom_free(lwg2);
1273 }
void spheroid_init(SPHEROID *s, double a, double b)
Initialize a spheroid object for use in geodetic functions.
Definition: lwspheroid.c:39
double b
Definition: liblwgeom.h:314
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1099
double radius
Definition: liblwgeom.h:318
LWGEOM * lwgeom_from_wkt(const char *wkt, const char check)
Definition: lwin_wkt.c:904
#define LW_PARSER_CHECK_NONE
Definition: liblwgeom.h:2013
char * s
Definition: cu_in_wkt.c:23
LWGEOM * lwgeom_from_hexwkb(const char *hexwkb, const char check)
Definition: lwin_wkb.c:797
double a
Definition: liblwgeom.h:313
double lwgeom_distance_spheroid(const LWGEOM *lwgeom1, const LWGEOM *lwgeom2, const SPHEROID *spheroid, double tolerance)
Calculate the geodetic distance from lwgeom1 to lwgeom2 on the spheroid.
Definition: lwgeodetic.c:2183
Here is the call graph for this function:
Here is the caller graph for this function: