如何使用纯sql表示投影? [英] How to express the projection using pure sql?

查看:195
本文介绍了如何使用纯sql表示投影?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用过

RGEO_FACTORY = RGeo::Geographic.simple_mercator_factory
RGEO_FACTORY.point(lon, lat).projection

但是现在我想使用sql来实现它.而且我在postgis数据库中有一个点(几何).

But now I want to use sql to implement it. And I have the point(geometry) in the postgis database.

我应该怎么做?

推荐答案

RGeo simple mercator factory docs 指出,它使用SRID 4326存储点,并使用SRID 3785进行投影. PostGIS为此具有 ST_Transform .这是一个很好的教程,涵盖了该主题.假设您将geom字段存储在"nodes"表中,并且在SRID 4326中,则可以使用ST_Transform获得与RGeo简单墨卡托相同的投影.使用ST_SRID了解哪个是您的geom字段的srid:

RGeo simple mercator factory docs state that it uses SRID 4326 to store points and SRID 3785 for projections. PostGIS has ST_Transform for that. Here's a nice tutorial covering the topic. Suppose you store your geom field in 'nodes' table and it's in SRID 4326, then you can use ST_Transform to get the same projection as RGeo simple mercator. Use ST_SRID to learn which is your geom field's srid:

select geom, ST_SRID(geom) from nodes limit 1;
                        geom                        | st_srid 
----------------------------------------------------+---------
 0101000020E61000004A97FE25A9523E40B6B9D683EEE74D40 |    4326

select ST_Transform(geom, 3785) from nodes limit 1;
                    st_transform                    
----------------------------------------------------
 0101000020C90E0000FE8D2A88D4C04941A418472F1AE25F41

如果您尝试将geom转换为相同的srid,则不会更改:

If you try to convert geom to the same srid, it doesn't change:

select ST_Transform(geom, 4326) from nodes limit 1;
                    st_transform                    
----------------------------------------------------
 0101000020E61000004A97FE25A9523E40B6B9D683EEE74D40

这篇关于如何使用纯sql表示投影?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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