Datenbank

Aus OCAD 11 Wiki - Deutsch
Zur Navigation springen Zur Suche springen

This function is available in OCAD 11 Professional.

Einführung zur Datenbankverbindung

In OCAD können Informationen, welche in einer Datenbank gelagert werden, einem Objekt hinzugefügt werden (z.B. Position des Objektes, Name des Standortes, URL-Link, Länge des Objektes etc.). Eine Datenbank ist folgendermassen strukturiert:

Hauptstruktur einer Datenbank

Tabelle

Eine Datenbank besteht normalerweise aus mehreren Tabellen. Es gibt verschiedene Formaen von Datenbanken: In einer Flatfile-Datenbank wie dBase, definiert jede Tabelle eine Datei und alle Tabellen eines Verzeichnisses bilden eine Datenbank. In anderen Datenbanken wie Microsoft Access oder in Tabellenkalkulationsprogrammen wie Microsoft Excel sind alle Tabellen der Datenbank in der gleichen Datei.

Satz

Eine Tabelle besteht aus Datensätzen. Ein Satz ist eine Zeile in der Tabelle, welche Informationen über ein OCAD-Objekt enthält.

Feld

Ein Datensatz besteht aus Feldern. Jedes Feld enthält eine einzige Information eines OCAD-Objektes, welches durch den enstprechenden Satz definiert wird. Normalerweise ist diese Information eine Nummer (z.B. x-Koordinate eines Objektes), sie kann jedoch auch ein Text sein. Jeder Satz besitzt einen Primärschlüssel (Nummerierung), welcher für die Identifikation des Satzes benötigt wird. Dies ist meistens eine Nummer.

Beispiel

Die folgende Tabelle enthält drei Datensätze. Jeder Satz beschreibt ein Flächenobjekt in OCAD und besteht aus sechs Feldern: ID, GRÖSSE, BESITZER und XCOOR, XCOOR, TYP. Die ID ist der Primärschlüssel, welcher von OCAD für die Identifikation des Satzes verwendet wird. Die GRÖSSE beschreibt die Grösse der Fläche. Im Feld BESITZER steht eine Nummer, welcher mit einer Sekundärtabelle verknüpft ist. Das vierte und fünfte Feld enthalten die Koordinaten und im letzten Feld wird der Typ der Fläche beschrieben.

ID GRÖSSE BESITZER XCOOR YCOOR TYP
1 724 29 754870 233386 Private Baufläche
2 702 12 754900 233442 Schule
3 422 13 754815 233505 Private Baufläche

In OCAD wird ein Satz folgendermassen dargestellt, wenn das entsprechende Objekt selektiert ist:

Database1.PNG

Einige Begriffe

Verbindung

Um mit einer Tabelle verbinden zu können, verwendet OCAD eine Datenbank-Verbindung. Die Verbindung enthält die Verknüpfung zur Datenbank, den Namen der Tabelle, den Namen des Primärschlüssel-Feldes und Informationen über andere Spezialfelder. Sie können für eine OCAD-Karte mehrere Datenbankverbindungen einrichten.

Datenbankverbindungen verwalten Space.PNGThis function is available in OCAD 11 Professional.

Neue Datenbankverbindung erstellen

Sie müssen eine Datenbankverbindung erstellen, was Sie mit den folgenden Schritten erledigen können:

  1. Wählen Sie den Befehl Datenbankverbindungen verwalten aus dem Datenbank-Menü.
  2. Der Dialog Datenbankverbindungen verwalten erscheint.
    Database2.PNG
  3. Klicken Sie auf die Schaltfläche Neu.
    DatabaseNewDataset.PNG
  4. Der Dialog Neue Datenbank-Verbingung erscheint. Wählen Sie die Option Neue Datenbank-Datei und wählen Sie einen Datenbanktyp oder verwenden Sie die Option Bestehende Datenquelle benutzen. Beachten Sie, dass die Access Database Engine installiert sein muss, wenn Sie Mircosoft Access oder Mircosoft Excel als Datenbanktyp wählen. Kontrollieren Sie in der Karteninformation aus dem Karte-Menü, ob die Access Database Engine installiert ist.
  5. Wenn eine neue Datenbank-Datei erstellt wird, erscheint der Dialog Datenbank-Datei speichern. Wenn Sie eine bestehende Datenquelle benutzen, müssen Sie das Verzeichnis der Datenquelle bestimmen, indem Sie auf Durchsuchen klicken oder via ODBC verbinden (Im Dialog Datenbankverbindungen verwalten).
  6. Die Verbindung wird erstellt. Ihre OCAD-Karte ist nun mit der Datenbank verbunden.

Wenn eine Datenbank-Verbindung neu erstellt wurd, zeigt OCAD nach dem Schliessen des Dialogs Datenbankverbindungen verwalten den Dialog Datenbank-Optionen an. Sie können zwei Optionen in diesem Dialog aktivieren:

dBase

Wenn OCAD mit einer dBase-Tabelle verbunden ist, sind weitere Funktionen verfügbar. In dBase ist jede Tabelle eine eigene Datei. Es ist Ihnen möglich, Feldeinstellungen innerhab OCAD zu bearbeiten. Wenn eine dBase-Tabelle geladen ist, ist die Schaltfläche Felder bearbeiten im Allgemein-Tab des Dialogs Datenbankverbindungen verwalten aktiviert. Klicken Sie auf diese, um den Dialog dBase-Tabelle zu öffnen.

DBaseTableDialog.PNG

Diese Dialogbox listet die Felder der dBase-Tabelle auf. Jedes Feld wird in einer Linie angezeigt. Mehrere Funktionen stehen Ihnen zur Verfügung:

  • Feldname:: Geben Sie den Namen für das Feld ein. Der Name muss mit einem Buchstaben starten und kann bis zu 10 Buchstaben und Nummern enthalten. Buchstaben werden in Grossbuchstaben umgewandelt.
  • Typ:: Wählen Sie entweder Buchstabe (C für Character), Nummer (N für Number) oder Gleitkommazahl (F für Float) als Feldtyp.
  • Länge:: Geben Sie hier die Anzahl Zeichen für das Feld ein.
  • Dezimalstellen:: Dieses Feld ist nur aktiviert, wenn der Typ F ist. Geben Sie die Anzahl Dezimalstellen hier ein.
  • Aufwärts schieben: Klicken Sie auf dieses Icon, um das selektierte Feld eine Linie aufwärts zu schieben.
  • Abwärts schieben: Klicken Sie auf dieses Icon, um das selektierte Feld eine Linie abwärts zu schieben.
  • Einfügen: Click this button to add a field. After adding the new field, the dBase table is restructured. Existing information is preserved.
  • Delete: Click this button to delete the selected field.
  • Character encoding: A character encoding type can be chosen in the corresponding dropdown list.


hint If you do not have installed the Borland Database Engine (BDE), only filenames with less than 8 characters are allowed (Example: 'test5678.dbf'). Click the Karteninformation command in the Karte menu to see, if the Borland Database Engine is installed or not. It can be downloaded from the internet for free.

ODBC

You can access to databases via ODBC (Open Manage Database Connection). This is an interface to connect to all kind of databases.

Click the ODBC button in the Manage Database Connections dialog to create a new ODBC data source or to modify an existing data source. The ODBC Data Source Administrator is started. This is a Microsoft program and contains its own online help. Here are just some hints: Normally you create a new User DNS.

For a connection to an Excel file, you select the Excel driver and the Excel (*.xls) file.
For a connection to an Access database, you select the Access driver and the Access (*.mdb) file.
For a connection to a flat file database like dBase you do not select the dBase file. Instead you select the folder where the dBase file is.

Allgemeine Einstellungen für selektierte Verbindung

The first of the three tabs in the Manage Database Connections dialog is about general settings of the currently selected dataset. In the first part the source of the database is given. It can be either a Database file or an ODBC data source. In the lower part of this tab, the Table which contains the desired information can be chosen. Define a Key field so that OCAD can identify the record. This field is mostly named ID.

Database3.PNG

Erstellen und bearbeiten von Sekundärtabellen

Secondary tables are tables which are linked to a field in the primary table. This is especially useful, when additional information is added. For example, imagine a map with all real estates of a village. Then, each owner would get a number, which is stored in the primary table. The secondary table would be linked to this number and would contain all names, addresses and contact information of the owners. If an owner changed his contact information, you would update the changes in the secondary table, which would have an effect on all his real estates.

In OCAD, secondary tables can be managed in the Secondary Tables tab of the Manage Database Connections dialog. Click the Add button to add a new one. The Secondary Table dialog appears. First, you have to define the Reference field in the primary table, which is the field, the secondary table is linked to. Then, choose the secondary table which must be in the same dataset. Finally, define a Key field for the secondary table and click the OK button.

Click the Edit button to change the settings of the secondary table.

Click the Remove button to remove the selected secondary table.

Fields which are linked to a secondary table are indicated with an asterisk (see below).

Database4.PNG

Click the asterisk to display the secondary table:

SecondaryTable.PNG

Spezialfelder definieren

Open this tab to define special fields. Special fields are automatically updated in the database when a modification to the object in the map is made. However, it does not work in the other direction. If you change such a field in the table, the object is not updated.

OCAD provides the following special fields:

  • Symbol field: The symbol number of the object is automatically copied to the database field which you have chosen in the dropdown list.
  • Text field: For text and line text objects, the text of the objects is automatically copied to the database field which you have chosen in the dropdown list. For multiline text, only the first line is copied.
  • Size field: The size of the object is automatically copied to the database field which you have chosen in the dropdown list. For line objects the length and for area objects the area is taken. Adjust the units in the corresponding fields as well as the number of decimals.
  • Easting: For point objects the horizontal coordinate is copied to the chosen database field. For line, area and text objects it is the horizontal coordinate of the start point.
  • Northing: For point objects the vertical coordinate is copied to the chosen database field. For line, area and text objects it is the vertical coordinate of the start point.
  • Angle: For point and text objects the angle is copied to the chosen database field.

Datenbank-Box Space.PNGThis function is available in OCAD 11 Professional.

Objekt verknüpfen

When the map was connected to a database, the Database Box appears below the Symbolbox.

Database5.PNG

Hint.jpg The Database Box is shown right below the Symbolbox by default. Only one row of the Symbolbox is visible. To move the Database Box down, simply click and drag the grey bar between symbol and database box down.

To link an object:

  1. Select the object which you want to link to a record.
  2. Click the Link button in the Database Box.
  3. The Link Object dialog appears.
    Database6.PNG
  4. Select the dataset which contains the desired record.
  5. Enter a key. This number is used for the key field. Unless you make any changes, OCAD takes always the next free integer.
  6. Check the Create new record option. If the object is to be linked to a record which already exists, uncheck this option and enter the key of the record.
  7. Click the OK button.
  8. The Datensatz is shown in the Database Box now.

To remove a link:

  1. Select the object which the link is to be removed from.
  2. Click the Link button in the Database Box.
  3. The Link Object dialog appears.
  4. Click the Remove button.
  5. The link is removed from the object but the record is not deleted from the table.

Learn how to link multiple objects to records in the Datenbankeinträge erstellen und aktualisieren article.

Datensätze in OCAD

This is how a record looks in the Database Box:

Database7.PNG

The Key field is indicated with a K behind the field name. A S means, that this is a Spezialfeld. A link to a Sekundärtabellen is indicated with an asterisk. If no sign appears in this column, it is just a normal field.

It is possible to open an URL directly from the Database Box. Press the Ctrl key and click the field. OCAD opens the URL in the web browser. This works for local files (for example a picture), too:

Database8.PNG

OCAD opens the file in the default program.

Objekt suchen

Find an object with help of the key by clicking the Find button in the Database Box. The Find Object dialog appears.

FindObjectDialog.PNG

Select a dataset and enter the key. Click the OK button. OCAD will display the record in the Dialog Box and will move the view to the corresponding object. Furthermore, the object will be selected.

SQL-Abfrage

Click the SQL Query button to select database objects by a certain criteria. The Select Database Object dialog appears.

SelectDatabaseObject.PNG

In the SELECT FROM part of the dialog, choose a dataset.

In the WHERE part you can give a condition:

Field: Choose a field of the selected dataset. When you double-click a field name it is added to the SQL statement box.
Operator: Select an operator. When you double-click an operator it is added to the SQL statement box.
Value: Select a Value. When you double-click a value it is added to the SQL statement box.

The SQL statement should always contain the components FIELD - OPERATOR - VALUE (example: Length > 430). An SQL statement can be cleared, saved or loaded by clicking the corresponding button to the right of the SQL statement box.

Click the Select button to start the database query. The found objects are selected and the corresponding records are displayed in a table.

Datenbankeinträge erstellen und aktualisieren Space.PNGThis function is available in OCAD 11 Professional.

With this function, new records can be created or updated for all objects with the selected symbol:

  1. Choose the Create and Update Records command in the Database menu.
  2. The Create and Update Records dialog appears.
    CreateandUpdateRecords.PNG
  3. Select the Dataset the records are to be created in and click the OK button.
  4. New records are created and linked to all objects with the selected symbol(s). The next free integers are used for the key fields. If they are already linked to records, the records are updated. Spezialfelder are updated automatically.

As an example, assume that you want to create an OCAD Internet Map with a street find function. All street names must be linked to the database. OCAD provides a simple way to create these links.

  1. Make sure you have enabled the Spezialfelder for text.
  2. Select all symbols which are used for street names.
  3. Choose the Create and Update Records command from the Database menu.
  4. Select the dataset and click OK.

Now all street names are linked to a record which contains the street name itself as a field.

Spezialfelder aktualisieren Space.PNGThis function is available in OCAD 11 Professional.

Spezialfelder are only updated automatically when the linked object is edited. When objects are linked to a database and the database is edited with another program, the Spezialfelder are not updated, until you use the Update Special Fields function in the Database menu. The same applies for fields which were edited manually in OCAD.

The Update Special Fields dialog opens. Select a dataset or choose the All datasets option. Then, check all special fields you want to update and click the Update button.

Objekt erstellen Space.PNGThis function is available in OCAD 11 Professional.

CreateObjectsFromTableExample.PNG

With this option, objects can be created with location and text data from the database.

  1. Select the symbol the new objects shall get. This must be a point or a text symbol.
  2. Choose the Create Objects from Table command in the Database menu.
  3. The Create Objects from Table dialog appears.
    CreateObjectsFromTable.PNG
  4. Select the dataset which contains the information the object is to be created with.
  5. Enter a condition. This condition must be an SQL statement: FIELDNAME OPERATOR VALUE (Examples: SIZE > 500, City='Baar'). If this field is empty, all records in the table get an object on the map.
  6. Select the field for the Easting and Northing which determines the position of the new object.
  7. Choose between m and km as a unit of measure.
  8. If a text symbol was selected in the beginning, you have to select a text field. The content of the text field is used as the text of the OCAD object.
  9. You can give a horizontal and vertical offset. This is useful for example when you want to import city names. First create a point object for each city, then create a text object with the city name with an offset, so that the name does not overlap with the point object.
  10. Finally, click the OK button.

Symbole anhand Datenbankeinträgen zuordnen Space.PNGThis function is available in OCAD 11 Professional.

After importing for example a Shape file the objects have no symbol assigned and appear as Unsymbolisierte Objekte. With this command you can use the information in the database table to assign OCAD symbols to the objects.

Choose the Assign Symbols by Records command in the Database menu. The Assign Symbols by Records dialog appears.

AssignSymbolsByRecords.PNG

In this dialog box you can create a list of conditions. You can save the list to a condition file (*.cnt) for later use. You can load an existing condition file to modify or execute it. You have the following possibilities in the Assign Symbols by Records dialog:

  • Dataset: Select here the dataset which should be used to assign symbols. Check All to execute the condition for all datasets.
  • Load: Click this button to load an existing condition file (*.cnt).
  • Save: Click this button to save the changes to a condition file (*.cnt).
  • Save as: Click this button to save the changes to a different condition file (*.cnt).
  • Symbol: Select here a symbol. For those objects the condition is true, the symbol number will be assigned.
  • Condition: Enter the condition here. This must be a SQL statement: FIELDNAME OPERATOR VALUE (Example: TYPE = 'BUILDING').
  • Move up: Click this button to move up the selected condition.
  • Move down: Click this button to move down the selected condition.
  • Add: Click this button to add a condition to the list.
  • Delete: Click this button to delete the selected condition.
  • Execute: Click this button to execute the assignment.

Texte anhand Datenbankeinträgen zuordnen Space.PNGThis function is available in OCAD 11 Professional.

AddTextsbyRecordsExample.PNG

With this function it is possible to add a text which is written in a field of a record to an OCAD object.

  1. Choose the Add Texts by Records command in the Database menu.
  2. The Add Texts by Records dialog appears.
  3. Choose a Dataset or check the All option to take all datasets into consideration.
  4. Choose the field which contains the Text to be added.
  5. Assign a text or line text symbol. If no symbol is assigned, the text appears as Unsymbolisierte Objekte.
  6. You can either replace the existing objects or add new objects.
  7. Enter an Object offset if you want to have the text slightly displaced from the existing object.
  8. Click the OK button.

Objektrichtungen anhand Datenbankeinträgen definieren Space.PNGThis function is available in OCAD 11 Professional.

With this function the object direction can be defined by an angle (in degrees) from a field of the database.

Choose the Define Object Directions by Records command from the Database menu. A dialog appears. Choose a Dataset in the dropdown list or check the All option to take all datasets into consideration. The define the Angle field. Click the OK button when finished.

The following things are rotated according to the angle field:

  • Text objects
  • Point objects
  • The pattern of area objects

OCAD does not rotate line or line text objects!

Objekte anhand Datenbankeinträgen verschmelzen Space.PNGThis function is available in OCAD 11 Professional.

With this function, objects with the same value on a specified database field are merged. They also must have the same symbol.

Choose the Merge Objects by Records command in the Database menu. A dialog appears. Choose a Dataset or check the All option to take all datasets into consideration. Then choose the field with the value to be used for merging the objects. Click the OK button when finished.

The merged objects have to be linked again to the database.

Example:
MergeObjectsByRecord.PNG

You have different river segments on a map. Each river segment have the same river name. With the Merge Objects by Records function, they can easily be merged to one object.

Objekte mit Verknüpfung selektieren Space.PNGThis function is available in OCAD 11 Professional.

Objekte mit Verknüpfung und entsprechendem Datenbankeintrag selektieren

Choose this function in the Database menu to select all objects with a link to an existing record.

Objekte mit Verknüpfung und fehlendem Datenbankeintrag selektieren

Choose this function in the Database menu to select all objects which are linked to a record but the record was not found.

Objekte mit Verknüpfung zu demselben Datensatz selektieren

Choose this function in the Database menu. By choosing this function, multiple objects which link to the same record are selected.

Delete Records without Linked Object Space.PNGThis function is available in OCAD 11 Professional.

Use this function to delete unused database records for example after using the Part of Map function.

Choose Delete Records without Linked Object in the Database menu. The Delete Records without Linked Object dialog appears.

Delete Records without Linked Object

Select the dataset and click the Find button. OCAD checks for

  • records in the selected dataset
  • links to OCAD objects found. OCAD does not check if the objects also exists.
  • records in the selected dataset without a link to an OCAD object

The ids of the records without a link to an OCAD object are shown in the Records to delete field. Please note that only the first 100 ids are shown. For the complete list of ids please use the Copy report to Clipboard function.

Click the Copy report to Clipboard icon to copy a list with the record ids to the Windows Clipboard. You can paste this list into an text document.

Example of this report:

*** Records found in dataset: (35982)
198
199
200 
...

*** Linked objects found: (818)
199
18421
202
...

*** Records without linked objects found: (35165)
49535
49536
49537
...

Click the Delete button to delete the records according the list from the Records to delete field. The number of the deleted records are shown in the left status bar during the deleting process. Press the ESC key to abort this process.

Hint.jpg Please note that is not possible to undo this process. So please backup your database before starting the deleting process.

Delete Database Record when Deleting Object Space.PNGThis function is available in OCAD 11 Professional.

If this option is checked in the Database menu, the corresponding record is deleted when you delete a linked object in OCAD.

Create Database Record when Cutting Object Space.PNGThis function is available in OCAD 11 Professional.

If this option is checked in the Database menu, a second database record is created when a linked object is cut.


Previous Chapter: GPS

Next Chapter: XML Script

Back to the Main Page.