Connecting to Others - 52North/IlwisCore GitHub Wiki

The communication between ilwis and external data-sources is done by the connectors

Construction

Unless you are programming a connector itself you don't create connectors yourself. You use the connectorfactory to generate an appropriate connector. The reason is here that as a programmer you don't have direct knowledge about the nature of the connectors. You only have a general interface to use. Suppose you want to save a raster-coverage to an ilwis3 file.

IRasterCoverage raster("file:///d:/data/someraster.img");
const ConnectorFactory *factory = kernel()->factory<ConnectorFactory>("ilwis::ConnectorFactory");
ConnectorInterface *connector = factory->createFromFormat(raster->source(), "map", "ilwis3");

The first line gets the connector factory from the system, the second line generates an appropriate connector for the "ilwis3" format named "map". This is not (yet) sufficient as it has to be connected to a data-source

raster->setConnector(connector, IlwisObject::cmOUTPUT); // ownership is transfered to the raster
raster->store(); // the actual storing.

The createFromFormat method accepts 3 parameters

  1. The resource for which a connector has to be created
  2. The type of output that should be generated. This string is connector dependend and can be found in the documentation of the connector. Ideally this would be connector independ but all libraries use different and often not compatible ways of identifying formats.
  3. Which connector can be used. as 2. is not necessarily unique, this parameter is necessary

There is a convenience method that wraps these things together

raster->connectTo(QUrl("file:///d:/data/someraster.img"),"map","ilwis3", Ilwis::IlwisObject::cmOUTPUT);
raster->store();

The connectTo is very similar to the traditional 'open' methods for files in some programming languages.

Though reading also involves a connector it often is invisible

IRasterCoverage myraster("file:///d:/data/someraster.img");

generates a connector, behind the scenes. The system

  1. queries the existing connectorfactories who can handle 'someraster.img'
  2. creates a input connector
  3. sets the input connector of myraster to the generated connector

Note that you don't have influence over which connector is used. In most cases this is ok but in case you have multiple connectors that can handle the same format and you have preference over one you need to be able to select it.

PrepareOptions option("connector","gdal"); //  we specify a specific connector
IRasterCoverage myraster("file:///d:/data/someraster.img", option);