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.
After instantiating an instance of StkCityDatabase, queries can be made to obtain a set of cities matching a set of criteria. The following example demonstrates how to query the database for cities:
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(); query.setCityName(Pattern.compile("Philadelphia")); // only look in PA, because there's also a New Philadelphia in Ohio query.setProvinceName(Pattern.compile("Pennsylvania")); // Get the database entries matching the query and print out the Longitude and Latitude of each. for (StkCityDatabaseEntry entry : db.getEntries(query)) { System.out.format("%s: Longitude %f, Latitude %f%n", entry.getCityName(), entry.getLongitude(), entry.getLatitude()); }
A city database is comprised of a total of three files which have the same base filename with different file extensions. The file extension determines the type of data contained by that file. Not all files are required. If an optional data file is not present, then that information will be silently omitted from the database entries.
File | Contents | Required? |
---|---|---|
Main database file | Required | |
Countries, City Types, Central Bodies | Optional | |
Generic database information | Optional |
The first file contains fixed-width fields, where one row represents a single entry. The remaining contain a standard text format.
This is the main city database file; it contains all searchable fields. The format, starting at column zero, is as follows:
Column | Width | Description |
---|---|---|
0-6 | 7 | City Key. Unique integer identifier |
7-36 | 30 | City Name |
37-38 | 2 | City Type:
|
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 (in degrees) |
133-149 | 17 | Longitude (in degrees) |
151-162 | 12 | Central Body |
This is the country and city type file. It contains a list of all the valid countries, city types, and central bodies for the database, and defines the lists returned from the getCountries, and getCityTypes, and getCentralBodies methods.
Begin Country ARGENTINA AUSTRALIA AUSTRIA UNITED KINGDOM URUGUAY USA WESTERN SAMOA End Country Begin Type Populated Place Administration Center National Capital End Type Begin Central_Body Earth End Central_Body
This is the generic database file, which contains version information and the date of last update of the database. This information is returned from the Version (get) and LastUpdateDate (get) properties.
BEGIN DatabaseUpdate Version 1.0 LastUpdate 20110711 END DatabaseUpdate
In order to use city information in other analysis in DME Component Libraries, it is useful to create a Platform object which represents the city. To make this easy, static methods are defined in StkCityDatabaseEntryExtensions and StkCityDatabaseExtensions that create a platform from a single database entry, or create a list of platforms for all entries matching a query, as the following example demonstrates:
for (StkCityDatabaseEntry entry : db.getEntries(query)) { // A Platform object can be created from a single database entry. Platform platform = StkCityDatabaseEntryExtensions.createPlatform(entry); } // Or, a list of Platforms can be created from all entries matching a query. ArrayList<Platform> platforms = StkCityDatabaseExtensions.createPlatforms(db, query);