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"
57 #include "utils/builtins.h"
59 #include "../postgis_config.h"
60 #include "lwgeom_pg.h"
62 #include "lwgeom_transform.h"
76 #define XLINK_NS ((char *) "http://www.w3.org/1999/xlink")
77 #define GML_NS ((char *) "http://www.opengis.net/gml")
78 #define GML32_NS ((char *) "http://www.opengis.net/gml/3.2")
84 POSTGIS_DEBUGF(3,
"ST_GeomFromGML ERROR %i", error_code);
108 if (PG_ARGISNULL(0)) PG_RETURN_NULL();
109 xml_input = PG_GETARG_TEXT_P(0);
113 root_srid = PG_GETARG_INT32(1);
119 postgis_initialize_cache(fcinfo);
123 lwgeom->
srid = root_srid;
128 PG_RETURN_POINTER(geom);
140 ns = xmlGetNsList(xnode->doc, xnode);
146 if (ns == NULL) {
return !is_strict; }
153 for (p=ns ; *p ; p++)
155 if ((*p)->href == NULL || (*p)->prefix == NULL ||
156 xnode->ns == NULL || xnode->ns->prefix == NULL)
continue;
158 if (!xmlStrcmp(xnode->ns->prefix, (*p)->prefix))
160 if ( !strcmp((
char *) (*p)->href,
GML_NS)
161 || !strcmp((
char *) (*p)->href,
GML32_NS))
186 return xmlGetProp(xnode, prop);
192 value = xmlGetNsProp(xnode, prop, (xmlChar *)
GML_NS);
196 if (
value == NULL)
value = xmlGetNoNsProp(xnode, prop);
210 prop = xmlGetNsProp(node, (xmlChar *)
"type", (xmlChar *)
XLINK_NS);
211 if (prop == NULL)
return false;
212 if (strcmp((
char *) prop,
"simple"))
218 prop = xmlGetNsProp(node, (xmlChar *)
"href", (xmlChar *)
XLINK_NS);
219 if (prop == NULL)
return false;
238 xmlXPathContext *ctx;
239 xmlXPathObject *xpath;
240 xmlNodePtr node, ret_node;
241 xmlChar *href, *p, *node_id;
243 href = xmlGetNsProp(xnode, (xmlChar *)
"href", (xmlChar *)
XLINK_NS);
244 id =
lwalloc((xmlStrlen(xnode->ns->prefix) * 2 + xmlStrlen(xnode->name)
245 + xmlStrlen(href) +
sizeof(
"//:[@:id='']") + 1));
250 sprintf(
id,
"//%s:%s[@%s:id='%s']", (
char *) xnode->ns->prefix,
251 (
char *) xnode->name,
252 (
char *) xnode->ns->prefix,
255 ctx = xmlXPathNewContext(xnode->doc);
264 ns = xmlGetNsList(xnode->doc, xnode);
265 for (n=ns ; *n; n++) xmlXPathRegisterNs(ctx, (*n)->prefix, (*n)->href);
269 xpath = xmlXPathEvalExpression((xmlChar *)
id, ctx);
271 if (xpath == NULL || xpath->nodesetval == NULL || xpath->nodesetval->nodeNr != 1)
274 xmlXPathFreeObject(xpath);
275 xmlXPathFreeContext(ctx);
278 ret_node = xpath->nodesetval->nodeTab[0];
279 xmlXPathFreeObject(xpath);
280 xmlXPathFreeContext(ctx);
283 for (node = xnode ; node != NULL ; node = node->parent)
285 if (node->type != XML_ELEMENT_NODE)
continue;
289 if (!xmlStrcmp(node_id, p))
305 projPJ in_pj, out_pj;
306 char *text_in, *text_out;
311 text_in = GetProj4StringSPI(srid_in);
312 text_out = GetProj4StringSPI(srid_out);
322 elog(ERROR,
"gml_reproject_pa: reprojection failed");
342 if (SPI_OK_CONNECT != SPI_connect ())
343 lwpgerror(
"gml_is_srid_planar: could not connect to SPI manager");
346 sprintf(query,
"SELECT position('+units=m ' in proj4text) \
347 FROM spatial_ref_sys WHERE srid='%d'", srid);
349 err = SPI_exec(query, 1);
350 if (err < 0) lwpgerror(
"gml_is_srid_planar: error executing query %d", err);
353 if (SPI_processed <= 0)
359 result = SPI_getvalue(SPI_tuptable->vals[0], SPI_tuptable->tupdesc, 1);
360 is_planar = atoi(result);
380 srsname =
gmlGetProp(node, (xmlChar *)
"srsName");
384 if (node->parent == NULL)
411 if (!strncmp((
char *) srsname,
"EPSG:", 5))
416 else if (!strncmp((
char *) srsname,
"urn:ogc:def:crs:EPSG:", 21)
417 || !strncmp((
char *) srsname,
"urn:x-ogc:def:crs:EPSG:", 23)
418 || !strncmp((
char *) srsname,
"urn:EPSG:geographicCRS:", 23))
423 else if (!strncmp((
char *) srsname,
424 "http://www.opengis.net/gml/srs/epsg.xml#", 40))
432 for (p = (
char *) srsname ; *p ; p++);
433 for (--p ; *p != sep ; p--)
434 if (!isdigit(*p))
gml_lwpgerror(
"unknown spatial reference system", 5);
436 srs->
srid = atoi(++p);
479 if (space_before)
while (isspace(*d)) d++;
480 for (st = INIT, p = d ; *p ; p++)
485 if (st == INIT || st == NEED_DIG) st = DIG;
486 else if (st == NEED_DIG_DEC) st = DIG_DEC;
487 else if (st == NEED_DIG_EXP || st == EXP) st = DIG_EXP;
488 else if (st == DIG || st == DIG_DEC || st == DIG_EXP);
493 if (st == DIG) st = NEED_DIG_DEC;
496 else if (*p ==
'-' || *p ==
'+')
498 if (st == INIT) st = NEED_DIG;
499 else if (st == EXP) st = NEED_DIG_EXP;
502 else if (*p ==
'e' || *p ==
'E')
504 if (st == DIG || st == DIG_DEC) st = EXP;
507 else if (isspace(*p))
509 if (!space_after)
gml_lwpgerror(
"invalid GML representation", 11);
510 if (st == DIG || st == DIG_DEC || st == DIG_EXP)st = END;
511 else if (st == NEED_DIG_DEC) st = END;
518 if (st != DIG && st != NEED_DIG_DEC && st != DIG_DEC && st != DIG_EXP && st != END)
530 xmlChar *gml_coord, *gml_ts, *gml_cs, *gml_dec;
539 gml_coord = xmlNodeGetContent(xnode);
540 p = (
char *) gml_coord;
550 if (gml_ts == NULL) ts =
' ';
553 if (xmlStrlen(gml_ts) > 1 || isdigit(gml_ts[0]))
561 if (gml_cs == NULL) cs =
',';
564 if (xmlStrlen(gml_cs) > 1 || isdigit(gml_cs[0]))
571 gml_dec =
gmlGetProp(xnode, (xmlChar *)
"decimal");
572 if (gml_dec == NULL) dec =
'.';
575 if (xmlStrlen(gml_dec) > 1 || isdigit(gml_dec[0]))
581 if (cs == ts || cs == dec || ts == dec)
587 while (isspace(*p)) p++;
588 for (q = p, gml_dims=0, digit =
false ; *p ; p++)
591 if (isdigit(*p)) digit =
true;
599 if (*(p+1) ==
'\0')
gml_lwpgerror(
"invalid GML representation", 19);
608 else if (digit && (*p == ts || *(p+1) ==
'\0'))
610 if (*p == ts) *p =
'\0';
613 if (gml_dims < 2 || gml_dims > 3)
632 else if (*p == dec && dec !=
'.') *p =
'.';
656 for (xyz = xnode->children ; xyz != NULL ; xyz = xyz->next)
658 if (xyz->type != XML_ELEMENT_NODE)
continue;
661 if (!strcmp((
char *) xyz->name,
"X"))
664 c = xmlNodeGetContent(xyz);
669 else if (!strcmp((
char *) xyz->name,
"Y"))
672 c = xmlNodeGetContent(xyz);
677 else if (!strcmp((
char *) xyz->name,
"Z"))
680 c = xmlNodeGetContent(xyz);
688 if (!z) *hasz =
false;
701 xmlChar *dimension, *gmlpos;
711 dimension =
gmlGetProp(xnode, (xmlChar *)
"srsDimension");
712 if (dimension == NULL)
713 dimension =
gmlGetProp(xnode, (xmlChar *)
"dimension");
714 if (dimension == NULL) dim = 2;
717 dim = atoi((
char *) dimension);
719 if (dim < 2 || dim > 3)
722 if (dim == 2) *hasz =
false;
725 gmlpos = xmlNodeGetContent(xnode);
726 pos = (
char *) gmlpos;
727 while (isspace(*pos)) pos++;
732 for (p=pos, gml_dim=0, digit=
false ; *pos ; pos++)
734 if (isdigit(*pos)) digit =
true;
735 if (digit && (*pos ==
' ' || *(pos+1) ==
'\0'))
737 if (*pos ==
' ') *pos =
'\0';
741 else if (gml_dim == 2)
743 else if (gml_dim == 3)
753 if (gml_dim == 2) *hasz =
false;
754 if (gml_dim < 2 || gml_dim > 3 || gml_dim != dim)
768 xmlChar *dimension, *gmlposlist;
776 dimension =
gmlGetProp(xnode, (xmlChar *)
"srsDimension");
777 if (dimension == NULL)
778 dimension =
gmlGetProp(xnode, (xmlChar *)
"dimension");
779 if (dimension == NULL) dim = 2;
782 dim = atoi((
char *) dimension);
784 if (dim < 2 || dim > 3)
gml_lwpgerror(
"invalid GML representation", 27);
786 if (dim == 2) *hasz =
false;
789 gmlposlist = xmlNodeGetContent(xnode);
790 poslist = (
char *) gmlposlist;
798 while (isspace(*poslist)) poslist++;
799 for (p=poslist, gml_dim=0, digit=
false ; *poslist ; poslist++)
801 if (isdigit(*poslist)) digit =
true;
802 if (digit && (*poslist ==
' ' || *(poslist+1) ==
'\0'))
804 if (*poslist ==
' ') *poslist =
'\0';
814 pt.
x = pt.
y = pt.
z = pt.
m = 0.0;
817 else if (*(poslist+1) ==
'\0')
852 for (xa = xnode ; xa != NULL ; xa = xa->next)
854 if (xa->type != XML_ELEMENT_NODE)
continue;
856 if (xa->name == NULL)
continue;
858 if (!strcmp((
char *) xa->name,
"pos"))
861 if (pa == NULL) pa = tmp_pa;
865 else if (!strcmp((
char *) xa->name,
"posList"))
868 if (pa == NULL) pa = tmp_pa;
872 else if (!strcmp((
char *) xa->name,
"coordinates"))
875 if (pa == NULL) pa = tmp_pa;
879 else if (!strcmp((
char *) xa->name,
"coord"))
882 if (pa == NULL) pa = tmp_pa;
886 else if (!strcmp((
char *) xa->name,
"pointRep") ||
887 !strcmp((
char *) xa->name,
"pointProperty"))
891 for (xb = xa->children ; xb != NULL ; xb = xb->next)
893 if (xb->type != XML_ELEMENT_NODE)
continue;
895 if (!strcmp((
char *) xb->name,
"Point"))
901 if (!found || xb == NULL)
905 if (xb == NULL || xb->children == NULL)
909 if (tmp_pa->npoints != 1)
915 else if (srs.
srid != *root_srid)
917 if (pa == NULL) pa = tmp_pa;
922 if (pa == NULL)
gml_lwpgerror(
"invalid GML representation", 32);
939 if (xnode->children == NULL)
949 *root_srid = srs.
srid;
954 if (srs.
srid != *root_srid)
974 if (xnode->children == NULL)
984 *root_srid = srs.
srid;
989 if (srs.
srid != *root_srid)
1011 xmlChar *interpolation=NULL;
1016 for (xa = xnode->children ; xa != NULL ; xa = xa->next)
1018 if (xa->type != XML_ELEMENT_NODE)
continue;
1020 if (!strcmp((
char *) xa->name,
"segments"))
1026 if (!found)
gml_lwpgerror(
"invalid GML representation", 37);
1031 for (xa = xa->children, lss=0; xa != NULL ; xa = xa->next)
1033 if (xa->type != XML_ELEMENT_NODE)
continue;
1035 if (strcmp((
char *) xa->name,
"LineStringSegment"))
continue;
1038 interpolation =
gmlGetProp(xa, (xmlChar *)
"interpolation");
1039 if (interpolation != NULL)
1041 if (strcmp((
char *) interpolation,
"linear"))
1043 xmlFree(interpolation);
1051 if (ppa[lss]->npoints < 2)
1055 if (lss == 0)
gml_lwpgerror(
"invalid GML representation", 40);
1058 if (lss == 1) pa = ppa[0];
1071 size_t cp_point_size =
sizeof(
POINT3D);
1072 size_t final_point_size = *hasz ?
sizeof(
POINT3D) :
sizeof(
POINT2D);
1084 for (i = 1; i < lss; i++)
1091 cp_point_size * (ppa[i]->npoints - 1));
1093 npoints += ppa[i]->
npoints - 1;
1125 if (ppa[0]->npoints < 4
1155 if (xnode->children == NULL)
1160 for (xa = xnode->children ; xa != NULL ; xa = xa->next)
1164 if (xa->type != XML_ELEMENT_NODE)
continue;
1166 if (strcmp((
char *) xa->name,
"outerBoundaryIs") &&
1167 strcmp((
char *) xa->name,
"exterior"))
continue;
1169 for (xb = xa->children ; xb != NULL ; xb = xb->next)
1171 if (xb->type != XML_ELEMENT_NODE)
continue;
1173 if (strcmp((
char *) xb->name,
"LinearRing"))
continue;
1178 if (ppa[0]->npoints < 4
1191 for (ring=1, xa = xnode->children ; xa != NULL ; xa = xa->next)
1195 if (xa->type != XML_ELEMENT_NODE)
continue;
1197 if (strcmp((
char *) xa->name,
"innerBoundaryIs") &&
1198 strcmp((
char *) xa->name,
"interior"))
continue;
1200 for (xb = xa->children ; xb != NULL ; xb = xb->next)
1202 if (xb->type != XML_ELEMENT_NODE)
continue;
1204 if (strcmp((
char *) xb->name,
"LinearRing"))
continue;
1210 if (ppa[ring]->npoints < 4
1221 if (ppa == NULL || ppa[0] == NULL)
gml_lwpgerror(
"invalid GML representation", 44);
1225 for (i=0 ; i < ring ; i++)
1243 xmlChar *interpolation=NULL;
1247 if (xnode->children == NULL)
1253 interpolation =
gmlGetProp(xnode, (xmlChar *)
"interpolation");
1254 if (interpolation != NULL)
1256 if (strcmp((
char *) interpolation,
"planar"))
1258 xmlFree(interpolation);
1263 for (xa = xnode->children ; xa != NULL ; xa = xa->next)
1266 if (xa->type != XML_ELEMENT_NODE)
continue;
1268 if (strcmp((
char *) xa->name,
"exterior"))
continue;
1270 for (xb = xa->children ; xb != NULL ; xb = xb->next)
1273 if (xb->type != XML_ELEMENT_NODE)
continue;
1275 if (strcmp((
char *) xb->name,
"LinearRing"))
continue;
1290 if (pa == NULL)
gml_lwpgerror(
"invalid GML representation", 47);
1306 xmlChar *interpolation=NULL;
1314 if (strcmp((
char *) xnode->name,
"PolygonPatch"))
1318 interpolation =
gmlGetProp(xnode, (xmlChar *)
"interpolation");
1319 if (interpolation != NULL)
1321 if (strcmp((
char *) interpolation,
"planar"))
1323 xmlFree(interpolation);
1329 for (xa = xnode->children ; xa != NULL ; xa = xa->next)
1332 if (strcmp((
char *) xa->name,
"exterior"))
continue;
1335 for (xb = xa->children ; xb != NULL ; xb = xb->next)
1337 if (xb->type != XML_ELEMENT_NODE)
continue;
1339 if (strcmp((
char *) xb->name,
"LinearRing"))
continue;
1344 if (ppa[0]->npoints < 4
1359 for (ring=1, xa = xnode->children ; xa != NULL ; xa = xa->next)
1361 if (xa->type != XML_ELEMENT_NODE)
continue;
1363 if (strcmp((
char *) xa->name,
"interior"))
continue;
1366 for (xb = xa->children ; xb != NULL ; xb = xb->next)
1368 if (xb->type != XML_ELEMENT_NODE)
continue;
1369 if (strcmp((
char *) xb->name,
"LinearRing"))
continue;
1375 if (ppa[ring]->npoints < 4
1388 if (ppa == NULL || ppa[0] == NULL)
gml_lwpgerror(
"invalid GML representation", 50);
1392 for (i=0 ; i < ring ; i++)
1414 for (xa = xnode->children ; xa != NULL ; xa = xa->next)
1416 if (xa->type != XML_ELEMENT_NODE)
continue;
1418 if (!strcmp((
char *) xa->name,
"patches"))
1424 if (!found)
gml_lwpgerror(
"invalid GML representation", 51);
1427 for (patch=0, xa = xa->children ; xa != NULL ; xa = xa->next)
1429 if (xa->type != XML_ELEMENT_NODE)
continue;
1431 if (strcmp((
char *) xa->name,
"PolygonPatch"))
continue;
1436 if (patch > 1)
gml_lwpgerror(
"invalid GML representation", 52);
1441 if (!patch)
gml_lwpgerror(
"invalid GML representation", 53);
1467 *root_srid = srs.
srid;
1471 if (xnode->children == NULL)
1475 for (xa = xnode->children ; xa != NULL ; xa = xa->next)
1477 if (xa->type != XML_ELEMENT_NODE)
continue;
1479 if (!strcmp((
char *) xa->name,
"patches") ||
1480 !strcmp((
char *) xa->name,
"trianglePatches"))
1486 if (!found)
return geom;
1489 for (xa = xa->children ; xa != NULL ; xa = xa->next)
1491 if (xa->type != XML_ELEMENT_NODE)
continue;
1493 if (strcmp((
char *) xa->name,
"Triangle"))
continue;
1495 if (xa->children != NULL)
1517 *root_srid = srs.
srid;
1521 if (xnode->children == NULL)
1524 for (xa = xnode->children ; xa != NULL ; xa = xa->next)
1527 if (xa->type != XML_ELEMENT_NODE)
continue;
1529 if (!strcmp((
char *) xa->name,
"pointMembers"))
1531 for (xb = xa->children ; xb != NULL ; xb = xb->next)
1538 else if (!strcmp((
char *) xa->name,
"pointMember"))
1540 if (xa->children != NULL)
1563 *root_srid = srs.
srid;
1567 if (xnode->children == NULL)
1570 for (xa = xnode->children ; xa != NULL ; xa = xa->next)
1573 if (xa->type != XML_ELEMENT_NODE)
continue;
1575 if (strcmp((
char *) xa->name,
"lineStringMember"))
continue;
1576 if (xa->children != NULL)
1598 *root_srid = srs.
srid;
1602 if (xnode->children == NULL)
1605 for (xa = xnode->children ; xa != NULL ; xa = xa->next)
1609 if (xa->type != XML_ELEMENT_NODE)
continue;
1611 if (!strcmp((
char *) xa->name,
"curveMembers"))
1613 for (xb = xa->children ; xb != NULL ; xb = xb->next)
1620 else if (!strcmp((
char *) xa->name,
"curveMember"))
1622 if (xa->children != NULL)
1645 *root_srid = srs.
srid;
1649 if (xnode->children == NULL)
1652 for (xa = xnode->children ; xa != NULL ; xa = xa->next)
1655 if (xa->type != XML_ELEMENT_NODE)
continue;
1657 if (strcmp((
char *) xa->name,
"polygonMember"))
continue;
1658 if (xa->children != NULL)
1680 *root_srid = srs.
srid;
1684 if (xnode->children == NULL)
1687 for (xa = xnode->children ; xa != NULL ; xa = xa->next)
1690 if (xa->type != XML_ELEMENT_NODE)
continue;
1692 if (!strcmp((
char *) xa->name,
"surfaceMembers"))
1694 for (xb = xa->children ; xb != NULL ; xb = xb->next)
1701 else if (!strcmp((
char *) xa->name,
"surfaceMember"))
1703 if (xa->children != NULL)
1728 *root_srid = srs.
srid;
1732 if (xnode->children == NULL)
1736 for (xa = xnode->children ; xa != NULL ; xa = xa->next)
1738 if (xa->type != XML_ELEMENT_NODE)
continue;
1740 if (!strcmp((
char *) xa->name,
"polygonPatches"))
1746 if (!found)
return geom;
1748 for (xa = xa->children ; xa != NULL ; xa = xa->next)
1751 if (xa->type != XML_ELEMENT_NODE)
continue;
1753 if (strcmp((
char *) xa->name,
"PolygonPatch"))
continue;
1776 *root_srid = srs.
srid;
1780 if (xnode->children == NULL)
1783 for (xa = xnode->children ; xa != NULL ; xa = xa->next)
1785 if (xa->type != XML_ELEMENT_NODE)
continue;
1793 if ( !strcmp((
char *) xa->name,
"pointMember")
1794 || !strcmp((
char *) xa->name,
"lineStringMember")
1795 || !strcmp((
char *) xa->name,
"polygonMember")
1796 || !strcmp((
char *) xa->name,
"geometryMember"))
1798 if (xa->children == NULL)
break;
1800 parse_gml(xa->children, hasz, root_srid));
1813 xmlNodePtr xmlroot=NULL;
1814 int xml_size = strlen(xml);
1821 xmldoc = xmlReadMemory(xml, xml_size, NULL, NULL, XML_PARSE_SAX1);
1822 if (!xmldoc || (xmlroot = xmlDocGetRootElement(xmldoc)) == NULL)
1829 lwgeom =
parse_gml(xmlroot, &hasz, &root_srid);
1837 lwgeom->
srid = root_srid;
1862 xmlNodePtr xa = xnode;
1865 while (xa != NULL && (xa->type != XML_ELEMENT_NODE
1868 if (xa == NULL)
gml_lwpgerror(
"invalid GML representation", 55);
1873 *root_srid = srs.
srid;
1876 if (!strcmp((
char *) xa->name,
"Point"))
1879 if (!strcmp((
char *) xa->name,
"LineString"))
1882 if (!strcmp((
char *) xa->name,
"Curve"))
1885 if (!strcmp((
char *) xa->name,
"LinearRing"))
1888 if (!strcmp((
char *) xa->name,
"Polygon"))
1891 if (!strcmp((
char *) xa->name,
"Triangle"))
1894 if (!strcmp((
char *) xa->name,
"Surface"))
1897 if (!strcmp((
char *) xa->name,
"MultiPoint"))
1900 if (!strcmp((
char *) xa->name,
"MultiLineString"))
1903 if (!strcmp((
char *) xa->name,
"MultiCurve"))
1906 if (!strcmp((
char *) xa->name,
"MultiPolygon"))
1909 if (!strcmp((
char *) xa->name,
"MultiSurface"))
1912 if (!strcmp((
char *) xa->name,
"PolyhedralSurface"))
1915 if ((!strcmp((
char *) xa->name,
"Tin")) ||
1916 !strcmp((
char *) xa->name,
"TriangulatedSurface" ))
1919 if (!strcmp((
char *) xa->name,
"MultiGeometry"))
LWGEOM * lwline_as_lwgeom(const LWLINE *obj)
projPJ lwproj_from_string(const char *txt)
Get a projection from a string representation.
LWCOLLECTION * lwcollection_construct_empty(uint8_t type, int srid, char hasz, char hasm)
void lwgeom_free(LWGEOM *geom)
int ptarray_is_closed_3d(const POINTARRAY *pa)
LWTIN * lwtin_add_lwtriangle(LWTIN *mobj, const LWTRIANGLE *obj)
int ptarray_transform(POINTARRAY *pa, projPJ inpj, projPJ outpj)
Transform given POINTARRAY from inpj projection to outpj projection.
uint8_t * getPoint_internal(const POINTARRAY *pa, uint32_t n)
LWGEOM * lwpoly_as_lwgeom(const LWPOLY *obj)
LWMLINE * lwmline_add_lwline(LWMLINE *mobj, const LWLINE *obj)
LWLINE * lwline_construct_empty(int srid, char hasz, char hasm)
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...
LWMPOINT * lwmpoint_add_lwpoint(LWMPOINT *mobj, const LWPOINT *obj)
LWMPOLY * lwmpoly_add_lwpoly(LWMPOLY *mobj, const LWPOLY *obj)
LWPSURFACE * lwpsurface_add_lwpoly(LWPSURFACE *mobj, const LWPOLY *obj)
void * lwrealloc(void *mem, size_t size)
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
LWPOINT * lwpoint_construct(int srid, GBOX *bbox, POINTARRAY *point)
#define POLYHEDRALSURFACETYPE
POINTARRAY * ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints)
Create a new POINTARRAY with no points.
LWPOLY * lwpoly_construct(int srid, GBOX *bbox, uint32_t nrings, POINTARRAY **points)
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,...
LWCOLLECTION * lwcollection_add_lwgeom(LWCOLLECTION *col, const LWGEOM *geom)
Appends geom to the collection managed by col.
LWTRIANGLE * lwtriangle_construct(int srid, GBOX *bbox, POINTARRAY *points)
void * lwalloc(size_t size)
int ptarray_is_closed_2d(const POINTARRAY *pa)
LWGEOM * lwtriangle_as_lwgeom(const LWTRIANGLE *obj)
#define LW_TRUE
Return types for functions with status returns.
#define SRID_UNKNOWN
Unknown SRID value.
LWPOINT * lwpoint_construct_empty(int srid, char hasz, char hasm)
LWLINE * lwline_construct(int srid, GBOX *bbox, POINTARRAY *points)
POINTARRAY * ptarray_merge(POINTARRAY *pa1, POINTARRAY *pa2)
Merge two given POINTARRAY and returns a pointer on the new aggregate one.
POINTARRAY * ptarray_flip_coordinates(POINTARRAY *pa)
Reverse X and Y axis on a given POINTARRAY.
LWPOLY * lwpoly_construct_empty(int srid, char hasz, char hasm)
LWTRIANGLE * lwtriangle_construct_empty(int srid, char hasz, char hasm)
LWGEOM * lwgeom_force_2d(const LWGEOM *geom)
Strip out the Z/M components of an LWGEOM.
This library is the generic geometry handling section of PostGIS.
static LWGEOM * parse_gml_surface(xmlNodePtr xnode, bool *hasz, int *root_srid)
Parse GML Surface (3.1.1)
struct struct_gmlSrs gmlSrs
static xmlNodePtr get_xlink_node(xmlNodePtr xnode)
Return a xmlNodePtr on a node referenced by a XLink or NULL otherwise.
static POINTARRAY * parse_gml_pos(xmlNodePtr xnode, bool *hasz)
Parse gml:pos.
PG_FUNCTION_INFO_V1(geom_from_gml)
Ability to parse GML geometry fragment and to return an LWGEOM or an error message.
static bool is_xlink(xmlNodePtr node)
Return true if current node contains a simple XLink Return false otherwise.
static LWGEOM * parse_gml_patch(xmlNodePtr xnode, bool *hasz, int *root_srid)
Parse GML PolygonPatch (3.1.1)
static LWGEOM * parse_gml_msurface(xmlNodePtr xnode, bool *hasz, int *root_srid)
Parse GML MultiSurface (3.1.1)
static LWGEOM * parse_gml(xmlNodePtr xnode, bool *hasz, int *root_srid)
Parse GML.
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.
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 POINTARRAY * gml_reproject_pa(POINTARRAY *pa, int srid_in, int srid_out)
Use Proj4 to reproject a given POINTARRAY.
static LWGEOM * parse_gml_mcurve(xmlNodePtr xnode, bool *hasz, int *root_srid)
Parse GML MultiCurve (3.1.1)
static xmlChar * gmlGetProp(xmlNodePtr xnode, xmlChar *prop)
Retrieve a GML property from a node or NULL otherwise Respect namespaces if presents in the node elem...
Datum geom_from_gml(PG_FUNCTION_ARGS)
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...
static bool is_gml_namespace(xmlNodePtr xnode, bool is_strict)
Return false if current element namespace is not a GML one Return true otherwise.
static void parse_gml_srs(xmlNodePtr xnode, gmlSrs *srs)
Parse gml srsName attribute.
static LWGEOM * parse_gml_polygon(xmlNodePtr xnode, bool *hasz, int *root_srid)
Parse GML Polygon (2.1.2, 3.1.1)
static POINTARRAY * parse_gml_coordinates(xmlNodePtr xnode, bool *hasz)
Parse gml:coordinates.
static LWGEOM * parse_gml_line(xmlNodePtr xnode, bool *hasz, int *root_srid)
Parse GML lineString (2.1.2, 3.1.1)
static POINTARRAY * parse_gml_data(xmlNodePtr xnode, bool *hasz, int *root_srid)
Parse data coordinates.
static LWGEOM * parse_gml_mpoly(xmlNodePtr xnode, bool *hasz, int *root_srid)
Parse GML MultiPolygon (2.1.2, 3.1.1)
static POINTARRAY * parse_gml_coord(xmlNodePtr xnode, bool *hasz)
Parse gml:coord.
static LWGEOM * parse_gml_curve(xmlNodePtr xnode, bool *hasz, int *root_srid)
Parse GML Curve (3.1.1)
static void gml_lwpgerror(char *msg, __attribute__((__unused__)) int error_code)
static LWGEOM * parse_gml_mpoint(xmlNodePtr xnode, bool *hasz, int *root_srid)
Parse gml:MultiPoint (2.1.2, 3.1.1)
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_tin(xmlNodePtr xnode, bool *hasz, int *root_srid)
Parse GML Tin (and TriangulatedSurface) (3.1.1)
static LWGEOM * parse_gml_triangle(xmlNodePtr xnode, bool *hasz, int *root_srid)
Parse GML Triangle (3.1.1)
static LWGEOM * parse_gml_mline(xmlNodePtr xnode, bool *hasz, int *root_srid)
Parse gml:MultiLineString (2.1.2, 3.1.1)
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 LWGEOM * lwgeom_from_gml(const char *wkt)
Read GML.
char * text_to_cstring(const text *textptr)
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)