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

Definition at line 2755 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.

2756 {
2757  GSERIALIZED *geom1 = PG_GETARG_GSERIALIZED_P_COPY(0); /* will be modified */
2758  GSERIALIZED *geom2 = PG_GETARG_GSERIALIZED_P(1);
2759  GSERIALIZED *ret;
2760  LWGEOM *lwgeom1 = lwgeom_from_gserialized(geom1);
2761  LWGEOM *lwgeom2 = lwgeom_from_gserialized(geom2);
2762  LWPOINT *lwpoint;
2763  POINT4D factors;
2764 
2765  lwpoint = lwgeom_as_lwpoint(lwgeom2);
2766  if ( lwpoint == NULL )
2767  {
2768  lwgeom_free(lwgeom1);
2769  lwgeom_free(lwgeom2);
2770  PG_FREE_IF_COPY(geom1, 0);
2771  PG_FREE_IF_COPY(geom2, 1);
2772  lwpgerror("Scale factor geometry parameter must be a point");
2773  PG_RETURN_NULL();
2774  }
2775  if ( ! lwpoint->point->npoints )
2776  {
2777  /* empty point, return input untouched */
2778  lwgeom_free(lwgeom1);
2779  lwgeom_free(lwgeom2);
2780  PG_FREE_IF_COPY(geom2, 1);
2781  PG_RETURN_POINTER(geom1);
2782  }
2783  getPoint4d_p(lwpoint->point, 0, &factors);
2784  if ( ! FLAGS_GET_Z(lwpoint->flags ) ) factors.z = 1;
2785  if ( ! FLAGS_GET_M(lwpoint->flags ) ) factors.m = 1;
2786 
2787  lwgeom_scale(lwgeom1, &factors);
2788 
2789  /* Construct GSERIALIZED */
2790  ret = geometry_serialize(lwgeom1);
2791 
2792  /* Cleanup */
2793  lwgeom_free(lwgeom1);
2794  lwgeom_free(lwgeom2);
2795  PG_FREE_IF_COPY(geom1, 0);
2796  PG_FREE_IF_COPY(geom2, 1);
2797 
2798  PG_RETURN_POINTER(ret);
2799 }
double m
Definition: liblwgeom.h:336
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
int npoints
Definition: liblwgeom.h:355
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1050
void lwgeom_scale(LWGEOM *geom, const POINT4D *factors)
Definition: lwgeom.c:1742
LWPOINT * lwgeom_as_lwpoint(const LWGEOM *lwgeom)
Definition: lwgeom.c:80
POINTARRAY * point
Definition: liblwgeom.h:395
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
Definition: liblwgeom.h:124
double z
Definition: liblwgeom.h:336
uint8_t flags
Definition: liblwgeom.h:392
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
#define FLAGS_GET_M(flags)
Definition: liblwgeom.h:125
int getPoint4d_p(const POINTARRAY *pa, int n, POINT4D *point)
Definition: lwgeom_api.c:231

Here is the call graph for this function: