This is documentation for Mathematica 5, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.2)

Documentation / Mathematica / Add-ons & Links / Standard Packages / Miscellaneous /


Mathematica's programming capabilities allow you to create powerful customized tools. In this package, one approach to a sample database is used. This database, containing information about cities, is expandable and can be used with other functions.

Accessing the CityData database.

The database currently contains only position location for a number of cities around the world. Positions are stored as latitudes and longitudes in a degree, minute, second or degree, minute format.

This loads the package.

In[1]:= << Miscellaneous`CityData`

This gives the latitude and longitude of Montreal.

In[2]:= CityData["Montreal", CityPosition]


This returns the information in the database about Washington.

In[3]:= CityData["Washington"]


Cities defined in Miscellaneous`CityData`.

You can give a more precise name for a city using the form cityname, countryname, with more precise indicators such as state names following, if necessary. The database also checks the spelling of your request. If there is no matching name, but a name that is close, that name will be suggested to you.

This city is in the database under the name Rome.

In[4]:= CityData["Roma", CityPosition]


The CityDistance function.

The function CityDistance uses the positions in the database to determine the distance between two cities. The default method of computing distance is SphericalDistance from the package Miscellaneous`Geodesy`.

This gives the distance between Washington and Montreal.

In[5]:= CityDistance["Washington", "Montreal"]//N


Controlling information in the database.

The database is quite expandable; you can add additional cities and additional information for each city.

This places position information for Champaign, Illinois, into the database.

In[6]:= CityPosition[{"Champaign", "USA", "IL"}] =
{{40, 7, 5}, {-88, -14, -48}};

Here is the position of Champaign.

In[7]:= CityData["Champaign", CityPosition]


This adds a new field to the database to hold population information.

In[8]:= AppendTo[$CityFields, CityPopulation];

Here is the population for Washington.

In[9]:= CityPopulation[{"Washington", "USA", "DC"}] = 638000;

This accesses all data about Washington in the database.

In[10]:= CityData["Washington"]