PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ parse_gml_poslist()

static POINTARRAY* parse_gml_poslist ( xmlNodePtr  xnode,
bool *  hasz 
)
static

Parse gml:posList.

Definition at line 766 of file lwgeom_in_gml.c.

767 {
768  xmlChar *dimension, *gmlposlist;
769  char *poslist, *p;
770  int dim, gml_dim;
771  POINTARRAY *dpa;
772  POINT4D pt = {0, 0, 0, 0};
773  bool digit;
774 
775  /* Retrieve gml:srsDimension attribute if any */
776  dimension = gmlGetProp(xnode, (xmlChar *) "srsDimension");
777  if (dimension == NULL) /* in GML 3.0.0 it was dimension */
778  dimension = gmlGetProp(xnode, (xmlChar *) "dimension");
779  if (dimension == NULL) dim = 2; /* We assume that we are in common 2D */
780  else
781  {
782  dim = atoi((char *) dimension);
783  xmlFree(dimension);
784  if (dim < 2 || dim > 3) gml_lwpgerror("invalid GML representation", 27);
785  }
786  if (dim == 2) *hasz = false;
787 
788  /* Retrieve gml:posList string */
789  gmlposlist = xmlNodeGetContent(xnode);
790  poslist = (char *) gmlposlist;
791 
792  /* HasZ?, !HasM, 1 point */
793  dpa = ptarray_construct_empty(1, 0, 1);
794 
795  /* gml:posList pattern: x1 y1 x2 y2
796  * x1 y1 z1 x2 y2 z2
797  */
798  while (isspace(*poslist)) poslist++; /* Eat extra whitespaces if any */
799  for (p=poslist, gml_dim=0, digit=false ; *poslist ; poslist++)
800  {
801  if (isdigit(*poslist)) digit = true;
802  if (digit && (*poslist == ' ' || *(poslist+1) == '\0'))
803  {
804  if (*poslist == ' ') *poslist = '\0';
805 
806  gml_dim++;
807  if (gml_dim == 1) pt.x = parse_gml_double(p, true, true);
808  else if (gml_dim == 2) pt.y = parse_gml_double(p, true, true);
809  else if (gml_dim == 3) pt.z = parse_gml_double(p, true, true);
810 
811  if (gml_dim == dim)
812  {
813  ptarray_append_point(dpa, &pt, LW_FALSE);
814  pt.x = pt.y = pt.z = pt.m = 0.0;
815  gml_dim = 0;
816  }
817  else if (*(poslist+1) == '\0')
818  gml_lwpgerror("invalid GML representation", 28);
819 
820  p = poslist+1;
821  digit = false;
822  }
823  }
824 
825  xmlFree(gmlposlist);
826 
827  return dpa; /* ptarray_clone_deep(dpa); */
828 }
#define LW_FALSE
Definition: liblwgeom.h:77
POINTARRAY * ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints)
Create a new POINTARRAY with no points.
Definition: ptarray.c:70
int ptarray_append_point(POINTARRAY *pa, const POINT4D *pt, int allow_duplicates)
Append a point to the end of an existing POINTARRAY If allow_duplicate is LW_FALSE,...
Definition: ptarray.c:156
static double parse_gml_double(char *d, bool space_before, bool space_after)
Parse a string supposed to be a double.
static xmlChar * gmlGetProp(xmlNodePtr xnode, xmlChar *prop)
Retrieve a GML property from a node or NULL otherwise Respect namespaces if presents in the node elem...
static void gml_lwpgerror(char *msg, __attribute__((__unused__)) int error_code)
Definition: lwgeom_in_gml.c:82
double m
Definition: liblwgeom.h:355
double x
Definition: liblwgeom.h:355
double z
Definition: liblwgeom.h:355
double y
Definition: liblwgeom.h:355

References gml_lwpgerror(), gmlGetProp(), LW_FALSE, POINT4D::m, parse_gml_double(), ptarray_append_point(), ptarray_construct_empty(), POINT4D::x, POINT4D::y, and POINT4D::z.

Referenced by parse_gml_data().

Here is the call graph for this function:
Here is the caller graph for this function: