Postgresql PostGIS使用epsg 5186将仪表转换为度数
我有几个关于PostGIS中几何和地理的问题 我目前正在使用PostGIS和Postgresql 我的大部分空间数据来自韩国,基本上是纬度和经度 为了进行测试,我创建了两个具有相同纬度和经度数据但数据类型不同的表,一个用于SRID4326的地理,另一个用于SRID5186的几何Postgresql PostGIS使用epsg 5186将仪表转换为度数,postgresql,postgis,Postgresql,Postgis,我有几个关于PostGIS中几何和地理的问题 我目前正在使用PostGIS和Postgresql 我的大部分空间数据来自韩国,基本上是纬度和经度 为了进行测试,我创建了两个具有相同纬度和经度数据但数据类型不同的表,一个用于SRID4326的地理,另一个用于SRID5186的几何 create table geometry_stores ( id serial primary key, location geometry(POINT, 5186) not null );
create table geometry_stores
(
id serial primary key,
location geometry(POINT, 5186) not null
);
create table geography_stores
(
id serial primary key,
location geography(POINT, 4326) not null
);
你可以在这个链接上找到更多关于EPSG 5186的详细信息
以下是我的问题清单:
ST_DWithin(几何体g1、几何体g2、双精度距离(srid))代码>
距离是EPSG的一个单位吗?是否有任何方法可以使用EPSG 5186将米(例如1km)转换为srid的距离
select *
from geography_stores
where st_dwithin(location, st_setsrid(st_point(126.970769, 37.555479), 4326), same_distance_meter)
select st_distance(location, st_setsrid(st_point(126.970769, 37.555479), 5186))
from geometry_stores
where id = 1;
我尝试过这个查询,但得到了一些错误,即地理上只支持lon/lat坐标系。其中:内联期间的SQL函数“st_distancesphere”
select st_distancesphere(location, st_setsrid(st_point(126.970769, 37.555479), 5186))
from geometry_stores
where id = 1;
-------------------------------更新-----------------------------------------
select *
from users
where st_dwithin(location, st_setsrid(st_point(126.970769, 37.555479), 5186), 1)
这个查询给我32792923行,这是表中的所有数据
考虑到空间数据至少分布在10km范围内,似乎查询中的st_计算两个几何体之间的距离,单位(degeree)为EPSG5186,而不是米。然后,我想知道我是否可以将米转换为EPSG5186的单位(度),因为我想用米来查询,而不是度,我不知道EPSG5186的单位(度)有多远
距离是EPSG的单位吗
对。使用几何图形
类型几何图形的距离使用相应空间参考系统的测量单位进行计算
是否有任何方法可以使用EPSG 5186将米(例如1km)转换为srid的距离
根据EPSG:5186的单位已经是米,所以你不需要转换任何东西。请记住,使用地理
类型几何图形的距离也使用米
计算,例如:
SELECT
ST_Distance(
'SRID=4326;POINT(127.49 36.65)'::geometry,
'SRID=4326;POINT(128.06 36.43)'::geometry) AS geometry_distance,
ST_Distance(
'SRID=4326;POINT(127.49 36.65)'::geography,
'SRID=4326;POINT(128.06 36.43)'::geography) AS geography_distance
;
geometry_distance | geography_distance
-------------------+--------------------
0.610982814815612 | 56578.57823391
(1 Zeile)
那么,如果我对以下查询给出完全相同的距离,它们应该产生不同的结果还是相同的结果?因为我的理解是,SRID5186的几何体已经在地球变形的情况下投影,那么它们应该产生相同的结果吗
select *
from geography_stores
where st_dwithin(location, st_setsrid(st_point(126.970769, 37.555479), 4326), same_distance_meter)
结果会有所不同。它们可能具有相同的测量单位,但它们不会投影到同一个曲面上。以下示例将坐标从4326
转换为5186
,并计算距离:
SELECT
ST_Distance(
'SRID=4326;POINT(127.49 36.65)'::geography,
'SRID=4326;POINT(128.06 36.43)'::geography),
ST_Distance(
ST_Transform('SRID=4326;POINT(127.49 36.65)'::geometry,5186),
ST_Transform('SRID=4326;POINT(128.06 36.43)'::geometry,5186));
st_distance | st_distance
----------------+------------------
56578.57823391 | 56582.0899018353
(1 Zeile)
使用以下查询计算几何图形表上的距离时,它给出的是度,而不是米。考虑到地球的变形,有没有办法把这个度数转换成米
select st_distance(location, st_setsrid(st_point(126.970769, 37.555479), 5186))
from geometry_stores
where id = 1;
数据类型不是您要查找的吗?正如文件所说:
无论使用哪种空间参考系统,测量返回的单位(ST_距离、ST_长度、ST_周长、ST_面积)以及输入ST_数据的单位均以米为单位
为了好玩,下面的查询计算两个点之间的距离,明确定义4326
球体,使用并将坐标从geometry
投射到geography
,这基本上是一样的:
SELECT
ST_DistanceSpheroid(
'POINT(127.49 36.65)',
'POINT(128.06 36.43)',
'SPHEROID["WGS 84",6378137,298.257223563]'),
ST_Distance(
'SRID=4326;POINT(127.49 36.65)'::geography,
'SRID=4326;POINT(128.06 36.43)'::geography);
st_distancespheroid | st_distance
---------------------+----------------
56578.5782339123 | 56578.57823391
关于何时使用几何学
或地理
的问题,报告说:
“您选择的类型应以您正在构建的应用程序的预期工作区域为条件。您的数据是否跨越全球或大的大陆地区,还是州、县或市的本地数据?”
需要考虑的事项:
- 用例覆盖的区域很小:坚持使用
,并使用更适合您所在区域的SRS几何图形
- 用例覆盖大面积(国家/大陆):使用
——尽管可能会慢一点地理
- 您想使用的功能是否支持地理信息?大多数PostGIS功能不支持它!查看此项了解更多详细信息。如果要使用的函数不支持
,则除了使用地理
;-)之外,您别无选择因为您的用例主要涉及韩国,所以我几何图形
SELECT ST_Distance( 'SRID=4326;POINT(127.49 36.65)'::geometry, 'SRID=4326;POINT(128.06 36.43)'::geometry) AS geometry_distance, ST_Distance( 'SRID=4326;POINT(127.49 36.65)'::geography, 'SRID=4326;POINT(128.06 36.43)'::geography) AS geography_distance ; geometry_distance | geography_distance -------------------+-------------------- 0.610982814815612 | 56578.57823391 (1 Zeile)
SELECT ST_Distance( 'SRID=4326;POINT(127.49 36.65)'::geography, 'SRID=4326;POINT(128.06 36.43)'::geography), ST_Distance( ST_Transform('SRID=4326;POINT(127.49 36.65)'::geometry,5186), ST_Transform('SRID=4326;POINT(128.06 36.43)'::geometry,5186)); st_distance | st_distance ----------------+------------------ 56578.57823391 | 56582.0899018353 (1 Zeile)
SELECT ST_DistanceSpheroid( 'POINT(127.49 36.65)', 'POINT(128.06 36.43)', 'SPHEROID["WGS 84",6378137,298.257223563]'), ST_Distance( 'SRID=4326;POINT(127.49 36.65)'::geography, 'SRID=4326;POINT(128.06 36.43)'::geography); st_distancespheroid | st_distance ---------------------+---------------- 56578.5782339123 | 56578.57823391
SELECT ST_AsText(ST_Transform('SRID=4326;POINT(126.808183 37.463557)'::geometry,5186)); st_astext ------------------------------------------ POINT(183030.248454493 540476.713582621) (1 Zeile)
SELECT --Transforming from 4326 to 5186 and calculating the distance ST_Distance( ST_Transform('SRID=4326;POINT(126.808183 37.463557)'::geometry, 5186), ST_Transform('SRID=4326;POINT(126.970769 37.555479)'::geometry, 5186)), -- Distance using geography ST_Distance( 'SRID=4326;POINT(126.808183 37.463557)'::geography, 'SRID=4326;POINT(126.970769 37.555479)'::geography); st_distance | st_distance ------------------+--------------- 17627.3383377316 | 17627.3138509