50 #include <libxml/tree.h> 51 #include <libxml/parser.h> 52 #include <libxml/xpath.h> 53 #include <libxml/xpathInternals.h> 56 #include "executor/spi.h" 58 #include "../postgis_config.h" 59 #include "lwgeom_pg.h" 61 #include "lwgeom_transform.h" 75 #define XLINK_NS ((char *) "http://www.w3.org/1999/xlink") 76 #define GML_NS ((char *) "http://www.opengis.net/gml") 77 #define GML32_NS ((char *) "http://www.opengis.net/gml/3.2") 83 POSTGIS_DEBUGF(3,
"ST_GeomFromGML ERROR %i", error_code);
107 if (PG_ARGISNULL(0)) PG_RETURN_NULL();
108 xml_input = PG_GETARG_TEXT_P(0);
112 root_srid = PG_GETARG_INT32(1);
116 lwgeom->
srid = root_srid;
121 PG_RETURN_POINTER(geom);
133 ns = xmlGetNsList(xnode->doc, xnode);
139 if (ns == NULL) {
return !is_strict; }
146 for (p=ns ; *p ; p++)
148 if ((*p)->href == NULL || (*p)->prefix == NULL ||
149 xnode->ns == NULL || xnode->ns->prefix == NULL)
continue;
151 if (!xmlStrcmp(xnode->ns->prefix, (*p)->prefix))
153 if ( !strcmp((
char *) (*p)->href,
GML_NS)
154 || !strcmp((
char *) (*p)->href,
GML32_NS))
179 return xmlGetProp(xnode, prop);
185 value = xmlGetNsProp(xnode, prop, (xmlChar *)
GML_NS);
186 if (value == NULL) value = xmlGetNsProp(xnode, prop, (xmlChar *)
GML32_NS);
189 if (value == NULL) value = xmlGetNoNsProp(xnode, prop);
203 prop = xmlGetNsProp(node, (xmlChar *)
"type", (xmlChar *)
XLINK_NS);
204 if (prop == NULL)
return false;
205 if (strcmp((
char *) prop,
"simple"))
211 prop = xmlGetNsProp(node, (xmlChar *)
"href", (xmlChar *) XLINK_NS);
212 if (prop == NULL)
return false;
231 xmlXPathContext *ctx;
232 xmlXPathObject *xpath;
233 xmlNodePtr node, ret_node;
234 xmlChar *href, *p, *node_id;
236 href = xmlGetNsProp(xnode, (xmlChar *)
"href", (xmlChar *)
XLINK_NS);
237 id =
lwalloc((xmlStrlen(xnode->ns->prefix) * 2 + xmlStrlen(xnode->name)
238 + xmlStrlen(href) +
sizeof(
"//:[@:id='']") + 1));
243 sprintf(
id,
"//%s:%s[@%s:id='%s']", (
char *) xnode->ns->prefix,
244 (
char *) xnode->name,
245 (
char *) xnode->ns->prefix,
248 ctx = xmlXPathNewContext(xnode->doc);
257 ns = xmlGetNsList(xnode->doc, xnode);
258 for (n=ns ; *n; n++) xmlXPathRegisterNs(ctx, (*n)->prefix, (*n)->href);
262 xpath = xmlXPathEvalExpression((xmlChar *)
id, ctx);
264 if (xpath == NULL || xpath->nodesetval == NULL || xpath->nodesetval->nodeNr != 1)
267 xmlXPathFreeObject(xpath);
268 xmlXPathFreeContext(ctx);
271 ret_node = xpath->nodesetval->nodeTab[0];
272 xmlXPathFreeObject(xpath);
273 xmlXPathFreeContext(ctx);
276 for (node = xnode ; node != NULL ; node = node->parent)
278 if (node->type != XML_ELEMENT_NODE)
continue;
282 if (!xmlStrcmp(node_id, p))
298 projPJ in_pj, out_pj;
299 char *text_in, *text_out;
304 text_in = GetProj4StringSPI(srid_in);
305 text_out = GetProj4StringSPI(srid_out);
315 elog(ERROR,
"gml_reproject_pa: reprojection failed");
335 if (SPI_OK_CONNECT != SPI_connect ())
336 lwpgerror(
"gml_is_srid_planar: could not connect to SPI manager");
339 sprintf(query,
"SELECT position('+units=m ' in proj4text) \ 340 FROM spatial_ref_sys WHERE srid='%d'", srid);
342 err = SPI_exec(query, 1);
343 if (err < 0) lwpgerror(
"gml_is_srid_planar: error executing query %d", err);
346 if (SPI_processed <= 0)
352 result = SPI_getvalue(SPI_tuptable->vals[0], SPI_tuptable->tupdesc, 1);
353 is_planar = atoi(result);
373 srsname =
gmlGetProp(node, (xmlChar *)
"srsName");
377 if (node->parent == NULL)
404 if (!strncmp((
char *) srsname,
"EPSG:", 5))
409 else if (!strncmp((
char *) srsname,
"urn:ogc:def:crs:EPSG:", 21)
410 || !strncmp((
char *) srsname,
"urn:x-ogc:def:crs:EPSG:", 23)
411 || !strncmp((
char *) srsname,
"urn:EPSG:geographicCRS:", 23))
416 else if (!strncmp((
char *) srsname,
417 "http://www.opengis.net/gml/srs/epsg.xml#", 40))
425 for (p = (
char *) srsname ; *p ; p++);
426 for (--p ; *p != sep ; p--)
427 if (!isdigit(*p))
gml_lwpgerror(
"unknown spatial reference system", 5);
429 srs->
srid = atoi(++p);
472 if (space_before)
while (isspace(*d)) d++;
473 for (st = INIT, p = d ; *p ; p++)
478 if (st == INIT || st == NEED_DIG) st = DIG;
479 else if (st == NEED_DIG_DEC) st = DIG_DEC;
480 else if (st == NEED_DIG_EXP || st == EXP) st = DIG_EXP;
481 else if (st == DIG || st == DIG_DEC || st == DIG_EXP);
486 if (st == DIG) st = NEED_DIG_DEC;
489 else if (*p ==
'-' || *p ==
'+')
491 if (st == INIT) st = NEED_DIG;
492 else if (st == EXP) st = NEED_DIG_EXP;
495 else if (*p ==
'e' || *p ==
'E')
497 if (st == DIG || st == DIG_DEC) st = EXP;
500 else if (isspace(*p))
502 if (!space_after)
gml_lwpgerror(
"invalid GML representation", 11);
503 if (st == DIG || st == DIG_DEC || st == DIG_EXP)st = END;
504 else if (st == NEED_DIG_DEC) st = END;
511 if (st != DIG && st != NEED_DIG_DEC && st != DIG_DEC && st != DIG_EXP && st != END)
523 xmlChar *gml_coord, *gml_ts, *gml_cs, *gml_dec;
532 gml_coord = xmlNodeGetContent(xnode);
533 p = (
char *) gml_coord;
543 if (gml_ts == NULL) ts =
' ';
546 if (xmlStrlen(gml_ts) > 1 || isdigit(gml_ts[0]))
554 if (gml_cs == NULL) cs =
',';
557 if (xmlStrlen(gml_cs) > 1 || isdigit(gml_cs[0]))
564 gml_dec =
gmlGetProp(xnode, (xmlChar *)
"decimal");
565 if (gml_dec == NULL) dec =
'.';
568 if (xmlStrlen(gml_dec) > 1 || isdigit(gml_dec[0]))
574 if (cs == ts || cs == dec || ts == dec)
580 while (isspace(*p)) p++;
581 for (q = p, gml_dims=0, digit =
false ; *p ; p++)
584 if (isdigit(*p)) digit =
true;
592 if (*(p+1) ==
'\0')
gml_lwpgerror(
"invalid GML representation", 19);
601 else if (digit && (*p == ts || *(p+1) ==
'\0'))
603 if (*p == ts) *p =
'\0';
606 if (gml_dims < 2 || gml_dims > 3)
625 else if (*p == dec && dec !=
'.') *p =
'.';
649 for (xyz = xnode->children ; xyz != NULL ; xyz = xyz->next)
651 if (xyz->type != XML_ELEMENT_NODE)
continue;
654 if (!strcmp((
char *) xyz->name,
"X"))
657 c = xmlNodeGetContent(xyz);
662 else if (!strcmp((
char *) xyz->name,
"Y"))
665 c = xmlNodeGetContent(xyz);
670 else if (!strcmp((
char *) xyz->name,
"Z"))
673 c = xmlNodeGetContent(xyz);
680 if (!x || !y)
gml_lwpgerror(
"invalid GML representation", 24);
681 if (!z) *hasz =
false;
695 xmlChar *dimension, *gmlpos;
705 dimension =
gmlGetProp(xnode, (xmlChar *)
"srsDimension");
706 if (dimension == NULL)
707 dimension =
gmlGetProp(xnode, (xmlChar *)
"dimension");
708 if (dimension == NULL) dim = 2;
711 dim = atoi((
char *) dimension);
713 if (dim < 2 || dim > 3)
716 if (dim == 2) *hasz =
false;
719 gmlpos = xmlNodeGetContent(xnode);
720 pos = (
char *) gmlpos;
721 while (isspace(*pos)) pos++;
726 for (p=pos, gml_dim=0, digit=
false ; *pos ; pos++)
728 if (isdigit(*pos)) digit =
true;
729 if (digit && (*pos ==
' ' || *(pos+1) ==
'\0'))
731 if (*pos ==
' ') *pos =
'\0';
735 else if (gml_dim == 2)
737 else if (gml_dim == 3)
747 if (gml_dim == 2) *hasz =
false;
748 if (gml_dim < 2 || gml_dim > 3 || gml_dim != dim)
762 xmlChar *dimension, *gmlposlist;
770 dimension =
gmlGetProp(xnode, (xmlChar *)
"srsDimension");
771 if (dimension == NULL)
772 dimension =
gmlGetProp(xnode, (xmlChar *)
"dimension");
773 if (dimension == NULL) dim = 2;
776 dim = atoi((
char *) dimension);
778 if (dim < 2 || dim > 3)
gml_lwpgerror(
"invalid GML representation", 27);
780 if (dim == 2) *hasz =
false;
783 gmlposlist = xmlNodeGetContent(xnode);
784 poslist = (
char *) gmlposlist;
792 while (isspace(*poslist)) poslist++;
793 for (p=poslist, gml_dim=0, digit=
false ; *poslist ; poslist++)
795 if (isdigit(*poslist)) digit =
true;
796 if (digit && (*poslist ==
' ' || *(poslist+1) ==
'\0'))
798 if (*poslist ==
' ') *poslist =
'\0';
810 else if (*(poslist+1) ==
'\0')
845 for (xa = xnode ; xa != NULL ; xa = xa->next)
847 if (xa->type != XML_ELEMENT_NODE)
continue;
849 if (xa->name == NULL)
continue;
851 if (!strcmp((
char *) xa->name,
"pos"))
854 if (pa == NULL) pa = tmp_pa;
858 else if (!strcmp((
char *) xa->name,
"posList"))
861 if (pa == NULL) pa = tmp_pa;
865 else if (!strcmp((
char *) xa->name,
"coordinates"))
868 if (pa == NULL) pa = tmp_pa;
872 else if (!strcmp((
char *) xa->name,
"coord"))
875 if (pa == NULL) pa = tmp_pa;
879 else if (!strcmp((
char *) xa->name,
"pointRep") ||
880 !strcmp((
char *) xa->name,
"pointProperty"))
884 for (xb = xa->children ; xb != NULL ; xb = xb->next)
886 if (xb->type != XML_ELEMENT_NODE)
continue;
888 if (!strcmp((
char *) xb->name,
"Point"))
894 if (!found || xb == NULL)
898 if (xb == NULL || xb->children == NULL)
902 if (tmp_pa->npoints != 1)
908 else if (srs.
srid != *root_srid)
910 if (pa == NULL) pa = tmp_pa;
915 if (pa == NULL)
gml_lwpgerror(
"invalid GML representation", 32);
932 if (xnode->children == NULL)
942 *root_srid = srs.
srid;
947 if (srs.
srid != *root_srid)
967 if (xnode->children == NULL)
977 *root_srid = srs.
srid;
982 if (srs.
srid != *root_srid)
1004 xmlChar *interpolation=NULL;
1009 for (xa = xnode->children ; xa != NULL ; xa = xa->next)
1011 if (xa->type != XML_ELEMENT_NODE)
continue;
1013 if (!strcmp((
char *) xa->name,
"segments"))
1019 if (!found)
gml_lwpgerror(
"invalid GML representation", 37);
1024 for (xa = xa->children, lss=0; xa != NULL ; xa = xa->next)
1026 if (xa->type != XML_ELEMENT_NODE)
continue;
1028 if (strcmp((
char *) xa->name,
"LineStringSegment"))
continue;
1031 interpolation =
gmlGetProp(xa, (xmlChar *)
"interpolation");
1032 if (interpolation != NULL)
1034 if (strcmp((
char *) interpolation,
"linear"))
1036 xmlFree(interpolation);
1044 if (ppa[lss]->npoints < 2)
1048 if (lss == 0)
gml_lwpgerror(
"invalid GML representation", 40);
1051 if (lss == 1) pa = ppa[0];
1064 for (last = npoints = i = 0; i < lss ; i++)
1066 if (i + 1 == lss) last = 1;
1078 npoints += ppa[i]->
npoints - 1;
1109 if (ppa[0]->npoints < 4
1139 if (xnode->children == NULL)
1144 for (xa = xnode->children ; xa != NULL ; xa = xa->next)
1148 if (xa->type != XML_ELEMENT_NODE)
continue;
1150 if (strcmp((
char *) xa->name,
"outerBoundaryIs") &&
1151 strcmp((
char *) xa->name,
"exterior"))
continue;
1153 for (xb = xa->children ; xb != NULL ; xb = xb->next)
1155 if (xb->type != XML_ELEMENT_NODE)
continue;
1157 if (strcmp((
char *) xb->name,
"LinearRing"))
continue;
1162 if (ppa[0]->npoints < 4
1175 for (ring=1, xa = xnode->children ; xa != NULL ; xa = xa->next)
1179 if (xa->type != XML_ELEMENT_NODE)
continue;
1181 if (strcmp((
char *) xa->name,
"innerBoundaryIs") &&
1182 strcmp((
char *) xa->name,
"interior"))
continue;
1184 for (xb = xa->children ; xb != NULL ; xb = xb->next)
1186 if (xb->type != XML_ELEMENT_NODE)
continue;
1188 if (strcmp((
char *) xb->name,
"LinearRing"))
continue;
1194 if (ppa[ring]->npoints < 4
1205 if (ppa == NULL || ppa[0] == NULL)
gml_lwpgerror(
"invalid GML representation", 44);
1209 for (i=0 ; i < ring ; i++)
1227 xmlChar *interpolation=NULL;
1231 if (xnode->children == NULL)
1237 interpolation =
gmlGetProp(xnode, (xmlChar *)
"interpolation");
1238 if (interpolation != NULL)
1240 if (strcmp((
char *) interpolation,
"planar"))
1242 xmlFree(interpolation);
1247 for (xa = xnode->children ; xa != NULL ; xa = xa->next)
1250 if (xa->type != XML_ELEMENT_NODE)
continue;
1252 if (strcmp((
char *) xa->name,
"exterior"))
continue;
1254 for (xb = xa->children ; xb != NULL ; xb = xb->next)
1257 if (xb->type != XML_ELEMENT_NODE)
continue;
1259 if (strcmp((
char *) xb->name,
"LinearRing"))
continue;
1274 if (pa == NULL)
gml_lwpgerror(
"invalid GML representation", 47);
1290 xmlChar *interpolation=NULL;
1298 if (strcmp((
char *) xnode->name,
"PolygonPatch"))
1302 interpolation =
gmlGetProp(xnode, (xmlChar *)
"interpolation");
1303 if (interpolation != NULL)
1305 if (strcmp((
char *) interpolation,
"planar"))
1307 xmlFree(interpolation);
1313 for (xa = xnode->children ; xa != NULL ; xa = xa->next)
1316 if (strcmp((
char *) xa->name,
"exterior"))
continue;
1319 for (xb = xa->children ; xb != NULL ; xb = xb->next)
1321 if (xb->type != XML_ELEMENT_NODE)
continue;
1323 if (strcmp((
char *) xb->name,
"LinearRing"))
continue;
1328 if (ppa[0]->npoints < 4
1343 for (ring=1, xa = xnode->children ; xa != NULL ; xa = xa->next)
1345 if (xa->type != XML_ELEMENT_NODE)
continue;
1347 if (strcmp((
char *) xa->name,
"interior"))
continue;
1350 for (xb = xa->children ; xb != NULL ; xb = xb->next)
1352 if (xb->type != XML_ELEMENT_NODE)
continue;
1353 if (strcmp((
char *) xb->name,
"LinearRing"))
continue;
1359 if (ppa[ring]->npoints < 4
1372 if (ppa == NULL || ppa[0] == NULL)
gml_lwpgerror(
"invalid GML representation", 50);
1376 for (i=0 ; i < ring ; i++)
1398 for (xa = xnode->children ; xa != NULL ; xa = xa->next)
1400 if (xa->type != XML_ELEMENT_NODE)
continue;
1402 if (!strcmp((
char *) xa->name,
"patches"))
1408 if (!found)
gml_lwpgerror(
"invalid GML representation", 51);
1411 for (patch=0, xa = xa->children ; xa != NULL ; xa = xa->next)
1413 if (xa->type != XML_ELEMENT_NODE)
continue;
1415 if (strcmp((
char *) xa->name,
"PolygonPatch"))
continue;
1420 if (patch > 1)
gml_lwpgerror(
"invalid GML representation", 52);
1425 if (!patch)
gml_lwpgerror(
"invalid GML representation", 53);
1451 *root_srid = srs.
srid;
1455 if (xnode->children == NULL)
1459 for (xa = xnode->children ; xa != NULL ; xa = xa->next)
1461 if (xa->type != XML_ELEMENT_NODE)
continue;
1463 if (!strcmp((
char *) xa->name,
"patches") ||
1464 !strcmp((
char *) xa->name,
"trianglePatches"))
1470 if (!found)
return geom;
1473 for (xa = xa->children ; xa != NULL ; xa = xa->next)
1475 if (xa->type != XML_ELEMENT_NODE)
continue;
1477 if (strcmp((
char *) xa->name,
"Triangle"))
continue;
1479 if (xa->children != NULL)
1501 *root_srid = srs.
srid;
1505 if (xnode->children == NULL)
1508 for (xa = xnode->children ; xa != NULL ; xa = xa->next)
1511 if (xa->type != XML_ELEMENT_NODE)
continue;
1513 if (!strcmp((
char *) xa->name,
"pointMembers"))
1515 for (xb = xa->children ; xb != NULL ; xb = xb->next)
1522 else if (!strcmp((
char *) xa->name,
"pointMember"))
1524 if (xa->children != NULL)
1547 *root_srid = srs.
srid;
1551 if (xnode->children == NULL)
1554 for (xa = xnode->children ; xa != NULL ; xa = xa->next)
1557 if (xa->type != XML_ELEMENT_NODE)
continue;
1559 if (strcmp((
char *) xa->name,
"lineStringMember"))
continue;
1560 if (xa->children != NULL)
1582 *root_srid = srs.
srid;
1586 if (xnode->children == NULL)
1589 for (xa = xnode->children ; xa != NULL ; xa = xa->next)
1593 if (xa->type != XML_ELEMENT_NODE)
continue;
1595 if (!strcmp((
char *) xa->name,
"curveMembers"))
1597 for (xb = xa->children ; xb != NULL ; xb = xb->next)
1604 else if (!strcmp((
char *) xa->name,
"curveMember"))
1606 if (xa->children != NULL)
1629 *root_srid = srs.
srid;
1633 if (xnode->children == NULL)
1636 for (xa = xnode->children ; xa != NULL ; xa = xa->next)
1639 if (xa->type != XML_ELEMENT_NODE)
continue;
1641 if (strcmp((
char *) xa->name,
"polygonMember"))
continue;
1642 if (xa->children != NULL)
1664 *root_srid = srs.
srid;
1668 if (xnode->children == NULL)
1671 for (xa = xnode->children ; xa != NULL ; xa = xa->next)
1674 if (xa->type != XML_ELEMENT_NODE)
continue;
1676 if (!strcmp((
char *) xa->name,
"surfaceMembers"))
1678 for (xb = xa->children ; xb != NULL ; xb = xb->next)
1685 else if (!strcmp((
char *) xa->name,
"surfaceMember"))
1687 if (xa->children != NULL)
1712 *root_srid = srs.
srid;
1716 if (xnode->children == NULL)
1720 for (xa = xnode->children ; xa != NULL ; xa = xa->next)
1722 if (xa->type != XML_ELEMENT_NODE)
continue;
1724 if (!strcmp((
char *) xa->name,
"polygonPatches"))
1730 if (!found)
return geom;
1732 for (xa = xa->children ; xa != NULL ; xa = xa->next)
1735 if (xa->type != XML_ELEMENT_NODE)
continue;
1737 if (strcmp((
char *) xa->name,
"PolygonPatch"))
continue;
1760 *root_srid = srs.
srid;
1764 if (xnode->children == NULL)
1767 for (xa = xnode->children ; xa != NULL ; xa = xa->next)
1769 if (xa->type != XML_ELEMENT_NODE)
continue;
1777 if ( !strcmp((
char *) xa->name,
"pointMember")
1778 || !strcmp((
char *) xa->name,
"lineStringMember")
1779 || !strcmp((
char *) xa->name,
"polygonMember")
1780 || !strcmp((
char *) xa->name,
"geometryMember"))
1782 if (xa->children == NULL)
break;
1784 parse_gml(xa->children, hasz, root_srid));
1797 xmlNodePtr xmlroot=NULL;
1798 int xml_size = strlen(xml);
1805 xmldoc = xmlReadMemory(xml, xml_size, NULL, NULL, XML_PARSE_SAX1);
1806 if (!xmldoc || (xmlroot = xmlDocGetRootElement(xmldoc)) == NULL)
1813 lwgeom =
parse_gml(xmlroot, &hasz, &root_srid);
1821 lwgeom->
srid = root_srid;
1849 xmlNodePtr xa = xnode;
1852 while (xa != NULL && (xa->type != XML_ELEMENT_NODE
1855 if (xa == NULL)
gml_lwpgerror(
"invalid GML representation", 55);
1860 *root_srid = srs.
srid;
1863 if (!strcmp((
char *) xa->name,
"Point"))
1866 if (!strcmp((
char *) xa->name,
"LineString"))
1869 if (!strcmp((
char *) xa->name,
"Curve"))
1872 if (!strcmp((
char *) xa->name,
"LinearRing"))
1875 if (!strcmp((
char *) xa->name,
"Polygon"))
1878 if (!strcmp((
char *) xa->name,
"Triangle"))
1881 if (!strcmp((
char *) xa->name,
"Surface"))
1884 if (!strcmp((
char *) xa->name,
"MultiPoint"))
1887 if (!strcmp((
char *) xa->name,
"MultiLineString"))
1890 if (!strcmp((
char *) xa->name,
"MultiCurve"))
1893 if (!strcmp((
char *) xa->name,
"MultiPolygon"))
1896 if (!strcmp((
char *) xa->name,
"MultiSurface"))
1899 if (!strcmp((
char *) xa->name,
"PolyhedralSurface"))
1902 if ((!strcmp((
char *) xa->name,
"Tin")) ||
1903 !strcmp((
char *) xa->name,
"TriangulatedSurface" ))
1906 if (!strcmp((
char *) xa->name,
"MultiGeometry"))
static LWGEOM * parse_gml_triangle(xmlNodePtr xnode, bool *hasz, int *root_srid)
Parse GML Triangle (3.1.1)
static LWGEOM * parse_gml_mpoly(xmlNodePtr xnode, bool *hasz, int *root_srid)
Parse GML MultiPolygon (2.1.2, 3.1.1)
POINTARRAY * ptarray_construct(char hasz, char hasm, uint32_t npoints)
Construct an empty pointarray, allocating storage and setting the npoints, but not filling in any inf...
LWTIN * lwtin_add_lwtriangle(LWTIN *mobj, const LWTRIANGLE *obj)
LWLINE * lwline_construct_empty(int srid, char hasz, char hasm)
LWTRIANGLE * lwtriangle_construct_empty(int srid, char hasz, char hasm)
static POINTARRAY * parse_gml_poslist(xmlNodePtr xnode, bool *hasz)
Parse gml:posList.
static LWGEOM * parse_gml_linearring(xmlNodePtr xnode, bool *hasz, int *root_srid)
Parse GML LinearRing (3.1.1)
static void gml_lwpgerror(char *msg, int error_code)
static void parse_gml_srs(xmlNodePtr xnode, gmlSrs *srs)
Parse gml srsName attribute.
int ptarray_is_closed_3d(const POINTARRAY *pa)
LWPSURFACE * lwpsurface_add_lwpoly(LWPSURFACE *mobj, const LWPOLY *obj)
static LWGEOM * parse_gml_point(xmlNodePtr xnode, bool *hasz, int *root_srid)
Parse GML point (2.1.2, 3.1.1)
static LWGEOM * parse_gml_patch(xmlNodePtr xnode, bool *hasz, int *root_srid)
Parse GML PolygonPatch (3.1.1)
POINTARRAY * ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints)
Create a new POINTARRAY with no points.
void lwgeom_free(LWGEOM *geom)
static xmlChar * gmlGetProp(xmlNodePtr xnode, xmlChar *prop)
Retrieve a GML propertie from a node or NULL otherwise Respect namespaces if presents in the node ele...
static POINTARRAY * parse_gml_coordinates(xmlNodePtr xnode, bool *hasz)
Parse gml:coordinates.
static int gml_is_srid_planar(int srid)
Return 1 if given srid is planar (0 otherwise, i.e geocentric srid) Return -1 if srid is not in spati...
#define POLYHEDRALSURFACETYPE
static LWGEOM * parse_gml_tin(xmlNodePtr xnode, bool *hasz, int *root_srid)
Parse GML Tin (and TriangulatedSurface) (3.1.1)
static LWGEOM * parse_gml_coll(xmlNodePtr xnode, bool *hasz, int *root_srid)
Parse GML MultiGeometry (2.1.2, 3.1.1)
static double parse_gml_double(char *d, bool space_before, bool space_after)
Parse a string supposed to be a double.
static LWGEOM * parse_gml(xmlNodePtr xnode, bool *hasz, int *root_srid)
Parse GML.
LWMLINE * lwmline_add_lwline(LWMLINE *mobj, const LWLINE *obj)
LWPOINT * lwpoint_construct_empty(int srid, char hasz, char hasm)
int ptarray_is_closed_2d(const POINTARRAY *pa)
Datum geom_from_gml(PG_FUNCTION_ARGS)
LWGEOM * lwpoly_as_lwgeom(const LWPOLY *obj)
static POINTARRAY * parse_gml_coord(xmlNodePtr xnode, bool *hasz)
Parse gml:coord.
static POINTARRAY * gml_reproject_pa(POINTARRAY *pa, int srid_in, int srid_out)
Use Proj4 to reproject a given POINTARRAY.
POINTARRAY * ptarray_flip_coordinates(POINTARRAY *pa)
Reverse X and Y axis on a given POINTARRAY.
static xmlNodePtr get_xlink_node(xmlNodePtr xnode)
Return a xmlNodePtr on a node referenced by a XLink or NULL otherwise.
static LWGEOM * parse_gml_mcurve(xmlNodePtr xnode, bool *hasz, int *root_srid)
Parse GML MultiCurve (3.1.1)
LWGEOM * lwline_as_lwgeom(const LWLINE *obj)
static LWGEOM * parse_gml_msurface(xmlNodePtr xnode, bool *hasz, int *root_srid)
Parse GML MultiSurface (3.1.1)
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, then a duplicate point will not be added.
projPJ lwproj_from_string(const char *txt)
Get a projection from a string representation.
LWPOLY * lwpoly_construct(int srid, GBOX *bbox, uint32_t nrings, POINTARRAY **points)
#define LW_TRUE
Return types for functions with status returns.
LWLINE * lwline_construct(int srid, GBOX *bbox, POINTARRAY *points)
#define SRID_UNKNOWN
Unknown SRID value.
struct struct_gmlSrs gmlSrs
LWGEOM * lwgeom_force_2d(const LWGEOM *geom)
Strip out the Z/M components of an LWGEOM.
uint8_t * getPoint_internal(const POINTARRAY *pa, int n)
PG_FUNCTION_INFO_V1(geom_from_gml)
Ability to parse GML geometry fragment and to return an LWGEOM or an error message.
char * text2cstring(const text *textptr)
int ptarray_point_size(const POINTARRAY *pa)
static POINTARRAY * parse_gml_pos(xmlNodePtr xnode, bool *hasz)
Parse gml:pos.
static LWGEOM * parse_gml_mpoint(xmlNodePtr xnode, bool *hasz, int *root_srid)
Parse gml:MultiPoint (2.1.2, 3.1.1)
LWGEOM * lwtriangle_as_lwgeom(const LWTRIANGLE *obj)
static bool is_xlink(xmlNodePtr node)
Return true if current node contains a simple XLink Return false otherwise.
LWTRIANGLE * lwtriangle_construct(int srid, GBOX *bbox, POINTARRAY *points)
static POINTARRAY * parse_gml_data(xmlNodePtr xnode, bool *hasz, int *root_srid)
Parse data coordinates.
static LWGEOM * parse_gml_curve(xmlNodePtr xnode, bool *hasz, int *root_srid)
Parse GML Curve (3.1.1)
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
LWMPOINT * lwmpoint_add_lwpoint(LWMPOINT *mobj, const LWPOINT *obj)
static bool is_gml_namespace(xmlNodePtr xnode, bool is_strict)
Return false if current element namespace is not a GML one Return true otherwise. ...
void * lwrealloc(void *mem, size_t size)
LWPOLY * lwpoly_construct_empty(int srid, char hasz, char hasm)
void lwgeom_add_bbox(LWGEOM *lwgeom)
Compute a bbox if not already computed.
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
static LWGEOM * parse_gml_surface(xmlNodePtr xnode, bool *hasz, int *root_srid)
Parse GML Surface (3.1.1)
static LWGEOM * parse_gml_psurface(xmlNodePtr xnode, bool *hasz, int *root_srid)
Parse GML PolyhedralSurface (3.1.1) Nota: It's not part of SF-2.
LWPOINT * lwpoint_construct(int srid, GBOX *bbox, POINTARRAY *point)
void * lwalloc(size_t size)
static LWGEOM * parse_gml_mline(xmlNodePtr xnode, bool *hasz, int *root_srid)
Parse gml:MultiLineString (2.1.2, 3.1.1)
LWCOLLECTION * lwcollection_construct_empty(uint8_t type, int srid, char hasz, char hasm)
int ptarray_transform(POINTARRAY *geom, projPJ inpj, projPJ outpj)
Transform given POINTARRAY from inpj projection to outpj projection.
LWCOLLECTION * lwcollection_add_lwgeom(LWCOLLECTION *col, const LWGEOM *geom)
Appends geom to the collection managed by col.
LWMPOLY * lwmpoly_add_lwpoly(LWMPOLY *mobj, const LWPOLY *obj)
static LWGEOM * parse_gml_polygon(xmlNodePtr xnode, bool *hasz, int *root_srid)
Parse GML Polygon (2.1.2, 3.1.1)
static LWGEOM * lwgeom_from_gml(const char *wkt)
Read GML.
static LWGEOM * parse_gml_line(xmlNodePtr xnode, bool *hasz, int *root_srid)
Parse GML lineString (2.1.2, 3.1.1)
This library is the generic geometry handling section of PostGIS.
POINTARRAY * ptarray_merge(POINTARRAY *pa1, POINTARRAY *pa2)
Merge two given POINTARRAY and returns a pointer on the new aggregate one.