Avoid an error if area can’t be computed

This commit is contained in:
Paul Chavard 2020-09-20 13:18:36 +02:00
parent 709de29b40
commit 50c0955465
2 changed files with 14 additions and 6 deletions

View file

@ -45,12 +45,20 @@ module ChampHelper
"Culture : #{geo_area.culture} - Surface : #{geo_area.surface} ha"
when GeoArea.sources.fetch(:selection_utilisateur)
if geo_area.polygon?
capture do
concat "Une aire de surface #{geo_area.area} m"
concat content_tag(:sup, "2")
if geo_area.area.present?
capture do
concat "Une aire de surface #{geo_area.area} m"
concat content_tag(:sup, "2")
end
else
"Une aire de surface inconnue"
end
elsif geo_area.line?
"Une ligne longue de #{geo_area.length} m"
if geo_area.length.present?
"Une ligne longue de #{geo_area.length} m"
else
"Une ligne de longueur inconnue"
end
elsif geo_area.point?
"Un point situé à #{geo_area.location}"
end

View file

@ -79,13 +79,13 @@ class GeoArea < ApplicationRecord
def area
if polygon? && RGeo::Geos.supported?
rgeo_geometry.area.round(1)
rgeo_geometry.area&.round(1)
end
end
def length
if line? && RGeo::Geos.supported?
rgeo_geometry.length.round(1)
rgeo_geometry.length&.round(1)
end
end