| 245 | == ogr_fdw foreign data wrapper for spatial data == |
| 246 | |
| 247 | Unfortunately seems PostgreSQL Apt does not include ogr_fdw spatial data wrapper. |
| 248 | The wrapper utilizes GDAL, so much of plumbing needed is already installed for you as part of PostGIS. |
| 249 | Compiling 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 |
| 254 | cd ~/ |
| 255 | mkdir sources |
| 256 | cd sources |
| 257 | sudo apt-get install git |
| 258 | sudo apt-get install postgresql-server-dev-9.6 |
| 259 | sudo apt-get install make |
| 260 | sudo apt-get install gcc |
| 261 | sudo apt-get install libgdal1-dev |
| 262 | |
| 263 | sudo git clone -b master https://github.com/pramsey/pgsql-ogr-fdw.git pgsql_ogr_fdw |
| 264 | cd pgsql_ogr_fdw |
| 265 | export PATH=/usr/lib/postgresql/9.6/bin:$PATH |
| 266 | make && make install |
| 267 | }}} |
| 268 | |
| 269 | After you done, you can install the ogr_fdw extension in your database |
| 270 | |
| 271 | |
| 272 | {{{ |
| 273 | sudo -u postgres psql |
| 274 | }}} |
| 275 | |
| 276 | {{{ |
| 277 | |
| 278 | \connect gisdb; |
| 279 | CREATE EXTENSION ogr_fdw SCHEMA postgis; |
| 280 | CREATE 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 |
| 284 | CREATE 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 |
| 292 | IMPORT FOREIGN SCHEMA ogr_all |
| 293 | FROM SERVER svr_shp INTO staging; |
| 294 | |
| 295 | |
| 296 | }}} |