XNA and GIS (3) – Using Fonts

The recent release of Microsoft’s XNA Game Studio Refresh offers one important new feature: font support. If we want to build any sort of mapping application, text is an absolute necessity. So here is a quick tutorial of how to incorporate font into a XNA program. For a complete description, check out the Game Studio documentation.

Font Preparation

Font is treated similar to any other 2D sprite in XNA except for the source of the texture. Instead of relying on graphics, XNA obtains the font from the font files already installed on your computer. Examples include Times New Roman, Courier New, and Arial.

Preparing to use a font is simple. In any XNA program, right-click in the Solution Explorer and select Add New Item. Scroll to the bottom and select the Sprite Font icon:

xna_spritefont


Read the rest of this entry »

XNA Game Studio Express Refresh

Microsoft has released an update (“refresh”) for the XNA Game Studio Express so I encourage everyone to go and download it. This update includes official support for fonts which we will start using very soon here at Spatial Horizons. Before you can install this 83MB update, you must have the C# Express Service Pack 1 installed first.

World Mapper (3)

This project continues our initial exploration into creating mapping applications using XNA. Last time we setup the basic application and today we will add some new functionality.

Resizing the Image

I first created a larger background image (800 pixels x 400) to be used for the rest of this project. Two new variables were added:

int mapWidth = 800;
int mapHeight = 400;

…and used in the Initialize Function:

graphics.PreferredBackBufferWidth = mapWidth;
graphics.PreferredBackBufferHeight = mapHeight;


Read the rest of this entry »

World Mapper (2)

We will now create a simple XNA program that uses some of the functionality discussed in our last 2 posts (XNA and GIS [1][2]). It will also introduce how to include input from the keyboard and mouse.

For the first time, we’ve added the option to download the source code at the bottom of this page. The primary reason for doing this is because our projects are becoming too complex to list the entire source code in the post itself. Instead, we will now try to highlight only the new and most important code snippets.


Read the rest of this entry »

XNA and GIS (2) – Using Textures

As mentioned in our previous post, XNA offers a graphical framework to build some cool mapping applications. We will first discuss several coding techniques as it relates to our objectives before building an actual XNA program. For more general XNA tutorials, I encourage you to see some of the sites discussed in the last post.

Open Visual C# Express (after installing the XNA Game Studio Express) and create a new Windows Game. The new project comes with all of the base XNA code already setup in several functions. In fact, you can go ahead and press F5 to compile and run the program right away. A form should display with a light blue background.


Read the rest of this entry »

XNA and GIS (1) – Introduction

Put very simply, our ultimate goal is to build a mapping application from scratch. Obviously, this will take some time so we will split this objective into several smaller projects. The first set of projects will work towards creating a program that features mapping, “mash-up” capabilities, and GPS integration.

Why build a GIS from scratch when there are both open source and proprietary mapping applications available? Because it’s fun…and it provides a tremendous learning experience on the core topics of geography and computer science. Having complete control over the program, from the map engine to the interface, also presents the unique opportunity to create an application designed exactly the way you want.


Read the rest of this entry »

GeoNames Search (3)

In our last post, we created an application that queried the GeoNames webservice and returned the results into a table. A logical next step would be to add the capability to map the results on a world map. So today will be use some of the code we already wrote for the WorldMapper project to add that functionality.

Here is how my final form looked after I added a world map picture and 2 new buttons:

GeoNames3


Read the rest of this entry »

GeoNames Search (2)

In this demonstration, a simple C# application will be created to search the GeoNames database and display the results in tabular form. Let’s begin by creating a new Windows Application in Visual C# Express.

A simple form can be set up to capture the necessary input parameters: location name, country, and the number of rows returned. At the bottom of the form, add a DataGridView control to display the XML results. My completed form looks like this:

GeoNamesSearch1


Read the rest of this entry »

GeoNames Search (1)

Geonames.org is a great resource for free geographic information. It is a collection of millions of locations that can be searched online or downloaded for offline use. In this project, we will build a simple application to query the Geonames web service and display the results in a table and on a map.


Read the rest of this entry »

World Mapper (1)

One of the objectives of this website is to create our own mapping applications. This requires a strong knowledge base of geography, mathematics, and computer programming. So before we can jump into the more advanced projects, we have to start with the basics. We’ve already been investigating GPS in our previous posts but today we will create a very basic mapping application.

Our “World Mapper” program begins by acquiring a map of the earth. I downloaded this one from Wikipedia Commons and shrunk it down to 400 pixels by 200 pixels.

WorldMap

Read the rest of this entry »