Changes between Version 2 and Version 3 of UsersWikiPostGIS23UbuntuPGSQL96Apt


Ignore:
Timestamp:
Mar 25, 2017, 11:56:50 PM (7 years ago)
Author:
robe
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • UsersWikiPostGIS23UbuntuPGSQL96Apt

    v2 v3  
    243243For more information, visit the [http://www.bostongis.com/PrinterFriendly.aspx?content_name=postgis_tut01 Boston GIS] tutorial in the section "Load Towns Data"
    244244
     245== ogr_fdw foreign data wrapper for spatial data ==
     246
     247Unfortunately seems PostgreSQL Apt does not include ogr_fdw spatial data wrapper.
     248The wrapper utilizes GDAL, so much of plumbing needed is already installed for you as part of PostGIS.
     249Compiling isn't too difficult.  On a vanilla Ubuntu, I was able to compile and install with following:
     250
     251
     252{{{
     253#for compiling ogr_fdw
     254cd ~/
     255mkdir sources
     256cd sources
     257sudo apt-get install git
     258sudo apt-get install postgresql-server-dev-9.6
     259sudo apt-get install make
     260sudo apt-get install gcc
     261sudo apt-get install libgdal1-dev
     262
     263sudo git clone -b master https://github.com/pramsey/pgsql-ogr-fdw.git pgsql_ogr_fdw
     264cd pgsql_ogr_fdw
     265export PATH=/usr/lib/postgresql/9.6/bin:$PATH
     266make && make install
     267}}}
     268
     269After you done, you can install the ogr_fdw extension in your database
     270
     271
     272{{{
     273sudo -u postgres psql
     274}}}
     275
     276{{{
     277
     278\connect gisdb;
     279CREATE EXTENSION ogr_fdw SCHEMA postgis;
     280CREATE SCHEMA IF NOT EXISTS staging ;
     281
     282-- here I assume you have a file in root of /gis_data folder that postgres process has read rights to
     283-- any file that gdal can read will do e.g shape file, CSV, etc
     284CREATE SERVER svr_shp
     285  FOREIGN DATA WRAPPER ogr_fdw
     286  OPTIONS (
     287    datasource '/gis_data',
     288    format 'ESRI Shapefile' );
     289
     290
     291-- this will link in all your shapefile tables in folder gis_data as foreign tables
     292IMPORT FOREIGN SCHEMA ogr_all
     293FROM SERVER svr_shp INTO staging;
     294
     295
     296}}}