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); }
LWGEOM* wkt_parser_polygon_add_ring(LWGEOM *poly, POINTARRAY *pa, char dimcheck) { LWDEBUG(4,"entered"); /* Bad inputs are a problem */ if( ! (pa && poly) ) { SET_PARSER_ERROR(PARSER_ERROR_OTHER); return NULL; } /* Rings must agree on dimensionality */ if( FLAGS_NDIMS(poly->flags) != FLAGS_NDIMS(pa->flags) ) { ptarray_free(pa); lwgeom_free(poly); SET_PARSER_ERROR(PARSER_ERROR_MIXDIMS); return NULL; } /* Apply check for minimum number of points, if requested. */ if( (global_parser_result.parser_check_flags & LW_PARSER_CHECK_MINPOINTS) && (pa->npoints < 4) ) { ptarray_free(pa); lwgeom_free(poly); SET_PARSER_ERROR(PARSER_ERROR_MOREPOINTS); return NULL; } /* Apply check for not closed rings, if requested. */ if( (global_parser_result.parser_check_flags & LW_PARSER_CHECK_CLOSURE) && ! (dimcheck == 'Z' ? ptarray_isclosedz(pa) : ptarray_isclosed2d(pa)) ) { ptarray_free(pa); lwgeom_free(poly); SET_PARSER_ERROR(PARSER_ERROR_UNCLOSED); return NULL; } /* If something goes wrong adding a ring, error out. */ if ( LW_FAILURE == lwpoly_add_ring(lwgeom_as_lwpoly(poly), pa) ) { ptarray_free(pa); lwgeom_free(poly); SET_PARSER_ERROR(PARSER_ERROR_OTHER); return NULL; } return poly; }
/* * 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); }