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

◆ parse_gml_pos()

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

Parse gml:pos.

Definition at line 777 of file lwgeom_in_gml.c.

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