Last active
December 19, 2019 11:38
-
-
Save lydonchandra/86e4cb6e332b3e7f1830740ed484bccb to your computer and use it in GitHub Desktop.
getX3d.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select getX3d( ST_GeomFromText( | |
'POLYHEDRALSURFACE Z ( | |
((12 0 10, 8 8 10, 8 10 20, 12 2 20, 12 0 10)), | |
((8 8 10, 0 12 10, 0 14 20, 8 10 20, 8 8 10)), | |
((0 12 10, -8 8 10, -8 10 20, 0 14 20, 0 12 10)) | |
)' | |
), ST_GeomFromText( | |
'POLYHEDRALSURFACE Z ( | |
((12 0 10, 8 8 10, 8 10 20, 12 2 20, 12 0 10)), | |
((8 8 10, 0 12 10, 0 14 20, 8 10 20, 8 8 10)), | |
((0 12 10, -8 8 10, -8 10 20, 0 14 20, 0 12 10)) | |
)' | |
), ST_GeomFromEWKT('LINESTRING(-20 -20, -10 -10, 0 0, 10 10, 40 40)') ); | |
create or replace function getX3d( variadic geoms geometry[] ) | |
returns text as | |
$$ | |
declare x3dPrefix text := '<X3D><Scene><Transform>'; | |
declare x3dSuffix text := '</Transform></Scene></X3D>'; | |
declare x3dShapePrefix text := '<Shape><Appearance><Material emissiveColor=''0 0 1''/></Appearance>'; | |
declare x3dShapeSuffix text := '</Shape>'; | |
declare x3dText text := x3dPrefix; | |
declare x3dGeom geometry; | |
declare x3dShape text = ''; | |
begin | |
for idx in 1..array_length( geoms, 1 ) loop | |
x3dGeom := geoms[idx]; | |
x3dShape := ST_AsX3D(x3dGeom); | |
x3dText := x3dText || x3dShapePrefix || x3dShape || x3dShapeSuffix; | |
end loop; | |
x3dText := x3dText || x3dSuffix; | |
return x3dText; | |
end; | |
$$ | |
language 'plpgsql'; | |
-- SELECT '<X3D> | |
-- <Scene> | |
-- <Transform> | |
-- <Shape> | |
-- <Appearance> | |
-- <Material emissiveColor=''0 0 1''/> | |
-- </Appearance> ' || | |
-- ST_AsX3D( ST_GeomFromText( | |
-- 'POLYHEDRALSURFACE Z ( | |
-- ((12 0 10, 8 8 10, 8 10 20, 12 2 20, 12 0 10)), | |
-- ((8 8 10, 0 12 10, 0 14 20, 8 10 20, 8 8 10)), | |
-- ((0 12 10, -8 8 10, -8 10 20, 0 14 20, 0 12 10)) | |
-- )' | |
-- ) ) || | |
-- '</Shape> <Shape> | |
-- <Appearance> | |
-- <Material emissiveColor=''0 0 1''/> | |
-- </Appearance>' || | |
-- '</Shape> <Shape> | |
-- <Appearance> | |
-- <Material emissiveColor=''0 0 1''/> | |
-- </Appearance>' || | |
-- ST_AsX3D( ST_GeomFromEWKT('POLYHEDRALSURFACE( ((0 0 0, 0 0 1, 0 1 1, 0 1 0, 0 0 0)), | |
-- ((0 0 0, 0 1 0, 1 1 0, 1 0 0, 0 0 0)), ((0 0 0, 1 0 0, 1 0 1, 0 0 1, 0 0 0)), | |
-- ((1 1 0, 1 1 1, 1 0 1, 1 0 0, 1 1 0)), | |
-- ((0 1 0, 0 1 1, 1 1 1, 1 1 0, 0 1 0)), ((0 0 1, 1 0 1, 1 1 1, 0 1 1, 0 0 1)) )')) || | |
-- ST_AsX3D( ST_GeomFromEWKT('LINESTRING(-20 -20, -10 -10, 0 0, 10 10, 40 40)')) || | |
-- '</Shape> | |
-- </Transform> | |
-- </Scene> | |
-- </X3D>' As x3ddoc; | |
-- -- SELECT ST_GeomFromText( | |
-- -- 'POLYHEDRALSURFACE Z ( | |
-- -- ((12 0 10, 8 8 10, 8 10 20, 12 2 20, 12 0 10)), | |
-- -- ((8 8 10, 0 12 10, 0 14 20, 8 10 20, 8 8 10)), | |
-- -- ((0 12 10, -8 8 10, -8 10 20, 0 14 20, 0 12 10)) | |
-- -- )' | |
-- -- ); | |
-- -- SELECT '<X3D> | |
-- -- <Scene> | |
-- -- <Transform> | |
-- -- <Shape> | |
-- -- <Appearance> | |
-- -- <Material emissiveColor=''0 0 1''/> | |
-- -- </Appearance> ' || | |
-- -- ST_AsX3D( ST_GeomFromEWKT('POLYHEDRALSURFACE( ((0 0 0, 0 0 1, 0 1 1, 0 1 0, 0 0 0)), | |
-- -- ((0 0 0, 0 1 0, 1 1 0, 1 0 0, 0 0 0)), ((0 0 0, 1 0 0, 1 0 1, 0 0 1, 0 0 0)), | |
-- -- ((1 1 0, 1 1 1, 1 0 1, 1 0 0, 1 1 0)), | |
-- -- ((0 1 0, 0 1 1, 1 1 1, 1 1 0, 0 1 0)), ((0 0 1, 1 0 1, 1 1 1, 0 1 1, 0 0 1)) )')) || | |
-- -- '</Shape> | |
-- -- </Transform> | |
-- -- </Scene> | |
-- -- </X3D>' As x3ddoc; | |
-- -- SELECT ST_GeomFromText( | |
-- -- 'POLYHEDRALSURFACEZ( | |
-- -- ((1.0 1.0 0.0, 1.0 0.0 0.0, 0.0 0.0 0.0, 1.0 1.0 0.0)), | |
-- -- ((1.0 0.0 0.0, 1.0 0.0 1.0, 0.0 0.0 0.0, 1.0 0.0 0.0)), | |
-- -- ((1.0 0.0 0.0, 1.0 1.0 0.0, 1.0 1.0 1.0, 1.0 0.0 0.0)), | |
-- -- ((1.0 0.0 1.0, 1.0 0.0 0.0, 1.0 1.0 1.0, 1.0 0.0 1.0)), | |
-- -- ((1.0 1.0 1.0, 1.0 1.0 0.0, 0.0 1.0 1.0, 1.0 1.0 1.0)), | |
-- -- ((1.0 1.0 1.0, 1.0 0.0 0.0, 0.0 1.0 0.0, 1.0 1.0 1.0)), | |
-- -- ((1.0 1.0 0.0, 0.0 0.0 0.0, 0.0 1.0 1.0, 1.0 1.0 0.0)), | |
-- -- ((1.0 0.0 0.0, 0.0 0.0 0.0, 0.0 1.0 0.0, 1.0 0.0 0.0)), | |
-- -- ((0.0 0.0 0.0, 0.0 0.0 1.0, 0.0 1.0 1.0, 0.0 0.0 0.0)), | |
-- -- ((0.0 0.0 0.0, 0.0 1.0 1.0, 0.0 1.0 0.0, 0.0 0.0 0.0)), | |
-- -- ((1.0 1.0 0.0, 1.0 1.0 1.0, 1.0 0.0 0.0, 1.0 1.0 0.0)), | |
-- -- ((1.0 0.0 0.0, 1.0 1.0 1.0, 1.0 0.0 1.0, 1.0 0.0 0.0)))',4328) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment