PostGIS  3.7.0dev-r@@SVN_REVISION@@

◆ geography_project()

Datum geography_project ( PG_FUNCTION_ARGS  )

Definition at line 958 of file geography_measurement.c.

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