geosvg
🗺 Generate SVGs or Cartesian points of a path from a GPX file or list of coordinates
Get an SVG string, the svg's path
string or list of Cartesian coordinates mapped to the path supplied by a GPX file or an array of geographical coordinates (lat/long).
Install
$ npm install geosvg
Usage
import geosvg from "geosvg";
const gpx = readFileSync(PATH_TO_GPX, "utf-8");
const coordinates = [
{ latitude: 28.1234, longitude: 77.4567 },
{ latitude: 28.1235, longitude: 77.4568 },
{ latitude: 28.1236, longitude: 77.4569 },
];
const svg = geosvg.fromGpx(gpx).toSvg();
const svg = geosvg.fromCoordinates(coordinates).toSvg();
const svgPath = geosvg.fromGpx(gpx).toSvgPath();
const svgPath = geosvg.fromCoordinates(coordinates).toSvgPath();
const points = geosvg.fromGpx(gpx).toCartesianDetails();
const points = geosvg.fromCoordinates(coordinates).toCartesianDetails();
Options
.toSvg(options?)
, .toSvgPath(options?)
{
smooth?: boolean = true;
smoothing?: number = 0.2;
accuracy?: number = 0.001;
scale?: number = undefined;
svg?: {
width?: number = undefined;
height?: number = undefined;
stroke?: string = "red";
strokeWidth?: number = 4;
strokeLinecap?: string = "round";
strokeMiterlimit?: number = 4;
fill?: string = "none";
};
}
.toCartesianDetails(options?)
{
accuracy?: number = 0.001;
}
License
MIT