Datum sfcgal_make_solid(PG_FUNCTION_ARGS) { GSERIALIZED *output; GSERIALIZED *input = PG_GETARG_GSERIALIZED_P(0); LWGEOM *lwgeom = lwgeom_from_gserialized(input); PG_FREE_IF_COPY(input, 0); if (! lwgeom) { lwerror("sfcgal_make_solid: Unable to deserialize input"); } FLAGS_SET_SOLID( lwgeom->flags, 1); output = geometry_serialize( lwgeom ); lwgeom_free(lwgeom); PG_RETURN_POINTER(output); }
/* * Return a TGEOM pointer from an LWGEOM * Caution: Geometries from LWGEOM are copied */ TGEOM* tgeom_from_lwgeom(const LWGEOM *lwgeom) { int i, solid; LWTIN *tin; LWPSURFACE *psurf; TGEOM *tgeom = NULL; tgeom = tgeom_new(0, FLAGS_GET_Z(lwgeom->flags), FLAGS_GET_M(lwgeom->flags)); if (lwgeom->srid < 1) tgeom->srid = SRID_UNKNOWN; else tgeom->srid = lwgeom->srid; if (lwgeom_is_empty(lwgeom)) return tgeom; switch (lwgeom->type) { case TINTYPE: tgeom->type = TINTYPE; tin = (LWTIN *) lwgeom; for (i=0 ; i < tin->ngeoms ; i++) tgeom = tgeom_add_triangle(tgeom, (LWTRIANGLE *) tin->geoms[i]); break; case POLYHEDRALSURFACETYPE: tgeom->type = POLYHEDRALSURFACETYPE; psurf = (LWPSURFACE *) lwgeom; for (i=0 ; i < psurf->ngeoms ; i++) tgeom = tgeom_add_polygon(tgeom, (LWPOLY *) psurf->geoms[i]); break; /* TODO handle COLLECTIONTYPE */ default: lwerror("tgeom_from_lwgeom: unknown geometry type %i - %s", tgeom->type, lwtype_name(tgeom->type)); } for (solid=1, i=1 ; i <= tgeom->nedges ; i++) { if (tgeom->edges[i]->count != 2) { LWDEBUGF(3, "no solid, edges: [%i], count: [%i] (%lf,%lf,%lf,%lf)->(%lf,%lf,%lf,%lf)\n", i, tgeom->edges[i]->count, tgeom->edges[i]->s->x, tgeom->edges[i]->s->y, tgeom->edges[i]->s->z, tgeom->edges[i]->s->m, tgeom->edges[i]->e->x, tgeom->edges[i]->e->y, tgeom->edges[i]->e->z, tgeom->edges[i]->e->m); solid = 0; break; } } FLAGS_SET_SOLID(tgeom->flags, solid); return tgeom; }