PostGIS  3.1.6dev-r@@SVN_REVISION@@

◆ parse_gml_pos()

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

Parse gml:pos.

Definition at line 829 of file lwgeom_in_gml.c.

830 {
831  xmlChar *dimension, *gmlpos;
832  int dim, gml_dim;
833  POINTARRAY *dpa;
834  char *pos, *p;
835  bool digit;
836  POINT4D pt = {0, 0, 0, 0};
837 
838  /* HasZ, !HasM, 1 Point */
839  dpa = ptarray_construct_empty(1, 0, 1);
840 
841  dimension = gmlGetProp(xnode, "srsDimension");
842  if (dimension == NULL) /* in GML 3.0.0 it was dimension */
843  dimension = gmlGetProp(xnode, "dimension");
844  if (dimension == NULL) dim = 2; /* We assume that we are in 2D */
845  else
846  {
847  dim = atoi((char *) dimension);
848  xmlFree(dimension);
849  if (dim < 2 || dim > 3)
850  gml_lwpgerror("invalid GML representation", 25);
851  }
852  if (dim == 2) *hasz = false;
853 
854  /* We retrieve gml:pos string */
855  gmlpos = xmlNodeGetContent(xnode);
856  pos = (char *) gmlpos;
857  while (isspace(*pos)) pos++; /* Eat extra whitespaces if any */
858 
859  /* gml:pos pattern: x1 y1
860  * x1 y1 z1
861  */
862  for (p=pos, gml_dim=0, digit=false ; *pos ; pos++)
863  {
864  if (isdigit(*pos)) digit = true;
865  if (digit && (*pos == ' ' || *(pos+1) == '\0'))
866  {
867  if (*pos == ' ') *pos = '\0';
868  gml_dim++;
869  if (gml_dim == 1)
870  pt.x = parse_gml_double(p, true, true);
871  else if (gml_dim == 2)
872  pt.y = parse_gml_double(p, true, true);
873  else if (gml_dim == 3)
874  pt.z = parse_gml_double(p, true, true);
875 
876  p = pos+1;
877  digit = false;
878  }
879  }
880  xmlFree(gmlpos);
881 
882  /* Test again coherent dimensions on each coord */
883  if (gml_dim == 2) *hasz = false;
884  if (gml_dim < 2 || gml_dim > 3 || gml_dim != dim)
885  gml_lwpgerror("invalid GML representation", 26);
886 
887  ptarray_append_point(dpa, &pt, LW_FALSE);
888 
889  return dpa; /* ptarray_clone_deep(dpa); */
890 }
#define LW_FALSE
Definition: liblwgeom.h:108
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, const char *charProp)
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:428
double z
Definition: liblwgeom.h:428
double y
Definition: liblwgeom.h:428

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: