I'm using RoR with PostGIS to store locations data. I'm trying to store an estimated location using circle (e.g. center point with radius).
I've tried something like that, but it doesn't work:
@location = Location.new(:place_id => place.id,
:circle => %{ST_Buffer(ST_MakePoint(#{latitude}, #{longitude})::geography, #{accuracy})})
I've also tried using RGeo and it's factory but not sure how to use it exactly.
Any help will be appreciated. Thanks.
Edit 1: I made some progress.
factory = RGeo::Cartesian.factory
center_point = factory.point(latitude, longitude)
circle = center_point.buffer(accuracy)
@location = Location.new(:place_id => place.id,
:circle => circle)
BUT - now it throws the following exception:
can't cast RGeo::Cartesian::Polygon Impl to string
Again, any help will be appreciated.
It looks like the column named circle
in the locations
table is a text column and not a geometry column. What does you schema look like?
You will probably want to set your SRID as well.
circle = RGeo::Cartesian.factory.point(0, 0).buffer(20)
@location = Location.new(:place_id => place.id, :circle => circle)
@locaiton.save
Another, and probably better option would be to just store the exact location and query for the location with a certain distance. You can use either the distance operator (http://postgis.net/docs/manual-2.1/geometry_distance_centroid.html) or the overlaps operator (http://postgis.net/docs/manual-2.1/geometry_overlaps.html).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With