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

Parse gml:posList.

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

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

Here is the call graph for this function:

Here is the caller graph for this function: