Table Joins

Introduction

Benefits of linking data to overlays

Joining a table to an overlay

Fill Column using a joined table

Introduction

Non-spatial data from a database table, spread sheet, or text file can be loaded in a Cadcorp SIS Overlay Table Join. A Table Join allows one-to-many connections and requires therefore a unique schema column on the  SIS spatial overlay. Table Joins are created on an overlay not a dataset and are therefore stored in the SWD. The dataset read elsewhere will have no information on any join within the SIS Workspace Definition (SWD). Only a single Table Join is permitted for each overlay. Joined columns retrieve values from a table via the Join expression.

SIS is able to read following non-spatial database and file formats:


Note: File based datasets can be read via a direct to file connection, as ActiveX Objects, or ODBC Data Source. Cadcorp SIS (64 bit) will use ADO (via the Microsoft Access Database Engine) to read Microsoft Excel *.xlsx files, Cadcorp SIS (32 bit) uses DAO to read spread sheets. Cadcorp SIS (64 bit) can only read .xlsx files and not .xls spread sheets.

Back to top of page

Benefits of linking data to overlays

Linking tables allows you to query data from external non-spatial data sources. Spatial data which is represented as overlays in SIS can be linked to non-spatial items via a unique identifier. Furthermore, the Overlay Table Join allows you to create one-to-many connections between the spatial items and non-spatial data.

Linking data allows you to minimize the size of geographic datasets and facilitate the benefits of relational database technologies. The same data source can be referenced by several SIS overlays. Linking data will help to reduce the amount of duplicate data and maintain the actuality of data sources.

It is possible to facilitate spatial queries based on the item geometry in SIS in order to derive values from a linked non-spatial data source.

Note: Due to limitations with the current implementation of sorting, the Table Window no longer allows sorting operations on Overlays with a Joined Table which has many-to-one joins enabled.

Back to top of page

Joining a table to an overlay

Also see the API method: SetOverlayJoinTable.

A Table Join can be initiated via the Connect command from the Join drop-down list of the Overlays dialog Schema tab:

The Connect wizard allows you to select and setup the appropriate data connection to access the data table. 

The Database Types dialog will be displayed to allow you to select one of the available Database or File Types:

Microsoft SQL Server

Connects to a Microsoft SQL Server database

PostgreSQL

Connects to a PostgreSQL database

Oracle 8

Connects to an Oracle 8i, or later, database

File-based database

Reads one of the supported database formats directly from a file, e.g. Microsoft Access .mdb/accdb, or SQLite .db/.sqlite

Comma Separated File

Reads delimited data, e.g. comma- or tab-separated, from a file.

ActiveX Data Objects

Connects to a OLE-DB Data Source using Microsoft ActiveX Data Objects.

ODBC Data Source

Connects to an ODBC Data Source.

Select the location of the database or file and then click Next

The next display depends on the option chosen in the above Database Types dialog. Each option will display dialogs to eanable the required dataset to be chosen.

When the file has been selected the Recordset dialog will be displayed:

Once a table connection has been established the table column for the Overlay Table Join can be selected.

The Database Tables/Columns pane shows the tables and columns available in the connected database.

The Selected columns pane shows the selected database table columns. Use the Alias column in this list (move the slider to the right to reveal) to map the database column name onto a SIS property/attribute name:

If the recordset is being used as part of a database-based dataset, then you can enter existing property names (e.g. _shape$) to redefine the created items' properties.

Select the entire table or expand the list to display individual fields. Click Add>> to move the required item(s) to the Selected columns pane.

SQL Where: the SQL WHERE clause can be used to join several different tables, or restrict which rows are imported. Do not include the WHERE SQL keyword. A Dynamic connection updates recordsets when the source dataset is changed.

The final step of the connection wizard allows you to configure the join. The join expression must be defined from a unique schema expression to a connected table column. A one-to-many connection can be allowed for the table join. It is not necessary to display the column which is used for the join. By definition this column will be identical with an existing column in the Overlay Data Schema. Joined table columns can be added to the dataset schema or replace the existing dataset schema.

Untick any of the boxes for any of the joined columns not to be displayed.

The Allow one-to-many relationships will allow multiple rows in the joined table to be added to single items in the overlay.

Select Import joined columns as attributes if required and enter the Attribute prefix.

Select Append columns to Schema or Replace Schema columns as appropriate.

Click on the Join from expression... fx button to display the Expression Builder dialog:

In the above example the Schema column "ID" is selected. Click OK.

Select the ... to Table Column from the drop-down list and click Finish.

The connect wizard will close and complete the table join. At the Overlays dialog Join tab click OK.

The Refresh, Properties and Disconnect options are only enabled for overlays with an active Table Join:

Back to top of page

Fill Column using a joined table

Example

This example includes the steps to create a joined table. If you only wish to see details of filling a joined table column go to step 10.

Taking "TableJoinEx1.bds" as the base dataset file and "Details.csv" as the file to be joined.

  1. Select Add Overlay [Home-Map]. In the Overlay Types dialog select the File icon and click Next.

  2. In the File Browser dialog navigate to the required file, in this example TableJoinEx1.bds and click Finish.

  3. Open the Overlays dialog (Overlays [Home-Map] or press F2) and select the Connect command from the Join drop-down box on the Schema tab.

  4. In the Database Types dialog select the Comma Separated File option and click Next.

  5. In the File Browser dialog navigate to the required file, in this example Details.csv and click Next.

  6. The Database file dialog will be displayed:



    This dialog confirms the Details.csv file is Delimited.

    Click Next.

    The File format dialog will be displayed:



    This dialog confirms the field delimiter is a comma with the text qualifier as a " (double-quote).

    Checking the First Row Contains Field Names tickbox will use the values in the first row as field names rather than data values. For this example check this tickbox.

    Click Next.

    The Database columns dialog will be displayed:



    No settings need be changed for this example. However, if you need to change the Field Options Name or Type, select the corresponding column to activate the Field Options section. Date formats can be changed using the Date Format option.

    Click Next.

  7. The Recordset dialog will be displayed:



    In this example select Details in the Database Tables/Columns and click Add>> to move the columns to the Selected columns pane.

    Click Next.

  8. The Join Configuration dialog will be displayed:



    Click the Join from expression... dialog fx button , and choose ID from the Expression Builder dialog Schema drop-down list:



    Click OK.

    Select ID from the ...to Table Column drop-down list:



    Check the Allow one-to-many relationships tickbox.

    Click Finish.

  9. Click OK on the Overlays dialog.

  10. Go to the View ribbon tab and select Table [View-Document Views].

  11. Go to the Table ribbon tab and select Add-Expression [Table-Column].

    Enter the name for the new column, i.e. MyNewColumn@:


    Note: The dataset type entered must be "@".

    Click OK.

  12. In the Table Window select the new column (MyNewColumn) and click Fill [Table-Column] to display the Fill Column dialog:



    Select the required column from the Expression drop-down list, in this example Incident_Type is selected.

    Join.Incident_Type will now be displayed in the Expression box.

    Click OK.

  13. The table column MyNewColumn will now be populated with the required data.


Top of page

Send comments on this topic.

Click to return to www.cadcorp.com

© Copyright 2000-2017 Computer Aided Development Corporation Limited (Cadcorp).