PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ parse_gml_pos()

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

Parse gml:pos.

Definition at line 693 of file lwgeom_in_gml.c.

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().

694 {
695  xmlChar *dimension, *gmlpos;
696  int dim, gml_dim;
697  POINTARRAY *dpa;
698  char *pos, *p;
699  bool digit;
700  POINT4D pt;
701 
702  /* HasZ, !HasM, 1 Point */
703  dpa = ptarray_construct_empty(1, 0, 1);
704 
705  dimension = gmlGetProp(xnode, (xmlChar *) "srsDimension");
706  if (dimension == NULL) /* in GML 3.0.0 it was dimension */
707  dimension = gmlGetProp(xnode, (xmlChar *) "dimension");
708  if (dimension == NULL) dim = 2; /* We assume that we are in 2D */
709  else
710  {
711  dim = atoi((char *) dimension);
712  xmlFree(dimension);
713  if (dim < 2 || dim > 3)
714  gml_lwpgerror("invalid GML representation", 25);
715  }
716  if (dim == 2) *hasz = false;
717 
718  /* We retrieve gml:pos string */
719  gmlpos = xmlNodeGetContent(xnode);
720  pos = (char *) gmlpos;
721  while (isspace(*pos)) pos++; /* Eat extra whitespaces if any */
722 
723  /* gml:pos pattern: x1 y1
724  * x1 y1 z1
725  */
726  for (p=pos, gml_dim=0, digit=false ; *pos ; pos++)
727  {
728  if (isdigit(*pos)) digit = true;
729  if (digit && (*pos == ' ' || *(pos+1) == '\0'))
730  {
731  if (*pos == ' ') *pos = '\0';
732  gml_dim++;
733  if (gml_dim == 1)
734  pt.x = parse_gml_double(p, true, true);
735  else if (gml_dim == 2)
736  pt.y = parse_gml_double(p, true, true);
737  else if (gml_dim == 3)
738  pt.z = parse_gml_double(p, true, true);
739 
740  p = pos+1;
741  digit = false;
742  }
743  }
744  xmlFree(gmlpos);
745 
746  /* Test again coherent dimensions on each coord */
747  if (gml_dim == 2) *hasz = false;
748  if (gml_dim < 2 || gml_dim > 3 || gml_dim != dim)
749  gml_lwpgerror("invalid GML representation", 26);
750 
751  ptarray_append_point(dpa, &pt, LW_FALSE);
752 
753  return dpa; /* ptarray_clone_deep(dpa); */
754 }
double x
Definition: liblwgeom.h:352
static void gml_lwpgerror(char *msg, int error_code)
Definition: lwgeom_in_gml.c:81
POINTARRAY * ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints)
Create a new POINTARRAY with no points.
Definition: ptarray.c:70
static xmlChar * gmlGetProp(xmlNodePtr xnode, xmlChar *prop)
Retrieve a GML propertie from a node or NULL otherwise Respect namespaces if presents in the node ele...
static double parse_gml_double(char *d, bool space_before, bool space_after)
Parse a string supposed to be a double.
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, then a duplicate point will not be added.
Definition: ptarray.c:156
#define LW_FALSE
Definition: liblwgeom.h:77
double z
Definition: liblwgeom.h:352
double y
Definition: liblwgeom.h:352
Here is the call graph for this function:
Here is the caller graph for this function: