问题描述
Rails 4 + Postgres.地理空间新手.很高兴接受涉及RGeo,Geokit,Geocoder或任何其他可帮助解决此问题的宝石的解决方案.
Rails 4 + Postgres. New to geospatial. Happy to accept solutions that involve RGeo, Geokit, Geocoder, or any other gem that helps solve this issue.
模型包含两个字段latitude
和longitude
.
我有一个offset
属性,它包含一个以米为单位的距离,一个orientation
属性,它包含四个基本方向(N,E,W,S)之一.
I have an offset
attribute that contains a distance in meters and an orientation
attribute that contains one of the 4 cardinal directions (N, E, W, S).
示例:offset: 525.5 orientation: W
Example:offset: 525.5 orientation: W
将offset
距离加到lat-long位置上的标准方法是什么,以便通过距离相加得到一个新的lat-long对?
What's a standard way of adding the offset
distance to the lat-long position, to give me a new lat-long pair as the result of the distance addition?
推荐答案
进行了一些挖掘,结果发现存在一个奇异的库函数(考虑了曲率,几何,投影,位置和位置).数学假设),这有助于增加到特定表面位置的距离.
It took a little bit of digging, and it turns out that there is a singular-ish library function (accounting for curvature, geometric, projection, location & mathematical assumptions) that helps add a distance to a specific surface position.
功能:ST_Project
在以下使用:
SELECT ST_AsGeoJSON(ST_Project('POINT(longitude latitude)'::geography, offset, radians(orientation)))
SELECT ST_AsGeoJSON(ST_Project('POINT(longitude latitude)'::geography, offset, radians(orientation)))
它来自PostGIS,因此可以在Ruby/Rails中使用,尽管还不能作为本机Ruby对象(宝石还没有包装它),但是可以作为PostGIS查询.
It's from PostGIS and therefore useable in Ruby/Rails, although not yet as native Ruby objects (gems haven't wrapped it yet), but as a PostGIS query instead.
offset
以米为单位. orientation
以度为单位("N" = 0,"E" = 90,等等)
offset
is in meters. orientation
is in degrees ('N'=0, 'E'=90, etc.)
希望这种解决方案可以帮助其他人寻找相同的东西.
Hopefully, this solution helps others looking for the same thing.
这篇关于将距离添加到特定的纬度/经度位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!