PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ parse_gml_pos()

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

Parse gml:pos.

Definition at line 699 of file lwgeom_in_gml.c.

700 {
701  xmlChar *dimension, *gmlpos;
702  int dim, gml_dim;
703  POINTARRAY *dpa;
704  char *pos, *p;
705  bool digit;
706  POINT4D pt = {0, 0, 0, 0};
707 
708  /* HasZ, !HasM, 1 Point */
709  dpa = ptarray_construct_empty(1, 0, 1);
710 
711  dimension = gmlGetProp(xnode, (xmlChar *) "srsDimension");
712  if (dimension == NULL) /* in GML 3.0.0 it was dimension */
713  dimension = gmlGetProp(xnode, (xmlChar *) "dimension");
714  if (dimension == NULL) dim = 2; /* We assume that we are in 2D */
715  else
716  {
717  dim = atoi((char *) dimension);
718  xmlFree(dimension);
719  if (dim < 2 || dim > 3)
720  gml_lwpgerror("invalid GML representation", 25);
721  }
722  if (dim == 2) *hasz = false;
723 
724  /* We retrieve gml:pos string */
725  gmlpos = xmlNodeGetContent(xnode);
726  pos = (char *) gmlpos;
727  while (isspace(*pos)) pos++; /* Eat extra whitespaces if any */
728 
729  /* gml:pos pattern: x1 y1
730  * x1 y1 z1
731  */
732  for (p=pos, gml_dim=0, digit=false ; *pos ; pos++)
733  {
734  if (isdigit(*pos)) digit = true;
735  if (digit && (*pos == ' ' || *(pos+1) == '\0'))
736  {
737  if (*pos == ' ') *pos = '\0';
738  gml_dim++;
739  if (gml_dim == 1)
740  pt.x = parse_gml_double(p, true, true);
741  else if (gml_dim == 2)
742  pt.y = parse_gml_double(p, true, true);
743  else if (gml_dim == 3)
744  pt.z = parse_gml_double(p, true, true);
745 
746  p = pos+1;
747  digit = false;
748  }
749  }
750  xmlFree(gmlpos);
751 
752  /* Test again coherent dimensions on each coord */
753  if (gml_dim == 2) *hasz = false;
754  if (gml_dim < 2 || gml_dim > 3 || gml_dim != dim)
755  gml_lwpgerror("invalid GML representation", 26);
756 
757  ptarray_append_point(dpa, &pt, LW_FALSE);
758 
759  return dpa; /* ptarray_clone_deep(dpa); */
760 }
#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 x
Definition: liblwgeom.h:355
double z
Definition: liblwgeom.h:355
double y
Definition: liblwgeom.h:355

References gml_lwpgerror(), gmlGetProp(), LW_FALSE, 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: