PostGIS  2.5.0dev-r@@SVN_REVISION@@
Datum ST_Scale ( PG_FUNCTION_ARGS  )

Definition at line 2917 of file lwgeom_functions_basic.c.

References LWPOINT::flags, FLAGS_GET_M, FLAGS_GET_Z, geometry_serialize(), getPoint4d_p(), lwgeom_as_lwpoint(), lwgeom_free(), lwgeom_from_gserialized(), lwgeom_scale(), POINT4D::m, POINTARRAY::npoints, LWPOINT::point, and POINT4D::z.

2918 {
2919  GSERIALIZED *geom1 = PG_GETARG_GSERIALIZED_P_COPY(0); /* will be modified */
2920  GSERIALIZED *geom2 = PG_GETARG_GSERIALIZED_P(1);
2921  GSERIALIZED *ret;
2922  LWGEOM *lwgeom1 = lwgeom_from_gserialized(geom1);
2923  LWGEOM *lwgeom2 = lwgeom_from_gserialized(geom2);
2924  LWPOINT *lwpoint;
2925  POINT4D factors;
2926 
2927  lwpoint = lwgeom_as_lwpoint(lwgeom2);
2928  if ( lwpoint == NULL )
2929  {
2930  lwgeom_free(lwgeom1);
2931  lwgeom_free(lwgeom2);
2932  PG_FREE_IF_COPY(geom1, 0);
2933  PG_FREE_IF_COPY(geom2, 1);
2934  lwpgerror("Scale factor geometry parameter must be a point");
2935  PG_RETURN_NULL();
2936  }
2937  if ( ! lwpoint->point->npoints )
2938  {
2939  /* empty point, return input untouched */
2940  lwgeom_free(lwgeom1);
2941  lwgeom_free(lwgeom2);
2942  PG_FREE_IF_COPY(geom2, 1);
2943  PG_RETURN_POINTER(geom1);
2944  }
2945  getPoint4d_p(lwpoint->point, 0, &factors);
2946  if ( ! FLAGS_GET_Z(lwpoint->flags ) ) factors.z = 1;
2947  if ( ! FLAGS_GET_M(lwpoint->flags ) ) factors.m = 1;
2948 
2949  lwgeom_scale(lwgeom1, &factors);
2950 
2951  /* Construct GSERIALIZED */
2952  ret = geometry_serialize(lwgeom1);
2953 
2954  /* Cleanup */
2955  lwgeom_free(lwgeom1);
2956  lwgeom_free(lwgeom2);
2957  PG_FREE_IF_COPY(geom1, 0);
2958  PG_FREE_IF_COPY(geom2, 1);
2959 
2960  PG_RETURN_POINTER(ret);
2961 }
double m
Definition: liblwgeom.h:351
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1137
void lwgeom_scale(LWGEOM *geom, const POINT4D *factors)
Definition: lwgeom.c:2013
LWPOINT * lwgeom_as_lwpoint(const LWGEOM *lwgeom)
Definition: lwgeom.c:160
POINTARRAY * point
Definition: liblwgeom.h:410
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
Definition: liblwgeom.h:139
double z
Definition: liblwgeom.h:351
int getPoint4d_p(const POINTARRAY *pa, uint32_t n, POINT4D *point)
Definition: lwgeom_api.c:113
uint8_t flags
Definition: liblwgeom.h:407
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
#define FLAGS_GET_M(flags)
Definition: liblwgeom.h:140
uint32_t npoints
Definition: liblwgeom.h:370

Here is the call graph for this function: