/* takes a GEOMETRY and returns an X3D representation */ extern char * lwgeom_to_x3d3(const LWGEOM *geom, char *srs, int precision, int opts, const char *defid) { int type = geom->type; switch (type) { case POINTTYPE: return asx3d3_point((LWPOINT*)geom, srs, precision, opts, defid); case LINETYPE: return asx3d3_line((LWLINE*)geom, srs, precision, opts, defid); case POLYGONTYPE: { /** We might change this later, but putting a polygon in an indexed face set * seems like the simplest way to go so treat just like a mulitpolygon */ LWCOLLECTION *tmp = (LWCOLLECTION*)lwgeom_as_multi(geom); char *ret = asx3d3_multi(tmp, srs, precision, opts, defid); lwcollection_free(tmp); return ret; } case TRIANGLETYPE: return asx3d3_triangle((LWTRIANGLE*)geom, srs, precision, opts, defid); case MULTIPOINTTYPE: case MULTILINETYPE: case MULTIPOLYGONTYPE: return asx3d3_multi((LWCOLLECTION*)geom, srs, precision, opts, defid); case POLYHEDRALSURFACETYPE: return asx3d3_psurface((LWPSURFACE*)geom, srs, precision, opts, defid); case TINTYPE: return asx3d3_tin((LWTIN*)geom, srs, precision, opts, defid); case COLLECTIONTYPE: return asx3d3_collection((LWCOLLECTION*)geom, srs, precision, opts, defid); default: lwerror("lwgeom_to_x3d3: '%s' geometry type not supported", lwtype_name(type)); return NULL; } }
// trying to make polygon to be valid // accept only string-polygon in wkb format static VALUE make_valid(VALUE self, VALUE geom_wkb) { VALUE result; LWGEOM *valid_lwg; int wkb_size_a; wkb_size_a = RSTRING_LEN(geom_wkb); lwg = lwgeom_from_wkb(RSTRING_PTR(geom_wkb), wkb_size_a, 0); valid_lwg = lwgeom_make_valid(lwg); //make multi valid_lwg = lwgeom_as_multi(valid_lwg); char *wkb_str = (char*)lwgeom_to_wkb(valid_lwg, WKB_HEX, NULL); return rb_str_new2(wkb_str); }