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

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

1143 {
1144  LWGEOM *lwg1, *lwg2;
1145  double d;
1146  SPHEROID s;
1147 
1148  /* Init and force spherical */
1149  spheroid_init(&s, 6378137.0, 6356752.314245179498);
1150  s.a = s.b = s.radius;
1151 
1152  /* Line/line distance, 1 degree apart */
1153  lwg1 = lwgeom_from_wkt("LINESTRING(-30 10, -20 5, -10 3, 0 1)", LW_PARSER_CHECK_NONE);
1154  lwg2 = lwgeom_from_wkt("LINESTRING(-10 -5, -5 0, 5 0, 10 -5)", LW_PARSER_CHECK_NONE);
1155  d = lwgeom_distance_spheroid(lwg1, lwg2, &s, 0.0);
1156  CU_ASSERT_DOUBLE_EQUAL(d, s.radius * M_PI / 180.0, 0.00001);
1157  lwgeom_free(lwg1);
1158  lwgeom_free(lwg2);
1159 
1160  /* Line/line distance, crossing, 0.0 apart */
1161  lwg1 = lwgeom_from_wkt("LINESTRING(-30 10, -20 5, -10 3, 0 1)", LW_PARSER_CHECK_NONE);
1162  lwg2 = lwgeom_from_wkt("LINESTRING(-10 -5, -5 20, 5 0, 10 -5)", LW_PARSER_CHECK_NONE);
1163  d = lwgeom_distance_spheroid(lwg1, lwg2, &s, 0.0);
1164  CU_ASSERT_DOUBLE_EQUAL(d, 0.0, 0.00001);
1165  lwgeom_free(lwg1);
1166  lwgeom_free(lwg2);
1167 
1168  /* Line/point distance, 1 degree apart */
1169  lwg1 = lwgeom_from_wkt("POINT(-4 1)", LW_PARSER_CHECK_NONE);
1170  lwg2 = lwgeom_from_wkt("LINESTRING(-10 -5, -5 0, 5 0, 10 -5)", LW_PARSER_CHECK_NONE);
1171  d = lwgeom_distance_spheroid(lwg1, lwg2, &s, 0.0);
1172  CU_ASSERT_DOUBLE_EQUAL(d, s.radius * M_PI / 180.0, 0.00001);
1173  lwgeom_free(lwg1);
1174  lwgeom_free(lwg2);
1175 
1176  lwg1 = lwgeom_from_wkt("POINT(-4 1)", LW_PARSER_CHECK_NONE);
1177  lwg2 = lwgeom_from_wkt("POINT(-4 -1)", LW_PARSER_CHECK_NONE);
1178  d = lwgeom_distance_spheroid(lwg1, lwg2, &s, 0.0);
1179  CU_ASSERT_DOUBLE_EQUAL(d, s.radius * M_PI / 90.0, 0.00001);
1180  lwgeom_free(lwg1);
1181  lwgeom_free(lwg2);
1182 
1183  /* Poly/point distance, point inside polygon, 0.0 apart */
1184  lwg1 = lwgeom_from_wkt("POLYGON((-4 1, -3 5, 1 2, 1.5 -5, -4 1))", LW_PARSER_CHECK_NONE);
1185  lwg2 = lwgeom_from_wkt("POINT(-1 -1)", LW_PARSER_CHECK_NONE);
1186  d = lwgeom_distance_spheroid(lwg1, lwg2, &s, 0.0);
1187  CU_ASSERT_DOUBLE_EQUAL(d, 0.0, 0.00001);
1188  lwgeom_free(lwg1);
1189  lwgeom_free(lwg2);
1190 
1191  /* Poly/point distance, point inside polygon hole, 1 degree apart */
1192  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);
1193  lwg2 = lwgeom_from_wkt("POINT(-1 -1)", LW_PARSER_CHECK_NONE);
1194  d = lwgeom_distance_spheroid(lwg1, lwg2, &s, 0.0);
1195  CU_ASSERT_DOUBLE_EQUAL(d, 111178.142466, 0.1);
1196  lwgeom_free(lwg1);
1197  lwgeom_free(lwg2);
1198 
1199  /* Poly/point distance, point on hole boundary, 0.0 apart */
1200  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);
1201  lwg2 = lwgeom_from_wkt("POINT(2 2)", LW_PARSER_CHECK_NONE);
1202  d = lwgeom_distance_spheroid(lwg1, lwg2, &s, 0.0);
1203  CU_ASSERT_DOUBLE_EQUAL(d, 0.0, 0.00001);
1204  lwgeom_free(lwg1);
1205  lwgeom_free(lwg2);
1206 
1207  /* Medford test case #1 */
1208  lwg1 = lwgeom_from_hexwkb("0105000020E610000001000000010200000002000000EF7B8779C7BD5EC0FD20D94B852845400E539C62B9BD5EC0F0A5BE767C284540", LW_PARSER_CHECK_NONE);
1209  lwg2 = lwgeom_from_hexwkb("0106000020E61000000100000001030000000100000007000000280EC3FB8CCA5EC0A5CDC747233C45402787C8F58CCA5EC0659EA2761E3C45400CED58DF8FCA5EC0C37FAE6E1E3C4540AE97B8E08FCA5EC00346F58B1F3C4540250359FD8ECA5EC05460628E1F3C45403738F4018FCA5EC05DC84042233C4540280EC3FB8CCA5EC0A5CDC747233C4540", LW_PARSER_CHECK_NONE);
1210  d = lwgeom_distance_spheroid(lwg1, lwg2, &s, 0.0);
1211  CU_ASSERT_DOUBLE_EQUAL(d, 23630.8003, 0.1);
1212  lwgeom_free(lwg1);
1213  lwgeom_free(lwg2);
1214 
1215  /* Ticket #2351 */
1216  lwg1 = lwgeom_from_wkt("LINESTRING(149.386990599235 -26.3567415843982,149.386990599247 -26.3567415843965)", LW_PARSER_CHECK_NONE);
1217  lwg2 = lwgeom_from_wkt("POINT(149.386990599235 -26.3567415843982)", LW_PARSER_CHECK_NONE);
1218  d = lwgeom_distance_spheroid(lwg1, lwg2, &s, 0.0);
1219  CU_ASSERT_DOUBLE_EQUAL(d, 0.0, 0.00001);
1220  lwgeom_free(lwg1);
1221  lwgeom_free(lwg2);
1222 
1223  /* Ticket #2638, no "M" */
1224  lwg1 = lwgeom_from_wkt("LINESTRING (-41.0821 50.3036,50 -41)", LW_PARSER_CHECK_NONE);
1225  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);
1226  d = lwgeom_distance_spheroid(lwg1, lwg2, &s, 0.0);
1227  CU_ASSERT_DOUBLE_EQUAL(d, 0.0, 0.00001);
1228  lwgeom_free(lwg1);
1229  lwgeom_free(lwg2);
1230 
1231  /* Ticket #2638, with "M" */
1232  lwg1 = lwgeom_from_wkt("LINESTRING M (-41.0821 50.3036 1,50 -41 1)", LW_PARSER_CHECK_NONE);
1233  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);
1234  d = lwgeom_distance_spheroid(lwg1, lwg2, &s, 0.0);
1235  CU_ASSERT_DOUBLE_EQUAL(d, 0.0, 0.00001);
1236  lwgeom_free(lwg1);
1237  lwgeom_free(lwg2);
1238 }
void spheroid_init(SPHEROID *s, double a, double b)
Initialize a spheroid object for use in geodetic functions.
Definition: lwspheroid.c:20
double b
Definition: liblwgeom.h:270
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1006
double radius
Definition: liblwgeom.h:274
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
LWGEOM * lwgeom_from_hexwkb(const char *hexwkb, const char check)
Definition: lwin_wkb.c:753
double a
Definition: liblwgeom.h:269
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:2078

Here is the call graph for this function:

Here is the caller graph for this function: