Archive for the 'Mapserver' Category

Using MapServer (3) - CGI MapServer

Sunday, December 9th, 2007

This post is the third in a series on using MapServer. First-time visitors are encouraged to read part 1 to learn how to download and install MapServer on their computer. Additionally, the data layers used in this tutorial are available to download in this post.

We’ve already introduced MapServer and showed how to create a mapfile using GIS data. We will now introduce MapServer’s CGI functionality as a way to generate a map image. Later we will build on what we’ve learned to create a map using OpenLayers, a web mapping interface.

Introducing Mapserv.exe

At the heart of MapServer is a single file referred to as “mapserv”. With the MS4W package, it is a single executable found at C:\ms4w\Apache\cgi-bin\mapserv.exe. This file is the map production engine that uses a mapfile to generate a map image.

Mapserv.exe is usually accessed internally by MapServer-based packages such as ka-map or Mapscript. But it can also be called directly from a web browser as long as some required parameters are included.
(more…)

Using MapServer (2) - Generating Map Tiles

Wednesday, November 14th, 2007

This post is the second in a series on using MapServer. First-time visitors are encouraged to read part 1 which details how to download, setup, and create a web mapping site using MapServer. Additionally, the topic of map tiles has already been introduced in a previous series.

Once the MapServer for Windows (MS4W) package with ka-Map is installed on your local machine, some new mapping functionality becomes available. One area that interests us is the ability to automatically generate a set of map tiles.

ka-Map Configuration

The first step in creating a set of map tiles is to configure ka-Map to point to a valid MapServer mapfile (see here for more on a mapfile). Navigate to this directory: C:\ms4w\apps\ka-map-1.0\include and open the file named config.php in any text editor.

This configuration file contains several parameters which you should be familiar with before creating our map tiles. We won’t change any of their values yet but it is important to understand what they do. First, on lines 73 and 74, the pixel size of each tile to be generated is defined:

$tileWidth = 256;
$tileHeight = 256;

Lines 106 through 110 define the most important parameters:

$aszGMap = array (
         'title' => 'GMap 75',
         'path' => '../../gmap/htdocs/gmap75.map',
         'scales' => array( 40000000, 25000000, 12000000, 
                                 7500000, 3000000, 1000000 ),
         'format' =>'PNG'
 );

(more…)

Using QGIS (5) - Export to MapServer

Saturday, October 6th, 2007

Our last post for now on QGIS will cover an interesting feature added in the recent versions. A new “Export to MapServer Map” command creates a MapServer configuration file (simply called a “mapfile”) from an existing QGIS map. That mapfile can be used to then display the data on a website or use it in a desktop application. The desktop option is what we will take a look at because we will now have an easy way to create a mapfile that we can use with some of our MapServer/XNA tutorials we demonstrated in the past.

Python Installation

The Export to MapServer tool will only work if the Python programming language is installed on your computer. The latest version (2.5.1) of Python is required so we first need to download and install it here.

Open a QGIS Map

After the installation, go ahead and open a QGIS map. We will continue to use the world map project created in the previous posts. As a reminder, we have two layers in our map - a vector layer showing country outlines and a raster background image.

QGIS Map

(more…)

Mapscript and XNA (3)

Sunday, July 8th, 2007

Continuing with our program that combines Mapserver (via the Mapscript API) and XNA, we next added functionality to the update method our of XNA program. We check for a mouse click to initiate a map pan and also for key presses to zoom in, out and return to full extent. At the end, if any map event has occurred, the map will be updated. It is in the updating that a new Mapserver image is generated and prepared for displaying on-screen.

protected override void Update(GameTime gameTime)
{
    // check if a mouse click has occured
    mouse.Update();
    if (mouse.LeftButton == ButtonState.Pressed)
    {
        mapserver.ZoomMap(1, mouse.X, mouse.Y);
    }
 
    // check if a key has been pressed
    KeyboardState keyState = Keyboard.GetState();
    if (keyState.IsKeyDown(Keys.F))
    {
        graphics.ToggleFullScreen();
    }
    else if (keyState.IsKeyDown(Keys.Z))
    {
        mapserver.ZoomMap(2, mapserver.MapPixelCenter.X, 
                      mapserver.MapPixelCenter.Y);
    }
    else if (keyState.IsKeyDown(Keys.X))
    {
        mapserver.ZoomMap(-2, mapserver.MapPixelCenter.X, 
                      mapserver.MapPixelCenter.Y);
    }
    else if (keyState.IsKeyDown(Keys.C))
    {
        mapserver.ZoomMapFullExtent();
    }
    else if (keyState.IsKeyDown(Keys.Escape))
        this.Exit();
 
    // check if a new mapserver image needs to be generated
    if (mapserver.RefreshMap)
    {
        mapserver.UpdateMap(graphics.GraphicsDevice);
    }
 
    base.Update(gameTime);
}

(more…)

Mapscript and XNA (2)

Sunday, July 1st, 2007

In order to use Mapserver in XNA, we need to create a class that primarily serves as an interface between XNA and Mapscript (Mapserver’s API). Our last post discussed in general how to accomplish this but now let’s add some code.

MapserverXNA Class

We named the class MapserverXNA and the properties and methods look like this:

UML MapserverXNA Class
(more…)

Mapscript and XNA (1)

Sunday, June 24th, 2007

We’ve demonstrated a number of smaller projects over the past couple of months showcasing some simple mapping and XNA applications. Now things are starting to get more interesting as we build upon what we’ve learned in an effort to create more interesting products. This next series of posts combines aspects from several of our projects, including World Mapper, Using Mapserver, Mapscript Demo, and the Image Swapping example. Basically, we now have the opportunity to incorporate Mapserver-generated images into an XNA program.

(more…)

Mapscript Demo (3)

Saturday, June 9th, 2007

Mapscript Desktop Program
The final portion of this project involves adding some map functionality to our program. As a quick review, we first setup Mapserver on our computer and then created a simple desktop application (part 1, part 2) that used the Mapscript API.
(more…)

Mapscript Demo (2)

Saturday, June 2nd, 2007

Continuing with our exploring into Mapscript, our desktop mapping application needs some more setup. Our last post added a map file constant and now we will add two more variables to our form:

const string MAP_FILE = @"C:\ms4w\apps\gmap\htdocs\gmap75.map";
mapObj m_map;
rectObj m_fullExtent;

Both are Mapscript objects. The first (m_map) is our map object that will be the primary class used in this project. The second will simply remember the extent of the map upon startup, which is usually also the full extent of the map.

In the form’s constructor method, we setup our map to match our picture box size and the define the full extent:

m_map = new mapObj(MAP_FILE);
m_map.width = picMap.Width;
m_map.height = picMap.Height;
m_fullExtent = new rectObj(m_map.extent.minx, m_map.extent.miny, 
                   m_map.extent.maxx, m_map.extent.maxy, 0);

(more…)

Mapscript Demo (1)

Saturday, May 26th, 2007

In our last post, we setup MapServer using the MS4W package. That tutorial enabled us to have a working web mapping environment on a desktop machine without much hassle. If you haven’t read that post, I encourage you to read it before continuing.

Today’s project will build off that setup by creating a small desktop application that uses MapServer’s ability to generate map images. Since MapServer is just a program (mapserv.exe) and some required DLLs, it is possible to create stand-alone applications that don’t have a web component.

Introducing Mapscript

In their own words

MapScript provides a scripting interface for MapServer for the construction of Web and stand-alone applications. MapScript is used independently of CGI MapServer, it is a loadable module that adds MapServer capability to your favorite scripting language. MapScript currently exists in Php, Perl, Python, Ruby, Tcl, Java, and C# flavors.

(more…)

Using MapServer (1) - 10 Minute Tutorial

Saturday, May 19th, 2007

UPDATE: This post was originally posted in May 2007 but since has been updated to cover the more recent release of Mapserver version 5.0.0.

Most of our recent posts have focused on topics relating more to the components of a mapping application then on the maps and data. This post begins the first of several posts discussing free and open source mapping software applications. After introducing each software, we will explore various ways to create applications around them.

Introduction to MapServer

One of the most popular open source GIS applications is MapServer. Initially developed by the University of Minnesota, MapServer has evolved into a fast and easy-to-use internet map server.

“MapServer is an Open Source development environment for building spatially-enabled internet applications. MapServer is not a full-featured GIS system, nor does it aspire to be. Instead, MapServer excels at rendering spatial data (maps, images, and vector data) for the web.” - http://mapserver.gis.umn.edu/

(more…)