Returns an SVG figure representing a geometry value.
geometry-expression.ST_AsSVG([ format])
Name | Type | Description |
---|---|---|
format |
VARCHAR(128) |
A string defining the parameters to use when converting the geometry-expression to a SVG representation. If not specified, the default is 'SVG'. |
LONG VARCHAR Returns a complete or partial SVG document which renders the geometry-expression.
The ST_AsSVG method returns a complete or partial SVG document that can be used to graphically display geometries using an SVG viewer. Most major web browsers with the exception of Microsoft Internet Explorer include built-in SVG viewers.
A number of different options are supported and the desired format is selected using the optional format parameter. If the format parameter is not specified, the default is 'SVG'.
The format string defines an output format and parameters to the format. The format string has one of the following formats:
format-name |
format-name(parameter1=value1;parameter2=value2;...) |
parameter1=value1;parameter2=value2;... |
The first format specifies the format name and no parameters. All format parameters use their default values. The second format specifies the format name and a list of named parameter values. Parameters that are not supplied use their default values. The last format specifies only parameter values, and the format name defaults to 'SVG'.
The following format names may be used:
SVG The Scalable Vector Graphics (SVG) 1.1 format defined by the World Wide Web Consortium (W3C).
The following format parameters can be specified:
Format Name | Parameter Name | Default Value | Allowed Values | Description |
---|---|---|---|---|
SVG | Approximate | Yes | Yes or No | The Approximate parameter specifies whether or not to reduce the size of the output SVG document with a slight reduction in visible detail. The SVG data is approximated by not including points which are within the line width of the last point. With multiple megabyte geometries this can result in compression rates of 80% or more. |
SVG | Attribute | Automatically generated optional attributes | One or more SVG attributes that can be applied to SVG shape elements | By default, optional SVG shape attributes such as fill, stroke and stroke-width are generated. If the Attributes parameter is specified, then no optional SVG shape attributes are generated, and the Attribute value is used instead. Ignored if PathDataOnly=Yes is specified. |
SVG | DecimalDigits | Based on the number of decimal digits in the spatial reference system's snap to grid grid-size. The maximum default value is 5 and the minimum is 0. | integer | The DecimalDigits parameter limits the number of digits after the decimal place for coordinates generated in the SVG output. Specifying a negative number of digits indicates that the full precision of coordinates should be included in the SVG output. |
SVG | PathDataOnly | No (a complete SVG document is generated) | Yes or No | The PathDataOnly parameter specifies whether or not only data for the SVG Path Element should be generated. The PathDataOnly example below demonstrates how PathDataOnly=Yes can be used to build a complete SVG document that can be displayed. By default a complete SVG document is generated. The path data returned by PathDataOnly=Yes can be used to build more flexible SVG documents containing other elements, such as text. |
SVG | RandomFill | Yes | Yes or No | The RandomFill parameter specifies whether or not polygons should be filled by a randomly generated color. The sequence of colors used does not follow a well-defined sequence, and typically changes each time SVG output is generated. No indicates that only an outline of each polygon is drawn. The RandomFill parameter is ignored if the Attribute or PathDataOnly=Yes parameter is specified. |
SVG | Relative | Yes | Yes or No | The Relative parameter specifies if coordinates should be output in relative (offset) or absolute formats. Relative coordinate data is typically more compact than absolute coordinate data. |
By default, ST_AsSVG uses the original format for a geometry, if it is available. Otherwise, the internal format is used. For more information about internal and original formats, see STORAGE FORMAT clause, CREATE SPATIAL REFERENCE SYSTEM statement.
SQL/MM (ISO/IEC 13249-3: 2006) Vendor extension
The following returns a complete SVG document with polygons filled with random colors.
SELECT NEW ST_Polygon( 'Polygon(( 0 0, 0 20, 60 10, 0 0 ))' ) .ST_AsSVG() |
The following returns a complete SVG document with outlined polygons and limits coordinates to 3 digits after the decimal place.
SELECT NEW ST_Polygon( 'Polygon(( 0 0, 0 20, 60 10, 0 0 ))' ) .ST_AsSVG( 'RandomFill=No;DecimalDigits=3' ) |
The following returns a complete SVG documents with polygons filled with blue and coordinates with maximum precision. Any Shapes containing curves will contain invalid SVG because both fill="none" and fill="blue" are generated.
SELECT Shape.ST_AsSVG( 'Attribute=fill="blue";DecimalDigits=-1' ) FROM SpatialShapes |
The following returns a complete SVG document from SVG path data with relative coordinates limited to 5 digits after the decimal place.
SELECT '<?xml version="1.0" standalone="no"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> <svg viewBox="-180 -90 360 180" xmlns="http://www.w3.org/2000/svg" version="1.1"> <path fill="lightblue" stroke="black" stroke-width="0.1%" d="' || NEW ST_Polygon( 'Polygon(( 0 0, 0 20, 60 10, 0 0 ))' ) .ST_AsSVG( 'PathDataOnly=Yes' ) || '"/></svg>' |
The following returns SVG path data using absolute coordinates limited to 7 digits after the decimal place.
SELECT NEW ST_Polygon( 'Polygon(( 0 0, 0 20, 60 10, 0 0 ))' ) .ST_AsSVG( 'PathDataOnly=Yes;Relative=No;DecimalDigits=7' ) |
Discuss this page in DocCommentXchange.
|
Copyright © 2010, iAnywhere Solutions, Inc. - SQL Anywhere 12.0.0 |