Merge pull request #5389 from CoslaDigital/render_geojson
Allow whitespace between square brackets in GeoJSON polygons
This commit is contained in:
@@ -28,9 +28,9 @@ class Geozone < ApplicationRecord
|
|||||||
|
|
||||||
def normalized_coordinates
|
def normalized_coordinates
|
||||||
if geojson.present?
|
if geojson.present?
|
||||||
if geojson.match(/"coordinates"\s*:\s*\[{4}/)
|
if geojson.match(/"coordinates"\s*:\s*\[\s*\[\s*\[\s*\[/)
|
||||||
coordinates.reduce([], :concat).reduce([], :concat)
|
coordinates.reduce([], :concat).reduce([], :concat)
|
||||||
elsif geojson.match(/"coordinates"\s*:\s*\[{3}/)
|
elsif geojson.match(/"coordinates"\s*:\s*\[\s*\[\s*\[/)
|
||||||
coordinates.reduce([], :concat)
|
coordinates.reduce([], :concat)
|
||||||
else
|
else
|
||||||
coordinates
|
coordinates
|
||||||
|
|||||||
@@ -76,5 +76,77 @@ describe Geozone do
|
|||||||
[-3.9247799675785, 40.8789131852224]]
|
[-3.9247799675785, 40.8789131852224]]
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "handles coordinates with three-dimensional arrays" do
|
||||||
|
geozone = build(:geozone, geojson: '{
|
||||||
|
"geometry": {
|
||||||
|
"type": "Polygon",
|
||||||
|
"coordinates": [[[40.8792937308316, -3.9259027239257],
|
||||||
|
[40.8788966596619, -3.9249047078766],
|
||||||
|
[40.8789131852224, -3.9247799675785]]]
|
||||||
|
}
|
||||||
|
}')
|
||||||
|
|
||||||
|
expect(geozone.outline_points).to eq(
|
||||||
|
[[-3.9259027239257, 40.8792937308316],
|
||||||
|
[-3.9249047078766, 40.8788966596619],
|
||||||
|
[-3.9247799675785, 40.8789131852224]]
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "handles coordinates with three-dimensional arrays with spaces between brackets" do
|
||||||
|
geozone = build(:geozone, geojson: '{
|
||||||
|
"geometry": {
|
||||||
|
"type": "Polygon",
|
||||||
|
"coordinates": [[
|
||||||
|
[40.8792937308316, -3.9259027239257],
|
||||||
|
[40.8788966596619, -3.9249047078766],
|
||||||
|
[40.8789131852224, -3.9247799675785]
|
||||||
|
]]
|
||||||
|
}
|
||||||
|
}')
|
||||||
|
|
||||||
|
expect(geozone.outline_points).to eq(
|
||||||
|
[[-3.9259027239257, 40.8792937308316],
|
||||||
|
[-3.9249047078766, 40.8788966596619],
|
||||||
|
[-3.9247799675785, 40.8789131852224]]
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "handles coordinates with four-dimensional arrays" do
|
||||||
|
geozone = build(:geozone, geojson: '{
|
||||||
|
"geometry": {
|
||||||
|
"type": "Polygon",
|
||||||
|
"coordinates": [[[[40.8792937308316, -3.9259027239257],
|
||||||
|
[40.8788966596619, -3.9249047078766],
|
||||||
|
[40.8789131852224, -3.9247799675785]]]]
|
||||||
|
}
|
||||||
|
}')
|
||||||
|
|
||||||
|
expect(geozone.outline_points).to eq(
|
||||||
|
[[-3.9259027239257, 40.8792937308316],
|
||||||
|
[-3.9249047078766, 40.8788966596619],
|
||||||
|
[-3.9247799675785, 40.8789131852224]]
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "handles coordinates with four-dimensional arrays with spaces between brackets" do
|
||||||
|
geozone = build(:geozone, geojson: '{
|
||||||
|
"geometry": {
|
||||||
|
"type": "Polygon",
|
||||||
|
"coordinates": [[[
|
||||||
|
[40.8792937308316, -3.9259027239257],
|
||||||
|
[40.8788966596619, -3.9249047078766],
|
||||||
|
[40.8789131852224, -3.9247799675785]
|
||||||
|
]]]
|
||||||
|
}
|
||||||
|
}')
|
||||||
|
|
||||||
|
expect(geozone.outline_points).to eq(
|
||||||
|
[[-3.9259027239257, 40.8792937308316],
|
||||||
|
[-3.9249047078766, 40.8788966596619],
|
||||||
|
[-3.9247799675785, 40.8789131852224]]
|
||||||
|
)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user