PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ wkt_parser_collection_finalize()

LWGEOM* wkt_parser_collection_finalize ( int  lwtype,
LWGEOM col,
char *  dimensionality 
)

Definition at line 805 of file lwin_wkt.c.

References COLLECTIONTYPE, LWGEOM::flags, FLAGS_GET_M, FLAGS_GET_Z, FLAGS_NDIMS, LWCOLLECTION::geoms, LW_FAILURE, lwcollection_as_lwgeom(), lwcollection_construct_empty(), lwgeom_as_lwcollection(), lwgeom_free(), lwgeom_is_empty(), LWCOLLECTION::ngeoms, PARSER_ERROR_MIXDIMS, PARSER_ERROR_OTHER, SET_PARSER_ERROR, SRID_UNKNOWN, LWGEOM::type, wkt_dimensionality(), and wkt_parser_set_dims().

Referenced by yyparse().

806 {
807  uint8_t flags = wkt_dimensionality(dimensionality);
808  int flagdims = FLAGS_NDIMS(flags);
809 
810  /* No geometry means it is empty */
811  if( ! geom )
812  {
814  }
815 
816  /* There are 'Z' or 'M' tokens in the signature */
817  if ( flagdims > 2 )
818  {
820  int i;
821 
822  for ( i = 0 ; i < col->ngeoms; i++ )
823  {
824  LWGEOM *subgeom = col->geoms[i];
825  if ( FLAGS_NDIMS(flags) != FLAGS_NDIMS(subgeom->flags) &&
826  ! lwgeom_is_empty(subgeom) )
827  {
828  lwgeom_free(geom);
830  return NULL;
831  }
832 
833  if ( lwtype == COLLECTIONTYPE &&
834  ( (FLAGS_GET_Z(flags) != FLAGS_GET_Z(subgeom->flags)) ||
835  (FLAGS_GET_M(flags) != FLAGS_GET_M(subgeom->flags)) ) &&
836  ! lwgeom_is_empty(subgeom) )
837  {
838  lwgeom_free(geom);
840  return NULL;
841  }
842  }
843 
844  /* Harmonize the collection dimensionality */
845  if( LW_FAILURE == wkt_parser_set_dims(geom, flags) )
846  {
847  lwgeom_free(geom);
849  return NULL;
850  }
851  }
852 
853  /* Set the collection type */
854  geom->type = lwtype;
855 
856  return geom;
857 }
static int wkt_parser_set_dims(LWGEOM *geom, uint8_t flags)
Force the dimensionality of a geometry to match the dimensionality of a set of flags (usually derived...
Definition: lwin_wkt.c:101
uint8_t flags
Definition: liblwgeom.h:397
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1099
#define PARSER_ERROR_MIXDIMS
Definition: liblwgeom.h:2039
#define LW_FAILURE
Definition: liblwgeom.h:79
LWGEOM ** geoms
Definition: liblwgeom.h:509
static uint8_t wkt_dimensionality(char *dimensionality)
Definition: lwin_wkt.c:75
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:188
#define FLAGS_GET_Z(flags)
Macros for manipulating the &#39;flags&#39; byte.
Definition: liblwgeom.h:140
LWCOLLECTION * lwgeom_as_lwcollection(const LWGEOM *lwgeom)
Definition: lwgeom.c:192
#define SET_PARSER_ERROR(errno)
Definition: lwin_wkt.c:52
#define FLAGS_GET_M(flags)
Definition: liblwgeom.h:141
int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members) ...
Definition: lwgeom.c:1346
LWCOLLECTION * lwcollection_construct_empty(uint8_t type, int srid, char hasz, char hasm)
Definition: lwcollection.c:94
#define FLAGS_NDIMS(flags)
Definition: liblwgeom.h:152
unsigned char uint8_t
Definition: uthash.h:79
#define PARSER_ERROR_OTHER
Definition: liblwgeom.h:2045
#define COLLECTIONTYPE
Definition: liblwgeom.h:91
LWGEOM * lwcollection_as_lwgeom(const LWCOLLECTION *obj)
Definition: lwgeom.c:268
Here is the call graph for this function:
Here is the caller graph for this function: