PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ ST_Scale()

Datum ST_Scale ( PG_FUNCTION_ARGS  )

Definition at line 2800 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().

2801 {
2802  GSERIALIZED *geom1 = PG_GETARG_GSERIALIZED_P_COPY(0); /* will be modified */
2803  GSERIALIZED *geom2 = PG_GETARG_GSERIALIZED_P(1);
2804  GSERIALIZED *ret;
2805  LWGEOM *lwgeom1 = lwgeom_from_gserialized(geom1);
2806  LWGEOM *lwgeom2 = lwgeom_from_gserialized(geom2);
2807  LWPOINT *lwpoint;
2808  POINT4D factors;
2809 
2810  lwpoint = lwgeom_as_lwpoint(lwgeom2);
2811  if ( lwpoint == NULL )
2812  {
2813  lwgeom_free(lwgeom1);
2814  lwgeom_free(lwgeom2);
2815  PG_FREE_IF_COPY(geom1, 0);
2816  PG_FREE_IF_COPY(geom2, 1);
2817  lwpgerror("Scale factor geometry parameter must be a point");
2818  PG_RETURN_NULL();
2819  }
2820  if ( ! lwpoint->point->npoints )
2821  {
2822  /* empty point, return input untouched */
2823  lwgeom_free(lwgeom1);
2824  lwgeom_free(lwgeom2);
2825  PG_FREE_IF_COPY(geom2, 1);
2826  PG_RETURN_POINTER(geom1);
2827  }
2828  getPoint4d_p(lwpoint->point, 0, &factors);
2829  if ( ! FLAGS_GET_Z(lwpoint->flags ) ) factors.z = 1;
2830  if ( ! FLAGS_GET_M(lwpoint->flags ) ) factors.m = 1;
2831 
2832  lwgeom_scale(lwgeom1, &factors);
2833 
2834  /* Construct GSERIALIZED */
2835  ret = geometry_serialize(lwgeom1);
2836 
2837  /* Cleanup */
2838  lwgeom_free(lwgeom1);
2839  lwgeom_free(lwgeom2);
2840  PG_FREE_IF_COPY(geom1, 0);
2841  PG_FREE_IF_COPY(geom2, 1);
2842 
2843  PG_RETURN_POINTER(ret);
2844 }
double m
Definition: liblwgeom.h:352
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
int npoints
Definition: liblwgeom.h:371
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1099
void lwgeom_scale(LWGEOM *geom, const POINT4D *factors)
Definition: lwgeom.c:1786
LWPOINT * lwgeom_as_lwpoint(const LWGEOM *lwgeom)
Definition: lwgeom.c:129
POINTARRAY * point
Definition: liblwgeom.h:411
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
Definition: liblwgeom.h:140
double z
Definition: liblwgeom.h:352
uint8_t flags
Definition: liblwgeom.h:408
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
#define FLAGS_GET_M(flags)
Definition: liblwgeom.h:141
int getPoint4d_p(const POINTARRAY *pa, int n, POINT4D *point)
Definition: lwgeom_api.c:122
Here is the call graph for this function:
Here is the caller graph for this function: