ClickHouse function reference

Svg

Generates an SVG representation of geometric data.

Syntax:

Svg(geometry[, style])

Aliases:

  • SVG
  • svg

Arguments:

  • geometry (Geo): The geometric data to be converted to SVG.
  • style (String, optional): A style string to be applied to the SVG element.

Returns:

A string containing the SVG representation of the geometry. (String)

The function generates different SVG elements based on the input geometry type:

  • Point: SVG circle
  • Ring or Polygon: SVG polygon
  • MultiPolygon: SVG path

Examples:

Generate an SVG circle for a point:

SELECT
	svg((0., 0.)) AS svg_point;

Result:

| svg_point                              |
|----------------------------------------|
| <circle cx="0" cy="0" r="5" style=""/> |

Generate an SVG polygon for a taco-shaped area:

SELECT
	svg([(0., 0.), (5, 2), (10, 0), (8, 5), (10, 10), (5, 8), (0, 10), (2, 5)]) AS svg_taco;

Result:

| svg_taco                                                             |
|----------------------------------------------------------------------|
| <polygon points="0,0 2,5 0,10 5,8 10,10 8,5 10,0 5,2 0,0" style=""/> |

Generate an SVG path for a taco with a bite taken out:

SELECT
	svg([[(0., 0.), (5, 2), (10, 0), (8, 5), (10, 10), (5, 8), (0, 10), (2, 5)],
		[(4., 4.), (5, 5), (6, 4), (5, 3)]]) AS svg_bitten_taco;

Result:

| svg_bitten_taco                                                                                                                           |
|-------------------------------------------------------------------------------------------------------------------------------------------|
| <g fill-rule="evenodd"><path d="M 0,0 L 2,5 L 0,10 L 5,8 L 10,10 L 8,5 L 10,0 L 5,2 L 0,0M 4,4 L 5,3 L 6,4 L 5,5 L 4,4 z " style=""/></g> |

This function is useful for visualizing geometric data in SVG format, which can be embedded in web pages or used in data visualization tools.