OSM导入PostGreSQL数据库

来源:互联网 发布:淘宝店一件代发可靠吗 编辑:程序博客网 时间:2024/05/17 11:36

    0. 说在前面的话

    最近在接触OSM(OpenStreeMap)数据,根据介绍PostGreSQL的PostGis模块是众多Gis数据的默认数据库。 于是... ...

    

    1. PostGreSQL的安装

    具体的PostGreSQL安装就不再这里介绍了,推荐一篇文章写的很详细:http://www.v5cn.cn/?p=167

     文章中介绍的软件很是有用推荐:

  • Postgresql——Postgresql是一种对象关系型数据库。本文我们使用9.3.1版本。下载地址:http://www.postgresql.org/download/
  • osm2pgsql­——是由OpenStreetMap开发的一个命令行工具负责将OSM数据导入到基于PostgresSql的Postgis的数据库中,这样GeoServer才能调用数据发布服务器。下载地址:http://customdebug.com/osm/osm2pgsql.zip,其次我们还要指定osm2pgsql的gitHub地址因为我们需要的两个文件在里面可以找到一个是900913.sql一个是default.style,osm2pgsql在github的地址如下:https://github.com/openstreetmap/osm2pgsql
  • postgis (可选)——是一个空间数据库,它扩展自Postgresql对象关系型数据库,它添加了地理信息对象通过本地的SQL查询。因为在安装Postgresql是可以选择下载安装postgis所以它是可选的。单独下载地址:http://postgis.net/install
  • GeoServer——是一种有java开发的地理信息发布服务工具,支持OGC协议,如:WMS、WFS和WCS。下载地址:http://geoserver.org/display/GEOS/Download

      

    2. OSM数据导入PostGreSQL

       

            1.  下载osm2pgsql  在第一步已经提供下载地址。

            2.   最好设定一下PostGreSQL的环境变量,很简单的。设置jdk 一样 将 PostGreSQL 中的bin目录添加到PATH中

            创建OSM数据库  createdb -U postgres -E UTF8 osm

            添加PostGIS功能到数据库psql -U postgres -d osm -f “你PostgreSQL安装路径\share\contrib\postgis-2.1\postgis.sql”

            添加EPSG: 900913支持 psql -U postgres -d osm -f “本地的文件路径\900913.sql”

        添加hstore模式       create extension hstore;

            添加OSM数据到数据库

osm2pgsql.exe -k -d osm -U postgres -S  d:\maps\default.style  d:\maps\map.osm
  3. 期间可能会报一个错误(整了我两天郁闷死了)       

使用我第一步推荐的文章有一个错误: 会照成一个错误(如下) 。 使用了器推荐的create extension hstore; 依然报错

       

release notes: 'Windows version built by Dominik Perpeet <http://www.customdebug.com/osm2pgsql/index.html>'
Using projection SRS 900913 (Spherical Mercator)
Error reading style file line 151 (fields=4)
flag 'phstore' is invalid in non-hstore mode
Error occured, cleaning up
解决方案
Hi,
About phstore type, I think you can either cut those lines off the stylefile or use osm2pgsql in hstore more by adding -k into the command.








        


0 0