index.js
function stringify (gj) {
  if (gj.type === 'Feature') {
    gj = gj.geometry;
  }

  function pairWKT (c) {
    return c.join(' ');
  }

  function ringWKT (r) {
    return r.map(pairWKT).join(', ');
  }

  function ringsWKT (r) {
    return r.map(ringWKT).map(wrapParens).join(', ');
  }

  function multiRingsWKT (r) {
    return r.map(ringsWKT).map(wrapParens).join(', ');
  }

  function wrapParens (s) { return '(' + s + ')'; }

  switch (gj.type) {
    case 'Point':
      return 'POINT (' + pairWKT(gj.coordinates) + ')';
    case 'LineString':
      return 'LINESTRING (' + ringWKT(gj.coordinates) + ')';
    case 'Polygon':
      return 'POLYGON (' + ringsWKT(gj.coordinates) + ')';
    case 'MultiPoint':
      return 'MULTIPOINT (' + ringWKT(gj.coordinates) + ')';
    case 'MultiPolygon':
      return 'MULTIPOLYGON (' + multiRingsWKT(gj.coordinates) + ')';
    case 'MultiLineString':
      return 'MULTILINESTRING (' + ringsWKT(gj.coordinates) + ')';
    case 'GeometryCollection':
      return 'GEOMETRYCOLLECTION (' + gj.geometries.map(stringify).join(', ') + ')';
    default:
      throw new Error('stringify requires a valid GeoJSON Feature or geometry object as input');
  }
}
function stringify (gj) {
  if (gj.type === 'Feature') {
    gj = gj.geometry;
  }

  function pairWKT (c) {
    return c.join(' ');
  }

  function ringWKT (r) {
    return r.map(pairWKT).join(', ');
  }

  function ringsWKT (r) {
    return r.map(ringWKT).map(wrapParens).join(', ');
  }

  function multiRingsWKT (r) {
    return r.map(ringsWKT).map(wrapParens).join(', ');
  }

  function wrapParens (s) { return '(' + s + ')'; }

  switch (gj.type) {
    case 'Point':
      return 'POINT (' + pairWKT(gj.coordinates) + ')';
    case 'LineString':
      return 'LINESTRING (' + ringWKT(gj.coordinates) + ')';
    case 'Polygon':
      return 'POLYGON (' + ringsWKT(gj.coordinates) + ')';
    case 'MultiPoint':
      return 'MULTIPOINT (' + ringWKT(gj.coordinates) + ')';
    case 'MultiPolygon':
      return 'MULTIPOLYGON (' + multiRingsWKT(gj.coordinates) + ')';
    case 'MultiLineString':
      return 'MULTILINESTRING (' + ringsWKT(gj.coordinates) + ')';
    case 'GeometryCollection':
      return 'GEOMETRYCOLLECTION (' + gj.geometries.map(stringify).join(', ') + ')';
    default:
      throw new Error('stringify requires a valid GeoJSON Feature or geometry object as input');
  }
}
function stringify ( gj ) { if ( gj . type === 'Feature' ) { gj = gj . geometry ; } function pairWKT ( c ) { return c . join ( ' ' ) ; } function ringWKT ( r ) { return r . map ( pairWKT ) . join ( ', ' ) ; } function ringsWKT ( r ) { return r . map ( ringWKT ) . map ( wrapParens ) . join ( ', ' ) ; } function multiRingsWKT ( r ) { return r . map ( ringsWKT ) . map ( wrapParens ) . join ( ', ' ) ; } function wrapParens ( s ) { return '(' + s + ')' ; } switch ( gj . type ) { case 'Point' : return 'POINT (' + pairWKT ( gj . coordinates ) + ')' ; case 'LineString' : return 'LINESTRING (' + ringWKT ( gj . coordinates ) + ')' ; case 'Polygon' : return 'POLYGON (' + ringsWKT ( gj . coordinates ) + ')' ; case 'MultiPoint' : return 'MULTIPOINT (' + ringWKT ( gj . coordinates ) + ')' ; case 'MultiPolygon' : return 'MULTIPOLYGON (' + multiRingsWKT ( gj . coordinates ) + ')' ; case 'MultiLineString' : return 'MULTILINESTRING (' + ringsWKT ( gj . coordinates ) + ')' ; case 'GeometryCollection' : return 'GEOMETRYCOLLECTION (' + gj . geometries . map ( stringify ) . join ( ', ' ) + ')' ; default : throw new Error ( 'stringify requires a valid GeoJSON Feature or geometry object as input' ) ; } }
Stringifies a GeoJSON object into WKT
Stringifies a GeoJSON object into WKT