PostGIS  3.7.0dev-r@@SVN_REVISION@@

◆ parse_gml_pos()

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

Parse gml:pos.

Definition at line 781 of file lwgeom_in_gml.c.

782 {
783  xmlChar *dimension, *gmlpos;
784  int dim, gml_dim;
785  POINTARRAY *dpa;
786  char *pos, *p;
787  bool digit;
788  POINT4D pt = {0, 0, 0, 0};
789 
790  /* HasZ, !HasM, 1 Point */
791  dpa = ptarray_construct_empty(1, 0, 1);
792 
793  dimension = gmlGetProp(xnode, "srsDimension");
794  if (dimension == NULL) /* in GML 3.0.0 it was dimension */
795  dimension = gmlGetProp(xnode, "dimension");
796  if (dimension == NULL) dim = 2; /* We assume that we are in 2D */
797  else
798  {
799  dim = atoi((char *) dimension);
800  xmlFree(dimension);
801  if (dim < 2 || dim > 3)
802  gml_lwpgerror("invalid GML representation", 25);
803  }
804  if (dim == 2) *hasz = false;
805 
806  /* We retrieve gml:pos string */
807  gmlpos = xmlNodeGetContent(xnode);
808  pos = (char *) gmlpos;
809  while (isspace(*pos)) pos++; /* Eat extra whitespaces if any */
810 
811  /* gml:pos pattern: x1 y1
812  * x1 y1 z1
813  */
814  for (p=pos, gml_dim=0, digit=false ; *pos ; pos++)
815  {
816  if (isdigit(*pos)) digit = true;
817  if (digit && (*pos == ' ' || *(pos+1) == '\0'))
818  {
819  if (*pos == ' ') *pos = '\0';
820  gml_dim++;
821  if (gml_dim == 1)
822  pt.x = parse_gml_double(p, true, true);
823  else if (gml_dim == 2)
824  pt.y = parse_gml_double(p, true, true);
825  else if (gml_dim == 3)
826  pt.z = parse_gml_double(p, true, true);
827 
828  p = pos+1;
829  digit = false;
830  }
831  }
832  xmlFree(gmlpos);
833 
834  /* Test again coherent dimensions on each coord */
835  if (gml_dim == 2) *hasz = false;
836  if (gml_dim < 2 || gml_dim > 3 || gml_dim != dim)
837  gml_lwpgerror("invalid GML representation", 26);
838 
839  ptarray_append_point(dpa, &pt, LW_FALSE);
840 
841  return dpa; /* ptarray_clone_deep(dpa); */
842 }
#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, 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: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: