Merge pull request #9171 from tchak/fix-geo-json-with-z

fix(carto): no crash on points with elevation
This commit is contained in:
Paul Chavard 2023-06-12 13:33:52 +00:00 committed by GitHub
commit 8152382e58
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 1 deletions

View file

@ -110,7 +110,7 @@ class GeoArea < ApplicationRecord
def location
if point?
Geo::Coord.new(*geometry['coordinates'].reverse).to_s
Geo::Coord.new(*geometry['coordinates'][0..1].reverse).to_s
end
end

View file

@ -116,6 +116,15 @@ FactoryBot.define do
end
end
trait :point_with_z do
geometry do
{
"type": "Point",
"coordinates": [2.428439855575562, 46.538476837725796, 42]
}
end
end
trait :invalid_point do
geometry do
{

View file

@ -122,6 +122,20 @@ RSpec.describe GeoArea, type: :model do
end
end
context "when geo is a point" do
let(:geo_area) { build(:geo_area, :selection_utilisateur, :point, champ: nil) }
it "should return the label" do
expect(geo_area.label).to eq("Un point situé à 46°32'19\"N 2°25'42\"E")
end
end
context "when geo is a point with elevation" do
let(:geo_area) { build(:geo_area, :selection_utilisateur, :point_with_z, champ: nil) }
it "should return the label" do
expect(geo_area.label).to eq("Un point situé à 46°32'19\"N 2°25'42\"E")
end
end
context "when geo is a cadastre parcelle" do
let(:geo_area) { build(:geo_area, :selection_utilisateur, :cadastre, champ: nil) }
it "should return the label" do