PostGIS  3.3.9dev-r@@SVN_REVISION@@

◆ parse_gml_pos()

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

Parse gml:pos.

Definition at line 824 of file lwgeom_in_gml.c.

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

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: