从长时间的位置开始,知道这一点是否在圆圈内
因此,我有一个保存LATLONG数据的模型。而且我想制作一个我给出point_x,point_y的methode,并看到我的位置型号的点接近500m或更小。
这是一个点的范围:
Location.longlat.x = 43.3233
Location.lonlat.y = 23.3233
point_x = 32.3233
point_y = 23.323
我使用PostGIS为我的模型存储那些longlat坐标。到目前为止,我知道它将它们保存为球形点,为º。 因此,是否有一种方法可以将它们定义为平面点并计算它们是否接近500m或更少?
编辑:这就是我在模型中存储longlat坐标的方式:
t.geography "longlat", limit: {:srid=>4326, :type=>"st_point", :geographic=>true}
edit:我试图使用
ForecastLocation.all.each do |forecast_location|
ForecastLocation.where("ST_Distance_Sphere(ST_MakePoint(
{forecast_location.longlat.x},#{forecast_location.longlat.y}),
ST_MakePoint(#{circle_x},#{circle_y})<500")
forecastLocation = is Model name
longlat =上面定义的列,保存x,y
circle_x
circle_y =变量提出了要点,然后将此与我所有的forecastlocation进行比较。longlat
im tring是什么是与选择的答案中的相同的事情,但是只要让所有比500m的对象都更接近circle circle
So i have a model that saves latlong data. And i want to make a methode that i give a point_x, point_y , and sees if my Location model has a point that is near 500m or less.
Here is an exemple of points:
Location.longlat.x = 43.3233
Location.lonlat.y = 23.3233
point_x = 32.3233
point_y = 23.323
I store those longlat coordinates using postgis for my model. So far i know its save them as spherical points and are º.
So is there a method to define them as plane points and calculate if they are close to 500m or less ?
Edit: This is how i store longlat coordinates in my model:
t.geography "longlat", limit: {:srid=>4326, :type=>"st_point", :geographic=>true}
EDIT: script that im trying to use
ForecastLocation.all.each do |forecast_location|
ForecastLocation.where("ST_Distance_Sphere(ST_MakePoint(
{forecast_location.longlat.x},#{forecast_location.longlat.y}),
ST_MakePoint(#{circle_x},#{circle_y})<500")
ForecastLocation = is model name
longlat= column defined above , saves x,y
circle_x
circle_y = variables that makes the main point, and compare this one to all my ForecastLocation.longlat
What im tring is to do same thing as in the answer with the select , but just to have all objects that are closer than 500m of circle
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以通过 :
要在500米之内选择所有位置,您可以使用类似的东西:
where
位置
是您的表和x
/y < / code>是您的LAT /长列。
You can get the distance (in meters) between two points on a sphere via
ST_DistanceSphere
:To select all locations within 500 meters, you could use something like this:
where
locations
is your table andx
/y
are your lat / long columns.