PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ geography_line_locate_point()

Datum geography_line_locate_point ( PG_FUNCTION_ARGS  )

Definition at line 1349 of file geography_measurement.c.

1350 {
1351  GSERIALIZED *gs1 = PG_GETARG_GSERIALIZED_P(0);
1352  GSERIALIZED *gs2 = PG_GETARG_GSERIALIZED_P(1);
1353  bool use_spheroid = PG_GETARG_BOOL(2);
1354  double tolerance = FP_TOLERANCE;
1355  SPHEROID s;
1356  LWLINE *lwline;
1357  LWPOINT *lwpoint;
1358  POINTARRAY *pa;
1359  POINT4D p, p_proj;
1360  double ret;
1361 
1362  gserialized_error_if_srid_mismatch(gs1, gs2, __func__);
1363 
1364  /* Return NULL on empty argument. */
1365  if ( gserialized_is_empty(gs1) || gserialized_is_empty(gs2))
1366  {
1367  PG_FREE_IF_COPY(gs1, 0);
1368  PG_FREE_IF_COPY(gs2, 1);
1369  PG_RETURN_NULL();
1370  }
1371 
1372  if ( gserialized_get_type(gs1) != LINETYPE )
1373  {
1374  elog(ERROR,"%s: 1st arg is not a line", __func__);
1375  PG_RETURN_NULL();
1376  }
1377  if ( gserialized_get_type(gs2) != POINTTYPE )
1378  {
1379  elog(ERROR,"%s: 2st arg is not a point", __func__);
1380  PG_RETURN_NULL();
1381  }
1382 
1383  /* Set to sphere if requested */
1384  if ( ! use_spheroid ) {
1385  s.a = s.b = s.radius;
1386  }
1387  else {
1388  /* Initialize spheroid */
1389  spheroid_init_from_srid(gserialized_get_srid(gs1), &s);
1390  }
1391 
1394 
1395  pa = lwline->points;
1396  lwpoint_getPoint4d_p(lwpoint, &p);
1397 
1398  ret = ptarray_locate_point_spheroid(pa, &p, &s, tolerance, NULL, &p_proj);
1399 
1400  PG_RETURN_FLOAT8(ret);
1401 }
char * s
Definition: cu_in_wkt.c:23
void gserialized_error_if_srid_mismatch(const GSERIALIZED *g1, const GSERIALIZED *g2, const char *funcname)
Definition: gserialized.c:403
int32_t gserialized_get_srid(const GSERIALIZED *g)
Extract the SRID from the serialized form (it is packed into three bytes so this is a handy function)...
Definition: gserialized.c:126
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
Definition: gserialized.c:239
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
Definition: gserialized.c:152
uint32_t gserialized_get_type(const GSERIALIZED *g)
Extract the geometry type from the serialized form (it hides in the anonymous data area,...
Definition: gserialized.c:89
int lwpoint_getPoint4d_p(const LWPOINT *point, POINT4D *out)
Definition: lwpoint.c:57
LWLINE * lwgeom_as_lwline(const LWGEOM *lwgeom)
Definition: lwgeom.c:179
double ptarray_locate_point_spheroid(const POINTARRAY *pa, const POINT4D *p4d, const SPHEROID *s, double tolerance, double *mindistout, POINT4D *proj4d)
Locate a point along the point array defining a geographic line.
#define LINETYPE
Definition: liblwgeom.h:103
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:102
#define FP_TOLERANCE
Floating point comparators.
static LWPOINT * lwgeom_as_lwpoint(const LWGEOM *lwgeom)
Definition: lwinline.h:131
POINTARRAY * points
Definition: liblwgeom.h:483

References FP_TOLERANCE, gserialized_error_if_srid_mismatch(), gserialized_get_srid(), gserialized_get_type(), gserialized_is_empty(), LINETYPE, lwgeom_as_lwline(), lwgeom_as_lwpoint(), lwgeom_from_gserialized(), lwpoint_getPoint4d_p(), LWLINE::points, POINTTYPE, ptarray_locate_point_spheroid(), and s.

Here is the call graph for this function: