Skip to content
This repository was archived by the owner on Sep 19, 2024. It is now read-only.

PostgreSQL Connector

ridoo edited this page Nov 28, 2014 · 9 revisions

Quick start

Loading data from a database is simply done by

  1. create a resource with the connection URL
  2. setting access credentials
  3. work with the IlwisObject as usual

In a few lines of code this can look like this

IOOptions options; // important options to connect to database
QUrl connectionString("postgresql://localhost:5432/ilwis-pg-test/tl_2010_us_rails");
Resource rails(connectionString,itCOVERAGE);
options.addOption("pg.password", "postgres");
options.addOption("pg.user", "postgres");
//options.addOption("pg.schema", "public"); // default
// options.addOption("pg.features.order", "center,geom"); // declare order of geometries

IFeatureCoverage fcoverage;
fcoverage.prepare(rails,options);

fcoverage->connectTo(makeOutputPath("rails.shp"), "ESRI Shapefile", "gdal", IlwisObject::cmOUTPUT);
fcoverage->store(options);

The above code will load data from the database and store it back as ESRI Shape file. The data comes from the tl_2010_us_rails table in database ilwis-pg-test which is accessible from localhost and standard PostgreSQL port. As usual a resource with corresponding IlwisType is prepared with the user credentials set needed to access the database.

Details

The whole way of preparing and loading the data is like with other connectors. For PostgreSQL data sources one has to use the connection link as follows:

postgresql://<host>:<port>/<database>/<tablename>

tbd

Notes

  • Supported are flat feature tables
  • FeatureCoverage has CRS which was set for the first geometry column found
  • Postgresql Connector utilizes the geometry_columns table
  • multiple geometries are supported via ILWIS' track index

Clone this wiki locally