PostGIS中各种GIS数据格式的转换:
安装配置好PostGIS后,下一步就是把各种GIS数据灌入到PostGIS数据库中,这样可以统一数据的形式,方便管理。但麻烦也是不小,最大的麻烦就是GIS数据格式太多,而PostGIS本身只提供了一个shp2pg工具把shape文件转换到PostGIS数据库中,那如何把其他的GIS 数据加入呢?比如说MapInfo的mid格式,ESRI的e00格式呢?
这就要使用ogr这个工具了。Ogr目前是gdal的一个组成部分,那什么是gdal呢?其官方主页(http://www.doczj.com/doc/7ffa271e6bd97f192279e9fc.html)上如此介绍:
GDAL is a translator library for raster geospatial data formats that is released under an X/MIT style Open Source license by the Open Source Geospatial Foundation. As a library, it presents a single abstract data model to the calling application for all supported formats. It also comes with a variety of useful commandline utilties for data translation and processing.
简单地说,Gdal是一个各种Gis数据格式的转换软件库,ogr则是转换矢量GIS数据的软件库。
目前ogr能够支持的数据格式包括
字串3
Format Name Creation Georeferencing
Arc/Info Binary Coverage No Yes
Comma Separated Value (.csv) Yes No
DODS/OPeNDAP No Yes
DWG Yes No
DXF Yes No
ESRI Personal GeoDatabase No Yes
ESRI ArcSDE No Yes
ESRI Shapefile Yes Yes
FMEObjects Gateway No Yes
GML Yes No
GRASS No Yes
INTERLIS No Yes
Mapinfo File Yes Yes
Microstation DGN No No
MySQL No No
OGDI Vectors No Yes
ODBC No Yes
Oracle Spatial Yes Yes
PostgreSQL Yes Yes
S-57 (ENC) No Yes
SDTS No Yes
SQLite Yes No
UK .NTF No Yes
U.S. Census TIGER/Line No Yes
VRT - Virtual Datasource No Yes
应该说,这就基本包括了我们平常用到的所有矢量型GIS文件格式了。gdal支持的栅格数据格式参阅http://www.doczj.com/doc/7ffa271e6bd97f192279e9fc.html/formats_list.html
下面我们从源码编译安装gdal---因为我在Debian下使用apt方式安装的gdal并不支持postgresql数据库,其实更为简便的方法也许是去http://www.doczj.com/doc/7ffa271e6bd97f192279e9fc.html下载一个Fwtools的工具包,可以直接运行不用繁琐的编译,既有Windows的,也有Linux下用的,只不过这个包有些大。 字串4
1 下载最新的gdal-1.3.2
2 解压
3 ./configure --prefix=/opt/gdal --with-pg=/opt/pg/bin/pg_config --without-ogdi
这里我习惯把软件安装在/opt目录下。
--with-pg参数很重要,使ogr可以支持PostGIS,后面的参数是我的PostGIS安装的地方。
我在这里编译很多次失败,经过仔细查找,发现问题出在ogdi上,所以暂时我只好使它不支持ogdi。
4 make
5 make install
下面是使用过程,假设现在我要把一个rai.mid文件导入到数据库data1中:
$ ogr2ogr –f Postgresql PG:dbname=data1 rai.mid
注意,f参数后面跟的是导入的数据类型,最后那个文件才是要导出的文件。PG后面说明的是数据库的名字,需要是已经创建好的数据库,而数据表则由程序自动