As of PostGIS version 0.9, AsSVG() is part of the standard distribution. Thanks to Olivier Courtin for providing patches and refractions.net for integrating it within PostGIS. AsSVG() allows you to deliver absolute and relative SVG path-notation for lines, multilines, polygons and multipolygons and SVG cx,cy or x,y notation for point and multipoint features. Multipoint geometries are delimited by commas (","), GeometryCollection geometries are delimited by semicolons (";").
AsSVG() PostGIS function
Usage:SELECT AsSvg(geometry,[rel],[precision]) FROM <table>
geom
= geometry column of type MULTI(POINT|LINESTRING|POLYGON)rel
= optional argument to change output format, 0=absolute or 1=relative notationprecision
= optional argument to specify coordinate-precision
Note: svg has a y-down coordinate system so y-coords are multiplied by -1
AsSVGBox() plPgsql function
As of PostGIS version 1.0 the default data-type for geometry has changed to LWGEOM. As LWGEOM does not have a BOX-only subclass there's no way to receive SVGViewBox-notation from a Box3D or Box2D query. I've written a simple plpgsql function to accomplish this task. It returns SVGRect- or SVGViewBox notation for the geometry's bounding box.
Usage:SELECT AsSvgBox(geometry,[rel],[precision]) FROM <table>
geometry
= valid geometryrel
= optional argument to change output format, 0=rect or 1=viewBox notationprecision
= optional argument to specify coordinate-precision