将OSM文件导入到Postgres/PostGIS数据库中

8
我正在使用工具osm2pgsql将一个osm文件导入到postgres数据库中,使用phppgadmin作为管理工具。我只下载了一个小镇的osm文件并以xml格式保存,但在mac终端上导入时遇到了问题。由于我是个新手,所以需要帮助。我查看了几篇文章,但没有提供足够清晰的解释来满足我的需求。
谢谢。
我得到了以下错误信息,可能是一些小问题,不确定...
Using projection SRS 900913 (Spherical Mercator)
Setting up table: planet_osm_point
NOTICE:  table "planet_osm_point" does not exist, skipping
NOTICE:  table "planet_osm_point_tmp" does not exist, skipping
SELECT AddGeometryColumn('planet_osm_point', 'way', 900913, 'POINT', 2 );
 failed: ERROR:  function addgeometrycolumn(unknown, unknown, integer, unknown,     integer) does not exist
LINE 1: SELECT AddGeometryColumn('planet_osm_point', 'way', 900913, ...
           ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.
2个回答

7

您需要在PostgreSQL数据库中安装PostGIS扩展。假设您已经在计算机上安装了PostGIS,您需要执行以下操作:

psql <database> < /usr/share/postgresql/8.4/contrib/postgis-1.5/postgis.sql

具体到 postgis.sql 的路径将取决于您正在使用的发行版以及它如何打包 postgis。您可能还需要使用以下命令安装空间参考系统表:

psql <database> < /usr/share/postgresql/8.4/contrib/postgis-1.5/spatial_ref_sys.sql

我执行了那些 SQL 文件,现在我拥有了所有所需的函数。顺便说一句,谢谢你。我仍然不确定如何使用 osm2pgsql 进行导入。谢谢。 - John
当我尝试执行 postgis.sql 时,出现错误 Type "spheroid" already exists。我该如何修复它? - Glory to Russia
1
在PostgreSQL 9和PostGIS 2版本中,可以通过以下方式完成:CREATE EXTENSION postgis; CREATE EXTENSION postgis_topology; 更多信息 - Javier Mr
除了 Javier 先生,还请查看此链接:http://wiki.openstreetmap.org/wiki/PostGIS/Installation#Activate_PostGIS - Mahmoud Moravej

1

这是一个示例命令:

osm2pgsql -c -d your_country -U postgres -W -H localhost -P 5432 -s -k -x -p osm -S default.style ..\your_country.osm.bz2

以下是一些有用的网址: http://wiki.openstreetmap.org/wiki/Osm2pgsql http://www.gis.hsr.ch/wiki/Osm2pgsql

-S.


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接