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

Parse gml:posList.

Definition at line 751 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().

752 {
753  xmlChar *dimension, *gmlposlist;
754  char *poslist, *p;
755  int dim, gml_dim;
756  POINTARRAY *dpa;
757  POINT4D pt;
758  bool digit;
759 
760  /* Retrieve gml:srsDimension attribute if any */
761  dimension = gmlGetProp(xnode, (xmlChar *) "srsDimension");
762  if (dimension == NULL) /* in GML 3.0.0 it was dimension */
763  dimension = gmlGetProp(xnode, (xmlChar *) "dimension");
764  if (dimension == NULL) dim = 2; /* We assume that we are in common 2D */
765  else
766  {
767  dim = atoi((char *) dimension);
768  xmlFree(dimension);
769  if (dim < 2 || dim > 3) gml_lwerror("invalid GML representation", 27);
770  }
771  if (dim == 2) *hasz = false;
772 
773  /* Retrieve gml:posList string */
774  gmlposlist = xmlNodeGetContent(xnode);
775  poslist = (char *) gmlposlist;
776 
777  /* HasZ?, !HasM, 1 point */
778  dpa = ptarray_construct_empty(1, 0, 1);
779 
780  /* gml:posList pattern: x1 y1 x2 y2
781  * x1 y1 z1 x2 y2 z2
782  */
783  while (isspace(*poslist)) poslist++; /* Eat extra whitespaces if any */
784  for (p=poslist, gml_dim=0, digit=false ; *poslist ; poslist++)
785  {
786  if (isdigit(*poslist)) digit = true;
787  if (digit && (*poslist == ' ' || *(poslist+1) == '\0'))
788  {
789  if (*poslist == ' ') *poslist = '\0';
790 
791  gml_dim++;
792  if (gml_dim == 1) pt.x = parse_gml_double(p, true, true);
793  else if (gml_dim == 2) pt.y = parse_gml_double(p, true, true);
794  else if (gml_dim == 3) pt.z = parse_gml_double(p, true, true);
795 
796  if (gml_dim == dim)
797  {
798  ptarray_append_point(dpa, &pt, LW_FALSE);
799  gml_dim = 0;
800  }
801  else if (*(poslist+1) == '\0')
802  gml_lwerror("invalid GML representation", 28);
803 
804  p = poslist+1;
805  digit = false;
806  }
807  }
808 
809  xmlFree(gmlposlist);
810 
811  return ptarray_clone_deep(dpa);
812 }
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: