从长时间的位置开始,知道这一点是否在圆圈内

发布于 2025-01-24 00:52:38 字数 972 浏览 2 评论 0原文

因此,我有一个保存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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱的十字路口 2025-01-31 00:52:38

您可以通过

SELECT ST_DistanceSphere(
  ST_MakePoint(43.3233, 23.3233),
  ST_MakePoint(32.3233, 23.323)
);
--> 1122927.11865462

要在500米之内选择所有位置,您可以使用类似的东西:

SELECT *
FROM locations
WHERE ST_DistanceSphere(
  ST_MakePoint(x, y),
  ST_MakePoint(32.3233, 23.323)
) <= 500;

where 位置是您的表和x/y < / code>是您的LAT /长列。

You can get the distance (in meters) between two points on a sphere via ST_DistanceSphere:

SELECT ST_DistanceSphere(
  ST_MakePoint(43.3233, 23.3233),
  ST_MakePoint(32.3233, 23.323)
);
--> 1122927.11865462

To select all locations within 500 meters, you could use something like this:

SELECT *
FROM locations
WHERE ST_DistanceSphere(
  ST_MakePoint(x, y),
  ST_MakePoint(32.3233, 23.323)
) <= 500;

where locations is your table and x / y are your lat / long columns.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文