kernification
kernification

Reputation: 523

Calculating correct longitude / latitude Polygon area using RGeo in Ruby on Rails

I try to calculate a fields polygon size using RGeo gem. Therefore i do:

require 'rgeo'
require 'rgeo/proj4'

factory = RGeo::Geographic.spherical_factory(srid: 4326)
# factory = RGeo::Cartesian.factory(srid: 4326)
ring = factory.linear_ring(self.get_polygon.map { |lon, lat| factory.point(lon, lat) })
polygon = factory.polygon(ring)

polygon.area

With self.get_polygon is an array that looks like [[lon1,lat1], [lon2,lat2], [lon2,lat2], ...]. So it's longitude and latitude.

The error is:

Method RGeo::Geographic::SphericalPolygonImpl#area not defined.

When I use factory = RGeo::Cartesian.factory(srid: 4326) instead everything works fine but the area size in not correct.

Upvotes: 0

Views: 34

Answers (0)

Related Questions