PostGIS 3.0.6dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ geography_project()

Datum geography_project ( PG_FUNCTION_ARGS  )

Definition at line 979 of file geography_measurement.c.

980{
981 LWGEOM *lwgeom = NULL;
982 LWPOINT *lwp_projected;
983 GSERIALIZED *g = NULL;
984 GSERIALIZED *g_out = NULL;
985 double azimuth = 0.0;
986 double distance;
987 SPHEROID s;
988 uint32_t type;
989
990 /* Return NULL on NULL distance or geography */
991 if ( PG_NARGS() < 2 || PG_ARGISNULL(0) || PG_ARGISNULL(1) )
992 PG_RETURN_NULL();
993
994 /* Get our geometry object loaded into memory. */
995 g = PG_GETARG_GSERIALIZED_P(0);
996
997 /* Only return for points. */
999 if ( type != POINTTYPE )
1000 {
1001 elog(ERROR, "ST_Project(geography) is only valid for point inputs");
1002 PG_RETURN_NULL();
1003 }
1004
1005 distance = PG_GETARG_FLOAT8(1); /* Distance in Meters */
1006 lwgeom = lwgeom_from_gserialized(g);
1007
1008 /* EMPTY things cannot be projected from */
1009 if ( lwgeom_is_empty(lwgeom) )
1010 {
1011 lwgeom_free(lwgeom);
1012 elog(ERROR, "ST_Project(geography) cannot project from an empty start point");
1013 PG_RETURN_NULL();
1014 }
1015
1016 if ( PG_NARGS() > 2 && ! PG_ARGISNULL(2) )
1017 azimuth = PG_GETARG_FLOAT8(2); /* Azimuth in Radians */
1018
1019 /* Initialize spheroid */
1020 spheroid_init_from_srid(fcinfo, gserialized_get_srid(g), &s);
1021
1022 /* Handle the zero distance case */
1023 if( FP_EQUALS(distance, 0.0) )
1024 {
1025 PG_RETURN_POINTER(g);
1026 }
1027
1028 /* Calculate the length */
1029 lwp_projected = lwgeom_project_spheroid(lwgeom_as_lwpoint(lwgeom), &s, distance, azimuth);
1030
1031 /* Something went wrong... */
1032 if ( lwp_projected == NULL )
1033 {
1034 elog(ERROR, "lwgeom_project_spheroid returned null");
1035 PG_RETURN_NULL();
1036 }
1037
1038 /* Clean up, but not all the way to the point arrays */
1039 lwgeom_free(lwgeom);
1040 g_out = geography_serialize(lwpoint_as_lwgeom(lwp_projected));
1041 lwpoint_free(lwp_projected);
1042
1043 PG_FREE_IF_COPY(g, 0);
1044 PG_RETURN_POINTER(g_out);
1045}
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)...
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
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
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
Definition lwgeom.c:326
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
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.
#define FP_EQUALS(A, B)
static LWPOINT * lwgeom_as_lwpoint(const LWGEOM *lwgeom)
Definition lwinline.h:121
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:193
static double distance(double x1, double y1, double x2, double y2)
Definition lwtree.c:1032

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, and s.

Here is the call graph for this function: