Commit Graph

4 Commits

Author SHA1 Message Date
Javi Martín
1f627d34f1 Make sure polygons contain valid rings
According to the GeoJSON specification [1]:

> * A linear ring is a closed LineString with four or more positions.
> * The first and last positions are equivalent, and they MUST contain
>   identical values; their representation SHOULD also be identical.
> (...)
> * For type "Polygon", the "coordinates" member MUST be an array of
>   linear ring coordinate arrays.

Note that, for simplicity, right now we aren't checking whether the
coordinates are defined counterclockwise for exterior rings and
clockwise for interior rings, which is what the specification expects.

[1] https://datatracker.ietf.org/doc/html/rfc7946#section-3.1.6
2024-12-23 17:35:33 +01:00
Javi Martín
c3bda443a6 Make sure all lines in a MultiLineString are valid
Note we're starting to use hashes in tests because the objects here are
complex and using hashes makes the tests easier to read.
2024-12-23 17:35:33 +01:00
Javi Martín
9ef68f863a Make sure a LineString has at least two points
According to the GeoJSON specification [1]:

> For type "LineString", the "coordinates" member is an array of two or
> more positions.

Note that the same doesn't seem to apply to a MultiPoint [2]:

> For type "MultiPoint", the "coordinates" member is an array of
> positions.

[1] https://datatracker.ietf.org/doc/html/rfc7946#section-3.1.4
[2] https://datatracker.ietf.org/doc/html/rfc7946#section-3.1.3
2024-12-23 17:35:33 +01:00
CoslaJohn
5dbe2cbf24 Support FeatureCollection and MultiPolygon in geozones
We're reworking the format validation to correctly interpret feature
collection, feature, and geometry, according to RFC 7946 [1].

Since Leaflet interprets GeoJSON format, we're rendering the GeoJSON as
a layer instead of as a set of points. For that, we're normalizing the
GeoJSON to make sure it contains either a Feature or a
FeatureCollection. We're also adding the Leaflet images to the assets
path so the markers used for point geometries are rendered correctly.

Note we no longer allow a GeoJSON containing a geometry but not a
defined type. Since there might be invalid GeoJSON in existing Consul
Democracy databases, we're normalizing these existing geometry objects
to be part of a feature object.

We're also wrapping the outline points in a FeatureCollection object
because most of the large GIS systems eg ArcGIS, QGIS export geojson as
a complete FeatureCollection.

[1] https://datatracker.ietf.org/doc/html/rfc7946

Co-authored-by: Javi Martín <javim@elretirao.net>
2024-12-23 17:35:33 +01:00