Check the consistency of the metadata we want to enforce in the typmod: srid, type and dimensionality.
If things are inconsistent, shut down the query.
111{
120
121 POSTGIS_DEBUG(2, "Entered function");
122
123
124 if (typmod < 0) return gser;
125
126 POSTGIS_DEBUGF(3, "Got geom(type = %d, srid = %d, hasz = %d, hasm = %d)", geom_type, geom_srid, geom_z, geom_m);
127 POSTGIS_DEBUGF(3, "Got typmod(type = %d, srid = %d, hasz = %d, hasm = %d)", typmod_type, typmod_srid, typmod_z, typmod_m);
128
129
130
131
132
133
134
135
136
137
140 {
143 pfree(gser);
146 else
148 }
149
150
151 if ( typmod_srid > 0 && geom_srid == 0 )
152 {
154 geom_srid = typmod_srid;
155 }
156
157
158 if ( typmod_srid > 0 && typmod_srid != geom_srid )
159 {
160 ereport(ERROR, (
161 errcode(ERRCODE_INVALID_PARAMETER_VALUE),
162 errmsg("Geometry SRID (%d) does not match column SRID (%d)", geom_srid, typmod_srid) ));
163 }
164
165
166
168 {
169
173 geography_serialize(mgeom) :
174 geometry_serialize(mgeom);
175
176 gser = mgser;
180 }
181
182
183 if ( typmod_type > 0 &&
184
189
190 (typmod_type != geom_type)) )
191 {
192 ereport(ERROR, (
193 errcode(ERRCODE_INVALID_PARAMETER_VALUE),
194 errmsg(
"Geometry type (%s) does not match column type (%s)",
lwtype_name(geom_type),
lwtype_name(typmod_type)) ));
195 }
196
197
198 if ( typmod_z && ! geom_z )
199 {
200 ereport(ERROR, (
201 errcode(ERRCODE_INVALID_PARAMETER_VALUE),
202 errmsg("Column has Z dimension but geometry does not" )));
203 }
204
205
206 if ( geom_z && ! typmod_z )
207 {
208 ereport(ERROR, (
209 errcode(ERRCODE_INVALID_PARAMETER_VALUE),
210 errmsg("Geometry has Z dimension but column does not" )));
211 }
212
213
214 if ( typmod_m && ! geom_m )
215 {
216 ereport(ERROR, (
217 errcode(ERRCODE_INVALID_PARAMETER_VALUE),
218 errmsg("Column has M dimension but geometry does not" )));
219 }
220
221
222 if ( geom_m && ! typmod_m )
223 {
224 ereport(ERROR, (
225 errcode(ERRCODE_INVALID_PARAMETER_VALUE),
226 errmsg("Geometry has M dimension but column does not" )));
227 }
228
229 return gser;
230
231}
int32_t gserialized_get_srid(const GSERIALIZED *g)
Extract the SRID from the serialized form (it is packed into three bytes so this is a handy function)...
int gserialized_is_geodetic(const GSERIALIZED *g)
Check if a GSERIALIZED is a geography.
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
int gserialized_has_m(const GSERIALIZED *g)
Check if a GSERIALIZED has an M ordinate.
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
void gserialized_set_srid(GSERIALIZED *g, int32_t srid)
Write the SRID into the serialized form (it is packed into three bytes so this is a handy function).
int gserialized_has_z(const GSERIALIZED *g)
Check if a GSERIALIZED has a Z ordinate.
uint32_t gserialized_get_type(const GSERIALIZED *g)
Extract the geometry type from the serialized form (it hides in the anonymous data area,...
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
#define TYPMOD_GET_SRID(typmod)
Macros for manipulating the 'typemod' int.
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
void lwgeom_free(LWGEOM *geom)
LWGEOM * lwgeom_as_multi(const LWGEOM *lwgeom)
Create a new LWGEOM of the appropriate MULTI* type.
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
#define TYPMOD_GET_M(typmod)
uint8_t lwtype_multitype(uint8_t type)
LWPOINT * lwpoint_construct_empty(int32_t srid, char hasz, char hasm)
#define TYPMOD_GET_TYPE(typmod)
#define TYPMOD_GET_Z(typmod)