PostGIS  2.3.8dev-r@@SVN_REVISION@@

◆ ST_Scale()

Datum ST_Scale ( PG_FUNCTION_ARGS  )

Definition at line 2817 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, PG_FUNCTION_INFO_V1(), LWPOINT::point, ST_Points(), and POINT4D::z.

Referenced by ST_BoundingDiagonal().

2818 {
2819  GSERIALIZED *geom1 = PG_GETARG_GSERIALIZED_P_COPY(0); /* will be modified */
2820  GSERIALIZED *geom2 = PG_GETARG_GSERIALIZED_P(1);
2821  GSERIALIZED *ret;
2822  LWGEOM *lwgeom1 = lwgeom_from_gserialized(geom1);
2823  LWGEOM *lwgeom2 = lwgeom_from_gserialized(geom2);
2824  LWPOINT *lwpoint;
2825  POINT4D factors;
2826 
2827  lwpoint = lwgeom_as_lwpoint(lwgeom2);
2828  if ( lwpoint == NULL )
2829  {
2830  lwgeom_free(lwgeom1);
2831  lwgeom_free(lwgeom2);
2832  PG_FREE_IF_COPY(geom1, 0);
2833  PG_FREE_IF_COPY(geom2, 1);
2834  lwpgerror("Scale factor geometry parameter must be a point");
2835  PG_RETURN_NULL();
2836  }
2837  if ( ! lwpoint->point->npoints )
2838  {
2839  /* empty point, return input untouched */
2840  lwgeom_free(lwgeom1);
2841  lwgeom_free(lwgeom2);
2842  PG_FREE_IF_COPY(geom2, 1);
2843  PG_RETURN_POINTER(geom1);
2844  }
2845  getPoint4d_p(lwpoint->point, 0, &factors);
2846  if ( ! FLAGS_GET_Z(lwpoint->flags ) ) factors.z = 1;
2847  if ( ! FLAGS_GET_M(lwpoint->flags ) ) factors.m = 1;
2848 
2849  lwgeom_scale(lwgeom1, &factors);
2850 
2851  /* Construct GSERIALIZED */
2852  ret = geometry_serialize(lwgeom1);
2853 
2854  /* Cleanup */
2855  lwgeom_free(lwgeom1);
2856  lwgeom_free(lwgeom2);
2857  PG_FREE_IF_COPY(geom1, 0);
2858  PG_FREE_IF_COPY(geom2, 1);
2859 
2860  PG_RETURN_POINTER(ret);
2861 }
double m
Definition: liblwgeom.h:351
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
int npoints
Definition: liblwgeom.h:370
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1063
void lwgeom_scale(LWGEOM *geom, const POINT4D *factors)
Definition: lwgeom.c:1755
LWPOINT * lwgeom_as_lwpoint(const LWGEOM *lwgeom)
Definition: lwgeom.c:93
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
uint8_t flags
Definition: liblwgeom.h:407
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
#define FLAGS_GET_M(flags)
Definition: liblwgeom.h:140
int getPoint4d_p(const POINTARRAY *pa, int n, POINT4D *point)
Definition: lwgeom_api.c:244
Here is the call graph for this function:
Here is the caller graph for this function: