PostGIS  2.3.7dev-r@@SVN_REVISION@@
static void test_lwgeom_distance_sphere ( void  )
static

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

1172 {
1173  LWGEOM *lwg1, *lwg2;
1174  double d;
1175  SPHEROID s;
1176 
1177  /* Init and force spherical */
1178  spheroid_init(&s, 6378137.0, 6356752.314245179498);
1179  s.a = s.b = s.radius;
1180 
1181  /* Line/line distance, 1 degree apart */
1182  lwg1 = lwgeom_from_wkt("LINESTRING(-30 10, -20 5, -10 3, 0 1)", LW_PARSER_CHECK_NONE);
1183  lwg2 = lwgeom_from_wkt("LINESTRING(-10 -5, -5 0, 5 0, 10 -5)", LW_PARSER_CHECK_NONE);
1184  d = lwgeom_distance_spheroid(lwg1, lwg2, &s, 0.0);
1185  CU_ASSERT_DOUBLE_EQUAL(d, s.radius * M_PI / 180.0, 0.00001);
1186  lwgeom_free(lwg1);
1187  lwgeom_free(lwg2);
1188 
1189  /* Line/line distance, crossing, 0.0 apart */
1190  lwg1 = lwgeom_from_wkt("LINESTRING(-30 10, -20 5, -10 3, 0 1)", LW_PARSER_CHECK_NONE);
1191  lwg2 = lwgeom_from_wkt("LINESTRING(-10 -5, -5 20, 5 0, 10 -5)", LW_PARSER_CHECK_NONE);
1192  d = lwgeom_distance_spheroid(lwg1, lwg2, &s, 0.0);
1193  CU_ASSERT_DOUBLE_EQUAL(d, 0.0, 0.00001);
1194  lwgeom_free(lwg1);
1195  lwgeom_free(lwg2);
1196 
1197  /* Line/point distance, 1 degree apart */
1198  lwg1 = lwgeom_from_wkt("POINT(-4 1)", LW_PARSER_CHECK_NONE);
1199  lwg2 = lwgeom_from_wkt("LINESTRING(-10 -5, -5 0, 5 0, 10 -5)", LW_PARSER_CHECK_NONE);
1200  d = lwgeom_distance_spheroid(lwg1, lwg2, &s, 0.0);
1201  CU_ASSERT_DOUBLE_EQUAL(d, s.radius * M_PI / 180.0, 0.00001);
1202  lwgeom_free(lwg1);
1203  lwgeom_free(lwg2);
1204 
1205  lwg1 = lwgeom_from_wkt("POINT(-4 1)", LW_PARSER_CHECK_NONE);
1206  lwg2 = lwgeom_from_wkt("POINT(-4 -1)", LW_PARSER_CHECK_NONE);
1207  d = lwgeom_distance_spheroid(lwg1, lwg2, &s, 0.0);
1208  CU_ASSERT_DOUBLE_EQUAL(d, s.radius * M_PI / 90.0, 0.00001);
1209  lwgeom_free(lwg1);
1210  lwgeom_free(lwg2);
1211 
1212  /* Poly/point distance, point inside polygon, 0.0 apart */
1213  lwg1 = lwgeom_from_wkt("POLYGON((-4 1, -3 5, 1 2, 1.5 -5, -4 1))", LW_PARSER_CHECK_NONE);
1214  lwg2 = lwgeom_from_wkt("POINT(-1 -1)", LW_PARSER_CHECK_NONE);
1215  d = lwgeom_distance_spheroid(lwg1, lwg2, &s, 0.0);
1216  CU_ASSERT_DOUBLE_EQUAL(d, 0.0, 0.00001);
1217  lwgeom_free(lwg1);
1218  lwgeom_free(lwg2);
1219 
1220  /* Poly/point distance, point inside polygon hole, 1 degree apart */
1221  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);
1222  lwg2 = lwgeom_from_wkt("POINT(-1 -1)", LW_PARSER_CHECK_NONE);
1223  d = lwgeom_distance_spheroid(lwg1, lwg2, &s, 0.0);
1224  CU_ASSERT_DOUBLE_EQUAL(d, 111178.142466, 0.1);
1225  lwgeom_free(lwg1);
1226  lwgeom_free(lwg2);
1227 
1228  /* Poly/point distance, point on hole boundary, 0.0 apart */
1229  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);
1230  lwg2 = lwgeom_from_wkt("POINT(2 2)", LW_PARSER_CHECK_NONE);
1231  d = lwgeom_distance_spheroid(lwg1, lwg2, &s, 0.0);
1232  CU_ASSERT_DOUBLE_EQUAL(d, 0.0, 0.00001);
1233  lwgeom_free(lwg1);
1234  lwgeom_free(lwg2);
1235 
1236  /* Medford test case #1 */
1237  lwg1 = lwgeom_from_hexwkb("0105000020E610000001000000010200000002000000EF7B8779C7BD5EC0FD20D94B852845400E539C62B9BD5EC0F0A5BE767C284540", LW_PARSER_CHECK_NONE);
1238  lwg2 = lwgeom_from_hexwkb("0106000020E61000000100000001030000000100000007000000280EC3FB8CCA5EC0A5CDC747233C45402787C8F58CCA5EC0659EA2761E3C45400CED58DF8FCA5EC0C37FAE6E1E3C4540AE97B8E08FCA5EC00346F58B1F3C4540250359FD8ECA5EC05460628E1F3C45403738F4018FCA5EC05DC84042233C4540280EC3FB8CCA5EC0A5CDC747233C4540", LW_PARSER_CHECK_NONE);
1239  d = lwgeom_distance_spheroid(lwg1, lwg2, &s, 0.0);
1240  CU_ASSERT_DOUBLE_EQUAL(d, 23630.8003, 0.1);
1241  lwgeom_free(lwg1);
1242  lwgeom_free(lwg2);
1243 
1244  /* Ticket #2351 */
1245  lwg1 = lwgeom_from_wkt("LINESTRING(149.386990599235 -26.3567415843982,149.386990599247 -26.3567415843965)", LW_PARSER_CHECK_NONE);
1246  lwg2 = lwgeom_from_wkt("POINT(149.386990599235 -26.3567415843982)", LW_PARSER_CHECK_NONE);
1247  d = lwgeom_distance_spheroid(lwg1, lwg2, &s, 0.0);
1248  CU_ASSERT_DOUBLE_EQUAL(d, 0.0, 0.00001);
1249  lwgeom_free(lwg1);
1250  lwgeom_free(lwg2);
1251 
1252  /* Ticket #2638, no "M" */
1253  lwg1 = lwgeom_from_wkt("LINESTRING (-41.0821 50.3036,50 -41)", LW_PARSER_CHECK_NONE);
1254  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);
1255  d = lwgeom_distance_spheroid(lwg1, lwg2, &s, 0.0);
1256  CU_ASSERT_DOUBLE_EQUAL(d, 0.0, 0.00001);
1257  lwgeom_free(lwg1);
1258  lwgeom_free(lwg2);
1259 
1260  /* Ticket #2638, with "M" */
1261  lwg1 = lwgeom_from_wkt("LINESTRING M (-41.0821 50.3036 1,50 -41 1)", LW_PARSER_CHECK_NONE);
1262  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);
1263  d = lwgeom_distance_spheroid(lwg1, lwg2, &s, 0.0);
1264  CU_ASSERT_DOUBLE_EQUAL(d, 0.0, 0.00001);
1265  lwgeom_free(lwg1);
1266  lwgeom_free(lwg2);
1267 }
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:313
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1063
double radius
Definition: liblwgeom.h:317
LWGEOM * lwgeom_from_wkt(const char *wkt, const char check)
Definition: lwin_wkt.c:904
#define LW_PARSER_CHECK_NONE
Definition: liblwgeom.h:1985
char * s
Definition: cu_in_wkt.c:23
LWGEOM * lwgeom_from_hexwkb(const char *hexwkb, const char check)
Definition: lwin_wkb.c:790
double a
Definition: liblwgeom.h:312
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:2092

Here is the call graph for this function:

Here is the caller graph for this function: