PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ geography_project()

Datum geography_project ( PG_FUNCTION_ARGS  )

Definition at line 931 of file geography_measurement.c.

932 {
933  LWGEOM *lwgeom = NULL;
934  LWPOINT *lwp_projected;
935  GSERIALIZED *g = NULL;
936  GSERIALIZED *g_out = NULL;
937  double azimuth = 0.0;
938  double distance;
939  SPHEROID s;
940  uint32_t type;
941 
942  /* Return NULL on NULL distance or geography */
943  if ( PG_NARGS() < 2 || PG_ARGISNULL(0) || PG_ARGISNULL(1) )
944  PG_RETURN_NULL();
945 
946  /* Get our geometry object loaded into memory. */
947  g = PG_GETARG_GSERIALIZED_P(0);
948 
949  /* Only return for points. */
951  if ( type != POINTTYPE )
952  {
953  elog(ERROR, "ST_Project(geography) is only valid for point inputs");
954  PG_RETURN_NULL();
955  }
956 
957  distance = PG_GETARG_FLOAT8(1); /* Distance in Meters */
958  lwgeom = lwgeom_from_gserialized(g);
959 
960  /* EMPTY things cannot be projected from */
961  if ( lwgeom_is_empty(lwgeom) )
962  {
963  lwgeom_free(lwgeom);
964  elog(ERROR, "ST_Project(geography) cannot project from an empty start point");
965  PG_RETURN_NULL();
966  }
967 
968  if ( PG_NARGS() > 2 && ! PG_ARGISNULL(2) )
969  azimuth = PG_GETARG_FLOAT8(2); /* Azimuth in Radians */
970 
971  /* Initialize spheroid */
972  spheroid_init_from_srid(fcinfo, gserialized_get_srid(g), &s);
973 
974  /* Handle the zero distance case */
975  if( FP_EQUALS(distance, 0.0) )
976  {
977  PG_RETURN_POINTER(g);
978  }
979 
980  /* Calculate the length */
981  lwp_projected = lwgeom_project_spheroid(lwgeom_as_lwpoint(lwgeom), &s, distance, azimuth);
982 
983  /* Something went wrong... */
984  if ( lwp_projected == NULL )
985  {
986  elog(ERROR, "lwgeom_project_spheroid returned null");
987  PG_RETURN_NULL();
988  }
989 
990  /* Clean up, but not all the way to the point arrays */
991  lwgeom_free(lwgeom);
992  g_out = geography_serialize(lwpoint_as_lwgeom(lwp_projected));
993  lwpoint_free(lwp_projected);
994 
995  PG_FREE_IF_COPY(g, 0);
996  PG_RETURN_POINTER(g_out);
997 }
char * s
Definition: cu_in_wkt.c:23
int32_t gserialized_get_srid(const GSERIALIZED *s)
Extract the SRID from the serialized form (it is packed into three bytes so this is a handy function)...
Definition: g_serialized.c:100
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
uint32_t gserialized_get_type(const GSERIALIZED *s)
Extract the geometry type from the serialized form (it hides in the anonymous data area,...
Definition: g_serialized.c:86
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:1144
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:85
LWPOINT * lwgeom_as_lwpoint(const LWGEOM *lwgeom)
Definition: lwgeom.c:161
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
Definition: lwgeom.c:335
int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members)
Definition: lwgeom.c:1393
#define FP_EQUALS(A, B)
Datum distance(PG_FUNCTION_ARGS)
type
Definition: ovdump.py:41
unsigned int uint32_t
Definition: uthash.h:78

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: