PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ parse_gml_poslist()

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

Parse gml:posList.

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

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