The SDL Component Suite is an industry leading collection of components supporting scientific and engineering computing. Please visit the SDL Web site for more information....

Using TGeoDB

TGeoDB is a simple but efficient database for storing and retrieving geographic data. Each database entry holds a minimum set of data (e.g. name of entry, type of entry, or position data). Depending on the type of the data, additional information may be stored as binary large objects (BLOB). The structure of the database is optimized for retrieving data from the database. Thus, writing to the database is in general slower than reading from it.

In order to open an existing database or to create a new one, the user has to assign the name of the database to the property DBName. If the database already exists, the database is opened, otherwise a new database is created from scratch. The read-only property NumEntries returns the current number of database entries. The database should be closed after having finished to use it by setting the property DBName to an empty string. Please note that an open database may allocate a considerable amount of memory (roughly 100 bytes per database entry). On the other hand opening a database is time-consuming. So you have to make a compromise between memory usage and processing speed.

Data can be stored in the database by adding a new entry using the methods AddBorder, AddCity, AddRiver, AddRoad, AddRoute, AddLake, AddBLOB, or AddTown. In order to retrieve data you may use the array property Data which contains the basic data of all database entries. Additional data (such as outline data or binary data) can be retrieved by using the methods RetrievePolygon and RetrieveBLOB.

Data can be deleted by using the method DeleteData. There are two important points about the deletion of data: (1) deleting any data may change the database entry numbers (but not the database item IDs) of the remaining data. Thus you must not rely on database entry numbers - use the item IDs to identify a particular entry. (2) For performance reasons, deleting data which contains BLOBs or polgons does not actually delete the corresponding BLOB or polygon but marks it as "deleted". In order to reduce the size of the database you have to call the method GarbageCollection.

TGeoDB accelerates the access to its data by using indexes using a binary search algorithm. This reduces search times by a factor of 1000 and more compared to a linear search as it is carried out by the method SearchData. The following data is supported by high-speed indexed search: longitudes, latitudes (upper and lower limits if ranges are important), and database entry IDs. These indexes may either be accessed directly using the properties IxLatLow, IxLatHigh, IxLongLow, IxLongHigh, and IxItemID, or may be used indirectly and implicitly by calling the indexed search operations GetClosestLatLowIx, GetClosestLatHighIx, GetClosestLongLowIx, GetClosestLongHighIx, and GetClosestItemIDIx, respectively.


Limits of the TGeoDB

The database is limited to a maximum number of 2 billion entries. The total size of all BLOBs (outline data and custom BLOBs) must not exceed 2 GBytes. In practice, the size of the database is limited by the amount of available memory, since the basic data are kept in memory for performance reasons. However, this is not a severe restriction for small or medium sized applications, since a typical world map (at a scale of 1:1000000) requires about 100000 entries which comes down to about 10 MBytes of allocated memory.

The restriction of the total sum of all BLOBs to 2 GBytes is not a real restriction unless you try to store a huge number of photos as BLOBs at a high resolution. Assuming to store photos having a size of 1024 by 768 pixels , a single photo will require about 150 kBytes, which results in a capacity of about 13000 photos. If more BLOBs are to be stored you could either create several databases or you could extend the database by using the Tag parameter to store the BLOBs in external files.

Last Update: 2013-May-14