Dec 172017
 
Extension to the article "Mapping the world in Pascal" that was in Byte magazine. Lots of Pascal source code, and very interesting.
File CARTOG.ZIP from The Programmer’s Corner in
Category Science and Education
Extension to the article “Mapping the world in Pascal” that was in Byte magazine. Lots of Pascal source code, and very interesting.
File Name File Size Zip Size Zip Type
CART87.EXE 30560 13177 deflated
CARTOG.DOC 16763 6691 deflated
CARTOG.EXE 28368 12800 deflated
CARTOG.PAS 12754 4219 deflated
METAWNDO.EXE 88833 45923 deflated
PRTSCRN.EXE 2819 1749 deflated
RUN.BAT 41 40 deflated
RUN87.BAT 37 37 stored
WORLD.DAT 45366 28342 deflated

Download File CARTOG.ZIP Here

Contents of the CARTOG.DOC file


Last updated: 11/04/88

CARTOG
A Cartography Program from BYTE Magazine

This disk contains several versions of the program CARTOG.PAS
described in "Mapping the World in Pascal" by Robert Miller and
Francis Reddy (BYTE, December 1987, page 329). The program is a
simple tutorial which allows you to view the properties of various
map projections on a graphics screen. The code shows how many of
the more common projections are calculated, but is neither the
best nor the fastest means of doing so -- its purpose is the clear
illustration of how maps are computed. To make start-up of the
programs a little easier, we have included batch files. See below.

Files on This Disk

CARTOG DOC This documentation
CARTOG PAS Source code from BYTE, December 1987
METAWNDO EXE Auto-loading and terminating graphics driver
PRTSCRN EXE " " screen dump
RUN BAT Use this if you have no math coprocessor
CARTOG COM
RUN87 BAT Use this if you have a math coprocessor
CARTOG87 COM
WORLD DAT 6,000-point coastline database

If you have no 80x87, just type "RUN" at the DOS prompt; if
you do have an 80x87 installed, type "RUN87".

Getting Started

The MetaWindow graphics driver allows us to support CGA,
EGA, AT&T, and Hercules-type graphics cards. The driver will
first test for the card on your system, then report the card
detected above the CARTOG menu. You probably won't have to
worry about it, but if you are using a multi-mode card,
MetaWindow may not come to the correct conclusions! Check the
"Graphics: " line above the Menu -- if it does not match one of
the mode's of your card, or if CARTOG appears to run but draws
nothing on the graphics screen, you may need to modify the batch
file by adding the appropriate command switch from those listed
below.

Switch Graphics Board Resolution
-----------------------------------------------------------------
/A:1 AT&T Graphics Adaptor, 640x400 2-color
/A:2 AT&T Display Enhancement Board (DEB), 640x200 16-color
/A:3 AT&T Display Enhancement Board (DEB), 640x400 16-color
/C:1 IBM Color Graphics Adaptor (CGA) 640x200 2-color
/E:1 IBM Enhanced Graphics Adaptor (EGA) 640x350 mono
/E:2 IBM Enhanced Graphics Adaptor (EGA) 320x200 16-color
/E:3 IBM Enhanced Graphics Adaptor (EGA) 640x200 16-color
/E:4 IBM Enhanced Graphics Adaptor (EGA, 128K) 640x350 16-color
/E:5 IBM PS/2 Video Graphics Array (VGA) 640x480 16-color
/E:6 IBM Enhanced Graphics Adaptor (EGA) 640x350 2-color
/E:7 IBM PS/2 MultiColor Graphics Array (MCGA) 640x480 2-color
/H Hercules/AST Monochrome Graphics Adaptor, 720x348 mono
/O Toshiba 3100, 640x400 mono
/T:1 Tecmar Graphics-Master Adaptor, 720x352 mono
/T:3 Tecmar Graphics-Master Adaptor, 640x200 16-color
/T:4 Tecmar Graphics-Master Adaptor, 640x400 16-color
/U:1 Video-7 Vega Deluxe, 640x480 16-color
/V:1 Everex Edge Adaptor, 640x200 16-color
/V:2 Everex Edge Adaptor, 640x400 4-color

For example, the driver will identify the PS/2 video board as
"IBM EGA, 640 x 350" rather than "IBM VGA, 640 x 480." Altering
the batch file to read "Metawndo CARTOG /E:5" tells the program
what hardware to draw to. Please note that the MetaWindow driver,
although a terminate-and-stay-resident program, eliminates itself
from memory when you exit CARTOG. An additional note: Several
users have reported problems with certain cards (notably the
Paradise EGA card) and the Metawndo driver. While we cannnot
solve specific hardawre problems (other than providing the
command line switches above), we would appreciate problem
reports so that we may pass them on to MetaGraphics, makers of
the driver. Also, we are readying a version of CARTOG in the
latest version of Turbo Pascal, which includes extensive
graphics support.
To make CARTOG more flexible, you may specify a data file to
read on the command line. Otherwise, CARTOG looks for the file
WORLD.DAT.

T H E M A P S

The following briefly describes the types of maps CARTOG draws.
For more information, see the BYTE article and consult any
of the references mentioned therein.


Map 1: The Mercator

o Preserves shape but distorts area, especially
in polar regions;
o Poles lie at infinity;
o Meridians are straight, equally spaced lines;
o Parallels are straight lines spaced unequally, closest
near Equator;
o Meridians and parallels intersect at right angles.

Quick. Which is bigger: Greenland or South America? If
you're not at all sure, part of the blame rests with the Merca-
tor projection. Greenland is only one-eighth the size of South
America, but Mercator's projection makes it into a full-blown
continent! The map is often the only two-dimensional
representation of the Earth many students see. Its primary
purpose is navigational. A ship or plane following the same
compass course will travel a straight line when plotted on a
Mercator map. Gerhardus Mercator developed this projection in
1569 specifically as an aid to navigation. Mercator's
projection is classed as a cylindrical, and at first glance it
looks much like the Equidistant Cylindrical (Map 2 in the
program's menu).
But look again. On a Mercator map, the poles cannot be
shown because they lie at infinity, and the spacing between par-
allels increases with increasing distance from the equator. A
region at the 60th parallel plots twice as large as the same
area at the equator. Moved to 80 degrees, that same area becomes
33 times larger than at the equator! The Mercator is said to be
conformal -- it maintains the shapes of small areas at the ex-
pense of distorting sizes. In contrast, the Equidistant Cylin-
drical preserves neither.

Map 2: The Equidistant Cylindrical

o Preserves neither shapes nor areas;
o Poles shown as lines;
o Meridians and parallels are equidistant
straight lines intersecting at right angles;
o Easy to compute.

Imagine a globe tucked inside a cylinder so that only the
equator touches the sides. That's the basic idea behind this
and all other so-called "cylindrical" projections. "Graph
paper" may be the best way to describe the Equidistant Cylin-
drical. In this projection's simplest form the equator is
chosen to be the standard parallel, called Phi1. This means
that the equator is the latitude displayed true to scale and
without distortion. If meridians and parallels are equally
spaced, the result is a grid of tiny squares twice as long as it
is wide. Experiment with different values of Phi1 and watch what
happens to the map.
All in all, the Equidistant Cylindrical is not a very good
choice for displaying geographic data. It preserves neither area
nor shape and is best used when distortions are less important
than just getting the data on-screen as quickly as possible.

Map 3: The Sinusoidal

o Equal area;
o Central meridian is straight, all others sinusoidal
curves;
o Parallels equally spaced straight lines;
o Easy to compute.

The Sinusoidal projection is more useful and only slightly
more complex. Developed in the 16th century, the Sinusoidal
shows areas correctly and exhibits no distortion along the
equator and central meridian. Distortion becomes pronounced at
the outer meridians, extreme near the poles. Latitude lines are
straight, parallel, and equally spaced. The central meridian is
a straight line and crosses all parallels at right angles; other
meridians form curves, their curvature increasing with greater
distance from the map's center. You'll usually see the
Sinusoidal used for world maps, often in an "interrupted" form.
In this case the world is broken into sections, each with its
own central meridian. Some atlases also use the Sinusoidal for
South America, Africa, and the central Pacific.

Map 4: The Hammer

o Equal area;
o Equator and central meridian are striaght lines;
o Curvature of meridians increase as distance from
central meridian increases;
o Curvature of parallels increases with increasing
distance from the Equator.

This equal-area projection was developed in the late 19th
century by a German professor of surveying. It looks more
realistic than the other equal-area projection discussed here,
the Sinusoidal, but this realism comes at a price. Hammer's
projection has curved parallels and curved meridians, a feature
which makes it somewhat more difficult to construct. Of course,
it's a good choice for displaying global distributions because it
shows the whole world at a glance. Climatic data, the movement of
continents, the distribution of astronomical objects -- all have
been plotted on this projection in recent science journals.

Map 5: The Orthographic

o Perspective projection from infinite distance (like
the view through a telescope);
o Only one hemisphere can be shown at a time;
o Great distortion along the edge of the visible
hemisphere;
o Azimuthal -- directions from map center to every other
point on the map are shown correctly;

The problem in this projection is to determine whether or not
each point is visible from the viewing location (central meridian
and standard parallel) you choose. The Orthographic presents "the
view from infinity," the Earth as seen from far away in space.
The result is a map that looks very much like a globe. It is the
least useful map for making measurements because of the extreme
distortion near its edges -- in fact, the center of the map is
the only point without distortion. Unlike the other projections
mentioned here, the Orthographic plots only one hemisphere on a
single map. It is generally reserved for pictorial views, such as
for index maps in an atlas.

Scaling to a Graphics Board

CARTOG.PAS scales these maps for CGA graphics. To determine
how you alter the graphics constants for your specific system,
you must first examine the comment accompanying each of the
mapping procedures. In Procedure Sinusoidal, for example, the
comment states:

For R = 1: -Pi <= X <= Pi and -Pi/2 <= Y <= Pi/2.

This is the key for calculating the proper R to fill a given
graphics screen. R represents the radius of the scaled-down globe
from which the map is developed -- it's the radius of the globe
at the scale of the map. A large-scale map, such as a road map,
uses a very large "model" globe; a small-scale map, such as a
world map in an atlas, uses a small generating globe. This number
depends on the map projection, the size of the sheet on which the
map is being drawn, and the region being mapped.
To scale the maps to a computer screen, you need to know the
values returned by each map projection for a globe of unit
radius. You also need to know the resolution of your screen and
its aspect ratio -that is, the factor by which you need to divide
the X coordinate to compensate for non-square pixels. As an
example, let's find the R for displaying a full Sinusoidal map on
the CGA. The map's total range is 2Pi in X, Pi in Y. The map's X
axis must fit within 640 pixels, the Y axis must fit within 200
pixels. For the CGA, the aspect ratio is 2.4. So for X:

R = {( Screen - Screen ) / ( Map - Map )} / Aspect
Xmax Xmin Xmax Xmin

= (640 / 2Pi) / 2.4

= 42.4.

And for Y:

R = {(Screen - Screen) / (Map - Map )}
Ymax Ymin Ymax Ymin

= 200 / Pi

= 63.6.

The smallest R controls, so to fit a full Sinusoidal map on
the CGA requires an R of 42.4, which we rounded to 40 in
CARTOG.PAS. Note that this is also the correct value for the
Mercator and Equidistant Cylindrical projections. As it turned
out, we could use this value for all the projections, so we
defined it as a constant. In CARTOG, however, we make each map
fill the graphics screen by adjusting R when you choose a
projection. To make the Hammer and Orthographic maps as large as
possible on your graphics screen, you must go through the above
process to find the right R.
If you don't know the aspect ratio of your system, just plot
the Orthographic's grid and plug in values until it forms a
circle. Depending on your system, you may also need a different
aspect ratio to get proper screen dumps from your printer. The
following graphics constants work with most common display
resolutions.

EGA: Hercules: VGA:
CONST XCENTER = 320; XCENTER = 360; XCENTER = 320;
YCENTER = 174; YCENTER = 174; YCENTER = 240;
ASPECT = 1.37; ASPECT = 1.5; ASPECT = 1;
R = 70; R = 70; R = 70;

The Data

In programs like CARTOG, which require large quantities of
data, the file's format should be chosen carefully. You want to
take care to keep the size of the file small and facilitate fast
input. We decided against using an ASCII text file since the
conversion to binary numbers for the calculations would take too
long; a floating-point number format would have required a file
several times larger than the present one. The non-8087 version
of Turbo Pascal uses a floating-point format different from the
8087 version, further making portability a problem.
We decided to store the program's longitude and latitude
coordinates as integers. We chose to use a Pascal binary file.
The first two bytes of each record is a two-letter ASCII code:
'LS' means to draw line strings, beginning with the data point
in this record, and connect all subsequent points with records
containing an 'S' code. (This was done for reasons of downward
compatibility to other software and we have not yet bothered to
change it. Future versions of CARTOG will reduce this to one
byte.) Each record contains one data point consisting of a
longitude/latitude pair. The longitudes and latitudes are
stored as a (16 bit) integer representing hundredths of a
degree. Coordinates south of the equator and those west of
Greenwich are considered negative. This scheme produces a
relatively compact data file giving an adequate resolution of
data points for this purpose. The WORLD.DAT file distributed by
BYTE was compiled by the authors from two government-produced
world maps. For Antarctica, we used a polar view from the U.S.
Geological Survey's 1:40,000,000 "World Outline Map"; all else
was taken from the Defense Mapping Agency's "The World," which
is also available through the USGS. The resulting binary file,
which consists of about 6,000 latitude/longitude pairs, provides
a nice low-resolution view of the world.
We have subsequently obtained a high-resolution coastline
database from the Goddard Space Flight Center in Greenbelt,
Maryland. The smaller file contains about 15,000 points
(appropriate to a scale of about 1:8,000,000); the larger one
holds about 95,000 points (1:6,000,000), including international
boundaries and state boundaries within the U.S. For a nom-
inal copying/handling charge, we will be happy to send you these
data. All data are derived from WORLD DATABANK 1, which was ori-
ginally developed in the 1960s by the U.S. government.
For more information, feel free to contact me at the address
below:

Francis Reddy
c/o Parnau Graphics, Inc.
2857 S. 160th St.
New Berlin, WI 53151

Or call:

CompuServe (E-MAIL to Jeff Parnau) : 71555,126
Exec-PC BBS : 414-964-5160
TOPAZ BBS (E-MAIL to SYSOP or Frank Reddy): 414-784-6458

- - - - - - E N D - - - - - - -


 December 17, 2017  Add comments

Leave a Reply