如何添加 2 个点与它们之间的距离(SRID = 32636)? [英] How to add 2 points with distance between them (SRID = 32636)?

查看:87
本文介绍了如何添加 2 个点与它们之间的距离(SRID = 32636)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 python 3.6postgres DB

I'm using python 3.6 and postgres DB

我有一个表名:test_table 包含以下字段:名称(text),地理(geometry)

I have a table name: test_table with the following fields: name (text), geo (geometry)

地理字段的srid32636

我想编写一个python函数,它获取点X(wkt)并返回点之间距离为10米的点Y.即:

I want to write a python function which get point X (wkt) and return point Y with distance of 10 meters between the points. i.e:

X 和 Y 采用 WKT 格式

The X and Y are in WKT format

如何计算点 Y,其中 X 是输入?

How can I calculate the point Y with X is the input ?

好像不能用欧几里得距离,因为srid是32636

It seems that I can't use euclidean distance , because the srid is 32636

那我该怎么办?

推荐答案

您可以将您的 geometry 转换为 geographyST_Project 它(在你想要的方位角).这样做您可以轻松提供以米为单位的距离:

You could cast your geometry to geography and ST_Project it (in the azimuth you want). Doing so you can easily provide the distance in meters:

CREATE TEMPORARY TABLE test_table (name text, geo geometry(point,(32636)));
INSERT INTO test_table VALUES ('foo','SRID=32636;POINT(2076155.32235105 4828109.18280588)');

SELECT 
 ST_AsText(
  ST_Transform(
   ST_Project(
     ST_Transform(geo,4326)::geography,10,radians(45.0))::geometry,
   32636)
 )
FROM test_table;

                st_astext                 
------------------------------------------
 POINT(2076150.11319696 4828116.26815917)
(1 Zeile)

您可以使用ST_Distance检查距离:>

SELECT 
  ST_Distance(
    ST_Transform(geo,4326)::geography,
    ST_Project(ST_Transform(geo,4326)::geography,10,radians(45.0))::geometry )
FROM test_table;

st_distance 
-------------
          10

注意:我正在使用 ST_Transform 将您投影的 SRS 转换为 lon/lat SRS,以便我们可以将其转换为 geography代码>,否则我们会得到一个错误:

NOTE: I'm using ST_Transform to get from your projected SRS to a lon/lat SRS, so that we can cast it to geography, otherwise we'd get an error:

SELECT geo::geography FROM test_table;

ERROR:  Only lon/lat coordinate systems are supported in geography.

进一步阅读:计算 50 英里外的点(北,东北 45%,西南 45%)

这篇关于如何添加 2 个点与它们之间的距离(SRID = 32636)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆