My brother suggested that I should write a web app that lets students create and print blank maps. A blank map is a map that contains country borders, waters etc. but no text labels. The first use case is the following:
- User selects ‘Hungary’ from a list. A blank map of Hungary appears on screen.
- User enters a name of a Hungarian town or place in a textbox. A small marker appears on the map in the specified place, but without a text label.
- User repeats step 2 as many times as he wishes, with different towns.
- User prints the resulting image and uses it to practice for his upcoming history or geography exam. The exam task is the same: receiving a blank map with textless markers and you have to fill in the town names from memory.
So I started to write the app, and at step 1, I’ve ran into the first problem. I don’t have a database of blank maps. In order to let the user select a blank map from a list, someone has to create and fill a database of blank maps, in which the maps
table has the following (pseudo-)definition:
CREATE TABLE maps (
name TEXT PRIMARY KEY,
image BLOB,
minlat FLOAT,
minlon FLOAT,
maxlat FLOAT,
maxlon FLOAT
);
I decided to fill out one or two rows of this table myself, for testing. I downloaded this blank map of Hungary by a quick Google Search:
Now how on earth do I determine the coordinates? Let’s try and create an overlay in Google Earth:
As you can see I didn’t manage to position it precisely, the eastern borders are a bit off. So my question is:
Given an image file showing a map, how do I determine the exact lat/lon coordinates of its corners?
9
It depends on the map. Cartographic maps are projections of a (nearly) spherical surface onto a flat, two dimensional surface. That is:
(X, Y) = Fproj(Lat, Long)
where Fproj() is the projection function.
For instance, for a standard Mercator projection with the X axis on the equator, and the Y axis at the 0 Meridian:
X = Longitude
Y = ln(tan(Latitude) + sec(Latitude))
If you know the type of map projection, and the lat/long of the corners of the map, you may be able to determine the lat/long based on the X,Y coordinates by doing an inverse projection.
Wolfram MathWorld has a good catalog of map projections and their inverses.
If you are interested in displaying maps based on existing latitude and longitude data, and you are willing to write your own map projection functions (most are really easy to implement), you can use any of the several sources of databases and flat files that contain country borders, lakes, rivers, etc. A short search with my favorite search engine turns up these two:
Natural Earth Data
ThematicMapping.org
If you do not know the map projection, but you know that Latitude,Longitude of several points on the map, you can use interpolation to estimate the Lat,Long of points on the map based on the Lat, Long of nearby registered points.