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>
This commit is contained in:
CoslaJohn
2024-07-19 12:13:43 +01:00
committed by Javi Martín
parent bf4e79d42b
commit 5dbe2cbf24
12 changed files with 635 additions and 112 deletions

View File

@@ -110,8 +110,16 @@ describe "Admin geozones", :admin do
scenario "Show polygons when a heading is associated with a geozone" do
Setting["feature.map"] = true
geojson = <<~JSON
{
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [[[-0.1, 51.5], [-0.2, 51.4], [-0.3, 51.6]]]
}
}
JSON
geojson = '{ "geometry": { "type": "Polygon", "coordinates": [[-0.1,51.5],[-0.2,51.4],[-0.3,51.6]] } }'
geozone = create(:geozone, name: "Polygon me!")
budget = create(:budget)
group = create(:budget_group, budget: budget)
@@ -145,7 +153,16 @@ describe "Admin geozones", :admin do
scenario "Show polygons on geozone admin view" do
Setting["feature.map"] = true
geojson = '{ "geometry": { "type": "Polygon", "coordinates": [[-0.1,51.5],[-0.2,51.4],[-0.3,51.6]] } }'
geojson = <<~JSON
{
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [[[-0.1, 51.5], [-0.2, 51.4], [-0.3, 51.6]]]
}
}
JSON
geozone = create(:geozone, name: "Polygon me!", geojson: geojson)
visit admin_geozones_path