<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	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/"
	>

<channel>
	<title>iphone and gis development notes &#187; tilecache</title>
	<atom:link href="http:///wordpress/tag/tilecache/feed/" rel="self" type="application/rss+xml" />
	<link>/wordpress</link>
	<description>By Rupert</description>
	<lastBuildDate>Mon, 26 Jul 2010 05:06:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>iPhone Note #20:Integrating Mapserver/TileCache to RouteMe</title>
		<link>/wordpress/2010/01/iphone-note-20integrating-mapservertilecache-to-routeme/</link>
		<comments>/wordpress/2010/01/iphone-note-20integrating-mapservertilecache-to-routeme/#comments</comments>
		<pubDate>Thu, 14 Jan 2010 01:37:57 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[mapserver]]></category>
		<category><![CDATA[tilecache]]></category>

		<guid isPermaLink="false">/wordpress/?p=700</guid>
		<description><![CDATA[Below is a summary of how I was able to implement Mapserver, TileCache and Route-Me iPhone Mapping Framework. 1. Assuming you have a working Mapserver/TileCache setup. Take note of the ff parameters: resolution and bbox. Below is my tilecache.cfg: 61 [mapserver_australia_3857] 62 type=MapServerLayer 63 mapfile=/Users/rupert/projects/pelicancorp/DMOB/trunk/map/australia_3857.map 64 layers=all 65 extension=jpg 66 bbox=-20037508.34, -20037508.34, 20037508.34, 20037508.34 68]]></description>
			<content:encoded><![CDATA[<p>Below is a summary of how I was able to implement Mapserver, TileCache and Route-Me iPhone Mapping Framework. </p>
<p>1.  Assuming you have a <strong>working</strong> Mapserver/TileCache setup. Take note of the ff parameters: resolution and bbox. Below is my tilecache.cfg:</p>

<div class="wp_syntax"><div class="code"><pre class="conf" style="font-family:monospace;"> 61 [mapserver_australia_3857]
 62 type=MapServerLayer
 63 mapfile=/Users/rupert/projects/pelicancorp/DMOB/trunk/map/australia_3857.map
 64 layers=all
 65 extension=jpg
 66 bbox=-20037508.34, -20037508.34, 20037508.34, 20037508.34
 68 maxResolution=156543.033928041
 70 levels=20
 71 srs=EPSG:3857
 72 tms_type=google
 73 extent_type=loose
 74 spherical_mercator=true</pre></div></div>

<p>2. Grab the RMGenericMercatorWMSSource from <a href="http://groups.google.com/group/route-me-map/browse_thread/thread/b58fa1d20cf15823/e30c42d9c90a8170?lnk=gst&#038;q=Generic#e30c42d9c90a8170">http://groups.google.com/group/route-me-map/browse_thread/thread/b58fa1d20cf15823/e30c42d9c90a8170?lnk=gst&#038;q=Generic#e30c42d9c90a8170</a></p>
<p>3. By default without any changes, the RMGenericMercatorWMSSource could display Mapserver WMS Tiles. This is possible by passing an NSDictionary *parameters, which contains arrayValues and arrayKeys for creating an http 256&#215;256 image request to the http://127.0.0.1/cgi-bin/mapserv binary.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">//This would request to http://127.0.0.1/cgi-bin/mapserv</span>
<span style="color: #400080;">NSArray</span> <span style="color: #002200;">*</span>arrayValues <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSArray</span> alloc<span style="color: #002200;">&#93;</span> initWithObjects<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;/path-to/australia_3857.map&quot;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;all&quot;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;png&quot;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;EPSG:3857&quot;</span>,<span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;
<span style="color: #400080;">NSArray</span> <span style="color: #002200;">*</span>arrayKeys <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSArray</span> alloc<span style="color: #002200;">&#93;</span> initWithObjects<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;MAP&quot;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;LAYERS&quot;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;FORMAT&quot;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;SRS&quot;</span>, <span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;
<span style="color: #400080;">NSDictionary</span> <span style="color: #002200;">*</span>wmsParameters <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSDictionary</span> alloc<span style="color: #002200;">&#93;</span> initWithObjects<span style="color: #002200;">:</span> arrayValues forKeys<span style="color: #002200;">:</span>arrayKeys <span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>Resulting http requests to the mapserv binary:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">http://192.168.1.193:81/tilecache/tilecache.py?LAYERS=australia_3857&amp;SRS=EPSG:3857&amp;REQUEST=GetMap&amp;SERVICE=WMS&amp;STYLES=&amp;EXCEPTIONS=application%2Fvnd.ogc.se_inimage&amp;FORMAT=png&amp;VERSION=1.1.1&amp;WIDTH=256&amp;HEIGHT=256&amp;BBOX=16828376.000000,-4006523.000000,16833268.000000,-4001631.000000</pre></div></div>

<p>Note that the bbox values does not contain decimal places. Nevertheless, it still works on Mapserver.</p>
<p>4. Now, assuming we have a valid tilecache running. And it is tested from browser, i.e http://127.0.0.1/map/tilecache_3857.html, open up firebug to see the requests. Below is a sample&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">http://192.168.1.193:81/tilecache/tilecache.py?LAYERS=australia_3857&amp;FORMAT=jpg&amp;SERVICE=WMS&amp;VERSION=1.1.1&amp;REQUEST=GetMap&amp;STYLES=&amp;EXCEPTIONS=application%2Fvnd.ogc.se_inimage&amp;SRS=EPSG%3A3857&amp;BBOX=16123932.497377,-4539747.9811239,16143500.376618,-4520180.1018829&amp;WIDTH=256&amp;HEIGHT=256</pre></div></div>

<p>But it seems, route-me is not supplying the bbox values accurately, as the decimal values is truncated (BBOX=16828376.000000,-4006523.000000,16833268.000000,-4001631.000000) from our previous request(3). </p>
<p>After changing the wmsParameter values to create a tilecache request, I noticed that route-me is not displaying the tiles correctly.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">//Testing for Windows:TileCache - ?</span>
<span style="color: #400080;">NSArray</span> <span style="color: #002200;">*</span>arrayValues <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSArray</span> alloc<span style="color: #002200;">&#93;</span> initWithObjects<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;australia_3857&quot;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;png&quot;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;EPSG:3857&quot;</span>,<span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>; <span style="color: #11740a; font-style: italic;">//for WIndows</span>
&nbsp;
<span style="color: #11740a; font-style: italic;">//TileCache URL Parameters:</span>
<span style="color: #400080;">NSArray</span> <span style="color: #002200;">*</span>arrayKeys <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSArray</span> alloc<span style="color: #002200;">&#93;</span> initWithObjects<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;LAYERS&quot;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;FORMAT&quot;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;SRS&quot;</span>, <span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>5. The workaround is to use &#8220;double&#8221; instead of &#8220;floats&#8221; in the RMGenericMercatorWMSSource. You can download the zip from <a href="/wordpress/wp-content/uploads/2010/01/RMGenericMercatorWMSSource.zip" title="RMGenericMercatorWMSSource.zip">RMGenericMercatorWMSSource.zip</a>. I have modified &#8220;initialResolution&#8221; and &#8220;originShift&#8221; to both use <em>&#8220;double&#8221;</em>.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">typedef</span> <span style="color: #a61390;">struct</span> <span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">double</span> x;
	<span style="color: #a61390;">double</span> y;
<span style="color: #002200;">&#125;</span> CGDoublePoint;
&nbsp;
<span style="color: #a61390;">typedef</span> <span style="color: #a61390;">struct</span> <span style="color: #002200;">&#123;</span> 
	CGDoublePoint ul; 
	CGDoublePoint lr; 
<span style="color: #002200;">&#125;</span> CGXYRect;</pre></div></div>

<p>Afterwards, I copied the maxResolution and bbox (tilecache) and specified it for the initialResoultion and originShift respectively.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#import &quot;RMGenericMercatorWMSSource.h&quot;</span>
&nbsp;
CGFloat DegreesToRadians<span style="color: #002200;">&#40;</span>CGFloat degrees<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span><span style="color: #a61390;">return</span> degrees <span style="color: #002200;">*</span> M_PI <span style="color: #002200;">/</span> <span style="color: #2400d9;">180</span>;<span style="color: #002200;">&#125;</span>; 
CGFloat RadiansToDegrees<span style="color: #002200;">&#40;</span>CGFloat radians<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span><span style="color: #a61390;">return</span> radians <span style="color: #002200;">*</span> <span style="color: #2400d9;">180</span><span style="color: #002200;">/</span> M_PI;<span style="color: #002200;">&#125;</span>; 
&nbsp;
<span style="color: #a61390;">@implementation</span> RMGenericMercatorWMSSource
&nbsp;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span> initWithBaseUrl<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>baseUrl parameters<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSDictionary</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>params
<span style="color: #002200;">&#123;</span> 
	<span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">!</span><span style="color: #002200;">&#91;</span>super init<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span> 
		<span style="color: #a61390;">return</span> <span style="color: #a61390;">nil</span>; 
&nbsp;
	<span style="color: #11740a; font-style: italic;">// 156543.03392804062 for sideLength 256 pixels </span>
	<span style="color: #11740a; font-style: italic;">// initialResolution = 2 * M_PI * 6378137 / [self tileSideLength];</span>
	<span style="color: #11740a; font-style: italic;">// specify here whatever the resolution is from tilecache.</span>
	initialResolution <span style="color: #002200;">=</span> <span style="color: #2400d9;">156543.033928041</span>;
&nbsp;
	<span style="color: #11740a; font-style: italic;">// 20037508.342789244 </span>
	<span style="color: #11740a; font-style: italic;">//originShift = 2 * M_PI * 6378137 / 2;</span>
	<span style="color: #11740a; font-style: italic;">//originShift = 20037508.342789244f;</span>
	<span style="color: #11740a; font-style: italic;">// specify here whatever the bbox is from tilecache.</span>
	originShift <span style="color: #002200;">=</span> <span style="color: #2400d9;">20037508.32</span>;
&nbsp;
	NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;test initialResolution:%f originShift:%f&quot;</span>, initialResolution, originShift<span style="color: #002200;">&#41;</span>;
&nbsp;
	<span style="color: #11740a; font-style: italic;">// setup default parameters</span>
	<span style="color: #11740a; font-style: italic;">// use official EPSG:3857 by default, user can override to 900913 if needed.</span>
	wmsParameters <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSMutableDictionary</span> alloc<span style="color: #002200;">&#93;</span> initWithObjects<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSArray</span> alloc<span style="color: #002200;">&#93;</span> initWithObjects<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;EPSG:3857&quot;</span>,<span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;image/png&quot;</span>,<span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;GetMap&quot;</span>,<span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;1.1.1&quot;</span>,<span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;WMS&quot;</span>,<span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span> autorelease<span style="color: #002200;">&#93;</span> 
											  forKeys<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSArray</span> alloc<span style="color: #002200;">&#93;</span> initWithObjects<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;SRS&quot;</span>,<span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;FORMAT&quot;</span>,<span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;REQUEST&quot;</span>,<span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;VERSION&quot;</span>,<span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;SERVICE&quot;</span>,<span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span> autorelease<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>wmsParameters addEntriesFromDictionary<span style="color: #002200;">:</span>params<span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #11740a; font-style: italic;">// build WMS request URL template</span>
	urlTemplate <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSString</span> stringWithString<span style="color: #002200;">:</span>baseUrl<span style="color: #002200;">&#93;</span>;
	<span style="color: #400080;">NSEnumerator</span> <span style="color: #002200;">*</span>e <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>wmsParameters keyEnumerator<span style="color: #002200;">&#93;</span>;
	<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>key;
	<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>delimiter <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;&quot;</span>;
	<span style="color: #a61390;">while</span> <span style="color: #002200;">&#40;</span>key <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>e nextObject<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
		urlTemplate <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>urlTemplate stringByAppendingFormat<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;%@%@=%@&quot;</span>,
					   delimiter,
					   <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>key uppercaseString<span style="color: #002200;">&#93;</span> stringByAddingPercentEscapesUsingEncoding<span style="color: #002200;">:</span>NSASCIIStringEncoding<span style="color: #002200;">&#93;</span>, 
					   <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>wmsParameters objectForKey<span style="color: #002200;">:</span>key<span style="color: #002200;">&#93;</span> stringByAddingPercentEscapesUsingEncoding<span style="color: #002200;">:</span>NSASCIIStringEncoding<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
		delimiter <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;&amp;&quot;</span>;
	<span style="color: #002200;">&#125;</span>
	<span style="color: #a61390;">int</span> sideLength <span style="color: #002200;">=</span>  <span style="color: #002200;">&#91;</span>self tileSideLength<span style="color: #002200;">&#93;</span>;
	urlTemplate <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>urlTemplate stringByAppendingFormat<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;&amp;WIDTH=%d&amp;HEIGHT=%d&quot;</span>,sideLength,sideLength<span style="color: #002200;">&#93;</span> retain<span style="color: #002200;">&#93;</span>;
	<span style="color: #a61390;">return</span> self;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #11740a; font-style: italic;">// implement in subclass?</span>
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> uniqueTilecacheKey
<span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">return</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;AbstractMercatorWMSSource&quot;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>shortName
<span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">return</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Generic WMS Source&quot;</span>;
<span style="color: #002200;">&#125;</span>
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>longDescription
<span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">return</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Generic WMS Source&quot;</span>;
<span style="color: #002200;">&#125;</span>
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>shortAttribution
<span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">return</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Generic WMS Source&quot;</span>;
<span style="color: #002200;">&#125;</span>
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>longAttribution
<span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">return</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Generic WMS Source&quot;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">float</span><span style="color: #002200;">&#41;</span> minZoom
<span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">return</span> 1.0f;
<span style="color: #002200;">&#125;</span>
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">float</span><span style="color: #002200;">&#41;</span> maxZoom
<span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">return</span> 19.0f;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #11740a; font-style: italic;">// Converts given lat/lon in WGS84 Datum to XY in Spherical Mercator EPSG:3857 </span>
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span>CGPoint<span style="color: #002200;">&#41;</span> LatLonToMeters<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span>CLLocationCoordinate2D<span style="color: #002200;">&#41;</span> latlon 
<span style="color: #002200;">&#123;</span> 
	CGPoint meters; 
	meters.x <span style="color: #002200;">=</span> latlon.longitude <span style="color: #002200;">*</span> originShift <span style="color: #002200;">/</span> <span style="color: #2400d9;">180</span>; 
	meters.y <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">log</span><span style="color: #002200;">&#40;</span> <span style="color: #a61390;">tan</span><span style="color: #002200;">&#40;</span><span style="color: #002200;">&#40;</span><span style="color: #2400d9;">90.0</span> <span style="color: #002200;">+</span> latlon.latitude<span style="color: #002200;">&#41;</span> <span style="color: #002200;">*</span> M_PI <span style="color: #002200;">/</span> <span style="color: #2400d9;">360.0</span> <span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">/</span> <span style="color: #002200;">&#40;</span>M_PI <span style="color: #002200;">/</span> <span style="color: #2400d9;">180.0</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">*</span> originShift <span style="color: #002200;">/</span> <span style="color: #2400d9;">180</span>; 
	<span style="color: #a61390;">return</span> meters; 
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #11740a; font-style: italic;">//Converts XY point from Spherical Mercator EPSG:3857 to lat/lon in WGS84 Datum </span>
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span>CLLocationCoordinate2D<span style="color: #002200;">&#41;</span> MetersToLatLon<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span>CGPoint<span style="color: #002200;">&#41;</span> meters 
<span style="color: #002200;">&#123;</span> 
	CLLocationCoordinate2D latlon; 
	latlon.longitude <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span>meters.x <span style="color: #002200;">/</span> originShift<span style="color: #002200;">&#41;</span> <span style="color: #002200;">*</span> <span style="color: #2400d9;">180.0</span>; 
	latlon.latitude <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span>meters.y <span style="color: #002200;">/</span> originShift<span style="color: #002200;">&#41;</span> <span style="color: #002200;">*</span> <span style="color: #2400d9;">180.0</span>; 
	<span style="color: #11740a; font-style: italic;">//latlon.latitude = - 180 / M_PI * (2 * atan( exp( latlon.latitude * M_PI / 180.0)) - M_PI / 2.0); </span>
	latlon.latitude <span style="color: #002200;">=</span> <span style="color: #2400d9;">180</span> <span style="color: #002200;">/</span> M_PI <span style="color: #002200;">*</span> <span style="color: #002200;">&#40;</span><span style="color: #2400d9;">2</span> <span style="color: #002200;">*</span> <span style="color: #a61390;">atan</span><span style="color: #002200;">&#40;</span> <span style="color: #a61390;">exp</span><span style="color: #002200;">&#40;</span> latlon.latitude <span style="color: #002200;">*</span> M_PI <span style="color: #002200;">/</span> <span style="color: #2400d9;">180.0</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">-</span> M_PI <span style="color: #002200;">/</span> <span style="color: #2400d9;">2.0</span><span style="color: #002200;">&#41;</span>; 
	<span style="color: #a61390;">return</span> latlon; 
<span style="color: #002200;">&#125;</span> 
&nbsp;
<span style="color: #11740a; font-style: italic;">// Converts pixel coordinates in given zoom level of pyramid to EPSG:3857 </span>
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span>CGDoublePoint<span style="color: #002200;">&#41;</span> PixelsToMeters<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span><span style="color: #002200;">&#41;</span> px PixelY<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span><span style="color: #002200;">&#41;</span>py atZoom<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span><span style="color: #002200;">&#41;</span>zoom 
<span style="color: #002200;">&#123;</span> 
	<span style="color: #a61390;">double</span> resolution <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>self ResolutionAtZoom<span style="color: #002200;">:</span> zoom<span style="color: #002200;">&#93;</span>; 
	CGDoublePoint meters; 
	<span style="color: #a61390;">double</span> x <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span>px <span style="color: #002200;">*</span> resolution <span style="color: #002200;">-</span> originShift<span style="color: #002200;">&#41;</span>; 
	<span style="color: #a61390;">double</span> y <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span>py <span style="color: #002200;">*</span> resolution <span style="color: #002200;">-</span> originShift<span style="color: #002200;">&#41;</span>; 
&nbsp;
	meters.x <span style="color: #002200;">=</span> x;
	meters.y <span style="color: #002200;">=</span> y;
&nbsp;
	NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;px: %d py: %d resolution: %f originShift: %f x: %f y: %f&quot;</span>, px, py, resolution, originShift, x, y<span style="color: #002200;">&#41;</span>;
&nbsp;
	<span style="color: #a61390;">return</span> meters; 
<span style="color: #002200;">&#125;</span> 
&nbsp;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> tileURL<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span>RMTile<span style="color: #002200;">&#41;</span> tile 
<span style="color: #002200;">&#123;</span> 
	<span style="color: #11740a; font-style: italic;">//RMLatLongBounds tileBounds = [self TileLatLonBounds:tile];</span>
	<span style="color: #11740a; font-style: italic;">// Get BBOX coordinates in meters</span>
	CGXYRect tileBounds <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>self TileBounds<span style="color: #002200;">:</span>tile<span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>url <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>urlTemplate stringByAppendingFormat<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;&amp;BBOX=%f,%f,%f,%f&quot;</span>,
					 tileBounds.ul.x,
					 tileBounds.lr.y,
					 tileBounds.lr.x,
					 tileBounds.ul.y<span style="color: #002200;">&#93;</span>;
&nbsp;
	NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Tile %d,%d,%d yields %@&quot;</span>,tile.zoom, tile.x, tile.y, url<span style="color: #002200;">&#41;</span>; 
&nbsp;
	<span style="color: #a61390;">return</span> url; 
<span style="color: #002200;">&#125;</span> 
&nbsp;
&nbsp;
<span style="color: #11740a; font-style: italic;">//Returns bounds of the given tile in EPSG:3857 coordinates </span>
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span>CGXYRect<span style="color: #002200;">&#41;</span>  TileBounds<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span>RMTile<span style="color: #002200;">&#41;</span> tile 
<span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">int</span> sideLength <span style="color: #002200;">=</span>  <span style="color: #002200;">&#91;</span>self tileSideLength<span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #a61390;">int</span> zoom <span style="color: #002200;">=</span> tile.zoom;
	<span style="color: #a61390;">long</span> twoToZoom <span style="color: #002200;">=</span> <span style="color: #a61390;">pow</span><span style="color: #002200;">&#40;</span><span style="color: #2400d9;">2</span>,zoom<span style="color: #002200;">&#41;</span>;
	CGXYRect tileBounds; 
	tileBounds.ul <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>self PixelsToMeters<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span>tile.x <span style="color: #002200;">*</span> sideLength<span style="color: #002200;">&#41;</span> 
								  PixelY<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#40;</span>twoToZoom<span style="color: #002200;">-</span>tile.y<span style="color: #002200;">&#41;</span> <span style="color: #002200;">*</span> sideLength<span style="color: #002200;">&#41;</span> 
								  atZoom<span style="color: #002200;">:</span> zoom <span style="color: #002200;">&#93;</span>; 
	tileBounds.lr <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>self PixelsToMeters<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#40;</span>tile.x<span style="color: #002200;">+</span><span style="color: #2400d9;">1</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">*</span> sideLength<span style="color: #002200;">&#41;</span> 
								  PixelY<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#40;</span>twoToZoom<span style="color: #002200;">-</span>tile.y<span style="color: #002200;">-</span><span style="color: #2400d9;">1</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">*</span> sideLength<span style="color: #002200;">&#41;</span> 
								  atZoom<span style="color: #002200;">:</span> zoom<span style="color: #002200;">&#93;</span>;
	<span style="color: #a61390;">return</span> tileBounds; 
<span style="color: #002200;">&#125;</span> 
&nbsp;
<span style="color: #11740a; font-style: italic;">//Resolution (meters/pixel) for given zoom level (measured at Equator) </span>
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">double</span><span style="color: #002200;">&#41;</span> ResolutionAtZoom <span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span><span style="color: #002200;">&#41;</span> zoom 
<span style="color: #002200;">&#123;</span> 
	<span style="color: #a61390;">return</span> initialResolution <span style="color: #002200;">/</span> <span style="color: #a61390;">pow</span><span style="color: #002200;">&#40;</span><span style="color: #2400d9;">2</span>,zoom<span style="color: #002200;">&#41;</span>; 
<span style="color: #002200;">&#125;</span> 
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>

<p>6. Download <a href="/wordpress/wp-content/uploads/2010/01/TileCache_RouteMe.zip" title="TileCache_RouteMe.zip">TileCache_RouteMe.zip</a> Note: You need a valid mapserver and tilecache running.</p>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2010/01/iphone-note-20integrating-mapservertilecache-to-routeme/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>TileCache: Getting Cutoff on the edges</title>
		<link>/wordpress/2008/10/tilecache-getting-cutoff-on-the-edges/</link>
		<comments>/wordpress/2008/10/tilecache-getting-cutoff-on-the-edges/#comments</comments>
		<pubDate>Fri, 24 Oct 2008 06:37:43 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[tilecache]]></category>

		<guid isPermaLink="false">/wordpress/?p=275</guid>
		<description><![CDATA[In Tilecache, metaTiling creates larger tiles and chops them up. Note the difference between using metatile=yes and metatile=no. Figure 1: metatile=no Figure 2: metatile=yes]]></description>
			<content:encoded><![CDATA[<p>In Tilecache, metaTiling creates larger tiles and chops them up.<br />
Note the difference between using metatile=yes and metatile=no.</p>
<p><img src="/wordpress/wp-content/uploads/2008/10/metatile-no.png" alt="metatile_no.png" border="0" width="323" height="332" /></p>
<p>Figure 1: metatile=no</p>
<p><img src="/wordpress/wp-content/uploads/2008/10/metatile-yes.png" alt="metatile_yes.png" border="0" width="325" height="338" /></p>
<p>Figure 2: metatile=yes</p>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2008/10/tilecache-getting-cutoff-on-the-edges/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Recaching single tiles in Tilecache</title>
		<link>/wordpress/2008/09/recaching-single-tiles-in-tilecache/</link>
		<comments>/wordpress/2008/09/recaching-single-tiles-in-tilecache/#comments</comments>
		<pubDate>Mon, 22 Sep 2008 06:16:12 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[tilecache]]></category>

		<guid isPermaLink="false">/wordpress/?p=265</guid>
		<description><![CDATA[Got this one from IRC this morning.. In order to recache single tiles in TC, as long as it is not metatile (metatile=false), then we can simply append &#8220;FORCE=1&#8243; in the URL.. http://192.168.2.14/tilecache/tilecache.py?FORCE=1&#038;LAYERS=beijing_900913_wide_en&#038;MAP=%2Fmyhome%2Fmap%2Fbeijing%2Fnew%2Fbeijing_900913_wide_en%2Fbeijing.map&#038;FORMAT=jpg&#038;TRANSPARENT=true&#038;SERVICE=WMS&#038;VERSION=1.1.1&#038;REQUEST=GetMap&#038;STYLES=&#038;EXCEPTIONS=application%2Fvnd.ogc.se_inimage&#038;SRS=EPSG%3A900913&#038;BBOX=12951949.03168994,4852222.893873828,12952101.905746482,4852375.767930372&#038;WIDTH=256&#038;HEIGHT=256 Well for completeness, I gave my ofcmate a DELETE tool which wipes out everything in the /tilecache/map_dir directory..]]></description>
			<content:encoded><![CDATA[<p>Got this one from IRC this morning.. In order to recache single tiles in TC, as long as it is not metatile (metatile=false), then we can simply append &#8220;FORCE=1&#8243; in the URL..</p>
<p>http://192.168.2.14/tilecache/tilecache.py?<strong>FORCE=1</strong>&#038;LAYERS=beijing_900913_wide_en&#038;MAP=%2Fmyhome%2Fmap%2Fbeijing%2Fnew%2Fbeijing_900913_wide_en%2Fbeijing.map&#038;FORMAT=jpg&#038;TRANSPARENT=true&#038;SERVICE=WMS&#038;VERSION=1.1.1&#038;REQUEST=GetMap&#038;STYLES=&#038;EXCEPTIONS=application%2Fvnd.ogc.se_inimage&#038;SRS=EPSG%3A900913&#038;BBOX=12951949.03168994,4852222.893873828,12952101.905746482,4852375.767930372&#038;WIDTH=256&#038;HEIGHT=256</p>
<p><img src="/wordpress/wp-content/uploads/2008/09/picture-22.png" alt="Picture 2.png" border="0" width="531" height="275"/></p>
<p>Well for completeness, I gave my ofcmate a DELETE tool which wipes out everything in the /tilecache/map_dir directory.. </p>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2008/09/recaching-single-tiles-in-tilecache/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using GDALWARP to reproject raster that will fit with Google Satellite</title>
		<link>/wordpress/2008/07/using-gdalwarp-to-reproject-raster-that-will-fit-with-google-satellite/</link>
		<comments>/wordpress/2008/07/using-gdalwarp-to-reproject-raster-that-will-fit-with-google-satellite/#comments</comments>
		<pubDate>Tue, 29 Jul 2008 12:48:21 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[GDAL/OGR]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[maserver]]></category>
		<category><![CDATA[openlayers]]></category>
		<category><![CDATA[tilecache]]></category>

		<guid isPermaLink="false">/wordpress/?p=208</guid>
		<description><![CDATA[Just a couple of notes to onself using gdal: Use gdalwarp to reproject your GeoTIFF files! I wanted to use my own satellite images acquired from GeoEye, however, on some areas I wanted to use google sat images as well since I don&#8217;t have the coverage. In order to do so, I need to reproject]]></description>
			<content:encoded><![CDATA[<p>Just a couple of notes to onself using gdal: Use <em>gdalwarp</em> to reproject your GeoTIFF files! I wanted to use my own satellite images acquired from GeoEye, however, on some areas I wanted to use google sat images as well since I don&#8217;t have the coverage. In order to do so, I need to reproject the sat images to 900913. Note you need to specify this in your epsg file in my previous post.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">rupert:beijing_900913_satellite rupert$ gdalinfo Mosaic_RGB.tif
Driver: GTiff<span style="color: #000000; font-weight: bold;">/</span>GeoTIFF
Files: Mosaic_RGB.tif
Size is <span style="color: #000000;">4248</span>, <span style="color: #000000;">4553</span>
Coordinate System is:
GEOGCS<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #ff0000;">&quot;WGS 84&quot;</span>,
    DATUM<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #ff0000;">&quot;WGS_1984&quot;</span>,
        SPHEROID<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #ff0000;">&quot;WGS 84&quot;</span>,<span style="color: #000000;">6378137</span>,<span style="color: #000000;">298.2572235630016</span>,
            AUTHORITY<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #ff0000;">&quot;EPSG&quot;</span>,<span style="color: #ff0000;">&quot;7030&quot;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>,
        AUTHORITY<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #ff0000;">&quot;EPSG&quot;</span>,<span style="color: #ff0000;">&quot;6326&quot;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>,
    PRIMEM<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #ff0000;">&quot;Greenwich&quot;</span>,<span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>,
    UNIT<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #ff0000;">&quot;degree&quot;</span>,<span style="color: #000000;">0.0174532925199433</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>,
    AUTHORITY<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #ff0000;">&quot;EPSG&quot;</span>,<span style="color: #ff0000;">&quot;4326&quot;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
Origin = <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">116.291476140000000</span>,<span style="color: #000000;">40.025198500000002</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
Pixel Size = <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">0.000046860000000</span>,-<span style="color: #000000;">0.000035970000000</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
Metadata:
  <span style="color: #007800;">AREA_OR_POINT</span>=Area
  <span style="color: #007800;">TIFFTAG_XRESOLUTION</span>=<span style="color: #000000;">100</span>
  <span style="color: #007800;">TIFFTAG_YRESOLUTION</span>=<span style="color: #000000;">100</span>
Image Structure Metadata:
  <span style="color: #007800;">INTERLEAVE</span>=BAND
Corner Coordinates:
Upper Left  <span style="color: #7a0874; font-weight: bold;">&#40;</span> <span style="color: #000000;">116.2914761</span>,  <span style="color: #000000;">40.0251985</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>116d17<span style="color: #ff0000;">'29.31&quot;E, 40d 1'</span><span style="color: #000000;">30.71</span><span style="color: #ff0000;">&quot;N)
Lower Left  ( 116.2914761,  39.8614271) (116d17'29.31&quot;</span>E, 39d51<span style="color: #ff0000;">'41.14&quot;N)
Upper Right ( 116.4905374,  40.0251985) (116d29'</span><span style="color: #000000;">25.93</span><span style="color: #ff0000;">&quot;E, 40d 1'30.71&quot;</span>N<span style="color: #7a0874; font-weight: bold;">&#41;</span>
Lower Right <span style="color: #7a0874; font-weight: bold;">&#40;</span> <span style="color: #000000;">116.4905374</span>,  <span style="color: #000000;">39.8614271</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>116d29<span style="color: #ff0000;">'25.93&quot;E, 39d51'</span><span style="color: #000000;">41.14</span><span style="color: #ff0000;">&quot;N)
Center      ( 116.3910068,  39.9433128) (116d23'27.62&quot;</span>E, 39d56<span style="color: #ff0000;">'35.93&quot;N)
Band 1 Block=4248x1 Type=Byte, ColorInterp=Red
Band 2 Block=4248x1 Type=Byte, ColorInterp=Green
Band 3 Block=4248x1 Type=Byte, ColorInterp=Blue</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">rupert:beijing_900913_satellite rupert$ gdalwarp -s_srs epsg:<span style="color: #000000;">4326</span> -t_srs epsg:<span style="color: #000000;">900913</span> Mosaic_RGB.tif sat_4m_rgb.tif
Creating output <span style="color: #c20cb9; font-weight: bold;">file</span> that is 4245P x 4556L.
Processing input <span style="color: #c20cb9; font-weight: bold;">file</span> Mosaic_RGB.tif.
0...10...20...30...40...50...60...70...80...90...100 - done.</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">rupert:beijing_900913_satellite rupert$ gdalinfo sat_4m_rgb.tif
Driver: GTiff<span style="color: #000000; font-weight: bold;">/</span>GeoTIFF
Files: sat_4m_rgb.tif
Size is <span style="color: #000000;">4245</span>, <span style="color: #000000;">4556</span>
Coordinate System is:
PROJCS<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #ff0000;">&quot;Google Maps Global Mercator&quot;</span>,
    GEOGCS<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #ff0000;">&quot;WGS 84&quot;</span>,
        DATUM<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #ff0000;">&quot;WGS_1984&quot;</span>,
            SPHEROID<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #ff0000;">&quot;WGS 84&quot;</span>,<span style="color: #000000;">6378137</span>,<span style="color: #000000;">298.2572235630016</span>,
                AUTHORITY<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #ff0000;">&quot;EPSG&quot;</span>,<span style="color: #ff0000;">&quot;7030&quot;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>,
            AUTHORITY<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #ff0000;">&quot;EPSG&quot;</span>,<span style="color: #ff0000;">&quot;6326&quot;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>,
        PRIMEM<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #ff0000;">&quot;Greenwich&quot;</span>,<span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>,
        UNIT<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #ff0000;">&quot;degree&quot;</span>,<span style="color: #000000;">0.0174532925199433</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>,
        AUTHORITY<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #ff0000;">&quot;EPSG&quot;</span>,<span style="color: #ff0000;">&quot;4326&quot;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>,
    PROJECTION<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #ff0000;">&quot;Mercator_1SP&quot;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>,
    PARAMETER<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #ff0000;">&quot;central_meridian&quot;</span>,<span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>,
    PARAMETER<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #ff0000;">&quot;scale_factor&quot;</span>,<span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>,
    PARAMETER<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #ff0000;">&quot;false_easting&quot;</span>,<span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>,
    PARAMETER<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #ff0000;">&quot;false_northing&quot;</span>,<span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>,
    UNIT<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #ff0000;">&quot;metre&quot;</span>,<span style="color: #000000;">1</span>,
        AUTHORITY<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #ff0000;">&quot;EPSG&quot;</span>,<span style="color: #ff0000;">&quot;9001&quot;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
Origin = <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">12945507.907502911984921</span>,<span style="color: #000000;">4869604.732793668285012</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
Pixel Size = <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">5.219801430503303</span>,-<span style="color: #000000;">5.219801430503303</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
Metadata:
  <span style="color: #007800;">AREA_OR_POINT</span>=Area
Image Structure Metadata:
  <span style="color: #007800;">INTERLEAVE</span>=PIXEL
Corner Coordinates:
Upper Left  <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">12945507.908</span>, <span style="color: #000000;">4869604.733</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>116d17<span style="color: #ff0000;">'29.31&quot;E, 40d12'</span><span style="color: #000000;">53.10</span><span style="color: #ff0000;">&quot;N)
Lower Left  (12945507.908, 4845823.317) (116d17'29.31&quot;</span>E, 40d <span style="color: #000000;">3</span><span style="color: #ff0000;">'2.78&quot;N)
Upper Right (12967665.965, 4869604.733) (116d29'</span><span style="color: #000000;">25.89</span><span style="color: #ff0000;">&quot;E, 40d12'53.10&quot;</span>N<span style="color: #7a0874; font-weight: bold;">&#41;</span>
Lower Right <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">12967665.965</span>, <span style="color: #000000;">4845823.317</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>116d29<span style="color: #ff0000;">'25.89&quot;E, 40d 3'</span><span style="color: #000000;">2.78</span><span style="color: #ff0000;">&quot;N)
Center      (12956586.936, 4857714.025) (116d23'27.60&quot;</span>E, 40d <span style="color: #000000;">7</span><span style="color: #ff0000;">'58.12&quot;N)
Band 1 Block=4245x1 Type=Byte, ColorInterp=Red
Band 2 Block=4245x1 Type=Byte, ColorInterp=Green
Band 3 Block=4245x1 Type=Byte, ColorInterp=Blue</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>/wordpress/2008/07/using-gdalwarp-to-reproject-raster-that-will-fit-with-google-satellite/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Jpeg decoder problem on TileCache on MacOSX Leopard</title>
		<link>/wordpress/2008/05/jpeg-decoder-problem-on-tilecache-on-macosx-leopard/</link>
		<comments>/wordpress/2008/05/jpeg-decoder-problem-on-tilecache-on-macosx-leopard/#comments</comments>
		<pubDate>Mon, 12 May 2008 09:26:07 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[tilecache]]></category>
		<category><![CDATA[leopard]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">/wordpress/?p=184</guid>
		<description><![CDATA[There is a problem with a &#8220;jpeg decoder&#8221; because Python Imaging Library (PIL) cannot find the jpeg libraries. Remember that we installed kyngchaos UnixIO libraries, therefore the PIL setup.py script should point to use those libraries. Actually, I even installed the jpegsrc manually. I believe there is no need to do this, since UnixIO Image]]></description>
			<content:encoded><![CDATA[<p>There is a problem with a <em>&#8220;jpeg decoder&#8221;</em> because <a href="http://www.pythonware.com/products/pil/">Python Imaging Library (PIL)</a> cannot find the jpeg libraries. Remember that we installed <a href="http://www.kyngchaos.com/wiki/software:frameworks">kyngchaos UnixIO libraries</a>, therefore the PIL setup.py script should point to use those libraries. </p>
<p>Actually, I even installed the jpegsrc manually. I believe there is no need to do this, since UnixIO Image libraries is sufficient enough for PIL to install. What is important is to ensure that python tests succeeded. Once you get passed that, then installing PIL should work.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">1. Extract Imaging-1.1.6.tar.gz
2. Edit setup.py to reflect:
<span style="color: #007800;">JPEG_ROOT</span>=<span style="color: #ff0000;">&quot;/Library/Frameworks/UnixImageIO.framework/unix&quot;</span>
3. python setup.py build_ext <span style="color: #660033;">-i</span>
4. If no <span style="color: #7a0874; font-weight: bold;">test</span> fails, <span style="color: #000000; font-weight: bold;">then</span> go ahead and <span style="color: #c20cb9; font-weight: bold;">install</span>
5. python setup.py <span style="color: #c20cb9; font-weight: bold;">install</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>/wordpress/2008/05/jpeg-decoder-problem-on-tilecache-on-macosx-leopard/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using TileCache, OpenLayers, Mapserver for Projection 900913</title>
		<link>/wordpress/2008/04/using-tilecache-openlayers-mapserver-for-projection-900913/</link>
		<comments>/wordpress/2008/04/using-tilecache-openlayers-mapserver-for-projection-900913/#comments</comments>
		<pubDate>Tue, 08 Apr 2008 01:50:12 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[mapserver]]></category>
		<category><![CDATA[openlayers]]></category>
		<category><![CDATA[tilecache]]></category>

		<guid isPermaLink="false">http://www.gisnotes.com/wordpress/?p=166</guid>
		<description><![CDATA[I had a few problems with TileCache the other week which I am eager to blog about, since I knew for sure that later on, I might encounter the same. I don&#8217;t have the exact errors with me right now, so I&#8217;m jotting this down from my head&#8230; Classic Resolutions problem. Use extent_type=loose Can not]]></description>
			<content:encoded><![CDATA[<p>I had a few problems with <a href="www.tilecache.org">TileCache</a> the other week which I am eager to blog about, since I knew for sure that later on, I might encounter the same. I don&#8217;t have the exact errors with me right now, so I&#8217;m jotting this down from my head&#8230;</p>
<ol>
<li>Classic Resolutions problem. Use extent_type=loose</li>
<li>Can not set image type</li>
</ol>
<p>UPDATED (JAN 11, 2010): Classic Resolutions problem:</p>
<p>How are resolutions calculated? Assuming we have:</p>
<p>Original:<br />
	Lower Left (LL) or minx, miny: 12453557, -5434940<br />
	Upper Right (UR) or max, maxy: 16980842, -1180729</p>
<p>maxResolution = (max &#8211; minx)/tilesize = (16980842 &#8211; 12453557)/512 = 8842.353<br />
	where tilesize = 512.</p>
<p>Therefore, we can set/guess for max so that we have maxResolution as a whole number.</p>
<p>Adjusted:<br />
	minx, miny: 12453557, -5434940<br />
	maxx, maxy: 16980661, -1180729</p>
<p>gives a maxResolution (whole number) of 8842.</p>
<p>Now, you can use 8842 in both the TileCache.cfg and OpenLayers Javascript.<span id="more-166"></span><br />
<strong>A. Google BaseLayer + Road WMS Overlay = Validation approach before we proceed to TC.</strong></p>
<p>1. OpenLayers (OL) Code: <a href="http://www.gisnotes.com/platform/docs/examples/GoogleWMSRoads.cfm">http://www.gisnotes.com/platform/docs/examples/GoogleWMSRoads.cfm</a></p>
<p>2. Map File Configuration: <code>/home/map/beijing/new/beijing_google_roads</code></p>
<p>Well the above files are not exactly for TC, but it is a good demonstration that we could overlay our custom layers (WMS) on top of Google as the base layer. For a more detailed explanation regarding Google + OL, please read my previous <a href="/wordpress/index.php/2007/12/22/openlayers-google-spherical-mercator-example/">gisnote</a>. Also, this is a good test to see if our <a href="">Mapserver <em>mapfile</em> configuration</a> is correct. I do suggest not to proceed with OL + TC not unless you have validated the mapfile through OL (Google + WMS).</p>
<p><strong>B. Google900913 Tilecache as baselayer</strong></p>
<p>Ok.. so here it is..</p>
<p>1. OpenLayers Code: <a href="http://www.gisnotes.com/platform/docs/examples/TilecacheGoogle900913Base.cfm">http://www.gisnotes.com/platform/docs/examples/TilecacheGoogle900913Base.cfm</a></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">        window.<span style="color: #000066;">onload</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #003366; font-weight: bold;">var</span> options <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
                        projection<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">new</span> OpenLayers.<span style="color: #660066;">Projection</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;EPSG:900913&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
                        units<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;m&quot;</span><span style="color: #339933;">,</span>
&nbsp;
                        <span style="color: #006600; font-style: italic;">//maxResolution: 156543.0339,</span>
                        resolutions <span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #CC0000;">156543.03390000001</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">78271.516950000005</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">39135.758475000002</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">19567.879237500001</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">9783.9396187500006</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">4891.9698093750003</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">2445.9849046875001</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">1222.9924523437501</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">611.49622617187504</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">305.74811308593752</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">152.87405654296876</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">76.43702827148438</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">38.21851413574219</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">19.109257067871095</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">9.5546285339355475</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">4.7773142669677737</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">2.3886571334838869</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">1.1943285667419434</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0.59716428337097172</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0.29858214168548586</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
                        <span style="color: #006600; font-style: italic;">//zoom: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19] @ numZoomLevels: 20</span>
                        numZoomLevels<span style="color: #339933;">:</span> <span style="color: #CC0000;">20</span><span style="color: #339933;">,</span>
                        <span style="color: #006600; font-style: italic;">//maxExtent: new OpenLayers.Bounds(12823075.86334, 4800551.12375, 13101918.14248, 5021301.26141)</span>
                        <span style="color: #006600; font-style: italic;">//maxExtent: new OpenLayers.Bounds(12823075, 4800551, 13101918, 5021301)</span>
                        <span style="color: #006600; font-style: italic;">//maxExtent: new OpenLayers.Bounds(12848138, 4785083, 13080212, 5021118.5)</span>
                        maxExtent<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">new</span> OpenLayers.<span style="color: #660066;">Bounds</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span><span style="color: #CC0000;">20037508</span><span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">20037508</span><span style="color: #339933;">,</span><span style="color: #CC0000;">20037508</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">20037508.34</span><span style="color: #009900;">&#41;</span>
                    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
            OpenLayers.<span style="color: #660066;">IMAGE_RELOAD_ATTEMPTS</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">3</span><span style="color: #339933;">;</span>
            OpenLayers.<span style="color: #660066;">Util</span>.<span style="color: #660066;">onImageLoadErrorColor</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;transparent&quot;</span><span style="color: #339933;">;</span>
&nbsp;
            map <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> OpenLayers.<span style="color: #660066;">Map</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'mapdiv'</span><span style="color: #339933;">,</span>options<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #003366; font-weight: bold;">var</span> serverURL <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;/tilecache/tilecache.py&quot;</span><span style="color: #339933;">;</span>
            <span style="color: #006600; font-style: italic;">// start custom layer here</span>
            <span style="color: #003366; font-weight: bold;">var</span> layer_obj <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> OpenLayers.<span style="color: #660066;">Layer</span>.<span style="color: #660066;">WMS</span><span style="color: #009900;">&#40;</span>
                <span style="color: #3366CC;">&quot;Beijing&quot;</span><span style="color: #339933;">,</span>
                serverURL<span style="color: #339933;">,</span>
                <span style="color: #009900;">&#123;</span>
                    layers<span style="color: #339933;">:</span> <span style="color: #3366CC;">'beijing_900913'</span><span style="color: #339933;">,</span>
                    map<span style="color: #339933;">:</span> <span style="color: #3366CC;">'/home/map/beijing/new/beijing_900913/beijing.map'</span><span style="color: #339933;">,</span>
                    format<span style="color: #339933;">:</span> <span style="color: #3366CC;">'image/jpg'</span><span style="color: #339933;">,</span>
                    <span style="color: #3366CC;">'transparent'</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'off'</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            layer_obj.<span style="color: #660066;">setIsBaseLayer</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            layer_obj.<span style="color: #660066;">setVisibility</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            map.<span style="color: #660066;">addLayer</span><span style="color: #009900;">&#40;</span>layer_obj<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>2. TileCache Configuration: /wwwroot/tilecache/tilecache.cfg</p>

<div class="wp_syntax"><div class="code"><pre class="cnf" style="font-family:monospace;">[beijing_900913]
type=WMSLayer
url=http://127.0.0.1/cgi-bin/mapserv?map=/home/map/beijing/new/beijing_900913/beijing.map
layers=beijing_900913
metatile=true
extension=jpg
levels=20
resolutions=156543.03390000001, 78271.516950000005, 39135.758475000002, 19567.879237500001, 9783.9396187500006, 4891.9698093750003, 2445.9849046875001, 1222.9924523437501, 611.49622617187504, 305.74811308593752, 152.87405654296876, 76.43702827148438, 38.21851413574219, 19.109257067871095, 9.5546285339355475, 4.7773142669677737, 2.3886571334838869, 1.1943285667419434, 0.59716428337097172, 0.29858214168548586
srs=EPSG:900913
bbox=-20037508, -20037508, 20037508, 20037508.34
#maxResolution=156543.0339
extent_type=loose
debug=on</pre></div></div>

<p>You can either set resolutions or maxResolutions. I always wanted to be explicit, so setting the <strong>resolutions</strong> is my preference.</p>
<p>3. MapFile Configuration: <code>/home/map/beijing/new/beijing_900913/beijing.map</code><br />
I have a long mapfile, and using <a href="http://mapserver.gis.umn.edu/docs/reference/mapfile/Include">includes</a> helped a lot, see my previous <a href="/wordpress/index.php/2007/08/19/103/">gisnote</a>.  For debugging your mapfile, read this <a href="/wordpress/index.php/2007/08/24/mapserver-debug-output/">post.</a></p>
<p><strong>Always Remember&#8230;I believe when they made TC, I presume they always tested on WGS84(lonlat), this means if you don&#8217;t set anything explicit, it would <em>implicitly</em> set settings in WGS84(lon/lat)&#8230;</strong></p>
<ul>
<li>Ensure that you have the vector data in the necessary projection, in my case it&#8217;s 900913.</li>
<p><br/> </p>
<li>Ensure that the <em>resolutions</em> from OL (B.1) is reflected in TC configuration (B.2).</li>
<p><br/></p>
<li>Ensure that the <em>maxextents</em> from OL (B.1) is reflected in TC configuration (B.2) as <em>bbox</em>.</li>
<p><br/>
</ul>
<p><strong>C. Still can&#8217;t get it running?</strong></p>
<p>1. Narrow down the error.</p>
<p>2. <strong>tail -f /var/log/apache2/error.log</strong> and <strong>access.log</strong> is your bestfriend. It&#8217;s a good starting point to trace down what went wrong.  If you can&#8217;t see it from Apache&#8217;s error.log then ensure that <a href="/wordpress/index.php/2007/07/25/installing-tilecache/">python debugging is turned on.</a></p>
<p>3. Sometimes TC <strong>[a]</strong> gives you an obvious error or <strong>[b]</strong> its just a link to the mapserv request. </p>
<p>Examples of <strong>[a]</strong>:</p>
<ul>
<li><em>Classic Resolution problem stated above. </em>- If you followed my final notes above, then this should not happen. If you&#8217;ve set up things correctly but it&#8217;s still broken and you want to pull your hair out, then do a clean test stated below in D.</li>
<li><em>Cannot set image type</em> &#8211; Check the extensions from the mapfile and TC config. Are they both in jpg&#8217;s?</li>
</ul>
<p>The latter <strong>[b]</strong> is harder to debug. Most likely its a mapserver mapfile mishap and the easiest way to hunt this down is only thru your error.log (note: you need mapserver to have a debug=true when you compiled it, that&#8217;s another story.)</p>
<p><strong>D. Doing a clean test as always</strong><br />
1. Always disable any caching when testing. Disable cache from your browser, for FF I use the webdeveloper toolbar. It&#8217;s as easy as Disable -> Disable Cache.</p>
<p>2. Stop/Start Apache. Hoping Python get&#8217;s a clean start as well. If you found any pyc (python compiled) under TC source directory&#8230; then stop Apache; remove the pycs; start Apache.</p>
<p>3. Seeing the same images? Always remove the image caches! rm -Rf /data/tilecache/beijing_900913</p>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2008/04/using-tilecache-openlayers-mapserver-for-projection-900913/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installing TileCache on RedHat/CentOS</title>
		<link>/wordpress/2007/07/installing-tilecache/</link>
		<comments>/wordpress/2007/07/installing-tilecache/#comments</comments>
		<pubDate>Wed, 25 Jul 2007 12:36:45 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[tilecache]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[centos]]></category>
		<category><![CDATA[mod_python]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">/wordpress/?p=79</guid>
		<description><![CDATA[1. Install Apache ./configure &#8211;prefix=/usr/local/apache2 &#8211;enable-so &#8211;enable-rewrite &#8211;with-mpm=prefork make make install rm -Rf /usr/local/apache2/htdocs/* 2. Install mod_python-3.3.1 ./configure --with-apxs=/usr/local/apache2/bin/apxs make make install 3. Install Python Imaging Library (PIL) &#8211; Imaging-1.1.6 python setup.py install Note: To check if PIL was successfully installed: #python selftest.py ***Test Failed*** 1 failures. *** 1 tests of 57 failed. 47 ln]]></description>
			<content:encoded><![CDATA[<p>1. Install Apache<br />
./configure &#8211;prefix=/usr/local/apache2 &#8211;enable-so &#8211;enable-rewrite &#8211;with-mpm=prefork<br />
make<br />
make install<br />
rm -Rf /usr/local/apache2/htdocs/*</p>
<p>2. Install mod_python-3.3.1<br />
<code><br />
./configure --with-apxs=/usr/local/apache2/bin/apxs<br />
make<br />
make install<br />
</code></p>
<p>3. Install Python Imaging Library (PIL) &#8211; Imaging-1.1.6<br />
<code><br />
python setup.py install<br />
</code></p>
<p>Note: To check if PIL was successfully installed:<br />
#python selftest.py<br />
***Test Failed*** 1 failures.<br />
*** 1 tests of 57 failed.</p>
<p>   47  ln -s /usr/lib/libjpeg.so.62 /usr/lib/libjpeg.so<br />
   48  ldconfig<br />
   49  python setup.py install<br />
   51  python selftest.py<br />
   54  rm -rf Imaging-1.1.6<br />
   55  tar -zxvf Imaging-1.1.6.tar.gz<br />
   56  cd Imaging-1.1.6<br />
   58  python selftest.py -> still fails<br />
   59  python setup.py install<br />
   60  python selftest.py -> ok</p>
<p>4. Check if mod_python was sucessfully installed.<br />
<a href="http://www.dscpl.com.au/wiki/ModPython/Articles/GettingModPythonWorking">http://www.dscpl.com.au/wiki/ModPython/Articles/GettingModPythonWorking</a></p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: black;">&#91;</span>root@rupert-centos pytest<span style="color: black;">&#93;</span><span style="color: #808080; font-style: italic;"># python</span>
Python 2.4.3 <span style="color: black;">&#40;</span><span style="color: #808080; font-style: italic;">#1, Mar 14 2007, 18:51:08)</span>
<span style="color: black;">&#91;</span>GCC 4.1.1 <span style="color: #ff4500;">20070105</span> <span style="color: black;">&#40;</span>Red Hat 4.1.1-<span style="color: #ff4500;">52</span><span style="color: black;">&#41;</span><span style="color: black;">&#93;</span> on linux2
Type <span style="color: #483d8b;">&quot;help&quot;</span>, <span style="color: #483d8b;">&quot;copyright&quot;</span>, <span style="color: #483d8b;">&quot;credits&quot;</span> <span style="color: #ff7700;font-weight:bold;">or</span> <span style="color: #483d8b;">&quot;license&quot;</span> <span style="color: #ff7700;font-weight:bold;">for</span> more information.
<span style="color: #66cc66;">&amp;</span>gt<span style="color: #66cc66;">;&amp;</span>gt<span style="color: #66cc66;">;&amp;</span>gt<span style="color: #66cc66;">;</span> <span style="color: #ff7700;font-weight:bold;">import</span> mod_python
<span style="color: #66cc66;">&amp;</span>gt<span style="color: #66cc66;">;&amp;</span>gt<span style="color: #66cc66;">;&amp;</span>gt<span style="color: #66cc66;">;</span> mod_python.<span style="color: black;">version</span>
<span style="color: #483d8b;">'3.3.1'</span>
<span style="color: #66cc66;">&amp;</span>gt<span style="color: #66cc66;">;&amp;</span>gt<span style="color: #66cc66;">;&amp;</span>gt<span style="color: #66cc66;">;</span></pre></div></div>

<p>4. Edit httpd.conf</p>

<div class="wp_syntax"><div class="code"><pre class="conf" style="font-family:monospace;">&lt;directory&gt;
 AddHandler python-program .py
 PythonHandler TileCache.Service
 PythonOption TileCacheConfig /usr/local/apache2/htdocs/tilecache/tilecache.cfg
 PythonDebug On
 PythonPath &quot;sys.path + ['/usr/local/apache2/htdocs/tilecache/']&quot;
&lt;/directory&gt;
&nbsp;
&lt;directory&gt;
 AddHandler mod_python .py
 PythonHandler test
 PythonDebug On
&lt;/directory&gt;</pre></div></div>

<blockquote><p>Note: This syntax will work for all versions of mod_python. In version 3.0 and later, the name of the mod_python handler reference has actually been changed and thus it is now preferred to use &#8220;mod_python&#8221; instead of &#8220;python-program&#8221;. The old name though is still supported and will be used here to avoid confusion for those using version 2.7.</p></blockquote>
<p>5. Test your python</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> mod_python <span style="color: #ff7700;font-weight:bold;">import</span> apache
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> handler<span style="color: black;">&#40;</span>req<span style="color: black;">&#41;</span>:
      req.<span style="color: black;">log_error</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'handler'</span><span style="color: black;">&#41;</span>
      req.<span style="color: black;">content_type</span> = <span style="color: #483d8b;">'text/plain'</span>
      req.<span style="color: black;">send_http_header</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
      req.<span style="color: black;">write</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'mptest.py<span style="color: #000099; font-weight: bold;">\n</span>'</span><span style="color: black;">&#41;</span>
      <span style="color: #ff7700;font-weight:bold;">return</span> apache.<span style="color: black;">OK</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>/wordpress/2007/07/installing-tilecache/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>TileCache Experiment</title>
		<link>/wordpress/2007/02/tilecache-experiment/</link>
		<comments>/wordpress/2007/02/tilecache-experiment/#comments</comments>
		<pubDate>Fri, 16 Feb 2007 00:55:48 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[mapserver]]></category>
		<category><![CDATA[tilecache]]></category>
		<category><![CDATA[openlayers]]></category>

		<guid isPermaLink="false">/wordpress/?p=36</guid>
		<description><![CDATA[I am now able to do tilecache using TileCache1.3 from metacarta. Base from archives (archive-user.txt) From crschmidt at metacarta.com Wed Nov 22 17:54:29 2006 From: crschmidt at metacarta.com (Christopher Schmidt) Date: Wed, 22 Nov 2006 17:54:29 -0500 Subject: [OpenLayers-Users] TileCache - Tiling issues In-Reply-To: &#38;lt;4564D326.6020607@refractions.net&#38;gt; References: &#38;lt;4564D326.6020607@refractions.net&#38;gt; Message-ID: &#38;lt;20061122225429.GA18180@metacarta.com&#38;gt; &#160; On Wed, Nov 22, 2006]]></description>
			<content:encoded><![CDATA[<p>I am now able to do tilecache using TileCache1.3 from metacarta. Base from archives (archive-user.txt)</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">From crschmidt at metacarta.com  Wed Nov 22 17:54:29 2006
From: crschmidt at metacarta.com (Christopher Schmidt)
Date: Wed, 22 Nov 2006 17:54:29 -0500
Subject: [OpenLayers-Users] TileCache - Tiling issues
In-Reply-To: &amp;lt;4564D326.6020607@refractions.net&amp;gt;
References: &amp;lt;4564D326.6020607@refractions.net&amp;gt;
Message-ID: &amp;lt;20061122225429.GA18180@metacarta.com&amp;gt;
&nbsp;
On Wed, Nov 22, 2006 at 02:45:58PM -0800, Ben Brehmer wrote:
&amp;gt; Hello everyone,
&amp;gt;
&amp;gt; I have setup a basic OpenLayers application with TileCache doing the
&amp;gt; server-side caching. I was wondering if there is a way to pre-cache all
&amp;gt; the tiles (besides panning/zooming everywhere on the map)? I know in
&amp;gt; kamap there is a script that can be run to pre-cache all the tiles. Is
&amp;gt; there something similair for TileCache?
&nbsp;
In the TileCache directory, there is a 'Client.py' script. To pre-cache
your data, use it in the following manner:
&nbsp;
python Client.py &quot;http://example.com/tilecachelocation/tilecache.cgi?&quot;
&quot;layername&quot; startzoomlevel endzoomlevel [BBOX]
&nbsp;
Something like:
&nbsp;
python Client.py &quot;http://labs.metacarta.com/wms-c/Basic.py?&quot; &quot;basic&quot; 0 16
&nbsp;
Is what we used to precache all of the Vmap0 data in the MetaCarta VMap0
layer.
&nbsp;
&amp;gt; Also, I have attached two jpegs. Each has part of a symbol or label
&amp;gt; chopped off. I believe that the &quot;chopping&quot; occurs at the edge of a tile.
&amp;gt; Has anyone ever experience something like this in OpenLayers?
&nbsp;
This is based on your Mapserver setup, rather than something specific in
OpenLayers. Using WMS would result in the same visual result. Labels can
have this prevented using the &quot;PARTIALS OFF&quot; on your label layer, if
you're using Mapserver. I'm not aware of a way to prevent this in symbol
generation. 
&nbsp;
We are currently working on ka-map style rendering to add to TileCache,
to help people not run into this issue. No timeframe available yet on
when that'll be released. 
&nbsp;
Regards,
--
Christopher Schmidt
MetaCarta</pre></div></div>

<p>1.  TileCache Configuration: tilecache.cfg</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">[cache]
type=DiskCache
base=E:\\usr\\local\\apache2\\htdocs\\tmp\\
&nbsp;
[basemap]
type=WMSLayer
url=http://127.0.0.1/cgi-bin/mapserv.exe?map=/home/basemap/wmstest_longlat.map
layers=district,greens,major_river,minor_river
extension=png
&nbsp;
[roads]
type=WMSLayer
url=http://127.0.0.1/cgi-bin/mapserv.exe?map=/home/basemap/wmstest_longlat.map
layers=road4,road4label,road3,road3label,road2,road2label,road1,road1label,road11,road11label
extension=png</pre></div></div>

<p>2. Calling CFM Script: Test.cfm</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;">    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> request.mapserv<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;http://127.0.0.1/tilecache/tilecache.py&quot;</span><span style="color: #0000FF;">&gt;</span></span> 
&nbsp;
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #000000; font-weight: bold;">script</span> <span style="color: #0000FF;">src</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;/OpenLayers-2.2/lib/OpenLayers.js&quot;</span><span style="color: #0000FF;">&gt;</span></span><span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #000000; font-weight: bold;">script</span><span style="color: #0000FF;">&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #000000; font-weight: bold;">script</span> <span style="color: #0000FF;">type</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;text/javascript&quot;</span><span style="color: #0000FF;">&gt;</span></span><span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #000000; font-weight: bold;">script</span><span style="color: #0000FF;">&gt;</span></span>
        <span style="color: #808080; font-style: italic;">&lt;!--&lt;br /--&gt;</span>        //var lon = 116.3842;
        //var lat = 39.9150;
        var lon = 116.3846;
        var lat = 39.9202;
        var zoom = 16;
        var map, markers;
&nbsp;
        function init(){
      	    map = new OpenLayers.Map( $('map'), { maxResolution: 'auto'});
&nbsp;
	    var layer_base = new OpenLayers.Layer.WMS(
					&quot;Base Layer&quot;,
					&quot;<span style="color: #0000FF;">#request.mapserv#</span>&quot;,
					{
						layers: 'basemap',
						format: 'png', 'transparent': 'off'
					}
					);
&nbsp;
                map.addLayer(layer_base);
	   layer_base.setIsBaseLayer(true);	
&nbsp;
               ...more code here...
&nbsp;
       }
<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfset</span><span style="color: #0000FF;">&gt;</span></span></pre></div></div>

<p>I want to fine tune this script since I am getting odd tiles like duplicate tiles or tiles shown of different scale on the same scale.</p>
<p>3. Precaching:<br />
/d/Python24/python.exe Client.py &#8220;http://127.0.0.1/tilecache/tilecache.py&#8221; &#8220;roads&#8221; 14 16 116.35397,39.88984,116.42988,39.91918</p>
<p>I need to understand the &#8220;cache hit&#8221; or &#8220;cache miss&#8221; during execution.</p>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2007/02/tilecache-experiment/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>TileCache for Windows Revisited</title>
		<link>/wordpress/2007/01/tilecache13/</link>
		<comments>/wordpress/2007/01/tilecache13/#comments</comments>
		<pubDate>Wed, 17 Jan 2007 03:50:27 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[mapserver]]></category>
		<category><![CDATA[tilecache]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[mod_python]]></category>

		<guid isPermaLink="false">/wordpress/?p=22</guid>
		<description><![CDATA[1. Downloaded TileCache1.8 from http://www.tilecache.org/ 2. Get the current releases of python and mod_python. http://www.python.org/download/releases/2.5/ http://httpd.apache.org/modules/python-download.cgi -&#62; click on win32 binaries. Get the mod_python-3.3.1.win32-py2.5-Apache2.2.exe if your Apache is running on 2.2. http://www.pythonware.com/products/pil/ http://effbot.org/downloads/PIL-1.1.6.win32-py2.5.exe 3. Install python2.5 4. Install mod_python and python_imaging. 5. Edit httpd.conf LoadModule python_module modules/mod_python.so &#160; &#60;directory&#62; AddHandler python-program .py PythonHandler test PythonDebug]]></description>
			<content:encoded><![CDATA[<p>1. Downloaded TileCache1.8 from <a href="http://www.tilecache.org/">http://www.tilecache.org/</a></p>
<p>2. Get the current releases of python and mod_python.<br />
<a href="http://www.python.org/download/releases/2.5/">http://www.python.org/download/releases/2.5/</a></p>
<p><a href="http://httpd.apache.org/modules/python-download.cgi">http://httpd.apache.org/modules/python-download.cgi</a> -&gt; click on win32 binaries. Get the mod_python-3.3.1.win32-py2.5-Apache2.2.exe  if your Apache is running on 2.2.</p>
<p><a href="http://www.pythonware.com/products/pil/">http://www.pythonware.com/products/pil/</a></p>
<p>http://effbot.org/downloads/PIL-1.1.6.win32-py2.5.exe</p>
<p>3. Install python2.5</p>
<p>4. Install mod_python and python_imaging.</p>
<p>5. Edit httpd.conf</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">LoadModule python_module modules<span style="color: #000000; font-weight: bold;">/</span>mod_python.so
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;</span>directory<span style="color: #000000; font-weight: bold;">&gt;</span>
AddHandler python-program .py
PythonHandler <span style="color: #7a0874; font-weight: bold;">test</span>
PythonDebug On
<span style="color: #000000; font-weight: bold;">&lt;/</span>directory<span style="color: #000000; font-weight: bold;">&gt;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;</span>directory<span style="color: #000000; font-weight: bold;">&gt;</span>
	AddHandler python-program .py .cgi
	PythonHandler TileCache.Service
	PythonOption TileCacheConfig <span style="color: #000000; font-weight: bold;">/</span>wwwroot<span style="color: #000000; font-weight: bold;">/</span>tilecache<span style="color: #000000; font-weight: bold;">/</span>tilecache.cfg
	PythonDebug On
<span style="color: #000000; font-weight: bold;">&lt;/</span>directory<span style="color: #000000; font-weight: bold;">&gt;</span>
&nbsp;
ScriptInterpreterSource Registry
SetEnv PYTHONUNBUFFERED <span style="color: #000000;">1</span>
PassEnv PYTHONPATH</pre></div></div>

<p>6. run regedit. Navigate to HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\2.4\PythonPath. Append &#8220;E:\wwwroot\tilecache&#8221; to PYTHONPATH</p>
<p>D:\Python24\Lib;D:\Python24\DLLs;D:\Python24\Lib\lib-tk;E:\wwwroot\tilecache;</p>
<p>7. Put D:\Python24 in your WINDOWS PATH</p>
<p>8. Test if apache could read python by http://127.0.0.1/pytest/test.py</p>
<p>9. http://127.0.0.1/tilecache/test1.cfm</p>
<p>10. tilecache_seed.py &#8220;http://127.0.0.1/tilecache/tilecache.py&#8221; roads 12 17 &#8220;116.28229,39.85291,116.48657,39.98783&#8243;</p>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2007/01/tilecache13/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
