PostGIS  3.4.0dev-r@@SVN_REVISION@@
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Pages

◆ parse_gml_pos()

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

Parse gml:pos.

Definition at line 745 of file lwgeom_in_gml.c.

746 {
747  xmlChar *dimension, *gmlpos;
748  int dim, gml_dim;
749  POINTARRAY *dpa;
750  char *pos, *p;
751  bool digit;
752  POINT4D pt = {0, 0, 0, 0};
753 
754  /* HasZ, !HasM, 1 Point */
755  dpa = ptarray_construct_empty(1, 0, 1);
756 
757  dimension = gmlGetProp(xnode, (xmlChar *) "srsDimension");
758  if (dimension == NULL) /* in GML 3.0.0 it was dimension */
759  dimension = gmlGetProp(xnode, (xmlChar *) "dimension");
760  if (dimension == NULL) dim = 2; /* We assume that we are in 2D */
761  else
762  {
763  dim = atoi((char *) dimension);
764  xmlFree(dimension);
765  if (dim < 2 || dim > 3)
766  gml_lwpgerror("invalid GML representation", 25);
767  }
768  if (dim == 2) *hasz = false;
769 
770  /* We retrieve gml:pos string */
771  gmlpos = xmlNodeGetContent(xnode);
772  pos = (char *) gmlpos;
773  while (isspace(*pos)) pos++; /* Eat extra whitespaces if any */
774 
775  /* gml:pos pattern: x1 y1
776  * x1 y1 z1
777  */
778  for (p=pos, gml_dim=0, digit=false ; *pos ; pos++)
779  {
780  if (isdigit(*pos)) digit = true;
781  if (digit && (*pos == ' ' || *(pos+1) == '\0'))
782  {
783  if (*pos == ' ') *pos = '\0';
784  gml_dim++;
785  if (gml_dim == 1)
786  pt.x = parse_gml_double(p, true, true);
787  else if (gml_dim == 2)
788  pt.y = parse_gml_double(p, true, true);
789  else if (gml_dim == 3)
790  pt.z = parse_gml_double(p, true, true);
791 
792  p = pos+1;
793  digit = false;
794  }
795  }
796  xmlFree(gmlpos);
797 
798  /* Test again coherent dimensions on each coord */
799  if (gml_dim == 2) *hasz = false;
800  if (gml_dim < 2 || gml_dim > 3 || gml_dim != dim)
801  gml_lwpgerror("invalid GML representation", 26);
802 
803  ptarray_append_point(dpa, &pt, LW_FALSE);
804 
805  return dpa; /* ptarray_clone_deep(dpa); */
806 }
#define LW_FALSE
Definition: liblwgeom.h:94
POINTARRAY * ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints)
Create a new POINTARRAY with no points.
Definition: ptarray.c:59
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,...
Definition: ptarray.c:147
static double parse_gml_double(char *d, bool space_before, bool space_after)
Parse a string supposed to be a double.
static xmlChar * gmlGetProp(xmlNodePtr xnode, xmlChar *prop)
Retrieve a GML property from a node or NULL otherwise Respect namespaces if presents in the node elem...
static void gml_lwpgerror(char *msg, __attribute__((__unused__)) int error_code)
Definition: lwgeom_in_gml.c:81
double x
Definition: liblwgeom.h:414
double z
Definition: liblwgeom.h:414
double y
Definition: liblwgeom.h:414

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

Here is the call graph for this function:
Here is the caller graph for this function: