Jetson John
Jetson John

Reputation: 3829

How to convert WKT to SVG

I have some Well-known text (WKT) for representing geometry object such as Point, MultiPoint, LineString, Polygon, MultiPolygon etc. I have a multipolygon with in total 40000 Points.

I have found this plugin to convert SVG to WKT. Is there any JavaScript or PHP plugin which converts WKT to SVG?

Upvotes: 12

Views: 3317

Answers (4)

Tim Nguyen
Tim Nguyen

Reputation: 1213

Use Wellknown to convert WKT to GeoJSON, then use D3 to convert GeoJSON to SVG.

(Source: A comment by Arthur to the same question you asked here: https://gis.stackexchange.com/questions/72323/how-to-convert-wkt-to-svg)

Upvotes: 1

kallaballa
kallaballa

Reputation: 377

libnfporb has a command-line tool to convert wkt to svg: https://github.com/kallaballa/libnfporb/blob/master/examples/wkt_to_svg.cpp

you need to build the library to use it.

usage: ./wkt_to_svg some.wkt some.svg

(I am the author of libnfporb)

Upvotes: 0

Trifactor
Trifactor

Reputation: 59

You might take a slightly longer trip in your conversion, using MapBox's wellknown library to convert WKT to GeoJSON and then use D3 to display the GeoJSON as SVG Path element(s).

Upvotes: 1

elasticrash
elasticrash

Reputation: 1221

I know its been a long time but you could write one. a conversion between those two is fairly simple.

for example the following simple function converts a WKT polygon

    var s = data.split("POLYGON ((");
    var s2 = s[1].substring(0, s[1].length - 2).split(" ");

    var mysvg = "M";
    for (var i = 0; i < s2.length - 2; i += 2) {
        mysvg += (s2[i].substring(0, s2[i].length - 1)) + ",";
        mysvg += (s2[i + 1].substring(0, s2[i + 1].length - 1)) + "L";
    }
    mysvg = mysvg.substr(0, mysvg.length - 1) + "z";

Upvotes: 2

Related Questions