PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ parse_gml_poslist()

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

Parse gml:posList.

Definition at line 848 of file lwgeom_in_gml.c.

849{
850 xmlChar *dimension, *gmlposlist;
851 char *poslist, *p;
852 int dim, gml_dim;
853 POINTARRAY *dpa;
854 POINT4D pt = {0, 0, 0, 0};
855 bool digit;
856
857 /* Retrieve gml:srsDimension attribute if any */
858 dimension = gmlGetProp(xnode, "srsDimension");
859 if (dimension == NULL) /* in GML 3.0.0 it was dimension */
860 dimension = gmlGetProp(xnode, "dimension");
861 if (dimension == NULL) dim = 2; /* We assume that we are in common 2D */
862 else
863 {
864 dim = atoi((char *) dimension);
865 xmlFree(dimension);
866 if (dim < 2 || dim > 3) gml_lwpgerror("invalid GML representation", 27);
867 }
868 if (dim == 2) *hasz = false;
869
870 /* Retrieve gml:posList string */
871 gmlposlist = xmlNodeGetContent(xnode);
872 poslist = (char *) gmlposlist;
873
874 /* HasZ?, !HasM, 1 point */
875 dpa = ptarray_construct_empty(1, 0, 1);
876
877 /* gml:posList pattern: x1 y1 x2 y2
878 * x1 y1 z1 x2 y2 z2
879 */
880 while (isspace(*poslist)) poslist++; /* Eat extra whitespaces if any */
881 for (p=poslist, gml_dim=0, digit=false ; *poslist ; poslist++)
882 {
883 if (isdigit(*poslist)) digit = true;
884 if (digit && (*poslist == ' ' || *(poslist+1) == '\0'))
885 {
886 if (*poslist == ' ') *poslist = '\0';
887
888 gml_dim++;
889 if (gml_dim == 1) pt.x = parse_gml_double(p, true, true);
890 else if (gml_dim == 2) pt.y = parse_gml_double(p, true, true);
891 else if (gml_dim == 3) pt.z = parse_gml_double(p, true, true);
892
893 if (gml_dim == dim)
894 {
895 /* Add to ptarray, allowing dupes */
896 ptarray_append_point(dpa, &pt, LW_TRUE);
897 pt.x = pt.y = pt.z = pt.m = 0.0;
898 gml_dim = 0;
899 }
900 else if (*(poslist+1) == '\0')
901 gml_lwpgerror("invalid GML representation", 28);
902
903 p = poslist+1;
904 digit = false;
905 }
906 }
907
908 xmlFree(gmlposlist);
909
910 return dpa; /* ptarray_clone_deep(dpa); */
911}
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
#define LW_TRUE
Return types for functions with status returns.
Definition liblwgeom.h:93
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 double parse_gml_double(char *d, bool space_before, bool space_after)
Parse a string supposed to be a double.
static void gml_lwpgerror(char *msg, __attribute__((__unused__)) int error_code)
double m
Definition liblwgeom.h:414
double x
Definition liblwgeom.h:414
double z
Definition liblwgeom.h:414
double y
Definition liblwgeom.h:414

References gml_lwpgerror(), gmlGetProp(), LW_TRUE, POINT4D::m, 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: