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

◆ parse_gml_coordinates()

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

Parse gml:coordinates.

Definition at line 606 of file lwgeom_in_gml.c.

607{
608 xmlChar *gml_coord, *gml_ts, *gml_cs, *gml_dec;
609 char cs, ts, dec;
610 POINTARRAY *dpa;
611 int gml_dims;
612 char *p, *q;
613 bool digit;
614 POINT4D pt;
615
616 /* We begin to retrieve coordinates string */
617 gml_coord = xmlNodeGetContent(xnode);
618 p = (char *) gml_coord;
619
620 /* Default GML coordinates pattern: x1,y1 x2,y2
621 * x1,y1,z1 x2,y2,z2
622 *
623 * Cf GML 2.1.2 -> 4.3.1 (p18)
624 */
625
626 /* Retrieve separator between coordinates tuples */
627 gml_ts = gmlGetProp(xnode, "ts");
628 if (gml_ts == NULL) ts = ' ';
629 else
630 {
631 if (xmlStrlen(gml_ts) > 1 || isdigit(gml_ts[0]))
632 gml_lwpgerror("invalid GML representation", 15);
633 ts = gml_ts[0];
634 xmlFree(gml_ts);
635 }
636
637 /* Retrieve separator between each coordinate */
638 gml_cs = gmlGetProp(xnode, "cs");
639 if (gml_cs == NULL) cs = ',';
640 else
641 {
642 if (xmlStrlen(gml_cs) > 1 || isdigit(gml_cs[0]))
643 gml_lwpgerror("invalid GML representation", 16);
644 cs = gml_cs[0];
645 xmlFree(gml_cs);
646 }
647
648 /* Retrieve decimal separator */
649 gml_dec = gmlGetProp(xnode, "decimal");
650 if (gml_dec == NULL) dec = '.';
651 else
652 {
653 if (xmlStrlen(gml_dec) > 1 || isdigit(gml_dec[0]))
654 gml_lwpgerror("invalid GML representation", 17);
655 dec = gml_dec[0];
656 xmlFree(gml_dec);
657 }
658
659 if (cs == ts || cs == dec || ts == dec)
660 gml_lwpgerror("invalid GML representation", 18);
661
662 /* HasZ, !HasM, 1 Point */
663 dpa = ptarray_construct_empty(1, 0, 1);
664
665 while (isspace(*p)) p++; /* Eat extra whitespaces if any */
666 for (q = p, gml_dims=0, digit = false ; *p ; p++)
667 {
668
669 if (isdigit(*p)) digit = true; /* One state parser */
670
671 /* Coordinate Separator */
672 if (*p == cs)
673 {
674 *p = '\0';
675 gml_dims++;
676
677 if (*(p+1) == '\0') gml_lwpgerror("invalid GML representation", 19);
678
679 if (gml_dims == 1) pt.x = parse_gml_double(q, false, true);
680 else if (gml_dims == 2) pt.y = parse_gml_double(q, false, true);
681
682 q = p+1;
683
684 /* Tuple Separator (or end string) */
685 }
686 else if (digit && (*p == ts || *(p+1) == '\0'))
687 {
688 if (*p == ts) *p = '\0';
689 gml_dims++;
690
691 if (gml_dims < 2 || gml_dims > 3)
692 gml_lwpgerror("invalid GML representation", 20);
693
694 if (gml_dims == 3)
695 pt.z = parse_gml_double(q, false, true);
696 else
697 {
698 pt.y = parse_gml_double(q, false, true);
699 *hasz = false;
700 }
701
702 ptarray_append_point(dpa, &pt, LW_TRUE);
703 digit = false;
704
705 q = p+1;
706 gml_dims = 0;
707
708 /* Need to put standard decimal separator to atof handle */
709 }
710 else if (*p == dec && dec != '.') *p = '.';
711 }
712
713 xmlFree(gml_coord);
714
715 return dpa; /* ptarray_clone_deep(dpa); */
716}
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:107
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 x
Definition liblwgeom.h:400
double z
Definition liblwgeom.h:400
double y
Definition liblwgeom.h:400

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