TsGeo allow to format Polygon
class into GeoJSON output representation.
There are 2 ways to format output:
import {Coordinate} from "tsgeo/Coordinate";
import {Polygon} from "tsgeo/Polygon";
import {GeoJSON} from "tsgeo/Formatter/Polygon/GeoJSON";
/* Add the following in a method of TS class */
let polygon = new Polygon();
polygon.addPoint(new Coordinate(10, 20));
polygon.addPoint(new Coordinate(20, 40));
polygon.addPoint(new Coordinate(30, 40));
polygon.addPoint(new Coordinate(30, 20));
let formatter = new GeoJSON();
console.log(formatter.format(polygon));
This snippet display the following data:
{"type":"Polygon","coordinates":[[20,10],[40,20],[40,30],[20,30]]}
import {Coordinate} from "tsgeo/Coordinate";
import {Polygon} from "tsgeo/Polygon";
import {GeoJSON} from "tsgeo/Formatter/Polygon/GeoJSON";
/* Add the following in a method of TS class */
let polygon = new Polygon();
polygon.addPoint(new Coordinate(10, 20));
polygon.addPoint(new Coordinate(20, 40));
polygon.addPoint(new Coordinate(30, 40));
polygon.addPoint(new Coordinate(30, 20));
console.log(polygon.format(new GeoJSON()));
This snippet display the following data:
{"type":"Polygon","coordinates":[[20,10],[40,20],[40,30],[20,30]]}
Ajouter un commentaire