[][src]Trait geo_svg_io::geo_svg_writer::ToSvg

pub trait ToSvg {
    fn to_svg(&self) -> String;
}

Required methods

fn to_svg(&self) -> String

Return the Geometry as an SVG element (Note this does not return a full SVG)

This function produces an SVG element of the simplest type possible:

  • Polygon → <path>
  • LineString → <polyline>
  • Line → <line>
  • Triangle → <polygon> with three points
  • Rect → <rect> with x, y, width, and height

Complex Geometry types will return multiple SVG elements separated by newlines:

  • GeometryCollection → newline separated SVG elements corresponding to the individual Geometries it contains
  • MultiPolygon → newline separated elements
  • MultiLineString → newline separated elements

Examples

use geo_types::{ MultiPolygon, polygon };
use geo_svg_io::geo_svg_writer::ToSvg;

let poly1 = polygon![
            (x: 1.0, y: 1.0),
            (x: 4.0, y: 1.0),
            (x: 4.0, y: 4.0),
            (x: 1.0, y: 4.0),
            (x: 1.0, y: 1.0),
        ];

let poly2 = polygon!(
        exterior: [
            (x: 0.0, y: 0.0),
            (x: 6.0, y: 0.0),
            (x: 6.0, y: 6.0),
            (x: 0.0, y: 6.0),
            (x: 0.0, y: 0.0),],
        interiors:[[
            (x: 1.0, y: 1.0),
            (x: 4.0, y: 1.0),
            (x: 4.0, y: 4.0),
            (x: 1.50, y: 4.0),
            (x: 1.0, y: 1.0),]
            ]
        );

let mp = MultiPolygon(vec![poly1, poly2]);
let wkt_out = mp.to_svg();

let expected = String::from(
            r#"<path d="M1 1L4 1L4 4L1 4L1 1"/>
<path d="M0 0L6 0L6 6L0 6L0 0M1 1L4 1L4 4L1.5 4L1 1"/>"#,
        );

assert_eq!(wkt_out, expected);
Loading content...

Implementations on Foreign Types

impl<T: Float + Display> ToSvg for GeometryCollection<T>[src]

Geometries

impl<T: Float + Display> ToSvg for Geometry<T>[src]

impl<T: Float + Display> ToSvg for MultiPolygon<T>[src]

Polygons

impl<T: Float + Display> ToSvg for Polygon<T>[src]

impl<T: Float + Display> ToSvg for Rect<T>[src]

Rect

impl<T: Float + Display> ToSvg for Triangle<T>[src]

Triangle

impl<T: Float + Display> ToSvg for MultiLineString<T>[src]

Lines

impl<T: Float + Display> ToSvg for LineString<T>[src]

impl<T: Float + Display> ToSvg for Line<T>[src]

Line

Loading content...

Implementors

Loading content...