28 #include "../postgis_config.h" 36 #include "utils/elog.h" 37 #include "utils/array.h" 38 #include "utils/builtins.h" 39 #include "lib/stringinfo.h" 40 #include "catalog/pg_type.h" 43 #include "lwgeom_pg.h" 46 #include "lwgeom_transform.h" 65 char *
s = (
char*)palloc(64);
67 uint32 typmod = PG_GETARG_INT32(0);
73 POSTGIS_DEBUGF(3,
"Got typmod(srid = %d, type = %d, hasz = %d, hasm = %d)", srid, type, hasz, hasm);
76 if ( ! ( srid || type || hasz || hasm ) )
79 PG_RETURN_CSTRING(str);
83 str += sprintf(str,
"(");
88 else if ( (!type) && ( srid || hasz || hasm ) )
89 str += sprintf(str,
"Geometry");
93 str += sprintf(str,
"%s",
"Z");
97 str += sprintf(str,
"%s",
"M");
101 str += sprintf(str,
",");
105 str += sprintf(str,
"%d", srid);
108 str += sprintf(str,
")");
110 PG_RETURN_CSTRING(s);
130 POSTGIS_DEBUG(2,
"Entered function");
133 if (typmod < 0)
return gser;
135 POSTGIS_DEBUGF(3,
"Got geom(type = %d, srid = %d, hasz = %d, hasm = %d)", geom_type, geom_srid, geom_z, geom_m);
136 POSTGIS_DEBUGF(3,
"Got typmod(type = %d, srid = %d, hasz = %d, hasm = %d)", typmod_type, typmod_srid, typmod_z, typmod_m);
160 if ( typmod_srid > 0 && typmod_srid != geom_srid )
163 errcode(ERRCODE_INVALID_PARAMETER_VALUE),
164 errmsg(
"Geometry SRID (%d) does not match column SRID (%d)", geom_srid, typmod_srid) ));
168 if ( typmod_type > 0 &&
175 (typmod_type != geom_type)) )
178 errcode(ERRCODE_INVALID_PARAMETER_VALUE),
179 errmsg(
"Geometry type (%s) does not match column type (%s)",
lwtype_name(geom_type),
lwtype_name(typmod_type)) ));
183 if ( typmod_z && ! geom_z )
186 errcode(ERRCODE_INVALID_PARAMETER_VALUE),
187 errmsg(
"Column has Z dimension but geometry does not" )));
191 if ( geom_z && ! typmod_z )
194 errcode(ERRCODE_INVALID_PARAMETER_VALUE),
195 errmsg(
"Geometry has Z dimension but column does not" )));
199 if ( typmod_m && ! geom_m )
202 errcode(ERRCODE_INVALID_PARAMETER_VALUE),
203 errmsg(
"Column has M dimension but geometry does not" )));
207 if ( geom_m && ! typmod_m )
210 errcode(ERRCODE_INVALID_PARAMETER_VALUE),
211 errmsg(
"Geometry has M dimension but column does not" )));
226 if (ARR_ELEMTYPE(arr) != CSTRINGOID)
228 (errcode(ERRCODE_ARRAY_ELEMENT_ERROR),
229 errmsg(
"typmod array must be type cstring[]")));
231 if (ARR_NDIM(arr) != 1)
233 (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
234 errmsg(
"typmod array must be one-dimensional")));
236 if (ARR_HASNULL(arr))
238 (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
239 errmsg(
"typmod array must not contain nulls")));
241 deconstruct_array(arr,
242 CSTRINGOID, -2,
false,
'c',
243 &elem_values, NULL, &n);
251 for (i = 0; i < n; i++)
255 char *
s = DatumGetCString(elem_values[i]);
263 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
264 errmsg(
"Invalid geometry type modifier: %s", s)));
277 int srid = pg_atoi(DatumGetCString(elem_values[i]),
278 sizeof(
int32),
'\0');
280 POSTGIS_DEBUGF(3,
"srid: %d", srid);
301 ArrayType *arr = (ArrayType *) DatumGetPointer(PG_GETARG_DATUM(0));
305 srid_is_latlong(fcinfo, srid);
307 PG_RETURN_INT32(typmod);
318 ArrayType *arr = (ArrayType *) DatumGetPointer(PG_GETARG_DATUM(0));
320 PG_RETURN_INT32(typmod);
332 int32 typmod = PG_GETARG_INT32(1);
339 PG_RETURN_POINTER(arg);
351 int32 typmod = PG_GETARG_INT32(1);
358 PG_RETURN_POINTER(arg);
369 int32 typmod = PG_GETARG_INT32(0);
371 char *
s = (
char*)palloc(64);
376 if ( typmod < 0 || type == 0 )
377 ptr += sprintf(ptr,
"Geometry");
383 ptr += sprintf(ptr,
"%s",
"Z");
387 ptr += sprintf(ptr,
"%s",
"M");
389 stext = cstring2text(s);
391 PG_RETURN_TEXT_P(stext);
401 int32 typmod = PG_GETARG_INT32(0);
409 PG_RETURN_INT32(dims);
419 int32 typmod = PG_GETARG_INT32(0);
#define TYPMOD_GET_TYPE(typmod)
uint32_t gserialized_get_type(const GSERIALIZED *s)
Extract the geometry type from the serialized form (it hides in the anonymous data area...
Datum geometry_typmod_in(PG_FUNCTION_ARGS)
static uint32 gserialized_typmod_in(ArrayType *arr, int is_geography)
int clamp_srid(int srid)
Return a valid SRID from an arbitrary integer Raises a notice if what comes out is different from wha...
PG_FUNCTION_INFO_V1(postgis_typmod_out)
#define TYPMOD_GET_M(typmod)
#define TYPMOD_SET_Z(typmod)
Datum geography_enforce_typmod(PG_FUNCTION_ARGS)
int gserialized_has_m(const GSERIALIZED *gser)
Check if a GSERIALIZED has an M ordinate.
#define TYPMOD_GET_SRID(typmod)
Macros for manipulating the 'typemod' int.
int geometry_type_from_string(const char *str, uint8_t *type, int *z, int *m)
Calculate type integer and dimensional flags from string input.
#define TYPMOD_SET_M(typmod)
Datum geography_typmod_in(PG_FUNCTION_ARGS)
LWPOINT * lwpoint_construct_empty(int srid, char hasz, char hasm)
Datum postgis_typmod_srid(PG_FUNCTION_ARGS)
int gserialized_has_z(const GSERIALIZED *gser)
Check if a GSERIALIZED has a Z ordinate.
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
GSERIALIZED * postgis_valid_typmod(GSERIALIZED *gser, int32_t typmod)
Check the consistency of the metadata we want to enforce in the typmod: srid, type and dimensionality...
#define LW_TRUE
Return types for functions with status returns.
#define SRID_UNKNOWN
Unknown SRID value.
#define TYPMOD_SET_TYPE(typmod, type)
Datum postgis_typmod_type(PG_FUNCTION_ARGS)
Datum postgis_typmod_out(PG_FUNCTION_ARGS)
Datum postgis_typmod_dims(PG_FUNCTION_ARGS)
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
Datum geometry_enforce_typmod(PG_FUNCTION_ARGS)
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
int gserialized_is_geodetic(const GSERIALIZED *gser)
Check if a GSERIALIZED is a geography.
#define TYPMOD_SET_SRID(typmod, srid)
#define TYPMOD_GET_Z(typmod)
int32_t gserialized_get_srid(const GSERIALIZED *s)
Extract the SRID from the serialized form (it is packed into three bytes so this is a handy function)...
This library is the generic geometry handling section of PostGIS.