int lwcircstring_is_closed(const LWCIRCSTRING *curve) { if (FLAGS_GET_Z(curve->flags)) return ptarray_isclosed3d(curve->points); return ptarray_isclosed2d(curve->points); }
int ptarray_isclosedz(const POINTARRAY *in) { if ( FLAGS_GET_Z(in->flags) ) return ptarray_isclosed3d(in); else return ptarray_isclosed2d(in); }
/* * Construct a triangle from a LWLINE being * the shell * Pointarray from intput geom are cloned. * Input line must have 4 points, and be closed. */ LWTRIANGLE * lwtriangle_from_lwline(const LWLINE *shell) { LWTRIANGLE *ret; POINTARRAY *pa; if ( shell->points->npoints != 4 ) lwerror("lwtriangle_from_lwline: shell must have exactly 4 points"); if ( (!FLAGS_GET_Z(shell->flags) && !ptarray_isclosed2d(shell->points)) || (FLAGS_GET_Z(shell->flags) && !ptarray_isclosed3d(shell->points)) ) lwerror("lwtriangle_from_lwline: shell must be closed"); pa = ptarray_clone_deep(shell->points); ret = lwtriangle_construct(shell->srid, NULL, pa); if (lwtriangle_is_repeated_points(ret)) lwerror("lwtriangle_from_lwline: some points are repeated in triangle"); return ret; }
/** * Parse KML Polygon */ static LWGEOM* parse_kml_polygon(xmlNodePtr xnode, bool *hasz) { int ring; xmlNodePtr xa, xb; POINTARRAY **ppa = NULL; for (xa = xnode->children ; xa != NULL ; xa = xa->next) { /* Polygon/outerBoundaryIs */ if (xa->type != XML_ELEMENT_NODE) continue; if (!is_kml_namespace(xa, false)) continue; if (strcmp((char *) xa->name, "outerBoundaryIs")) continue; for (xb = xa->children ; xb != NULL ; xb = xb->next) { if (xb->type != XML_ELEMENT_NODE) continue; if (!is_kml_namespace(xb, false)) continue; if (strcmp((char *) xb->name, "LinearRing")) continue; ppa = (POINTARRAY**) lwalloc(sizeof(POINTARRAY*)); ppa[0] = parse_kml_coordinates(xb->children, hasz); if (ppa[0]->npoints < 4 || (!*hasz && !ptarray_isclosed2d(ppa[0])) || (*hasz && !ptarray_isclosed3d(ppa[0]))) lwerror("invalid KML representation"); } } for (ring=1, xa = xnode->children ; xa != NULL ; xa = xa->next) { /* Polygon/innerBoundaryIs */ if (xa->type != XML_ELEMENT_NODE) continue; if (!is_kml_namespace(xa, false)) continue; if (strcmp((char *) xa->name, "innerBoundaryIs")) continue; for (xb = xa->children ; xb != NULL ; xb = xb->next) { if (xb->type != XML_ELEMENT_NODE) continue; if (!is_kml_namespace(xb, false)) continue; if (strcmp((char *) xb->name, "LinearRing")) continue; ppa = (POINTARRAY**) lwrealloc((POINTARRAY *) ppa, sizeof(POINTARRAY*) * (ring + 1)); ppa[ring] = parse_kml_coordinates(xb->children, hasz); if (ppa[ring]->npoints < 4 || (!*hasz && !ptarray_isclosed2d(ppa[ring])) || (*hasz && !ptarray_isclosed3d(ppa[ring]))) lwerror("invalid KML representation"); ring++; } } /* Exterior Ring is mandatory */ if (ppa == NULL || ppa[0] == NULL) lwerror("invalid KML representation"); return (LWGEOM *) lwpoly_construct(4326, NULL, ring, ppa); }