PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ geography_project()

Datum geography_project ( PG_FUNCTION_ARGS  )

Definition at line 961 of file geography_measurement.c.

962 {
963  LWGEOM *lwgeom = NULL;
964  LWPOINT *lwp_projected;
965  GSERIALIZED *g = NULL;
966  GSERIALIZED *g_out = NULL;
967  double azimuth = 0.0;
968  double distance;
969  SPHEROID s;
970  uint32_t type;
971 
972  /* Return NULL on NULL distance or geography */
973  if ( PG_NARGS() < 2 || PG_ARGISNULL(0) || PG_ARGISNULL(1) )
974  PG_RETURN_NULL();
975 
976  /* Get our geometry object loaded into memory. */
977  g = PG_GETARG_GSERIALIZED_P(0);
978 
979  /* Only return for points. */
981  if ( type != POINTTYPE )
982  {
983  elog(ERROR, "ST_Project(geography) is only valid for point inputs");
984  PG_RETURN_NULL();
985  }
986 
987  distance = PG_GETARG_FLOAT8(1); /* Distance in Meters */
988  lwgeom = lwgeom_from_gserialized(g);
989 
990  /* EMPTY things cannot be projected from */
991  if ( lwgeom_is_empty(lwgeom) )
992  {
993  lwgeom_free(lwgeom);
994  elog(ERROR, "ST_Project(geography) cannot project from an empty start point");
995  PG_RETURN_NULL();
996  }
997 
998  if ( PG_NARGS() > 2 && ! PG_ARGISNULL(2) )
999  azimuth = PG_GETARG_FLOAT8(2); /* Azimuth in Radians */
1000 
1001  /* Initialize spheroid */
1002  spheroid_init_from_srid(gserialized_get_srid(g), &s);
1003 
1004  /* Handle the zero distance case */
1005  if( FP_EQUALS(distance, 0.0) )
1006  {
1007  PG_RETURN_POINTER(g);
1008  }
1009 
1010  /* Calculate the length */
1011  lwp_projected = lwgeom_project_spheroid(lwgeom_as_lwpoint(lwgeom), &s, distance, azimuth);
1012 
1013  /* Something went wrong... */
1014  if ( lwp_projected == NULL )
1015  {
1016  elog(ERROR, "lwgeom_project_spheroid returned null");
1017  PG_RETURN_NULL();
1018  }
1019 
1020  /* Clean up, but not all the way to the point arrays */
1021  lwgeom_free(lwgeom);
1022  g_out = geography_serialize(lwpoint_as_lwgeom(lwp_projected));
1023  lwpoint_free(lwp_projected);
1024 
1025  PG_FREE_IF_COPY(g, 0);
1026  PG_RETURN_POINTER(g_out);
1027 }
char * s
Definition: cu_in_wkt.c:23
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
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
LWPOINT * lwgeom_project_spheroid(const LWPOINT *r, const SPHEROID *spheroid, double distance, double azimuth)
Calculate the location of a point on a spheroid, give a start point, bearing and distance.
Definition: lwgeodetic.c:2105
void lwpoint_free(LWPOINT *pt)
Definition: lwpoint.c:213
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1155
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:102
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
Definition: lwgeom.c:344
#define FP_EQUALS(A, B)
static int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members)
Definition: lwinline.h:203
static LWPOINT * lwgeom_as_lwpoint(const LWGEOM *lwgeom)
Definition: lwinline.h:131
static double distance(double x1, double y1, double x2, double y2)
Definition: lwtree.c:1032
type
Definition: ovdump.py:42

References distance(), FP_EQUALS, gserialized_get_srid(), gserialized_get_type(), lwgeom_as_lwpoint(), lwgeom_free(), lwgeom_from_gserialized(), lwgeom_is_empty(), lwgeom_project_spheroid(), lwpoint_as_lwgeom(), lwpoint_free(), POINTTYPE, s, and ovdump::type.

Here is the call graph for this function: