先行输入:psql gis
\d  显示当前数据表
               List of relations
Schema | Name | Type | Owner
--------+--------------------+-------+----------
public | geography_columns | view | postgres
public | geometry_columns | table | gis
public | planet_osm_line | table | user
public | planet_osm_nodes | table | user
public | planet_osm_point | table | user
public | planet_osm_polygon | table | user
public | planet_osm_rels | table | user
public | planet_osm_roads | table | user
public | planet_osm_ways | table | user
public | spatial_ref_sys | table | gis
(10 rows)

再进入某一个数据表,语句为:\d planet_osm_roads

就会出现如下的显示:

     Table "public.planet_osm_roads"
Column | Type | Modifiers
--------------------+----------+-----------
osm_id | bigint |
access | text |
addr:housename | text |
addr:housenumber | text |
addr:interpolation | text |
admin_level | text |
aerialway | text |
aeroway | text |
amenity | text |
....
waterway | text |
wetland | text |
width | text |
wood | text |
z_order | integer |
way_area | real |
way | geometry |

然后就可以进行访问操作了,如下:

SELECT osm_id,name,way FROM planet_osm_roads LIMIT 1;

但是,后来在python中发现,psycopg2似乎不支持\d的输入,所以,我后来又换了一种查询的方法:

select planet_osm_roads.\"OSM_ID\", ST_AsText(planet_osm_roads.\"the_geom\") from public.planet_osm_roads;

这个语句相对来说更加正规一点,但是使用起来会麻烦一些,需要从最头上进入到数据库中,但是,查询结果肯定是一样的。

另外,由于openstreetmap中的the_geom是通过geometry数据类型来存储的,所以以上我使用了ST_AsTExt 函数进行格式转换。

格式转换之后,显示为:

( 'LINESTRING(12936024.28 4839648.07,12935424.71 4838722.06,12934892.21 4837629.71,12934289.2 4836007.5,12933955.4 4834815.49,12933523.99 4834253.51,12932398.66 4833859.51,12930942.93 4833698.73,12930017.2 4833337.34,12928792.52 4832545.6,12927333.4 4830992.71,12926605.54 4830332.04,12925976.25 4830134.83,12925216.94 4830137.07,12924226.69 4830471.27,12923535.34 4830870.63,12923537.07 4831566.67,12923670.37 4832229,12924035.56 4832857.78,12924368.51 4833585.97,12924703.14 4834446.89,12923880.16 4835708.54,12922724.27 4836241.84,12922132.27 4836939.92,12921903.85 4838034.36,12921642.24 4839195.88,12921447.77 4840290.58,12921153.05 4841352.77,12920474.79 4841645.26,12918234.82 4842608.73)')

应该代表的是各个node的GPS坐标值。

另外附上ST的函数集合:

获取几何对象的WKT描述 ST_AsText(geometry)
获取几何对象的WKB描述 ST_AsBinary(geometry)
获取几何对象的空间参考ID ST_SRID(geometry)
获取几何对象的维数 ST_Dimension(geometry)
获取几何对象的边界范围 ST_Envelope(geometry)
判断几何对象是否为空 ST_IsEmpty(geometry)
判断几何对象是否不包含特殊点(比如自相交) ST_IsSimple(geometry)
判断几何对象是否闭合 ST_IsClosed(geometry)
判断曲线是否闭合并且不包含特殊点 ST_IsRing(geometry)
获取多几何对象中的对象个数 ST_NumGeometries(geometry)
获取多几何对象中第N个对象 ST_GeometryN(geometry,int)
获取几何对象中的点个数 ST_NumPoints(geometry)
获取几何对象的第N个点 ST_PointN(geometry,integer)
获取多边形的外边缘 ST_ExteriorRing(geometry)
获取多边形内边界个数 ST_NumInteriorRings(geometry)
同上 ST_NumInteriorRing(geometry)
获取多边形的第N个内边界 ST_InteriorRingN(geometry,integer)
获取线的终点 ST_EndPoint(geometry)
获取线的起始点 ST_StartPoint(geometry)
获取几何对象的类型 GeometryType(geometry)
类似上,但是不检查M值,即POINTM对象会被判断为point ST_GeometryType(geometry)
获取点的X坐标 ST_X(geometry)
获取点的Y坐标 ST_Y(geometry)
获取点的Z坐标 ST_Z(geometry)
获取点的M值 ST_M(geometry)

如何查询postgresql+openstreetmap的更多相关文章

  1. 查询postgresql表结构和索引

    通过系统数据字典查询表结构 selectcol.table_schema,col.table_name,col.ordinal_position,col.column_name,col.data_ty ...

  2. PostgreSQL自学笔记:8 查询数据

    8 查询数据 8.1 基本查询语句 select语句的基本格式是: select {* | 字段1[,字段2,...]} [ from 表1,表2... [where 表达式] [group by & ...

  3. PostgreSQL与MySQL比较(转)

    Mysql 使用太广泛了,以至于我不得不将一些应用从mysql 迁移到postgresql, 很多开源软件都是以Mysql 作为数据库标准,并且以Mysql 作为抽象基础的,但是具体使用过程中,发现M ...

  4. postgresql语句

    查询oracle数据库所有表数据量 select t.table_name,t.num_rows from user_tables t ORDER BY t.num_rows desc 查询postg ...

  5. PostgreSQL快速入门

    一.PostgreSQL是什么? PostgreSQL是一个功能强大的开源对象关系数据库管理系统(ORDBMS). 用于安全地存储数据; 支持最佳做法,并允许在处理请求时检索它们. PostgreSQ ...

  6. RDKIT+postgresql做化合物数据存储与查找

    RDKIT: rdkit的安装与使用,直接conda  instal rdkit,不行的话,使用源码安装,将RDKIT源码下载解压到acaconda的pkg目录下,打开cmd,进入pkg下的 rdki ...

  7. 连续三月涨势明显,PostgreSQL 将崛起?

    33 分享 10 ​ DB-Engines 是全球最流行的数据库排行榜之一,在近几个月的排行榜中,PostgreSQL 都保持着非常好的势头,从最稳(10月)到一路高涨(11月),再到稳步上升(12月 ...

  8. CentOS 6.7 下 PostgreSQL 9.5 的安装与配置

    #yum方式安装(不同的系统版本对应的版本也不同) yum install postgresql-server #安装指定版本 yum install https://download.postgre ...

  9. Mysql 和 Postgresql(PGSQL) 对比

    Mysql 和 Postgresql(PGSQL) 对比 转载自:http://www.oschina.net/question/96003_13994 PostgreSQL与MySQL比较 MySQ ...

随机推荐

  1. 求System.arraycopy的用法

    public class Shuzufuzhi { public static void main(String args[]) {  int myArray[]={1,2,3,4,5,6};  in ...

  2. test lab ~ triangle test by using junit and coverage

    first set up a new folder as your test class place, and then let your package in test class folder b ...

  3. codevs1409 拦截导弹2

    [问题描述]一场战争正在 A 国与 B 国之间如火如荼的展开.B 国凭借其强大的经济实力开发出了无数的远程攻击导弹,B 国的领导人希望,通过这些导弹直接毁灭 A 国的指挥部,从而取得战斗的胜利!当然, ...

  4. 设置float之后vertical-align失效

    相关博文: 关于Vertical-Align你需要知道的事情 https://segmentfault.com/a/1190000002668492

  5. python走起之第十二话

    1. ORM介绍 orm英文全称object relational mapping,就是对象映射关系程序,简单来说我们类似python这种面向对象的程序来说一切皆对象,但是我们使用的数据库却都是关系型 ...

  6. [教程] [承風雅傳HSU]用ES4封裝Win7---ES4 Win7封裝教程(未完待續)

    [教程] [承風雅傳HSU]用ES4封裝Win7---ES4 Win7封裝教程(未完待續) a10036it 发表于 2015-7-27 21:11:19 https://www.itsk.com/t ...

  7. Redis在JAVA中的运用(工具类)

    最近项目需要用redis在中间做缓存所以写了一个工具类作为练习用 redis版本:redis_version:3.0.504 用到阿里的解析JSON的库:fastjson import org.apa ...

  8. eclipse中遇到的小问题

    1.在启动eclipse的时候,遇到了build path specifies execution enviroment J2SE-1.5.There are noJREs installed.的相关 ...

  9. 根据条件动态拼接LinQ的where条件字串

    var items1 = from c in customer == ? c.FirstName == == ? c.LastName == "BBB" : true) selec ...

  10. adb命令学习

    录制屏幕操作Android4.4版本以上支持录制屏幕 adb shell screenrecord /sdcard/demo.mp4 ADB logcat 输出时间信息: adb logcat -v ...