Tutorials

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…)

Using QGIS (4) – Raster Images

Wednesday, September 26th, 2007

Raster Image Sample

Geographic data can be separated into 2 types: vector and raster data. We’ve already introduced vector data (points, lines, and polygons) in our previous posts on QGIS. We now need to briefly discuss raster images and how to use them.

In terms of GIS, raster images (often referred to as just “rasters”) are pixel-based images of places on the earth. They are often captured from cameras on satellites or airplanes and the pictures can be taken in color, black and white, or include infrared wavelengths.

(more…)

Using QGIS (3) – More Layer Symbology

Sunday, September 23rd, 2007

This post continues a look at the basics of GIS using the mapping program Quantum GIS (QGIS). We’ve already covered how to install and use QGIS in a previous post. In addition, we also introduced shapefiles, including how to download and use them in QGIS. Before moving on to another topic, it is worth demonstrating another example of downloading a shapefile and setting up it’s symbology in QGIS.

Data Download

Shapefiles generally come in three types – points, lines, and polygons. Our previous examples have used line shapefiles but this time we will download a polygon shapefile. For example, we downloaded a countries of the world shapefile found here that looks like this when loaded into QGIS:

Countries of the World Shapefile

(more…)

Using QGIS (2) – Layer Symbology

Monday, September 17th, 2007

Our first post on using QGIS introduced the software along with how to download shapefiles, one of the most common GIS formats. Now we will explore how to use QGIS to make a better looking map.

Data Download

This time we are going to download a roads shapefile from the State of Michigan’s Center for Geographic Information. They offer downloads by county so go ahead and select a county and then chose to download the “MI Geographic Transportation” zip file. This zip file contains 3 shapefiles (named stroads, allroads, and railroad) but we will just use the “allroads” shapefile. For our example, we used the roads shapefile from the Washtenaw County transportation file.

Roads Symbology

Open QGIS and add the allroads shapefile.

QGIS Roads Plain

(more…)

Using QGIS (1) – Introduction

Sunday, September 9th, 2007

We’ve briefly mentioned QGIS before but it is worth a more in-depth look now. Some of our upcoming projects will require downloading and using GIS data so QGIS is a great program for viewing the data. In their own words,

Quantum GIS (QGIS) is a user friendly Open Source Geographic Information System (GIS) that runs on Linux, Unix, Mac OSX, and Windows. QGIS supports vector, raster, and database formats. QGIS is licensed under the GNU General Public License. QGIS lets you browse and create map data on your computer. It supports many common spatial data formats (e.g. ESRI ShapeFile, geotiff).

Let’s quickly describe how to install QGIS, download data, and make a basic map. This post is primarily for those who have not used GIS software or data before.

QGIS Installation

Download the current release (v0.8.1) of QGIS here and run the installation program. They recommend installing it to a file path without spaces (e.g. C:\QGIS) to enable GRASS functionality which we may use later on.

Running QGIS opens a blank map:

QGIS Blank Map

(more…)

Map Tiles (4) – XNA Program

Monday, August 13th, 2007

The last three posts discussed map tiles in some detail but without getting into programming. First, we described terminology surrounding map tiles. Then we setup a sample TileMap from an image of the world. And finally, we covered some “tile math” examples. Now we will wrap everything up by developing a mapping program that uses map tiles.

The program we created was built off one of our previous projects (see World Mapper parts 1,2,3) and, as always, the XNA framework. This project turned out to be much more complex than any of our previous programs so it would be impossible to cover all the source code in detail. Instead, this post will provide an overview of the program’s structure and then provide the source code for you to download and explore on your own.
(more…)

Map Tiles (3) – Tile Math

Monday, August 6th, 2007

Before using our Tile Map we created in the last post, a quick discussion on “tile math” might be helpful. More specifically, we need be able to easily switch between tile coordinates and real-world coordinates to create a complete tile mapping program.

We will use this map tile as an example:

Map Tile Sample
(more…)

Map Tiles (2) – Sample TileMap

Tuesday, July 24th, 2007

Our last post introduced the concept of map tiles and the benefits for using them in a desktop application. Before using map tiles in XNA, we need to create a sample “TileMap”. Normally, tile maps would be created automatically using some GIS or Mapping program. To gain a better understanding though, we will manually create a set of map tiles using this world map that we have used before:

World Map

The original image from the Wikimedia Commons is over 8 MB in size so we can cut it up in a graphics program and create each tile individually. All tiles will be the same size – 800 pixels wide by 400 pixels tall. Our sample TileMap will have 3 TileSets each a different scale (also referred to as “zoom levels”). They will be numbered from 0 to 2 with 0 being the farthest from ground level.
(more…)

Map Tiles (1) – Introduction

Sunday, July 15th, 2007

Google Maps ushered in a new era in web mapping: pre-rendered map tiles. Traditionally, web mapping followed a 4-tiered approach for generating map images:

Web Mapping 4 Steps

The benefits in this scenario are obvious. Maps at any scale can be produced and layers of information (e.g. roads, lakes, etc.) can be turned on or off with each map request. Map colors, shapes, and symbols can even be changed between requests. The unlimited possibilities come a cost though of slower rendering because each request requires the raw data to be accessed, combined with other layers, and the returned as a single image.
(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…)