PostGIS  2.1.10dev-r@@SVN_REVISION@@
static POINTARRAY* parse_gml_pos ( xmlNodePtr  xnode,
bool *  hasz 
)
static

Parse gml:pos.

Definition at line 684 of file lwgeom_in_gml.c.

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

Referenced by parse_gml_data().

685 {
686  xmlChar *dimension, *gmlpos;
687  int dim, gml_dim;
688  POINTARRAY *dpa;
689  char *pos, *p;
690  bool digit;
691  POINT4D pt;
692 
693  /* HasZ, !HasM, 1 Point */
694  dpa = ptarray_construct_empty(1, 0, 1);
695 
696  dimension = gmlGetProp(xnode, (xmlChar *) "srsDimension");
697  if (dimension == NULL) /* in GML 3.0.0 it was dimension */
698  dimension = gmlGetProp(xnode, (xmlChar *) "dimension");
699  if (dimension == NULL) dim = 2; /* We assume that we are in 2D */
700  else
701  {
702  dim = atoi((char *) dimension);
703  xmlFree(dimension);
704  if (dim < 2 || dim > 3)
705  gml_lwerror("invalid GML representation", 25);
706  }
707  if (dim == 2) *hasz = false;
708 
709  /* We retrieve gml:pos string */
710  gmlpos = xmlNodeGetContent(xnode);
711  pos = (char *) gmlpos;
712  while (isspace(*pos)) pos++; /* Eat extra whitespaces if any */
713 
714  /* gml:pos pattern: x1 y1
715  * x1 y1 z1
716  */
717  for (p=pos, gml_dim=0, digit=false ; *pos ; pos++)
718  {
719  if (isdigit(*pos)) digit = true;
720  if (digit && (*pos == ' ' || *(pos+1) == '\0'))
721  {
722  if (*pos == ' ') *pos = '\0';
723  gml_dim++;
724  if (gml_dim == 1)
725  pt.x = parse_gml_double(p, true, true);
726  else if (gml_dim == 2)
727  pt.y = parse_gml_double(p, true, true);
728  else if (gml_dim == 3)
729  pt.z = parse_gml_double(p, true, true);
730 
731  p = pos+1;
732  digit = false;
733  }
734  }
735  xmlFree(gmlpos);
736 
737  /* Test again coherent dimensions on each coord */
738  if (gml_dim == 2) *hasz = false;
739  if (gml_dim < 2 || gml_dim > 3 || gml_dim != dim)
740  gml_lwerror("invalid GML representation", 26);
741 
742  ptarray_append_point(dpa, &pt, LW_FALSE);
743 
744  return ptarray_clone_deep(dpa);
745 }
double x
Definition: liblwgeom.h:308
POINTARRAY * ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints)
Create a new POINTARRAY with no points.
Definition: ptarray.c:57
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_TRUE, then a duplicate point will not be added.
Definition: ptarray.c:141
#define LW_FALSE
Definition: liblwgeom.h:52
POINTARRAY * ptarray_clone_deep(const POINTARRAY *ptarray)
Deep clone a pointarray (also clones serialized pointlist)
Definition: ptarray.c:619
double z
Definition: liblwgeom.h:308
static void gml_lwerror(char *msg, int error_code)
Definition: lwgeom_in_gml.c:68
double y
Definition: liblwgeom.h:308

Here is the call graph for this function:

Here is the caller graph for this function: