Click or drag to resize

City Database Files

To obtain information about cities using STK database files, use the StkCityDatabase class. This type uses a directory and a base filename to identify a set of files with the same name but differing extensions which together define the database. For more information on the format of these files, see the section on the database format below.

City Databases in STK Components

After instantiating an instance of StkCityDatabase, queries can be made to obtain a set of cities matching a set of criteria. Here is an example of how to query the database for cities:

C#
StkCityDatabase db = new StkCityDatabase(dbDirectory, "stkCityDb");

// Create a query object and then populate it with the properties to query on.
// Regular expressions are used to query on strings.
StkCityDatabaseQuery query = new StkCityDatabaseQuery
{
    CityName = new Regex("Philadelphia"),
    //only look in PA, because there's also a New Philadelphia in Ohio
    ProvinceName = new Regex("Pennsylvania")
};

// Get the database entries matching the query and print out the Longitude and Latitude of each.
foreach (StkCityDatabaseEntry entry in db.GetEntries(query))
{
    Console.WriteLine("{0}: Longitude {1}, Latitude {2}", entry.CityName, entry.Longitude, entry.Latitude);
}
City Database Format

The city database is comprised of a total of three files. You can create your own city database by following the required format. For example, the stkCityDb database includes the following files:

File

Contents

stkCityDb.cd

Main database file

stkCityDb.cc

Countries

stkCityDb.gd

Latest update information

The first file contains fixed-width fields, where one row represents a single entry. The remaining contain a standard text format.

stkCityDb.cd File

This is the main city database file; it contains all searchable fields. The format, starting at column zero (0) is as follows:

Column

Width

Description

0-6

7

City Key. Unique integer identifier

7-36

30

City Name

37-38

2

City Type:

  • 1 - Populated Place

  • 2 - Administration Center

  • 3 - National Capital

39-58

20

Country

59-98

40

Province/State

99-101

3

Province rank

102-112

11

Population

113-115

3

Population Rank

116-132

17

Latitude (deg)

133-149

17

Longitude (deg)

151-162

12

Central Body

stkCityDb.cc File

This is the country and city type file. It contains a list of all the valid countries and city types. This file is used to build the list of country and city types available through the GetCountry and GetCityType methods.

Example stkCityDb.cc file
Begin Country
ALBANIA
ALGERIA
ARGENTINA
AUSTRALIA
AUSTRIA
CROATIA
CYPRUS
CZECH REPUBLIC
UNITED KINGDOM
URUGUAY
USA
UZBEKISTAN
VANUATU
VENEZUELA
WESTERN SAMOA
End Country

Begin Type
        Populated Place
        Administration Center
        National Capital
End Type

stkCityDb.gd File

This is the generic database file. It contains information concerning the last update of the database.

Example stkCityDb.gd file
BEGIN DatabaseUpdate
Version 1.0
LastUpdate 20110711
END DatabaseUpdate