Skip to content

Polygon models incompatible with GeoJSON spec #1135

@akoumjian

Description

@akoumjian

I came across this while using Leaflet.draw, but it is really an issue with compatibility between the L.Polygon class and the GeoJSON spec.

The GeoJSON polygon spec (http://geojson.org/geojson-spec.html#polygon) is supposed to consist of a LinearRing, described thus:

A LinearRing is closed LineString with 4 or more positions. The first and last positions are equivalent (they represent equivalent points). Though a LinearRing is not explicitly represented as a GeoJSON geometry type, it is referred to in the Polygon geometry type definition.

Since the L.Polygon does not create a last point the same as the first, exporting those coords to GeoJSON creates invalid objects which are rejected by applications which do implement the spec properly (ie: GeoDjango).

As a corollary, importing valid GeoJSON objects creates polygons with a hidden additional 4th marker for the last identical point. This isn't a problem until you start editing the shapes using tools like Leaflet.Draw and then you end up with weird appendages such as this one:

polygon appendage

If I were better as javascript, I would have submitted this with a pull request. My suggestion is to modify the L.Polygon to require, create, and account for this last point and that only has markers for all but the last point.

Of course, if easy compatibility with GeoJSON is not a priority, then it's not a problem at all. Just wanted to bring it to your attention.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions