PostGIS 3.7.0dev-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 610 of file lwgeom_in_gml.c.

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

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: