<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" version="2.0">

<channel>
	<title>Spatial Horizons</title>
	
	<link>http://spatialhorizons.com</link>
	<description>Exploring Geographic Technologies with GIS, GPS, C#, XNA, and Open Source Tools</description>
	<lastBuildDate>Thu, 18 Sep 2008 19:00:31 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/SpatialHorizons" type="application/rss+xml" /><feedburner:emailServiceId xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">SpatialHorizons</feedburner:emailServiceId><feedburner:feedburnerHostname xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">http://feedburner.google.com</feedburner:feedburnerHostname><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><item>
		<title>New Version Coming Soon</title>
		<link>http://spatialhorizons.com/2008/02/09/new-version-coming-soon/</link>
		<comments>http://spatialhorizons.com/2008/02/09/new-version-coming-soon/#comments</comments>
		<pubDate>Sat, 09 Feb 2008 18:35:41 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[Site News]]></category>

		<guid isPermaLink="false">http://spatialhorizons.com/2008/02/09/new-version-coming-soon/</guid>
		<description><![CDATA[Spatial Horizons was launched in 2006 to provide instruction and inspiration to readers interested in applications of geographic information systems (GIS). Our focus was to provide unique examples of geographic technologies in action.  For example, we learned how to use C# to read location information from a GPS device. We also took advantage of [...]]]></description>
			<content:encoded><![CDATA[<p>Spatial Horizons was launched in 2006 to provide instruction and inspiration to readers interested in applications of geographic information systems (GIS). Our focus was to provide unique examples of geographic technologies in action.  For example, we learned <a href="http://spatialhorizons.com/category/gps/">how to use C# to read location information from a GPS device</a>. We also took advantage of Microsoft&#8217;s new game development platform, XNA, to demonstrate <a href="http://spatialhorizons.com/category/xna/">how to build more powerful mapping applications</a>.</p>
<p><strong>Update:</strong> In 2008, Spatial Horizons is currently on hiatus while we work on other projects.  The future is uncertain but we hope to return in some form in 2009.  Stay tuned&#8230;  </p>
]]></content:encoded>
			<wfw:commentRss>http://spatialhorizons.com/2008/02/09/new-version-coming-soon/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>OpenLayers (1) – 10 Minute Tutorial</title>
		<link>http://spatialhorizons.com/2007/12/16/openlayers-1-10-minute-tutorial/</link>
		<comments>http://spatialhorizons.com/2007/12/16/openlayers-1-10-minute-tutorial/#comments</comments>
		<pubDate>Sun, 16 Dec 2007 15:08:51 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[OpenLayers]]></category>

		<guid isPermaLink="false">http://spatialhorizons.com/2007/12/16/openlayers-1-10-minute-tutorial/</guid>
		<description><![CDATA[This post introduces OpenLayers as a easy way to embed dynamic maps in a web page. First-time visitors are encouraged to read our previous posts on setting up MapServer and CGI MapServer for background information.
OpenLayers is a javascript library for creating maps on a web page. In their own words,
OpenLayers is a pure JavaScript library [...]]]></description>
			<content:encoded><![CDATA[<p class="moreinfo">This post introduces <a href="http://www.openlayers.org/">OpenLayers</a> as a easy way to embed dynamic maps in a web page. First-time visitors are encouraged to read our previous posts on <a href="http://spatialhorizons.com/2007/05/19/mapserver-1-10-minute-tutorial/">setting up MapServer</a> and <a href="http://spatialhorizons.com/2007/12/09/using-mapserver-3-cgi-mapserver/">CGI MapServer</a> for background information.</p>
<p>OpenLayers is a javascript library for creating maps on a web page. In their own words,</p>
<p class="shquote">OpenLayers is a pure JavaScript library for displaying map data in most modern web browsers, with no server-side dependencies. OpenLayers implements a (still-developing) JavaScript API for building rich web-based geographic applications, similar to the Google Maps and MSN Virtual Earth APIs, with one important difference &#8212; OpenLayers is Free Software, developed for and by the Open Source software community. &#8211; <a href="http://www.openlayers.org/">http://www.openlayers.org/</a></p>
<p>Setting up OpenLayers is incredibly easy if you want to display data from other existing sources on the web. See their <a href="http://www.openlayers.org/QuickTutorial/">Quick Tutorial</a> page for lots of sample HTML showing how to add a basic map in a web page.  In this tutorial, we will focus on how to create a map that uses our own data from MapServer.<br />
<span id="more-62"></span><br />
<strong>Tutorial Requirements</strong></p>
<p>Before beginning, you should already have MapServer setup on your computer. See our <a href="http://spatialhorizons.com/2007/05/19/mapserver-1-10-minute-tutorial/">previous post</a> to complete this task using the <a href="http://www.maptools.org/ms4w/">MS4W package</a>. Additionally, we will use GIS data and a MapServer mapfile from our <a href="http://spatialhorizons.com/2007/12/09/sample-dataset-world-map/">World Map sample dataset</a>.</p>
<p><strong>Download a Web Page from OpenLayers.org</strong></p>
<p>OpenLayers.org has a great <a href="http://openlayers.org/presentations/mappingyourdata/">screencast tutorial </a> showing how to setup and use OpenLayers. Accompanying the tutorial is a <a href="http://trac.openlayers.org/wiki/MappingYourData">wiki page</a> describing the steps covered in the video.  At the bottom of this page is a link to download an HTML document named lite.html that contains a good starting point for our tutorial. </p>
<p>Go ahead and download the file (<a href="http://trac.openlayers.org/attachment/wiki/MappingYourData/lite.html">direct link here</a>) to your desktop and open it in your favorite text editor. On line 10, note the reference to OpenLayers javascript file:</p>
<p>
<pre class="html">script src="http://openlayers.org/dev/lib/OpenLayers.js"</pre>
</p>
<p>Further down, lines 13 through 20 contain the all the javascript code necessary to embed a MapServer map in the web page:</p>
<p>
<pre lang="javascript">var map, layer;

function init(){
   map = new OpenLayers.Map( 'map' );
   layer = new OpenLayers.Layer.MapServer( "OpenLayers WMS",
       "http://labs.metacarta.com/wms/vmap0", {layers: 'basic'} );
   map.addLayer(layer);
   map.zoomToMaxExtent();</pre>
</p>
<p>In fact, without changing anything, you could open the web page in a browser and it will work fine because the data is coming from a remote server. The controls in the upper-left corner can be used to navigate around the map.</p>
<p><img src="http://spatialhorizons.com/wp-content/uploads/2007/12/openlayers_default.jpg" alt="<br />
OpenLayers" /></p>
<p><strong>Customizing the Javascript</strong></p>
<p>In order for the web page to display our own MapServer data, several changes need to be made to the Javascript in HTML file. </p>
<p>On line 17, the layer is initialized using the <a href="http://dev.openlayers.org/apidocs/files/OpenLayers/Layer/MapServer-js.html">OpenLayers.Layer.MapServer</a> class. Several parameters are required for the layer to work correctly. In the default example, the layer is named OpenLayers WMS (<a href="http://en.wikipedia.org/wiki/Web_map_server">Web Map Server</a>) and the MapServer location is http://labs.metacarta.com/wms/vmap0. The third parameter is informing the server to request the &#8220;basic&#8221; layer.</p>
<p>For our demonstration, we need to change the three parameters. First we will change the name to World Map. Next, we need to change the location to point to MapServer running on our local machine. Remembering our <a href="http://spatialhorizons.com/2007/12/09/using-mapserver-3-cgi-mapserver/">last post</a> on CGI MapServer, we already know that the path is <strong>http://localhost/cgi-bin/mapserv.exe</strong>. And finally, instead of requesting a layer name, we can just provide a file path to a mapfile. The final result looks like this:</p>
<p>
<pre lang="javascript">var map, layer;

function init(){
    map = new OpenLayers.Map( 'map' );
    layer = new OpenLayers.Layer.MapServer( "World Map",
       "http://localhost/cgi-bin/mapserv.exe", {map: 'C:/world_mapfile.map'} );
    map.addLayer(layer);
    map.zoomToMaxExtent();
}</pre>
</p>
<p>Save the file and open lite.html in a web browser. The map should now display your data described in the mapfile.</p>
<p><img src="http://spatialhorizons.com/wp-content/uploads/2007/12/openlayers_map1.jpg" alt="OpenLayers Map" / ></p>
<p><strong>More to Come</strong></p>
<p>OpenLayers offers a wide range of functionality that can be added our simple example.  For a list of examples, see <a href="http://trac.openlayers.org/wiki/UserRecipes">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://spatialhorizons.com/2007/12/16/openlayers-1-10-minute-tutorial/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using MapServer (3) – CGI MapServer</title>
		<link>http://spatialhorizons.com/2007/12/09/using-mapserver-3-cgi-mapserver/</link>
		<comments>http://spatialhorizons.com/2007/12/09/using-mapserver-3-cgi-mapserver/#comments</comments>
		<pubDate>Sun, 09 Dec 2007 15:15:44 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[Mapserver]]></category>

		<guid isPermaLink="false">http://spatialhorizons.com/2007/12/09/using-mapserver-3-cgi-mapserver/</guid>
		<description><![CDATA[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&#8217;ve already introduced MapServer and showed how to create a mapfile [...]]]></description>
			<content:encoded><![CDATA[<p class="moreinfo">This post is the third in a series on using <a href="http://mapserver.gis.umn.edu/">MapServer</a>. First-time visitors are encouraged to read <a href="http://spatialhorizons.com/2007/05/19/mapserver-1-10-minute-tutorial/">part 1</a> 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 <a href="http://spatialhorizons.com/2007/12/09/sample-dataset-world-map/">post</a>.</p>
<p>We&#8217;ve already <a href="http://spatialhorizons.com/2007/05/19/mapserver-1-10-minute-tutorial/">introduced MapServer</a> and <a href="http://spatialhorizons.com/2007/10/06/using-qgis-5-export-to-mapserver/">showed how to create a mapfile</a> using <a href="http://spatialhorizons.com/faqs#gis">GIS</a> data.  We will now introduce MapServer&#8217;s <a href="http://en.wikipedia.org/wiki/Common_Gateway_Interface">CGI</a> functionality as a way to generate a map image. Later we will build on what we&#8217;ve learned to create a map using <a href="http://www.openlayers.org/">OpenLayers</a>, a web mapping interface.</p>
<p><strong>Introducing Mapserv.exe</strong></p>
<p>At the heart of MapServer is a single file referred to as &#8220;mapserv&#8221;. With the <a href="http://www.maptools.org/ms4w/">MS4W package</a>, it is a single executable found at <strong>C:\ms4w\Apache\cgi-bin\mapserv.exe</strong>. This file is the map production engine that uses a mapfile to generate a map image. </p>
<p>Mapserv.exe is usually accessed internally by MapServer-based packages such as <a href="http://ka-map.maptools.org/">ka-map</a> or <a href="http://spatialhorizons.com/2007/05/26/mapscript-demo-1/">Mapscript</a>. But it can also be called directly from a web browser as long as some required parameters are included.<br />
<span id="more-140"></span><br />
<strong>Mapping from the Web Browser Address Bar</strong></p>
<p>In order to demonstrate Mapserv.exe, we already need to have some data and a mapfile ready to use.  We will be using the data and mapfile from our <a href="http://spatialhorizons.com/2007/12/09/sample-dataset-world-map/">World Map dataset</a>.</p>
<p>Open a web browser and enter the following: <strong>http://localhost/cgi-bin/mapserv.exe</strong>. If MapServer is correctly configured, you should see the following warning message:</p>
<p><img src="http://spatialhorizons.com/wp-content/uploads/2007/12/mapservercgi_noinfo.jpg" alt="CGI MapServer" /></p>
<p>This means mapserv.exe is working correctly so we can next tell it that we want to draw a map. Add <strong>?mode=map</strong> to the address so the full address is <strong>http://localhost/cgi-bin/mapserv.exe?mode=map</strong>. Pressing enter again returns another message:</p>
<p><img src="http://spatialhorizons.com/wp-content/uploads/2007/12/mapservercgi_nomap.jpg" alt="CGI MapServer" / ></p>
<p>This is expected because we have not provided a mapfile to display. The next variable to add is named &#8220;map&#8221; and it&#8217;s value is the file path to our mapfile. For example, it could be: <strong>http://localhost/cgi-bin/mapserv.exe?mode=map&#038;map=C:\world_mapfile.map</strong>.  If a valid mapfile is entered the browser will generate an image such as this:</p>
<p><img src="http://spatialhorizons.com/wp-content/uploads/2007/12/mapservercgi_map1.jpg" alt="CGI MapServer Map" /></p>
<p>A full list of CGI MapServer parameters can be found <a href="http://mapserver.gis.umn.edu/docs/reference/cgi/referencemanual-all-pages">here</a>.  For example, to generate an image of a specific map extent, the MAPEXT parameter can be used.  In our example, we added MAPEXT -20 -20 20 20 in the browser to get an address like this: <strong>http://localhost/cgi-bin/mapserv.exe?mode=map&#038; <br /> map=C:\James\GIS\Data\World\world_mapfile.map&#038;mapext=-20 -20 20 20</strong>. The image returned reflects the new extent.</p>
<p><img src="http://spatialhorizons.com/wp-content/uploads/2007/12/mapservercgi_map2.jpg" alt="CGI MapServer Map" /></p>
<p><strong>Conclusion</strong></p>
<p>Understanding how MapServer uses mapserv.exe to generate images will become more useful in our next post where we will setup a basic web mapping site using <a href="http://www.openlayers.org/">OpenLayers</a> that will need to directly access the CGI functionality of MapServer.</p>
]]></content:encoded>
			<wfw:commentRss>http://spatialhorizons.com/2007/12/09/using-mapserver-3-cgi-mapserver/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sample Dataset – World Map</title>
		<link>http://spatialhorizons.com/2007/12/09/sample-dataset-world-map/</link>
		<comments>http://spatialhorizons.com/2007/12/09/sample-dataset-world-map/#comments</comments>
		<pubDate>Sun, 09 Dec 2007 14:59:32 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[GIS Data]]></category>

		<guid isPermaLink="false">http://spatialhorizons.com/2007/12/09/sample-dataset-world-map/</guid>
		<description><![CDATA[A number of our posts have covered downloading and using GIS data but it should be more beneficial to readers if a single post contained all the instructions needed to acquire the data layers in each dataset. Our first such dataset, named &#8220;World Map&#8221;, has already been introduced but will be discussed in more depth [...]]]></description>
			<content:encoded><![CDATA[<p>A number of our posts have covered downloading and using GIS data but it should be more beneficial to readers if a single post contained all the instructions needed to acquire the data layers in each dataset. Our first such dataset, named &#8220;World Map&#8221;, has already been introduced but will be discussed in more depth here for the sake of new readers.</p>
<p><img src="http://spatialhorizons.com/wp-content/uploads/2007/12/mapservercgi_map1.jpg" alt="CGI MapServer Map" /><br />
<span id="more-147"></span></p>
<p><strong>Dataset Details</strong></p>
<ul>
<li>Number of data layers: 2</li>
<li>Map Projection: Geographic (see <a href="http://en.wikipedia.org/wiki/Plate_carr%C3%A9e_projection">Equirectangular projection</a>)
<li>Map Units: Decimal degrees</li>
<li>Map Extent(min x, min y, max x, max y): -180 -90 180 90</li>
</ul>
<p><strong>Layer 1: Countries Shapefile</strong></p>
<p>The first layer in this dataset is a polygon <a href="http://spatialhorizons.com/faqs#shapefile">shapefile</a> containing world countries.</p>
<p><img src="http://spatialhorizons.com/wp-content/uploads/2007/12/countries_shapefile.jpg" alt="Countries Shapefile" /></p>
<p>Source: <a href="http://www.cipotato.org/diva/data/MoreData.htm">http://www.cipotato.org/diva/data/MoreData.htm</a><br />
Direct download link: <a href="http://www.cipotato.org/diva/data/misc/world_adm0.zip">http://www.cipotato.org/diva/data/misc/world_adm0.zip</a></p>
<p>For more on using this shapefile, see our posts on <a href="http://spatialhorizons.com/2007/09/23/using-qgis-3-more-layer-symbology/">using QGIS</a>.</p>
<p><strong>Layer 2: World Raster</strong></p>
<p>The second data layer is a raster image of the entire world. The original image was very large but we downloaded it and resized to 600 x 300 pixels. Additionally, we had to create a world file to ensure it would spatially align correctly with our countries shapefile (see <a href="http://spatialhorizons.com/2007/09/26/using-qgis-4-raster-images/">this post</a> for more instructions).</p>
<p><img src="http://spatialhorizons.com/wp-content/uploads/2007/12/world_raster.jpg" alt="World Raster" /></p>
<p>Source: <a href="http://commons.wikimedia.org/wiki/World_map">http://commons.wikimedia.org/wiki/World_map</a><br />
Direct link to full-size image (8 MB):<a href="http://upload.wikimedia.org/wikipedia/commons/c/cf/WorldMap-A_non-Frame.png"> http://upload.wikimedia.org/wikipedia/commons/c/cf/WorldMap-A_non-Frame.png</a><br />
Resized Image: <a href="http://www.spatialhorizons.com/downloads/world_raster.tif">http://www.spatialhorizons.com/downloads/world_raster.tif</a><br />
World File: <a href="http://www.spatialhorizons.com/downloads/world_raster.tfw">http://www.spatialhorizons.com/downloads/world_raster.tfw</a></p>
<p><strong>Mapfile Creation</strong></p>
<p>The World Map dataset has been used for several of our projects involving MapServer.  Since MapServer requires a configuration file called a mapfile, one was generated using QGIS in <a href="http://spatialhorizons.com/2007/10/06/using-qgis-5-export-to-mapserver/">this post</a>.  Some minor modifications were made later on so the final version can be downloaded <a href="http://www.spatialhorizons.com/downloads/world_mapfile.map">here</a>.</p>
<p>In the mapfile, the file paths to the data layers should be changed though to reflect your directory structure.</p>
<p>
<pre code="csharp"> LAYER
    NAME 'world_raster'
    TYPE RASTER
    DATA 'C:\\Data\\World\\world_raster.tif'
  ...</pre>
</p>
<p>
<pre code="csharp">LAYER
    NAME 'world_adm0'
    TYPE POLYGON
    DATA 'C:\\Data\\World\\world_adm0.shp'
  ...</pre></p>
]]></content:encoded>
			<wfw:commentRss>http://spatialhorizons.com/2007/12/09/sample-dataset-world-map/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using MapServer (2) – Generating Map Tiles</title>
		<link>http://spatialhorizons.com/2007/11/14/using-mapserver-2-generating-map-tiles/</link>
		<comments>http://spatialhorizons.com/2007/11/14/using-mapserver-2-generating-map-tiles/#comments</comments>
		<pubDate>Wed, 14 Nov 2007 23:44:06 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[Map Tiles]]></category>
		<category><![CDATA[Mapserver]]></category>

		<guid isPermaLink="false">http://spatialhorizons.com/2007/11/14/using-mapserver-2-generating-map-tiles/</guid>
		<description><![CDATA[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 [...]]]></description>
			<content:encoded><![CDATA[<p class="moreinfo">This post is the second in a series on using <a href="http://mapserver.gis.umn.edu/">MapServer</a>. First-time visitors are encouraged to read <a href="http://spatialhorizons.com/2007/05/19/mapserver-1-10-minute-tutorial/">part 1</a> 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 <a href="http://spatialhorizons.com/category/map-tiles/">previous series</a>.</p>
<p>Once the <a href="http://www.maptools.org/ms4w/">MapServer for Windows (MS4W)</a> package with <a href="http://ka-map.maptools.org/">ka-Map</a> 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.</p>
<p><strong>ka-Map Configuration</strong></p>
<p>The first step in creating a set of map tiles is to configure ka-Map to point to a valid MapServer mapfile (see <a href="http://spatialhorizons.com/2007/10/06/using-qgis-5-export-to-mapserver/">here</a> for more on a mapfile). Navigate to this directory: <strong>C:\ms4w\apps\ka-map-1.0\include</strong> and open the file named <strong>config.php</strong> in any text editor.</p>
<p>This configuration file contains several parameters which you should be familiar with before creating our map tiles. We won&#8217;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:</p>
<p>
<pre lang="csharp">$tileWidth = 256;
$tileHeight = 256;</pre>
</p>
<p>Lines 106 through 110 define the most important parameters:</p>
<p>
<pre lang="csharp">$aszGMap = array (
         'title' => 'GMap 75',
         'path' => '../../gmap/htdocs/gmap75.map',
         'scales' => array( 40000000, 25000000, 12000000,
                                 7500000, 3000000, 1000000 ),
         'format' =>'PNG'
 );</pre>
</p>
<p><span id="more-134"></span><br />
By default, ka-Map is setup to use the GMap application that we downloaded and setup in the <a href="http://spatialhorizons.com/2007/05/19/mapserver-1-10-minute-tutorial/">first post</a>. So the values for the title, path, and scales reflect that.</p>
<p>The path variable is relative based on the location of config.php (config.php is in C:\ms4w\apps\ka-map-1.0\include and the gmap75.map file is in C:\ms4w\apps\gmap\htdocs).</p>
<p>The scales array contains all the map scales at which the tiles will be generated. Determining which scales and how many scale levels is completely configurable based on the user&#8217;s preference. For now we will leave them as-is.</p>
<p>Lastly, the output image format is defined as PNG.</p>
<p><strong>Precache.php</strong></p>
<p>ka-Map is a web-based interface for viewing MapServer-based maps using map tiles. Normally, ka-Map generates only the necessary map tiles needed to show in the browser&#8217;s window. But there is a separate file, named precache.php, that also comes with the ka-Map that does generate all the map tiles for every scale of the map.</p>
<p>Navigate to the following directory: <strong>C:\ms4w\apps\ka-map-1.0\htdocs</strong>. Scroll through the list of files to find the file <strong>precache.php</strong>. The good news is this file does not need to be modified in any way. It relies solely on the config.php settings described above to determine what mapfile and map scales to use when creating the map tiles.</p>
<p><strong>Running Precache.php</strong></p>
<p>Readers are encouraged to first read over <a href="http://ka-map.ominiverdi.org/wiki/index.php/Pre-caching_system" target="_blank">this article</a> in the ka-Map wiki about precache.php. You don&#8217;t have to understand everything it discusses &#8211; just glance over the parameters needed to run precache.php.</p>
<p>Running precache.php requires returning to the world of DOS prompts and command line. It is important to follow these steps exactly as listed otherwise it may not work correctly.</p>
<ol>
<li>Open a command prompt. On Windows, go to Start&#8230;Run and type <strong>cmd</strong>.</li>
<li>Type <strong>cd C:\ms4w\apps\ka-map-1.0\htdocs</strong> to go to the directory with precache.php.</li>
<li>Since precache.php is a PHP file, we need to run it using the PHP executable (php.exe). Fortunately this is already included with the MS4W package. Type <strong>C:\ms4w\Apache\cgi-bin\php.exe precache.php</strong> in the command prompt. We left out the required parameters on purpose here so you can see the usage instructions:
</ol>
<p><img src="http://spatialhorizons.com/wp-content/uploads/2007/11/precache_usage.jpg" alt="Precache.php Usage" /></p>
<p>We won&#8217;t need to use -f, -m, or -s options but we do need to add the tile_url parameter. This is the web address (hence &#8220;_url&#8221;) to ka-Map&#8217;s <strong>tile.php</strong> file. Even though the file is stored locally at <strong>C:\ms4w\apps\ka-map-1.0\htdocs\tile.php</strong>, we need to enter a valid URL. The usage instructions suggest using http://localhost/ka-map/htdocs/tile.php but that didn&#8217;t work for us. Instead we will use <strong>http://localhost/kamap/tile.php</strong>.</p>
<ol start="4">
<li>Type <strong>C:\ms4w\Apache\cgi-bin\php.exe precache.php http://localhost/kamap/tile.php</strong>. Press enter the map tiles will be generated.</li>
</ol>
<p>This process will take several minutes as all the tiles at each of the scale levels are generated. The command prompt will display information on each scale level. This information on meta tiles and tile counts is informative but not necessary to understand right now. In short, precache.php requests larger tiles (&#8221;meta tiles&#8221;) and then cuts them up to arrive at the final set of tiles.</p>
<p><strong>Viewing the Map Tile Cache</strong></p>
<p>Navigate to <strong>C:\ms4w\tmp\ms_tmp\kacache\gmap</strong>. Inside this folder should be a folder named for each scale level in the map. Inside each scale level folder our folders named __base__ and then a sub-folder named def. This is where the tile images can be found.</p>
<p>Because ka-Map tiles are generally only used internally and not designed for end-user interaction, there is a potentially confusing way to name tiles and tile folders. Anytime a folder or file contains the letters &#8220;t&#8221; or &#8220;l&#8221;, it means top or left. So instead of naming tiles with X/Ys or Row/Columns, ka-Map uses the &#8220;Left/Top&#8221; naming convention.  </p>
<p>It also names each tile based on it&#8217;s pixel location and tile size. Since the config.php was set to output 256&#215;256 tiles, each tile image will include top and left numbers based on multiples of 256. So if one tile is named t0l0.png, the adjacent tiles on each side would be named t0l256.png and t0l-256.png. Glance through the folders and view some of the individual tiles to get a sense of the tiling structure.</p>
<p><img src="http://spatialhorizons.com/wp-content/uploads/2007/11/kamap_tile_t-256l0.png" alt="kaMap Tile Example" /></p>
<p><img src="http://spatialhorizons.com/wp-content/uploads/2007/11/kamap_tile_t-256l-256.png" alt="kaMap Tile Example" /></p>
<p><strong>What&#8217;s the Benefit?</strong></p>
<p>Traditional usage of precache.php is for improving the load times on a web mapping site by caching all the tiles ahead of time.  For our objectives, having a complete set of pre-compiled map tiles means we can create a desktop application without including a GIS code library or GIS data. It also eliminates the extra processing time and would make deploying our applications easier. Instead of including extra DLLs and shapefiles, we simply need to include a folder of map tiles to run the application.</p>
<p><strong>Conclusion</strong></p>
<p>This post is probably the most technical topic we&#8217;ve covered to date. For now, simply understanding how to generate map tiles using precache.php is a what&#8217;s important. In the next post we will discuss the map tiles in some more depth, including how we can use them in other applications.</p>
]]></content:encoded>
			<wfw:commentRss>http://spatialhorizons.com/2007/11/14/using-mapserver-2-generating-map-tiles/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using SharpMap (4)</title>
		<link>http://spatialhorizons.com/2007/11/07/using-sharpmap-4/</link>
		<comments>http://spatialhorizons.com/2007/11/07/using-sharpmap-4/#comments</comments>
		<pubDate>Wed, 07 Nov 2007 23:55:19 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[SharpMap]]></category>

		<guid isPermaLink="false">http://spatialhorizons.com/2007/11/07/using-sharpmap-4/</guid>
		<description><![CDATA[This post concludes our tutorial introducing SharpMap and how to use it in a mapping application. We were planning to explore it in some more depth by demonstrating some additional functionality, but we are working on another project that will be discussed in the near future. In short, SharpMap has tremendous potential as a lightweight [...]]]></description>
			<content:encoded><![CDATA[<p>This post concludes our tutorial introducing <a href="http://www.codeplex.com/SharpMap">SharpMap</a> and how to use it in a mapping application. We were planning to explore it in some more depth by demonstrating some additional functionality, but we are working on another project that will be discussed in the near future. In short, SharpMap has tremendous potential as a lightweight component for adding mapping capabilities to desktop and web applications.</p>
<p>Our sample application&#8217;s source code is available to download below. It includes everything needed to compile and run the application using <a href="http://msdn2.microsoft.com/en-us/express/aa700756.aspx">Visual C# Express</a>. The SharpMap library, included in the download, is released under the GNU Lesser General Public License. For more information on that, see <a href="http://www.codeplex.com/SharpMap/Wiki/View.aspx?title=Is%20SharpMap%20free%20with%20no%20strings%20attached&#038;referringTitle=FAQ">here</a>.</p>
<p><img src="http://spatialhorizons.com/wp-content/uploads/2007/10/sharpmap_coloredmap.jpg" alt="SharpMap Demo Application" /></p>
<p><a href="http://spatialhorizons.com/downloads/SharpMapDemo.zip"><img border="0" alt="Download Source Code" src="http://spatialhorizons.com/downloads/code_download.jpg" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://spatialhorizons.com/2007/11/07/using-sharpmap-4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using SharpMap (3)</title>
		<link>http://spatialhorizons.com/2007/10/28/using-sharpmap-3/</link>
		<comments>http://spatialhorizons.com/2007/10/28/using-sharpmap-3/#comments</comments>
		<pubDate>Sun, 28 Oct 2007 23:31:54 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[SharpMap]]></category>

		<guid isPermaLink="false">http://spatialhorizons.com/2007/10/28/using-sharpmap-3/</guid>
		<description><![CDATA[Our third post in this series (part 1, part 2) on SharpMap continues the development of a basic mapping application programmed in C#. We will now add some more functionality to the program.

Zooming By Percentages
The SharpMap.Map class has a Zoom property that stores the map&#8217;s current width in the units of the map.  To [...]]]></description>
			<content:encoded><![CDATA[<p>Our third post in this series (<a href="http://spatialhorizons.com/2007/10/14/using-sharpmap-1/">part 1</a>, <a href="http://spatialhorizons.com/2007/10/20/using-sharpmap-2/">part 2</a>) on <a href="http://www.codeplex.com/SharpMap">SharpMap</a> continues the development of a basic mapping application programmed in C#. We will now add some more functionality to the program.</p>
<p><img src="http://spatialhorizons.com/wp-content/uploads/2007/10/sharpmap_coloredmap.jpg" alt="SharpMap with Coloring" /></p>
<p><strong>Zooming By Percentages</strong></p>
<p>The SharpMap.Map class has a Zoom property that stores the map&#8217;s current width in the units of the map.  To understand this better, add this line of code to the RefreshMap function we&#8217;ve already created:</p>
<p>
<pre lang="csharp">MessageBox.Show(_sharpMap.Zoom.ToString());</pre>
</p>
<p><span id="more-127"></span><br />
Running the program now should immediately display a value of almost exactly 360. This makes sense because our data source is a <a href="http://spatialhorizons.com/faqs#shapefile">shapefile</a> of the world, our map units are decimal degrees, and the width of the earth is 360 degrees.</p>
<p>So &#8220;zooming&#8221; is really just a process of changing the the width of the map.  Zooming in will require us to subtract from the SharpMap.Map.Zoom while zooming out adds a value to Zoom. We could simply use a constant value like 20 (degrees) but that is only applicable when our source data is in decimal degrees. If we switched to data in feet for example, adding or subtracting 20 feet from the a map width would takes hundreds of clicks to zoom in and out. </p>
<p>Instead, a better approach for zooming is to use a percentage change. Remember we defined a class-level constant in our the form&#8217;s code:</p>
<p>
<pre lang="csharp">const float ZOOM_FACTOR = 0.3f;</pre>
</p>
<p>We can use that value to zoom in or out 30% each time our zoom buttons are pressed.</p>
<p><strong>Zooming Code</strong></p>
<p>Double-clicking on the Zoom In button in our form will create the click event for the button. We only need to add 2 lines of code to change the Zoom value (i.e., map width).</p>
<p>
<pre lang="csharp">private void btnZoomIn_Click(object sender, EventArgs e)
{
    _sharpMap.Zoom -= _sharpMap.Zoom * ZOOM_FACTOR;
    RefreshMap();
}</pre>
</p>
<p>And zooming out does just the opposite:</p>
<p>
<pre lang="csharp">private void btnZoomOut_Click(object sender, EventArgs e)
{
    _sharpMap.Zoom += _sharpMap.Zoom * ZOOM_FACTOR;
    RefreshMap();
}</pre>
</p>
<p>Additionally, our Zoom to Full button click event looks like this:</p>
<p>
<pre lang="csharp">private void btnZoomFull_Click(object sender, EventArgs e)
{
    _sharpMap.ZoomToExtents();
    RefreshMap();
}</pre>
</p>
<p><strong>Panning Code</strong></p>
<p>We also can easily implement panning in this application. A map pan (or recenter) will occur any time the user clicks on the map image. The mouse click location will then become the map center. This process requires two steps: (1) convert the &#8220;image&#8221; coordinates to real-world coordinates and (2) recenter the map.</p>
<p>Fortunately the SharpMap.Map class has a ImageToWorld method to convert the mouse click coordinates to the real-world location in the map. Then we just need the change the map&#8217;s center coordinates before refreshing the map. The code is added to Picture Box&#8217;s mouse click event and looks like this:</p>
<p>
<pre lang="csharp">private void picMap_MouseClick(object sender, MouseEventArgs e)
{
    //--> Convert mouse click point from image coordinates to world coordinates
    SharpMap.Geometries.Point p = _sharpMap.ImageToWorld(new PointF(e.X, e.Y));

    //--> Recenter map
    _sharpMap.Center.X = p.X;
    _sharpMap.Center.Y = p.Y;

    RefreshMap();
}</pre>
</p>
<p>Running the program now allows the user to zoom in and out and pan around the map.</p>
<p><img src="http://spatialhorizons.com/wp-content/uploads/2007/10/sharpmap_labels2.jpg" alt=SharpMap Zooming" /></p>
<p>Next time we will add some more functionality to the application before moving on to another topic.</p>
]]></content:encoded>
			<wfw:commentRss>http://spatialhorizons.com/2007/10/28/using-sharpmap-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using SharpMap (2)</title>
		<link>http://spatialhorizons.com/2007/10/20/using-sharpmap-2/</link>
		<comments>http://spatialhorizons.com/2007/10/20/using-sharpmap-2/#comments</comments>
		<pubDate>Sat, 20 Oct 2007 15:41:21 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[SharpMap]]></category>

		<guid isPermaLink="false">http://spatialhorizons.com/2007/10/20/using-sharpmap-2/</guid>
		<description><![CDATA[Our previous post introduced SharpMap and how to use it in a C# program. We built a form and used a PictureBox control to display maps generated by SharpMap. We left off with a rather bland looking map of the world:

Adding Layer Styles
Adding colors to our countries layer is straightforward. In our form&#8217;s constructor, we [...]]]></description>
			<content:encoded><![CDATA[<p>Our <a href="http://spatialhorizons.com/2007/10/14/using-sharpmap-1/">previous post</a> introduced <a href="http://www.codeplex.com/SharpMap">SharpMap</a> and how to use it in a C# program. We built a form and used a PictureBox control to display maps generated by SharpMap. We left off with a rather bland looking map of the world:</p>
<p><img src="http://spatialhorizons.com/wp-content/uploads/2007/10/sharpmap_program1.jpg" alt="SharpMap Program" /></p>
<p><strong>Adding Layer Styles</strong></p>
<p>Adding colors to our countries layer is straightforward. In our form&#8217;s constructor, we simply define colors using the Style class:</p>
<p>
<pre lang="csharp">countriesLayer.Style.Fill = Brushes.LightGreen;
countriesLayer.Style.EnableOutline = true;
countriesLayer.Style.Outline = Pens.DarkGreen;</pre>
</p>
<p>We also switched the map&#8217;s background color:</p>
<p>
<pre lang="csharp">_sharpMap.BackColor = Color.LightBlue;</pre>
</p>
<p><span id="more-129"></span></p>
<p>Running the program now produces a better looking map:</p>
<p><img src="http://spatialhorizons.com/wp-content/uploads/2007/10/sharpmap_coloredmap.jpg" alt="SharpMap with Coloring" /></p>
<p><strong>Adding Labels</strong></p>
<p>SharpMap also allows for creating label layers to add to the map that display text from another layer&#8217;s attributes. In our example, we can display the names of the countries on the map using the following code:</p>
<p>
<pre lang="csharp">SharpMap.Layers.LabelLayer labelLayer =
     new SharpMap.Layers.LabelLayer("Country Names");
labelLayer.DataSource = countriesLayer.DataSource;
labelLayer.LabelColumn = "NAME";
labelLayer.Style.CollisionDetection = true;
labelLayer.Style.CollisionBuffer = new SizeF(10, 10);
labelLayer.MultipartGeometryBehaviour =
     SharpMap.Layers.LabelLayer.MultipartGeometryBehaviourEnum.Largest;
labelLayer.Style.Font = new Font(FontFamily.GenericSansSerif, 8);
_sharpMap.Layers.Add(labelLayer);</pre>
</p>
<p>In the code, we create a LabelLayer, assign it to the same data source as our countries layer, choose the field that contains the country names (&#8221;NAME&#8221;), and then define some additional properties. Enabling collision detection avoids some overlapping labels while the multi-part geometry behavior instructs SharpMap to label the largest polygon if a country has multiple shapes.</p>
<p>The final result is not perfect because there are just too many country names to display at once. Setting the collision buffer to 10,10 reduces the number of labels drawn but which country names are displayed is completely arbitrary.</p>
<p><img src="http://spatialhorizons.com/wp-content/uploads/2007/10/sharpmap_labels.jpg" alt="SharpMap with Labels" /></p>
<p>When we add code to the zoom in button in the next post, overlapping labels will become less of an issue:</p>
<p><img src="http://spatialhorizons.com/wp-content/uploads/2007/10/sharpmap_labels2.jpg" alt="SharpMap with Labels" /></p>
]]></content:encoded>
			<wfw:commentRss>http://spatialhorizons.com/2007/10/20/using-sharpmap-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using SharpMap (1)</title>
		<link>http://spatialhorizons.com/2007/10/14/using-sharpmap-1/</link>
		<comments>http://spatialhorizons.com/2007/10/14/using-sharpmap-1/#comments</comments>
		<pubDate>Sun, 14 Oct 2007 18:31:17 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[SharpMap]]></category>

		<guid isPermaLink="false">http://spatialhorizons.com/2007/10/14/using-sharpmap-1/</guid>
		<description><![CDATA[In our ongoing effort to explore various methods for developing mapping applications, we need to consider incorporating existing libraries instead of writing code ourselves.  One such solution is SharpMap.  SharpMap is an emerging open source mapping engine that provides functionality to access GIS data, such as shapefiles, and generate map images.  In [...]]]></description>
			<content:encoded><![CDATA[<p>In our ongoing effort to explore various methods for developing mapping applications, we need to consider incorporating existing libraries instead of writing code ourselves.  One such solution is <a href="http://www.codeplex.com/SharpMap">SharpMap</a>.  SharpMap is an emerging open source mapping engine that provides functionality to access GIS data, such as shapefiles, and generate map images.  In their own words,</p>
<p class="shquote">SharpMap is an easy-to-use mapping library for use in web and desktop applications. It provides access to many types of GIS data, enables spatial querying of that data, and renders beautiful maps. The engine is written in C# and based on the .Net 2.0 framework. SharpMap is released under GNU Lesser General Public License. [<a href="http://www.codeplex.com/SharpMap">quote source</a>]</p>
<p>So let&#8217;s go ahead and program a simple mapping application in C# that uses SharpMap. As with our other tutorials, this example is rather primitive on purpose to highlight specifically how easy it use to use SharpMap. Readers are encouraged to use this tutorial as a basis for creating much richer applications.</p>
<p><span id="more-99"></span></p>
<p><strong>Data Setup</strong></p>
<p>Before beginning, we need to download a GIS dataset to display in the program. Our recent <a href="http://spatialhorizons.com/2007/09/09/using-qgis-1-introduction/">posts</a> on QGIS discussed several options for download and viewing <a href="http://spatialhorizons.com/faqs/#shapefile">shapefiles</a>.  In <a href="http://spatialhorizons.com/2007/09/23/using-qgis-3-more-layer-symbology/">part 3</a> of that tutorial, we downloaded a shapefile showing countries of the world so that shapefile will be used again in this project.</p>
<p><strong>SharpMap Download</strong></p>
<p>We first need to download the latest release of SharpMap <a href="http://www.codeplex.com/SharpMap/Release/ProjectReleases.aspx?ReleaseId=154">here</a>. Download the version 0.9 binary file and unzip it to your hard drive.  The zip file contains 4 files but the only file we will use is the SharpMap.dll.</p>
<p><strong>Create a New C# Application</strong></p>
<p>Using the free <a href="http://msdn2.microsoft.com/en-us/express/aa700756.aspx">Visual C# Express program</a>, create a new C# windows application. Here are several links (<a href="http://msdn2.microsoft.com/en-us/library/ms379606(vs.80).aspx">link 1</a>, <a href="http://csharp.net-tutorials.com/basics/visual-csharp-express/">link 2</a>) if you need some background on using Visual C# Express.</p>
<p>The first step is to reference the SharpMap.dll we downloaded. Go to the Project menu iten, select Add Reference, then chose browse, and navigate to the SharpMap.dll.  It should then appear in the solution explorer as a project reference.</p>
<p><img src="http://spatialhorizons.com/wp-content/uploads/2007/10/sharpmap_reference.jpg" alt="Reference to SharpMap.dll" /></p>
<p>After switching to the form&#8217;s design view, add a Picture Box control to serve as our map image area. We added 3 buttons and a label to produce something that looks like this:</p>
<p><img src="http://spatialhorizons.com/wp-content/uploads/2007/10/sharpmap_form.jpg" alt="SharpMap Form" /></p>
<p>Press F5 to run the program although nothing special should happen yet.</p>
<p>Next go ahead and copy the shapefile to a folder in the project&#8217;s directory. For example, copy the shapefile (remember it is actually 3 separate files) into the program&#8217;s bin\debug folder.</p>
<p>Now switch to the code view for the form and begin by adding some class-level variables and constants. The main class we will use throughout the program is the SharpMap.Map class. Because we have already referenced the SharpMap.dll, Visual C# Express should allow classes from SharpMap&#8217;s library to be defined just like any other C# class. </p>
<p>
<pre lang="csharp">public partial class frmMap : Form
{
    //--> Define the SharpMap object
    SharpMap.Map _sharpMap;  

    //--> Set the zoom factor percentage
    const float ZOOM_FACTOR = 0.3f;

    //--> Define the data name and source
    const string DATA_NAME = "World Countries";
    const string DATA_PATH = @"world_adm0\world_adm0.shp";
</pre>
</p>
<p>Then in the form&#8217;s constructor, we first initialize the Map class with a size that matches the size of our Picture Box control.</p>
<p>
<pre lang="csharp">public frmMap()
{
    //--> Initialize the map
    _sharpMap = new SharpMap.Map(new Size(600, 300));
    _sharpMap.BackColor = Color.White;</pre>
</p>
<p>Now we can add our shapefile to the map via a 3-step process: (1) define a VectorLayer object, (2) set it&#8217;s data source, and (3) add it to the Map.</p>
<p>
<pre lang="csharp">//--> Add the countries shapefile to the map
SharpMap.Layers.VectorLayer countriesLayer = new SharpMap.Layers.VectorLayer(DATA_NAME);
countriesLayer.DataSource = new SharpMap.Data.Providers.ShapeFile(DATA_PATH);
_sharpMap.Layers.Add(countriesLayer);</pre>
</p>
<p>Next we need to set the map&#8217;s view to the entire extent of our layer using the ZoomToExtents() function.</p>
<p>
<pre lang="csharp">//--> Zoom the map to the entire extent
_sharpMap.ZoomToExtents();
RefreshMap();</pre>
</p>
<p>We also needed to alert SharpMap to draw our map and return it as an image. Because we will need to call this function from several spots in our program, a separate function was created called RefreshMap that does just that. The returned map image is then displayed in our Picture Box.</p>
<p>
<pre lang="csharp">private void RefreshMap()
{
    //--> Use SharpMap to generate the map image
    picMap.Image = _sharpMap.GetMap();
}</pre>
</p>
<p>Even without adding code to the buttons, we can still run the program at this point. Press F5 and you should see something like this:</p>
<p><img src="http://spatialhorizons.com/wp-content/uploads/2007/10/sharpmap_program1.jpg" alt="SharpMap Program" /></p>
<p>The map image was indeed generated by SharpMap but it lacks a decent coloring scheme. Next time we will correct that and later we will add functionality to the zooming buttons.</p>
]]></content:encoded>
			<wfw:commentRss>http://spatialhorizons.com/2007/10/14/using-sharpmap-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using QGIS (5) – Export to MapServer</title>
		<link>http://spatialhorizons.com/2007/10/06/using-qgis-5-export-to-mapserver/</link>
		<comments>http://spatialhorizons.com/2007/10/06/using-qgis-5-export-to-mapserver/#comments</comments>
		<pubDate>Sat, 06 Oct 2007 22:42:10 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[Mapserver]]></category>
		<category><![CDATA[QGIS]]></category>

		<guid isPermaLink="false">http://spatialhorizons.com/2007/10/06/using-qgis-5-export-to-mapserver/</guid>
		<description><![CDATA[Our last post for now on QGIS will cover an interesting feature added in the recent versions. A new &#8220;Export to MapServer Map&#8221; command creates a MapServer configuration file (simply called a &#8220;mapfile&#8221;) from an existing QGIS map. That mapfile can be used to then display the data on a website or use it in [...]]]></description>
			<content:encoded><![CDATA[<p>Our last post for now on <a href="http://www.qgis.org/">QGIS</a> will cover an interesting feature added in the recent versions. A new &#8220;Export to MapServer Map&#8221; command creates a MapServer configuration file (simply called a &#8220;mapfile&#8221;) 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 <a href="http://spatialhorizons.com/2007/06/24/mapscript-and-xna-1/">MapServer/XNA tutorials</a> we demonstrated in the past.</p>
<p><strong>Python Installation</strong></p>
<p>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 <a href="http://www.python.org/download/releases/2.5.1/">here</a>.</p>
<p><strong>Open a QGIS Map</strong></p>
<p>After the installation, go ahead and open a QGIS map. We will continue to use the world map project created in the <a href="http://spatialhorizons.com/2007/09/23/using-qgis-3-more-layer-symbology/">previous posts</a>.  As a reminder, we have two layers in our map &#8211; a vector layer showing country outlines and a raster background image.</p>
<p><img src="http://spatialhorizons.com/wp-content/uploads/2007/09/qgis_raster_aligned.jpg" alt="QGIS Map" /></p>
<p><span id="more-111"></span><br />
<strong>Export to MapServer</strong></p>
<p>Under the File menu option, select the &#8220;Export to MapServer Map&#8221; item:</p>
<p><img src="http://spatialhorizons.com/wp-content/uploads/2007/10/qgis_export2mapserver.jpg" alt="Export to MapServer" /></p>
<p>The window that opens requires you to input some information before creating the mapfile. First you need to select a location for the new mapfile. Then pick the QGIS project file that you will be creating it from (it does not automatically use the currently open project in QGIS).  Provide a map name, enter the size, and make sure the units drop-down box matches the map&#8217;s units. Our map is only in longitude/latitude units so we chose dd (decimal degrees). We will skip the box covering the Web Interface Definition so our filled out menu looks like this:</p>
<p><img src="http://spatialhorizons.com/wp-content/uploads/2007/10/qgis_export2mapserver2.jpg" alt="Export to MapServer" /></p>
<p>Press Ok to run the export and the mapfile will be created.</p>
<p><strong>Viewing the Mapfile</strong></p>
<p>Find the created mapfile and open it in your favorite text editor. The mapfile is a structured document that contains groups of elements that begin with a name (e.g., MAP, PROJECTION, LAYER) and end with END.  It also contains single-line attributes using the key-value syntax (e.g., NAME &#8216;World Map&#8217;, TRANSPARENCY 100, OUTLINECOLOR 0 0 0).  It is very similar to an XML file but without the brackets and slashes.</p>
<p>For a complete reference on the syntax of mapfiles, check out their <a href="http://mapserver.gis.umn.edu/docs/reference/mapfile">help</a> page on the web. Even without reading the help file, most of the mapfile can be understood by simply glancing at the text. For example, our world raster image appears in the mapfile like this:</p>
<pre>LAYER
    NAME 'world_raster'
    TYPE RASTER
    DATA 'M:\\World\\world_raster.tif'
    METADATA
      'wms_title' 'world_raster'
    END
    STATUS DEFAULT
    TRANSPARENCY 100
    PROJECTION
    'proj=longlat'
    'ellps=WGS84'
    'datum=WGS84'
    'no_defs'
    END
  END</pre>
<p>It is easy to determine the between the LAYER and END tags, the raster is described with it&#8217;s name, type, file location, and projection information.</p>
<p>Our shapefile of world countries is slightly longer but similar:</p>
<pre>LAYER
    NAME 'world_adm0'
    TYPE POLYGON
    DATA 'M:\\World\\world_adm0.shp'
    METADATA
      'wms_title' 'world_adm0'
    END
    STATUS DEFAULT
    TRANSPARENCY 100
    PROJECTION
    'proj=longlat'
    'ellps=WGS84'
    'datum=WGS84'
    'no_defs'
    END
    CLASS
       NAME 'world_adm0'
       STYLE
         SYMBOL 0
         SIZE 6
         OUTLINECOLOR 0 0 0
         COLOR 144 50 207
       END
    END
  END</pre>
<p>The major difference between this and the raster file is the addition of a CLASS and STYLE element. They define the coloring of the countries using the OUTLINECOLOR and COLOR attributes. </p>
<p>Sometimes our mapfile doesn&#8217;t exactly match how QGIS had it displayed. In our QGIS map, we displayed the countries with a transparent fill so only the black outlines showed on the map.  To make our exported mapfile match that, we need to remove the &#8220;COLOR 144 50 207&#8243; line and save the mapfile.</p>
<p><strong>Testing the Mapfile</strong></p>
<p>There are various ways our mapfile could be tested in another application. The coolest example would be to go back to our <a href="http://spatialhorizons.com/2007/06/24/mapscript-and-xna-1/">Mapscript/XNA tutorials</a>. The result of these tutorials was a C# program that uses <a href="http://msdn2.microsoft.com/en-us/xna/default.aspx">XNA</a> as the graphics engine and Mapscript (Mapserver&#8217;s API) to generate map images from a mapfile (download the project&#8217;s source code in this <a href="http://spatialhorizons.com/2007/07/08/mapscript-and-xna-3/">post</a>).</p>
<p>In our program, we simply need to change the line of code where our mapfile path is defined to point to our new mapfile created from the QGIS export.</p>
<p>
<pre lang="csharp">mapserver = new shMapserver(@"M:\World\world_mapfile.map", 600, 600);</pre>
</p>
<p>Running the program will prove that our new mapfile works and allow us to zoom around the world.</p>
<p><img src="http://spatialhorizons.com/wp-content/uploads/2007/10/xna_with_world_mapfile.jpg" alt="World Mapfile in XNA" /></p>
<p><strong>Conclusion</strong></p>
<p>QGIS is a free, easy-to-use, software program for viewing and exploring geographic data.  The reason for discussing it in some depth is that if we want to start developing our own mapping applications, we need to begin acquiring GIS data and making our own maps. QGIS also gives us an easy way to produce MapServer mapfiles as we demonstrated above.</p>
]]></content:encoded>
			<wfw:commentRss>http://spatialhorizons.com/2007/10/06/using-qgis-5-export-to-mapserver/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
