4.2. Walkthrough of the Main Components

 < Day Day Up > 

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


4.2.1. MapServer Executable

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.

Web Server Considerations

MapServer depends on the web server; because of this, you need to remember how important the web server is. MapServer application developers need to be aware of changes in web server development that might affect their applications. This book doesn't describe how to install or manage a web server, but other books are available. O'Reilly has web server management and web development titles available at http://web.oreilly.com/. Two of the hottest web server topics are managing large volumes of requests and properly handling security; both are equally important for MapServer applications. O'Reilly books such as Web Security, Privacy, and Commerce or Apache: The Definitive Guide may be helpful.

In general, MapServer application developers should rely on web server managers to help make sure the applications are secure and can handle the load.


The focus of this chapter is on using MapServer to create a map image. MapServer can also create scale bars, legends, and reference/key maps for your application, as discussed in Chapters 10 and 11.

4.2.2. MapServer's Map File

MapServer is like an engine that requires fuel to run and a fuel delivery system to get the fuel to the engine. The MapServer program needs to know what map layers to draw, how to draw them, and where the source data is located. The data is the fuel, and the map file also known as the mapping file or .map file serves as the delivery system. The map file is a text configuration file that lists the settings for drawing and interacting with the map. It includes information about what data layers to draw, where the geographic focus of the map is, what projection system is being used, and which output image format to use, and it sets the way the legends and scale bars are drawn. An extremely simple version of a map file is shown in Example 4-1.

Example 4-1. A basic mapping file with one layer
 MAP   SIZE 600 300   EXTENT -180 -90 180 90   LAYER     NAME countries     TYPE POLYGON     STATUS DEFAULT     DATA countries.shp     CLASS       OUTLINECOLOR 100 100 100     END   END END

When a request comes to a MapServer application, the request must specify what map file to use. Then MapServer creates the map based on the settings in the map file. This makes the map file the central piece of any MapServer application. Map files are covered in greater detail in Chapter 10, where the process of creating a MapServer application is discussed.

4.2.3. Data Sources

If the map file is the fuel delivery system, the data sources are the fuel. MapServer can use a vast array of data sources to create maps. Out-of-the-box support covers the most common formats. Optional data access add-ons open up access to dozens of vector and raster formats (formats supported by the GDAL and OGR libraries). These may be GIS data files, database connections, or even flat comma-separated text files using the Virtual Spatial Data format capabilities of OGR.

MapServer can also use the OGC web specifications to access and share data across the Internet. Map layers can be requested from remote servers that also use OGC specifications. More on data sources is discussed in Chapter 5. For more about the purpose and goals of the OGC and OGC web services, see Chapter 12.

4.2.4. Output Map Image

While the map file is the central part of any MapServer application, the map image that is generated is usually what the end user is after. After all the layers are processed and written to a web-friendly graphics file, the user's web browser is then directed to load the image into the web page for viewing. Many first-time users experience problems with MapServer not returning the output map image. Chapter 11 covers in more detail how to set up MapServer to handle the map image.

The map isn't the only image that can be created. Scale bars, graphic legends and reference maps can also be part of a MapServer application. These are handled in a similar manner as the map image. Chapters 10 and 11 show examples that use these.

     < Day Day Up > 


    Web Mapping
    Web Mapping Illustrated: Using Open Source GIS Toolkits
    ISBN: 0596008651
    EAN: 2147483647
    Year: 2005
    Pages: 138

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net