Uså of databases in cartographical library NGIS components

In given article we describe possibilities for operation with data sets linked with geographical objects in widespread format MapInfo displayed by means of library NGIS Components in programming Delphi environment .

The layer of a map in format MapInfo is stored in a following set of files

1.           TAB – the head description file of projection and a table design, additional information in scripts MapBasic is also stored in it.

2.           MAP – a file in which geographical coordinates of objects and their graphics design are stored.

3.           DAT – a file of tabled data, in a little bit changed format DBF.

4.           ID – a file linking coordinate-objective file MAP with tabled data in file DAT.

5.           IDX – index files for tabled file DAT.

In article «Use of cartography in the applications, by means of NGIS» we said, how it is possible to set TNMap component for showing geographical data in the application. In this part, we will talk about TNMapData component for operation with tabled data of file DAT from a set of files MapInfo and TNMapDataLink components for linking layers TNLayer from TNMap component to external data sets. Now we shall talk about each of them in detail.

TNMapData component. As we know, in Delphi, beginning from 3rd version abstract class TDataSet has been input from which all classes occur for operation with data sets. For convenience of operation TNMapData component is inherited from abstract class TDataSet that gives advantage to all of you for using visual components,for manipulating and drawing of data, such as TDBGrid, TDBEdit, TDBNavigator, etc.

Example of setting a component:

1. Create the new project.
2. Put on the form of TNMapData components.
3. Specify a file path in property «TabTableName» and make active a set having put property «Active» in true.
4. Further, put components for showing data TDataSource specifying data source TNMapData in it and TDBGrid set on TDataSource.

TNMapDataLink component. A component which simply allows to link a layer of a map to the external data source. The component is connected to data source TDataSource which can be connected to any data set TBDETable, TADOTable, etc. and be used link element a map and the data source.
Further, we shall give an example of setting a component. In an example we open table Vendors.db from standard delivery DBDEMOS (examples of data Delphi) and we shall link it to a map selected by the user of record in the table.The map will show the state of the USA to a user where the vendor is situated. It is possible to see a ready example in contents of library \Sample \OtherDataSet\.

Example of setting a component:

1. Create the new project.

2. Put on the form standard TTable components, TDataSource, TDBGrid.

3. Set TTable on table Vendors.db from DBDEMOS. Link TDataSource component to TTable and TDBGrid to TDataSource.

.

4. Set TNMap component and add two layers «State», «StateCap» (Example maps data in NGis library), the detailed description of setting TNMap component you can read in article «Use of cartography in the applications, by means of NGIS».

5. After preliminary setting of the form we shall pass to the main, linking a map with a data set. Link will occur on a column «State» tables «Vendors» and to a column «State» from a data set of a map «State» (DAT file).

6. Put TNMapDataLink component on the form. In the beginning, we shall connect it to the table «Vendors». For this purpose set properties «DataSource» and «DataField».

hgfh

7. Further, we connect a layer «State» maps to TNMapdataLink component, for this purpose select a layer and set following properties «DataLink» specifying in it on TNMapDataLink component and «DataLinkField» the field from a data set of a layer on which will occur link.

Now,selecting a record in TDBGrid, the state of USA on the map will show where the seller is. In addition, it is possible to add centering of the object on a map. For this purpose, set in TNMapDataLink component the property «CenterSelected» in true.