.. _ogrfdw-使用说明: OGR_FDW 使用说明 ================ .. note:: 此插件目前只支持 Yukon for Postgres 版本,安装包中包含有此插件。 安装 ---- Centos 7 安装: ~~~~~~~~~~~~~~ 1. 添加 PostgreSQL 软件源 .. code:: bash yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm 2. 安装 ogr_fdw .. code:: bash yum install -y ogr_fdw_13.x86_64 源码安装 ~~~~~~~~ `源码下载 `__ 下载好源码后,然后 ``./configure`` ,\ ``make``,\ ``make install`` 即可。 需要注意的是:在编译时有可能需要导出 pg_config ,gdal_config 所在路径. .. note:: 如果想要 ogr_fdw 插件支持 Oracle 数据库,则需要手动配置编译环境: 安装下列软件包: `oracle-instantclient-basic`_ `oracle-instantclient-sqlplus`_ `oracle-instantclient-devel`_ 下载 `SDK 软件包 `_ ,并将其解压到 ``/usr/lib/oracle/21/client64`` 目录下。此时该目录下有如下内容: ``bin lib sdk SDK_LICENSE SDK_README`` 导出 ``export ORACLE_HOME=/usr/lib/oracle/21/client64`` 环境变量 然后再次 configure gdal 库就可以看到 OCI 支持。 ``OCI support: yes`` 使用 ---- 使用 ``create extension ogr_fdw`` 创建扩展 Shapefile 文件 ~~~~~~~~~~~~~~ - 创建 server .. code:: sql CREATE SERVER shpdriver FOREIGN DATA WRAPPER ogr_fdw OPTIONS ( datasource '/home/pg13/data/shp', format 'ESRI Shapefile' ); 其中 datasource 为 Shapefile 文件所在路径。format 为格式。 - 创建外部表 .. code:: sql create foreign table shptable( geom geometry ) server shpdriver options (layer 'bjroad'); 其中 server 指定为我们上边创建的 server 名字,option 中添加了一个必须的 layer 选项,指定我们要连接到的图层。 - 查询数据 .. code:: sql select count(*) from shptable; select * from shptable; FileGDB 文件 ~~~~~~~~~~~~ - 创建 server .. code:: sql CREATE SERVER filegdbserver FOREIGN DATA WRAPPER ogr_fdw OPTIONS ( datasource '/home/pg13/data/bjroad.gdb.zip', format 'OpenFileGDB' ); 这里我们在 options 中指定数据格式为 OpenFileGDB - 创建外部表 .. code:: sql create foreign table filegdbtable( geom geometry(MULTILINESTRING, 4490) ) server filegdbserver options (layer 'bjroad_1'); 指定要链接的图层为 bjroad_1 - 查询数据 .. code:: sql select st_astext(geom) from filegdbtable; Oracle Spatial 数据库 ~~~~~~~~~~~~~~~~~~~~~ - 创建 server .. code:: sql CREATE SERVER ocidriver FOREIGN DATA WRAPPER ogr_fdw OPTIONS ( datasource 'OCI:supermap/supermap@(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.13.179)(PORT=1521))(CONNECT_DATA=(SID=helowin)))', format 'OCI'); 这里 datasource 中,我们指定的 Oracle Spatial 数据库地址,用户名,密码及 SID。格式为 OCI. - 创建外部表 .. code:: sql create foreign table ocitable( geom geometry ) server ocidriver options ( layer 'BJROAD'); 这里我们使用刚才导入的 bjroad.shp 数据,指定要链接的图层为 BJROAD. - 查询数据 .. code:: sql select count(*) from ocitable; 导入所有图层 ~~~~~~~~~~~~ 如果想导入某个 schema 下的所有图层,可以使用 import schema 方法。如果想导入所有 schema 请使用 ogr_all: .. code:: sql create schema shpschema; import foreign schema ogr_all from server shpdriver into shpschema; create schema filegdbschema; import foreign schema bjroad from server filegdbserver into filegdbschema; create schema ocishcema; import foreign schema ogr_all from server ocidriver into ocishcema; 如果在表名或者列名中含有中文字符,请使用如下选项来禁用过滤: .. code:: sql IMPORT FOREIGN SCHEMA ogr_all FROM SERVER fgdbtest INTO fgdbpreserve OPTIONS ( launder_table_names 'false', launder_column_names 'false' ); .. _oracle-instantclient-basic: https://download.oracle.com/otn_software/linux/instantclient/213000/oracle-instantclient-basic-21.3.0.0.0-1.x86_64.rpm .. _oracle-instantclient-sqlplus: https://download.oracle.com/otn_software/linux/instantclient/213000/oracle-instantclient-sqlplus-21.3.0.0.0-1.x86_64.rpm .. _oracle-instantclient-devel: https://download.oracle.com/otn_software/linux/instantclient/213000/oracle-instantclient-devel-21.3.0.0.0-1.x86_64.rpm