Skip to content

Commit

Permalink
bump geocrystal/ring_area
Browse files Browse the repository at this point in the history
  • Loading branch information
mamantoha committed Apr 30, 2024
1 parent a32ceb6 commit aa26153
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions shard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ dependencies:
github: geocrystal/geojson
ring_area:
github: geocrystal/ring_area
version: ">= 0.2.1"

development_dependencies:
ameba:
Expand Down
8 changes: 4 additions & 4 deletions src/geojson/area.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module GeoJSON
extend self

# Given a Geometry object, return contained area as square meters.
def area(object : GeoJSON::Object) : Float64
def area(object : GeoJSON::Object) : Float32 | Float64
case object
when GeoJSON::Polygon
polygon_area(object.coordinates)
Expand All @@ -22,7 +22,7 @@ module GeoJSON
end
end

private def polygon_area(coordinates) : Float64
private def polygon_area(coordinates) : Float32 | Float64
coordinates.each_with_index.reduce(0.0) do |area, (ring, i)|
if i == 0
# exterior ring
Expand All @@ -34,10 +34,10 @@ module GeoJSON
end
end

private def ring_area(coordinates) : Float64
private def ring_area(coordinates) : Float32 | Float64
coords = coordinates.map { |coordinate| [coordinate.longitude, coordinate.latitude] }

RingArea.ring_area(coords)
RingArea.ring_area(coords).to_meters
end
end
end

0 comments on commit aa26153

Please sign in to comment.