BUY THIS BOOK
Add to Cart

PDF $31.99

Safari Books Online

What is this?

Looking to Reprint or License this content?


Web Mapping Illustrated
Web Mapping Illustrated Using Open Source GIS Toolkits

By Tyler Mitchell
Book Price: $39.95 USD
£28.50 GBP
PDF Price: $31.99

Cover | Table of Contents | Colophon


Table of Contents

Chapter 1: Introduction to Digital Mapping
Not long ago, people drew and colored their maps by hand. Analyzing data and creating the resulting maps was slow and labor intensive. Digital maps, thanks to the ever-falling cost of processing power and storage, have opened up a whole new range of possibilities. With the click of a mouse or a few lines of code, your computer analyzes, draws, and color-themes your map data. From the global positioning system (GPS) in your car to the web site displaying local bus routes, digital mapping has gone mainstream.
Of course, learning to produce digital maps requires some effort. Map data can be used incorrectly, resulting in maps with errors or misleading content. Digital mapping doesn't guarantee quality or ethics, just like conventional mapping.
When you contrast the methods of conventional and digital mapping, the power of digital mapping becomes evident. The process of conventional mapping includes hand-drawn observations of the real world, transposed onto paper. If a feature changes, moves, or is drawn incorrectly, a new map needs to be created to reflect that change. Likewise if a map shows the extent of a city and that city grows, the extent of the map will need to be changed and the map will need to be completely recreated.
These problems are reduced with digital mapping. Because features are stored as distinct layers in a computer file, you can modify a map without starting from scratch. Once a feature is modified, the computer-based map instantly reflects the change the next time the feature is viewed. Interactive maps allow the user to view the precise area they are interested in, rather than be confined by the dimensions of a printed page. The user can also choose to view only certain pieces of content. The mapmaker doesn't have to guess which information the viewer wants to see but can make it possible for the reader to choose.
Instead of focusing on the details of a particular area of the world to map, the digital mapmaker can focus on how to best present information. This is much like the difference between an author and a web page designer. When you move into the digital realm, the focus is more on helping others find information rather than presenting static representations of information, as on a printed page. Today's mapmaker is often a web site developer, programmer, or some sort of geographic information analyst. Her focus is on managing and presenting information to a specific audience, be it in finance, forestry, or national defense, for instance.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
The Power of Digital Maps
When you contrast the methods of conventional and digital mapping, the power of digital mapping becomes evident. The process of conventional mapping includes hand-drawn observations of the real world, transposed onto paper. If a feature changes, moves, or is drawn incorrectly, a new map needs to be created to reflect that change. Likewise if a map shows the extent of a city and that city grows, the extent of the map will need to be changed and the map will need to be completely recreated.
These problems are reduced with digital mapping. Because features are stored as distinct layers in a computer file, you can modify a map without starting from scratch. Once a feature is modified, the computer-based map instantly reflects the change the next time the feature is viewed. Interactive maps allow the user to view the precise area they are interested in, rather than be confined by the dimensions of a printed page. The user can also choose to view only certain pieces of content. The mapmaker doesn't have to guess which information the viewer wants to see but can make it possible for the reader to choose.
Instead of focusing on the details of a particular area of the world to map, the digital mapmaker can focus on how to best present information. This is much like the difference between an author and a web page designer. When you move into the digital realm, the focus is more on helping others find information rather than presenting static representations of information, as on a printed page. Today's mapmaker is often a web site developer, programmer, or some sort of geographic information analyst. Her focus is on managing and presenting information to a specific audience, be it in finance, forestry, or national defense, for instance.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
The Difficulties of Making Maps
If you've worked with maps, digital or conventional, you'll know that despite my enthusiasm, mapping isn't always easy. Why do we often find it so difficult to make maps of the world around us? How well could you map out the way you normally drive to the supermarket? Usually, it's easier to describe your trip than it is to draw a map. Perhaps we have a perception of what a map must look like and therefore are afraid to draw our own, thinking it might look silly in comparison. Yet some maps drawn by a friend on a napkin might be of more use than any professional city map could ever be.
The element of personal knowledge, rather than general knowledge, is what can make a somewhat useful map into one that is very powerful. When words fail to describe the location of something that isn't general knowledge, a map can round out the picture for you. Maps can be used to supplement a verbal description, but because creating a map involves drawing a perspective from your head, it can be very intimidating. That intimidation and lack of ownership over maps has created an interesting dilemma. In our minds, maps are something that professionals create, not the average person. Yet a map like the one shown in Figure 1-1 can have much more meaning to someone than a professional map of the same area. So what are the professional maps lacking? They show mostly common information and often lack personal information that would make the map more useful or interesting to you.
Digital mapping isn't a new topic. Ever since computers could create graphic representations of the earth, people have been creating maps with them. In early computing, people used to draw with ASCII text-based maps. (I remember creating ASCII maps for role-playing games on a Tandy color computer.) However, designing graphics with ASCII symbols wasn't pretty. Thankfully, more sophisticated graphic techniques on personal computers allow you to create your own high-quality maps.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Different Kinds of Web Mapping
One very effective way to make map information available to a group of nontechnical end users is to make it available through a web page. Web mapping sites are becoming increasingly popular. There are two broad kinds of web mapping applications: static and interactive.
Static maps displayed as an image on a web page are quite common. If you already have a digital map (e.g., from scanning a document), you can be up and running very quickly with a static map on your web page. Basic web design skills are all you need for this because it is only a single image on a page.
This book doesn't teach web design skills. O'Reilly has other books that cover the topic of web design, from basic to advanced, including: Learning Web Design, Web Design in a Nutshell, HTML and XHTML: The Definitive Guide, and many more.
Interactive maps aren't as commonly seen because they require specialized skills to keep such sites up and running (not to mention the potential costs of buying off-the-shelf software). The term interactive implies that the viewer can somehow interact with the map. This can mean selecting different map data layers to view or zooming into a particular part of the map that you are interested in. All this is done while interacting with the web page and a map image that is repeatedly updated. For example, MapQuest is an interactive web mapping program for finding street addresses and driving directions. You can see it in action at http://www.mapquest.com.
Interactive maps that are accessed through web pages are referred to as web-based maps or simply web maps . These maps can be very powerful, but as mentioned, they can also be difficult to set up due to the technical skills required for maintaining a web server, a mapping server/program and management of the underlying map data. As you can see, these types of maps are fundamentally different from static maps because they are really a type of web-based program or application. Figure 1-2 shows a basic diagram of how an end user requests a map through a web mapping site and what happens behind the scenes. A user requests a map from the web server, and the server passes the request to the web mapping server, who then pulls together all the data. The map is passed all the way back to the end user's web browser.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Chapter 2: Digital Mapping Tasks and Tools
Maps can be beautiful. Some antique maps, found today in prints, writing paper, and even greeting cards, are appreciated more for their aesthetic value than their original cartographic use. The aspiring map maker can be intimidated by these masterpieces of science and art. Fortunately, the mapping process doesn't need to be intimidating or mystical.
Before you begin, you should know that all maps serve a specific purpose. If you understand that purpose, you've decoded the most important piece of a mapping project. This is true regardless of how the map is made. Traditional tools were pen and ink, not magic. Digital maps are just a drawing made up of points strung together into lines and shapes, or a mosaic of colored squares.
The purpose and fundamentals of digital mapping are no different and no more complex than traditional mapping. In the past, a cartographer would sit down, pull out some paper, and sketch a map. Of course, this took skill, knowledge, and a great deal of patience. Using digital tools, the computer is the canvas, and software tools do the drawing using geographic data as the knowledge base. Not only do digital tools make more mapping possible, in most cases digital solutions make the work ridiculously easy.
This chapter explores the common tasks, pitfalls, and issues involved in creating maps using computerized methods. This includes an overview of the types of tasks involved with digital mapping—the communication of information using a variety of powerful media including maps, images, and other sophisticated graphics. The goals of digital mapping are no different than that of traditional mapping: they present geographic or location-based information to a particular audience for a particular purpose. Perhaps your job requires you to map out a proposed subdivision. Maybe you want to show where the good fishing spots are in the lake by your summer cabin. Different reasons yield the same desired goal: a map.
For the most part, the terms geographic information and maps can be used interchangeably, but maps usually refer to the output (printed or digital) of the mapping process. Geographic information refers to digital data stored in files on a computer that's used for a variety of purposes.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Common Mapping Tasks
The process that produces a map requires three basic tasks: quantifying observations, locating the position of your observations, and visualizing the locations on a map. Digital tools have made these tasks more efficient and more accurate.
Quantifying observations
Measuring equipment such as laser range finders or imaging satellites provide discrete measurements that are less affected by personal interpretations. Traditional observations, such as manual photo interpretation or drawing features by hand, tend to introduce a biased view of the subject.
Locating positions of observations
Geographic referencing tools such as GPS receivers link on-the-earth locations to common mapping coordinate systems such as latitude and longitude. They calculate the receiver's location using satellite-based signals that help the GPS receiver calculate its location relative to satellites whose positions are well known. They act as a type of digital benchmark rather than using traditional survey or map referencing (best guess) methods. Traditional astronomical measurements or ground-based surveying techniques were useful but we now have common, consistent, and unbiased methods for calculating location.
Visualizing these locations on a map
Desktop mapping programs allow the user to compare location information with digital base map data. Traditional hand-drawn paper maps can't compete with the speed and flexibility of digital desktop mapping programs. Of course, digital mapping data is needed to do the job, but once data is available, infinite renditions of maps using the same base data is possible.
If a tool described here isn't effective, other tasks are affected. For example, poor recording of observations can still produce a map, but its accuracy is questionable.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Common Pitfalls, Deadends, and Irritations
Many maps can now be created in the safety of a home or office without the need to sail the seas to chart new territories. The traditional, nondigital methods of surveying to produce maps held certain dangers that are quite different from those of today. However, digital mapping has its own problems and irritations. The pitfalls today may not involve physical danger but instead involve poor quality, inappropriate data, or restricted access to the right kind of information.
A bad map isn't much better than a blank map. This book doesn't discuss good map design (the art of cartography), but an equally important factor plays into digital mapping: the quality of source data. Because maps are based on some sort of source data, it is imperative to have good quality information at the beginning. The maxim garbage in, garbage out definitely applies; bad data makes for bad maps and analysis. This is discussed in more detail in Chapter 5.
With the advent of digital mapping has come the loss of many traditional mapping skills. While digital tools can make maps, there are some traditional skills that are helpful. You might think that training in digital mapping would include the theory and techniques of traditional mapping processes, but it often doesn't. Today, many who do digital mapping are trained to use only a specific piece of software. Take away that software or introduce a large theoretical problem, and they may be lost. Map projection problems are a good example. If you don't understand how projections work, you can severely degrade the quality of your data when reprojecting and merging datasets as described in Chapter 8 and discussed in Appendix A.
Another example would be the ignorance of geometric computations. It was quite humiliating to realize that I didn't know how to calculate the area of an irregular polygon; nor was it even common knowledge to my most esteemed GIS colleagues. Figure 2-2 shows a range of common shapes and the formulae used to calculate their area.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Identifying the Types of Tasks for a Project
Just like carpenters, map makers know the value of using the right tool for the job. The digital map maker has a variety of tools to choose from, and each tool is designed for a certain task. Many tools can do one or two tasks well, and other tasks moderately well or not at all. There are five different types of tools used in digital mapping and its related disciplines. These are general categories which often overlap.
Viewing and mapping data aren't necessarily the same thing. Some applications are intended only for visualizing data, while others target map production. Map production is more focused on a high-quality visual product intended for print. In the case of this book, viewing tools are used for visually gathering information about the map data—how the data is laid out, where (geographically) the data covers, comparing it to other data, etc.
Mapping tools are used to publish data to the Internet through web mapping applications or web services. They can also be used to print a paper map. The concepts of viewing and mapping can be grouped together because they both involve a graphic output/product. They tend to be the final product after the activities in the following categories are completed.
Just viewing maps or images isn't usually the final goal of a project. Certain types of analysis are often required to make data visualization more understandable or presentable. This includes data classification (where similar features are grouped together into categories), spatial proximity calculations (features within a certain distance of another), and statistical summary (grouping data using statistical functions such as average or sum). Analysis tends to summarize information temporarily, whereas manipulating data can change or create new data.
This category can include creating features, which uses a process often referred to as digitizing. These features may be created as a result of some sort of analysis. For example, you might keep features that are within a certain study area.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Chapter 3: Converting and Viewing Maps
While presenting maps on the Web is fantastic, the data for those maps has to come from somewhere. You'll also want to have a toolkit for creating or modifying maps to fit your needs, especially if you're developing in an environment that isn't already GIS-oriented. This chapter introduces end-user applications for viewing and sharing data as well as low-level tools for data access and conversion.
While many other open source GIS and mapping tools exist, this chapter covers the small selection used throughout the remainder of this book. While many other excellent options exist, the sample of tools described here are robust enough for professional use. These free and open source GIS/mapping products are successfully used throughout industry, government, and academia.
For more general information and links to other tools, see the following reference web sites:
If you have the funds or already have the tools, you can, of course, use proprietary GIS software to create the data you'll be presenting with open source software. One of the best features of the open source tools is their ability to work with data created by proprietary applications and stored in proprietary formats.
The terms raster and vector are used throughout this chapter. They both refer to specific types of data. Raster data is organized as a matrix or grid that has rows and columns; each row/column intersection is a cell or pixel. Each cell has a value, for example, an elevation. Images and digital elevation models are rasters. They are a specific number of pixels high and wide, with each pixel representing a certain size on the ground; for example, Landsat satellite images are 185 × 185 km in size. Each pixel is 30 × 30 m in size.
Vector data is represented as coordinates that define points or points that are strung together to make lines and polygons. This data often has an associated table of information, one for every feature (point, line, or polygon) in the dataset. Keeping these distinctions in mind will help you better understand the remaining parts of this chapter.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Raster and Vector
The terms raster and vector are used throughout this chapter. They both refer to specific types of data. Raster data is organized as a matrix or grid that has rows and columns; each row/column intersection is a cell or pixel. Each cell has a value, for example, an elevation. Images and digital elevation models are rasters. They are a specific number of pixels high and wide, with each pixel representing a certain size on the ground; for example, Landsat satellite images are 185 × 185 km in size. Each pixel is 30 × 30 m in size.
Vector data is represented as coordinates that define points or points that are strung together to make lines and polygons. This data often has an associated table of information, one for every feature (point, line, or polygon) in the dataset. Keeping these distinctions in mind will help you better understand the remaining parts of this chapter.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
OpenEV
OpenEV is a powerful open source desktop viewer. It allows users to explore data in any of the image and vector data formats supported by the Geospatial Data Abstraction Library (GDAL/OGR), which will be introduced later in the chapter. OpenEV can be used for custom image analysis as well as drawing simple maps and creating new data. OpenEV comes as part of the FWTools package, available at http://fwtools.maptools.org.
Many users overlook OpenEV's ability to view and navigate in real time through images draped over 3D landscapes. Figure 3-1 shows an example of an image being viewed with OpenEV, and Figure 3-2 shows the same image but modified with one of the OpenEV image enhancement tools.
OpenEV is a good example of how GDAL/OGR capabilities can be accessed through other programming languages. OpenEV is built using Python, which makes OpenEV extensible and powerful because it has the flexibility of that language running behind it. The most powerful feature of OpenEV may be its ability to use Python capabilities within OpenEV; this allows access to GDAL/OGR functions and to any other Python module you need.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
MapServer
MapServer is the primary open source web mapping tool used in this book. The main MapServer site is at http://mapserver.gis.umn.edu.
There are numerous reasons people decide to use MapServer. One is the ability to make their mapping information broadly accessible to others, particularly over the Internet. Many GIS and mapping analysts need to create custom mapping products for those they support or work for; MapServer makes it possible for users to create maps without needing particular tools installed or assistance from mapping analysts. This in turn reduces the pressure on specialized staff.
Others come to MapServer because it is one of few solutions available for those with diverse data formats. MapServer, through the use of libraries such as GDAL/OGR, can access various data formats without data conversion.
Figure 3-1: A raw Landsat satellite image being viewed with OpenEV
Consider that you could have a collection of 10 different sets of mapping data, all of which need to appear on the same map simultaneously without any of the data being converted from its native format. The native formats can include those used by different commercial vendors. ESRI shapefiles, Intergraph Microstation design files (DGN), MapInfo TAB files, and Oracle spatial databases can all be mapped together without conversion. Other nonproprietary formats can be used as well, including the OGC standards for Geography Markup Language (GML), Web Map Server (WMS), Web Feature Server (WFS), and PostGIS and other databases. The ability to have simultaneous access to diverse data formats on the fly without conversion makes MapServer one of the only options for those who can't (or won't) do a wholesale conversion to a specific format.
Figure 3-2: A Landsat satellite image being viewed with OpenEV and an equalization enhancement
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Geospatial Data Abstraction Library (GDAL)
GDAL is part of the FWTools package available at http://fwtools.maptools.org. GDAL's home page (http://www.gdal.org) describes the project as:
...a translator library for raster geospatial data formats... As a library, it presents a single abstract data model to the calling application for all supported formats.
GDAL (often pronounced goodle) has three important features. First, it supports over 40 different raster formats. Second, it is available for other applications to use. Any application using the GDAL libraries can access all its supported formats, making custom programming for every desired format unnecessary. Third, prebuilt utilities help you use the functionality of the GDAL programming libraries without having to write your own program.
These three features offer a powerhouse of capability: imagine not worrying about what format an image is in. With GDAL supporting dozens of formats, the odds are that the formats you use are covered. Whether you need to do data conversion, display images in your custom program, or write a new driver for a custom image format, GDAL has programming interfaces or utilities available to help.
GDAL supports dozens of raster formats. This list is taken from the GDAL web site formats list page found at http://www.gdal.org/formats_list.html.
Arc/Info Binary Grid (.adf)
Microsoft Windows Device Independent Bitmap (.bmp)
BSB Nautical Chart Format (.kap)
VTP Binary Terrain Format (.bt)
CEOS (Spot, for instance)
First Generation USGS DOQ (.doq)
New Labelled USGS DOQ (.doq)
Military Elevation Data (.dt0, .dt1)
ERMapper Compressed Wavelets (.ecw)
ESRI .hdr labeled
ENVI .hdr labeled Raster
Envisat Image Product (.n1)
EOSAT FAST Format
FITS (.fits)
Graphics Interchange Format (.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
OGR Simple Features Library
OGR is part of the FWTools package that's available at http://fwtools.maptools.org. The OGR project home page (http://www.gdal.org/ogr) describes OGR as:
... a C++ open source library (and command line tools) providing read (and sometimes write) access to a variety of vector file formats including ESRI Shapefiles, S-57, SDTS, PostGIS, Oracle Spatial, and Mapinfo mid/mif and TAB formats.
The historical definition of the acronym OGR is irrelevant today, but it's used throughout the code base, making it difficult to change.
OGR supports more than 16 different vector formats and has utilities similar to GDAL's raster utilities.
The following list of the vector data formats supported by OGR was taken from the OGR formats web page at http://www.gdal.org/ogr/ogr_formats.html. The web page also shows which formats can be written or only read by OGR.
Arc/Info Binary Coverage
ESRI shapefile
DODS/OPeNDAP
FMEObjects Gateway
GML
IHO S-57 (ENC)
Mapinfo file
Microstation DGN
OGDI vectors
ODBC
Oracle Spatial
PostgreSQL
SDTS
UK .NTF
U.S. Census TIGER/Line
VRT: Virtual Datasource
OGR is part of the GDAL/OGR project and is packaged with GDAL. GDAL deals with raster or image data, and OGR deals with vector data. GDAL is to painting as OGR is to connect-the-dot drawings. These data access and conversion libraries cover the breadth of mapping data.
Like GDAL, OGR consists of a set of libraries that can be used in applications. It also comes with some powerful utilities:
ogrinfo
Interrogates a vector dataset and gives information about the features. This can be done with any format supported by OGR. The following code shows
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
PostGIS
PostgreSQL is a powerful enterprise-level relational database that is free and open source but also has commercial support options. It is the backbone of data repositories for many applications and web sites. Refractions Research (http://www.refractions.net) has created a product called PostGIS that extends PostgreSQL, allowing it to store several types of geographic data. The result is a robust and feature-rich database for storing and managing tabular and geographic data together. Having this ability makes PostgreSQL a spatial database, one in which the shapes of features are stored just like other tabular data.
PostgreSQL also has several native geometry data types, but according to Refractions, these aren't advanced enough for the kind of GIS data storage they needed. The PostGIS functions handle the PostGIS geometry types and not the native PostgreSQL geometry types.
This description is only part of the story. PostGIS isn't merely a geographic data storage extension. It has capabilities from other projects that allow it to manipulate geographic data directly in the database. The ability to manipulate data using simple SQL sets it ahead of many commercial alternatives that act only as proprietary data stores. Their geographic data is encoded so that only their proprietary tools can access and manipulate the data.
The more advanced PostGIS functions rely on an underlying set of libraries. These come from a Refraction project called Geometry Engine Open Source (GEOS). GEOS is a C++ library that meets the OGC specification for Simple Features for SQL. GEOS libraries can be used in custom applications and were not designed solely for use with PostGIS. For more information on GEOS, see http://geos.refractions.net/.
PostGIS allows you to use SQL statements to manipulate and create geographic data—for example, to buffer points and create circles. This is just the tip of the iceberg. PostGIS can be a GIS in and of itself while at the same time, all the power of PostgreSQL as a tabular database is available. GIS overlays, projecting and reprojecting of features into other coordinate systems, and spatial proximity queries are all possible using PostGIS. It is possible to have all the standard GIS overlay and data manipulation processes available in a server-side database solution. Example 3-1 illustrates the marriage of SQL and GIS capabilities by selecting points contained by another shape. More examples are shown in Chapter 13.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Summary of Applications
Table 3-1 summarizes the functions of each application discussed in this chapter: one checkmark shows peripheral use; two checks denotes common use.
Table 3-1: Summary of the types of functions each application generally plays
GDAL
OGR
PostGIS
OpenEV
MapServer
Viewing and mapping
Analysis
Manipulation
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Chapter 4: Installing MapServer
Whether you are preparing static map images for a web page or publishing an interactive web site, MapServer can do the job. Interactive maps allow users to zoom in to particular areas and turn map layers on or off. Applications can be made that let the user select a feature on the map and link it to other data. The possibilities are endless, but the final product is usually a point, click, and view process. The user identifies an area to view or a layer to look at, and the web page is updated with the requested content. If you need a static map, you can save the map for later use.
You can use MapServer from the command line or, for interested programmers, through an API. MapServer also can be used as a common gateway interface (CGI) application or scripted using common web programming languages such as PHP, Perl, Python, and Java. Whether using the CGI version or scripting your own, MapServer's runtime configuration files control what layers are shown and how they are drawn. Mapping data can easily be added to an existing application by editing the configuration file.
This chapter discusses what MapServer is, how it can be used, and how it works. It also covers how to set up the underlying programs that make up MapServer, so it can be used in custom applications. Examples of MapServer application development are given in Chapters 10 and 11.
MapServer usually works behind a web server application. The web server receives requests for maps and passes them to MapServer to create. MapServer generates the requested map image and hands it to the web server, which transmits it back to the user. Figure 4-1 shows how the user interacts with the web server which, in turn, makes requests to the MapServer program.
MapServer's primary function is reading data from various sources and pulling these layers together into a graphic file, also known as the map image. One layer may be a
Figure 4-1:
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
How MapServer Applications Operate
MapServer usually works behind a web server application. The web server receives requests for maps and passes them to MapServer to create. MapServer generates the requested map image and hands it to the web server, which transmits it back to the user. Figure 4-1 shows how the user interacts with the web server which, in turn, makes requests to the MapServer program.
MapServer's primary function is reading data from various sources and pulling these layers together into a graphic file, also known as the map image. One layer may be a
Figure 4-1: A diagram showing the basic operation of a MapServer application
satellite image, another the outline of your country or points showing a major city. Each layer is overlaid or drawn on top of the others and then printed into a web-friendly graphic for the user to see. A good example of the results of the overlapping and mapping process can be seen in Figure 4-2. You can see a satellite image (from a remote server), road lines, and city locations; the city labels are dynamically generated by MapServer.
This drawing process (a.k.a. rendering) occurs each time a request for a new map is made to MapServer, for instance, when a user zooms into the map for a closer look. This process also occurs when a user manually requests a redraw, such as when the content of one data layer changes, and the user wants to see the change.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Walkthrough of the Main Components
MapServer produces output graphic files based on the input requests from the user and how the map is defined. Key components include the MapServer executable or CGI program, a map file, data sources and output images. Figure 4-3 shows how all these components work together: after a user request, the MapServer CGI program accesses a map file, draws information from the data sources, and returns an image of the map.
Figure 4-2: A map showing various layers of information
The simplest form of MapServer runs as an executable CGI application on a web server. Technically, MapServer is considered an HTTP-based stateless process. Stateless means that it processes a request and then stops running. A CGI application receives requests from a web server, processes them, and then returns a response or data to the web server. CGI is by far the most popular due to its simplicity: no programming is required to get it working. You edit the text-based, runtime configuration file, create a web page, and then set them up to be served by a web server.
If you are a programmer, you don't need to use MapServer in CGI mode. Instead, you can create custom applications that use the MapServer API. However, this is considered an advanced topic, and an overview is discussed in Chapter 14.
Figure 4-3: Main MapServer application components
The MapServer CGI executable acts as a middle man between the mapping data files and the web server program requesting the map. The requests are passed in the form of CGI parameters from the web server to MapServer. The images that are created by MapServer are then fed back to the web server and, ultimately, to the user's web browser. More on the MapServer executable and how to install it is discussed later in this chapter.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Installing MapServer
MapServer runs on a variety of platforms, and the details for installing it vary depending on where you want to run it and how you want to integrate it with the rest of your system.
Many operating systems and processors can run MapServer successfully. A recent survey of MapServer application developers showed dozens of different implementations running on many processor speed and type combinations. Included in the survey results were the following operating systems:
  • Windows 2000, XP, 95
  • RedHat/SuSE/Debian/Mandrake Linux, Versions 6 through 9
  • Solaris
  • Mac OS X Panther
  • Vmware running Windows and Linux
  • FreeBSD
  • SCO Open Server
  • SGI IRIX
Reported processor speeds were as low as 120 MHz and as little as 64 MB of memory. Others use the latest processing and memory resources available. With the diversity and flexibility required to meet these cross-platform requirements many developers have found MapServer to be the only option for serving web-based maps.
Many documents or how-tos include information on compiling MapServer, which can lead you to assume that compiling MapServer from source code is required. For most users it isn't required. Acquiring binaries refers to the process of downloading executables and libraries that are ready to run on your operating system of choice, without compiling from source code.

Section 4.3.2.1: Windows versions

MapServer application designers wanting to use Microsoft Windows to run MapServer can download standard Windows packages that include everything you need to get started. The packages include all the required MapServer programs zipped into a single file for download. Packages are available from a few locations, including the main MapServer web site (
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Getting Help
During setup and installation of MapServer, there are different ways to get some help. These include commercial support, mailing lists, and an Internet relay chat (IRC) channel.
MapServer web site
  • The main web site with documentation is at http://mapserver.gis.umn.edu.
  • An FAQ is available at http://mapserver.gis.umn.edu/doc/mapserver-FAQ.html.
  • Bug tracking/reporting can be found at http://mapserver.gis.umn.edu/bugs/index.cgi.
MapServer mailing lists
  • Look for MapServer users at http://lists.umn.edu/archives/mapserver-users.html.
  • Find older archives at http://mapserver.gis.umn.edu/cgi-bin/wilma/mapserver-users.
  • Check out a searchable GMANE archive at http://dir.gmane.org/gmane.comp.gis.mapserver.user.
  • Find MapServer-dev at http://lists.gis.umn.edu/mailman/listinfo/mapserver-dev.
MapServer IRC channel
  • Look for #mapserver at irc.freenode.net.
Other references
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Chapter 5: Acquiring Map Data
You are probably eager to start on a project and try out all of these great tools. However, before you can jump in, you have some homework to do. The first step in any mapping project is identifying your data needs. Finding the information you require is your next step.
What you need will vary greatly depending on your goal, so you should first determine the goal or final product of your work. Along with this comes the need to assess what kind of map information you want to portray and at what level of detail. The following sections are a guide to thinking through all your requirements before starting a project.
If you want to make a custom map, you need to determine what kind of map data you require. There are two kinds of maps, each requiring different kinds of map data.
A vector map shows features made up of points, lines, or polygon areas, as in Figure 5-1. For instance, this can be a local road map or a global map showing locations of power stations and their respective countries.
An image or raster map is made from data sources such as aerial photography, satellite imagery, or computer-generated images of Earth's surface. Figure 5-2 shows an example of a raster map made from weather satellite data.
One variant of the raster map is the scanned map. When a paper map is scanned, it is converted into a digital raster map and can then be used as a layer on other maps. This is one way to make mapping data more readily available without having to recreate the maps using digital sources.
Figure 5-1: A vector map showing roads, country borders, and some major cities in North America
Figure 5-2: A raster map showing cloud cover over North America
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Appraising Your Data Needs
What you need will vary greatly depending on your goal, so you should first determine the goal or final product of your work. Along with this comes the need to assess what kind of map information you want to portray and at what level of detail. The following sections are a guide to thinking through all your requirements before starting a project.
If you want to make a custom map, you need to determine what kind of map data you require. There are two kinds of maps, each requiring different kinds of map data.
A vector map shows features made up of points, lines, or polygon areas, as in Figure 5-1. For instance, this can be a local road map or a global map showing locations of power stations and their respective countries.
An image or raster map is made from data sources such as aerial photography, satellite imagery, or computer-generated images of Earth's surface. Figure 5-2 shows an example of a raster map made from weather satellite data.
One variant of the raster map is the scanned map. When a paper map is scanned, it is converted into a digital raster map and can then be used as a layer on other maps. This is one way to make mapping data more readily available without having to recreate the maps using digital sources.
Figure 5-1: A vector map showing roads, country borders, and some major cities in North America
Figure 5-2: A raster map showing cloud cover over North America
A map often combines vector and raster data to create a more effective map than either could produce in isolation, as in Figure 5-3. Pure vector maps and pure raster maps are at opposite ends of a continuum of map types; many maps include both kinds of data.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Acquiring the Data You Need
Once you have determined your mapping and data needs, you have to find the appropriate data. To find such data, you can, for example, search the Internet, trade with friends, or download from a government site. This chapter takes you through several examples from searching for premade maps to finding data to do your own mapping and conversion.
Sometimes all you want is a premade, basic map of the world or a specific country. The Internet can be a good place to find these. One excellent site is the CIA World Factbook at http://www.cia.gov/cia/publications/factbook/geos/ag.html. Here you will find a basic political map for every country and also a detailed demographic, cultural, and political summaries. Large-size, print-quality reference maps are also available in Portable Document Format (PDF).
Another good resource is the University of Texas Online Map Library at http://www.lib.utexas.edu/maps/. With a brief walk through some of the links, you can find diverse maps that show, for example, a street map of Baghdad or a shaded relief map of the United Kingdom, nicely showing the Scottish Highlands. The library has scanned many of these maps and made them available to the public domain.
Premade maps from images or shaded elevation models are also available. The CIA Factbook (http://www.cia.gov/ciapublications/factbook) has small political maps for each country. Other reference maps that show more physical data (e.g., bathymetry and elevation) or even photographic examples of the earth can be found. The U.S. National Geophysical Data Center (NGDC) includes some beautiful premade gallery images of their more detailed source data; look for them at http://www.ngdc.noaa.gov/seg/topo/globegal.shtml.
The Internet contains a wealth of geographic information for your projects. It is a natural place to begin your quest for mapping data. Some government agencies make their mapping data freely available on the Internet. Certain organizations have even made it their mission to make mapping data available for others for free. Other groups have created catalogs of mapping data you can search.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Chapter 6: Analyzing Map Data
Finding data is helpful, but sometimes you need to explore it or do basic manipulation before you're ready to use it in your own maps. This chapter will lead you through acquiring the tools and data for some sample projects. Some of this sample data will be used in examples in other chapters as well. The techniques shown here don't produce lovely maps by themselves, but they can save you immense frustration when you go to use data to create maps.
This section will walk you through the process of acquiring some fairly simple data for the U.S. state of Minnesota. In order to keep things simple, you will use a well-known MapServer demonstration dataset. The MapServer web site always has copies of the latest versions of MapServer software available as well as demonstration datasets and applications.
First, go to http://mapserver.gis.umn.edu/dload.html. Beside the latest download version file, you will see a link to demo. This links to a ZIP file called workshop.zip.
The full path is http://maps.dnr.state.mn.us/mapserver_demos/workshop.zip. Now, download, and unzip the contents of this file. All you really need is the workshop/data folder.
Where you unzip doesn't matter, but you need to ensure that the folders contained in the archive are recreated when unzipped. This is usually the default for your archive software. In Winzip, this option is called Use Folder Names.
If you examine the contents of the data folder you will find 49 files. These are map data files in ESRI shapefile format and GeoTIFF images. To learn more about them, you will use a tool from the GDAL project. GDAL comes bundled with the FWTools package, as does the OpenEV viewer and other utilities used in this book.
You can acquire the latest version of FWTools for your operating system or distribution from http://fwtools.maptools.org/. Examples used in this book are for the Linux operating system, but for Windows users, I have included notes wh