cschwarz / wkx

A WKT/WKB/EWKT/EWKB/TWKB/GeoJSON parser and serializer.
MIT License
316 stars 62 forks source link

wkx should add closing points to polygons when necessary #16

Closed mike-marcacci closed 7 years ago

mike-marcacci commented 7 years ago

Some formats like GeoJSON don't require that a polygon's last point match its first, while others like WKT do.

For example:

var wkx = require("wkx");

var validGeoJSON = {type: 'Polygon', coordinates: [[[-117, 32], [-116, 33], [-115, 34]]]};
var invalidWkt = wkx.Geometry.parseGeoJSON(validGeoJSON).toWkt();

console.log(invalidWkt);
// => "POLYGON((-117 32,-116 33,-115 34))"

Wkx should ensure the presence of closing points when converting to a format that requires it, either by normalizing to closed topologies on input, or conditionally adding on output.

cschwarz commented 7 years ago

According to https://tools.ietf.org/html/rfc7946#section-3.1.6 that's also true for GeoJSON.

The first and last positions are equivalent, and they MUST contain identical values; their representation SHOULD also be identical.

mike-marcacci commented 7 years ago

Ah, yes – you are definitely correct there!