PostGIS  3.1.6dev-r@@SVN_REVISION@@

◆ geography_project()

Datum geography_project ( PG_FUNCTION_ARGS  )

Definition at line 962 of file geography_measurement.c.

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