<?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>mobile and gis dev notes &#187; sqlite3</title>
	<atom:link href="http:///wordpress/category/sqlite3/feed/" rel="self" type="application/rss+xml" />
	<link>/wordpress</link>
	<description>by rupert</description>
	<lastBuildDate>Sun, 22 Jan 2012 04:34:28 +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 Dev Note #21: Route-Me Offline Mapping from Database</title>
		<link>/wordpress/2010/08/iphone-dev-note-21-route-me-offline-mapping-from-database/</link>
		<comments>/wordpress/2010/08/iphone-dev-note-21-route-me-offline-mapping-from-database/#comments</comments>
		<pubDate>Thu, 12 Aug 2010 08:48:53 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[iphone]]></category>
		<category><![CDATA[sqlite3]]></category>
		<category><![CDATA[route-me]]></category>
		<category><![CDATA[sqlite]]></category>

		<guid isPermaLink="false">/wordpress/?p=744</guid>
		<description><![CDATA[Part I: Download the osm (openstreetmap) tiles 1. Download the tiles from osm using downloadosmtiles.pl - Download Geo-OSM-Tiles-0.02.tar.gz from CPAN - See README file. Compile and build perl Makefile.PL make make test make install - Copy downloadosmtiles.pl to /usr/bin - Usage: downloadosmtiles.pl --lat=min_lat:max_lat --lon=min_long:max_long --zoom=min_zoom:max_zoom How do you set the min_lat, max_lat and min_long, max_long? [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Part I: Download the osm (<a href="www.openstreetmap.org">openstreetmap</a>) tiles</strong><br />
1. Download the tiles from osm using <a href="http://search.cpan.org/~rotkraut/Geo-OSM-Tiles-0.02/downloadosmtiles.pl">downloadosmtiles.pl</a><br />
- Download <a href="http://search.cpan.org/CPAN/authors/id/R/RO/ROTKRAUT/Geo-OSM-Tiles-0.02.tar.gz">Geo-OSM-Tiles-0.02.tar.gz from CPAN</a><br />
- See README file. Compile and build</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">   perl Makefile.PL
   make
   make test
   make install</pre></div></div>

<p>- Copy downloadosmtiles.pl to /usr/bin<br />
- Usage:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">downloadosmtiles.pl <span style="color: #660033;">--lat</span>=min_lat:max_lat <span style="color: #660033;">--lon</span>=min_long:max_long <span style="color: #660033;">--zoom</span>=min_zoom:max_zoom</pre></div></div>

<p>How do you set the min_lat, max_lat and min_long, max_long?<br />
- Go to <a href="www.openstreetmap.org">www.openstreetmap.org</a><br />
- Click on the &#8220;Edit&#8221; tab<br />
- You will see the extent or bounds of the map under the section &#8220;Area to Export&#8221;<br />
- Alternatively, you can click on &#8220;Manually select a different area&#8221; to specifically choose an area.</p>
<p><img src="/wordpress/wp-content/uploads/2010/08/osm.png" alt="osm.png" border="0" width="670" height="209" /></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">downloadosmtiles.pl <span style="color: #660033;">--lat</span>=<span style="color: #000000;">6.9443</span>:<span style="color: #000000;">7.2261</span> <span style="color: #660033;">--lon</span>=<span style="color: #000000;">125.5082</span>:<span style="color: #000000;">125.7104</span> <span style="color: #660033;">--zoom</span>=<span style="color: #000000;">6</span>:<span style="color: #000000;">12</span></pre></div></div>

<p>The tiles will be downloaded to the current directory.<br />
<img src="/wordpress/wp-content/uploads/2010/08/dir.png" alt="dir.png" border="0" width="153" height="206" /></p>
<p><strong>Part II:Put the tiles in the sqlite database</strong><br />
1. Read <a href="http://groups.google.com/group/route-me-map/browse_thread/thread/934459dc136ffd28">Frank&#8217;s email to route-me group regarding map2sqlite</a></p>
<p>2. Download <a href="http://groups.google.com/group/route-me-map/files">map2sqlite-1.0.tar.bz2</a>. </p>
<p>3. Build the map2sqlite XCodeProj. Afterwards, find map2sqlite and drop it in /usr/bin.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">cp</span> map2sqlite <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin</pre></div></div>

<p>4. Run map2sqlite to import the tiles in sqlite.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">map2sqlite <span style="color: #660033;">-db</span> ph-1.0.0.db <span style="color: #660033;">-mapdir</span> ph-osm-map<span style="color: #000000; font-weight: bold;">/</span>
&nbsp;
<span style="color: #000000;">2010</span>-08-<span style="color: #000000;">12</span> <span style="color: #000000;">17</span>:<span style="color: #000000;">24</span>:<span style="color: #000000;">40.749</span> map2sqlite<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">14113</span>:<span style="color: #000000;">903</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> map2sqlite <span style="color: #000000;">1.0</span>
<span style="color: #000000;">2010</span>-08-<span style="color: #000000;">12</span> <span style="color: #000000;">17</span>:<span style="color: #000000;">24</span>:<span style="color: #000000;">40.756</span> map2sqlite<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">14113</span>:<span style="color: #000000;">903</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> Creating ph-1.0.0.db
<span style="color: #000000;">2010</span>-08-<span style="color: #000000;">12</span> <span style="color: #000000;">17</span>:<span style="color: #000000;">24</span>:<span style="color: #000000;">40.761</span> map2sqlite<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">14113</span>:<span style="color: #000000;">903</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> Importing map tiles at ph-osm-map<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #000000;">2010</span>-08-<span style="color: #000000;">12</span> <span style="color: #000000;">17</span>:<span style="color: #000000;">25</span>:<span style="color: #000000;">03.169</span> map2sqlite<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">14113</span>:<span style="color: #000000;">903</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> 
<span style="color: #000000;">2010</span>-08-<span style="color: #000000;">12</span> <span style="color: #000000;">17</span>:<span style="color: #000000;">25</span>:<span style="color: #000000;">03.170</span> map2sqlite<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">14113</span>:<span style="color: #000000;">903</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> Map statistics
<span style="color: #000000;">2010</span>-08-<span style="color: #000000;">12</span> <span style="color: #000000;">17</span>:<span style="color: #000000;">25</span>:<span style="color: #000000;">03.170</span> map2sqlite<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">14113</span>:<span style="color: #000000;">903</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #660033;">--------------</span>
<span style="color: #000000;">2010</span>-08-<span style="color: #000000;">12</span> <span style="color: #000000;">17</span>:<span style="color: #000000;">25</span>:<span style="color: #000000;">03.171</span> map2sqlite<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">14113</span>:<span style="color: #000000;">903</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> map db:            ph-1.0.0.db
<span style="color: #000000;">2010</span>-08-<span style="color: #000000;">12</span> <span style="color: #000000;">17</span>:<span style="color: #000000;">25</span>:<span style="color: #000000;">03.171</span> map2sqlite<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">14113</span>:<span style="color: #000000;">903</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #c20cb9; font-weight: bold;">file</span> <span style="color: #c20cb9; font-weight: bold;">size</span>:         <span style="color: #000000;">13758464</span> bytes
<span style="color: #000000;">2010</span>-08-<span style="color: #000000;">12</span> <span style="color: #000000;">17</span>:<span style="color: #000000;">25</span>:<span style="color: #000000;">03.172</span> map2sqlite<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">14113</span>:<span style="color: #000000;">903</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> tile directory:    ph-osm-map<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #000000;">2010</span>-08-<span style="color: #000000;">12</span> <span style="color: #000000;">17</span>:<span style="color: #000000;">25</span>:<span style="color: #000000;">03.172</span> map2sqlite<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">14113</span>:<span style="color: #000000;">903</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> number of tiles:   <span style="color: #000000;">9091</span>
<span style="color: #000000;">2010</span>-08-<span style="color: #000000;">12</span> <span style="color: #000000;">17</span>:<span style="color: #000000;">25</span>:<span style="color: #000000;">03.173</span> map2sqlite<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">14113</span>:<span style="color: #000000;">903</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> zoom levels:       <span style="color: #000000;">6</span> - <span style="color: #000000;">11</span>
<span style="color: #000000;">2010</span>-08-<span style="color: #000000;">12</span> <span style="color: #000000;">17</span>:<span style="color: #000000;">25</span>:<span style="color: #000000;">03.218</span> map2sqlite<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">14113</span>:<span style="color: #000000;">903</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> zoom level  <span style="color: #000000;">6</span>:        <span style="color: #000000;">12</span> tiles, <span style="color: #7a0874; font-weight: bold;">&#40;</span>    <span style="color: #000000;">28</span>,    <span style="color: #000000;">52</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>x<span style="color: #7a0874; font-weight: bold;">&#40;</span>    <span style="color: #000000;">31</span>,    <span style="color: #000000;">54</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>, <span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #007800;">x</span>=<span style="color: #000000;">112.500000</span>,<span style="color: #007800;">y</span>=<span style="color: #000000;">21.943047</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>x<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #007800;">x</span>=<span style="color: #000000;">129.375000</span>,<span style="color: #007800;">y</span>=<span style="color: #000000;">0.000000</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #000000;">2010</span>-08-<span style="color: #000000;">12</span> <span style="color: #000000;">17</span>:<span style="color: #000000;">25</span>:<span style="color: #000000;">03.219</span> map2sqlite<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">14113</span>:<span style="color: #000000;">903</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> zoom level  <span style="color: #000000;">7</span>:        <span style="color: #000000;">35</span> tiles, <span style="color: #7a0874; font-weight: bold;">&#40;</span>    <span style="color: #000000;">56</span>,   <span style="color: #000000;">105</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>x<span style="color: #7a0874; font-weight: bold;">&#40;</span>    <span style="color: #000000;">62</span>,   <span style="color: #000000;">109</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>, <span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #007800;">x</span>=<span style="color: #000000;">115.312500</span>,<span style="color: #007800;">y</span>=<span style="color: #000000;">21.943047</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>x<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #007800;">x</span>=<span style="color: #000000;">129.375000</span>,<span style="color: #007800;">y</span>=<span style="color: #000000;">2.811371</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #000000;">2010</span>-08-<span style="color: #000000;">12</span> <span style="color: #000000;">17</span>:<span style="color: #000000;">25</span>:<span style="color: #000000;">03.222</span> map2sqlite<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">14113</span>:<span style="color: #000000;">903</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> zoom level  <span style="color: #000000;">8</span>:       <span style="color: #000000;">117</span> tiles, <span style="color: #7a0874; font-weight: bold;">&#40;</span>   <span style="color: #000000;">112</span>,   <span style="color: #000000;">210</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>x<span style="color: #7a0874; font-weight: bold;">&#40;</span>   <span style="color: #000000;">124</span>,   <span style="color: #000000;">218</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>, <span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #007800;">x</span>=<span style="color: #000000;">115.312500</span>,<span style="color: #007800;">y</span>=<span style="color: #000000;">21.943047</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>x<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #007800;">x</span>=<span style="color: #000000;">127.968750</span>,<span style="color: #007800;">y</span>=<span style="color: #000000;">4.214943</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #000000;">2010</span>-08-<span style="color: #000000;">12</span> <span style="color: #000000;">17</span>:<span style="color: #000000;">25</span>:<span style="color: #000000;">03.223</span> map2sqlite<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">14113</span>:<span style="color: #000000;">903</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> zoom level  <span style="color: #000000;">9</span>:       <span style="color: #000000;">450</span> tiles, <span style="color: #7a0874; font-weight: bold;">&#40;</span>   <span style="color: #000000;">225</span>,   <span style="color: #000000;">420</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>x<span style="color: #7a0874; font-weight: bold;">&#40;</span>   <span style="color: #000000;">249</span>,   <span style="color: #000000;">437</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>, <span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #007800;">x</span>=<span style="color: #000000;">115.312500</span>,<span style="color: #007800;">y</span>=<span style="color: #000000;">21.289375</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>x<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #007800;">x</span>=<span style="color: #000000;">127.968750</span>,<span style="color: #007800;">y</span>=<span style="color: #000000;">4.214943</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #000000;">2010</span>-08-<span style="color: #000000;">12</span> <span style="color: #000000;">17</span>:<span style="color: #000000;">25</span>:<span style="color: #000000;">03.225</span> map2sqlite<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">14113</span>:<span style="color: #000000;">903</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> zoom level <span style="color: #000000;">10</span>:      <span style="color: #000000;">1715</span> tiles, <span style="color: #7a0874; font-weight: bold;">&#40;</span>   <span style="color: #000000;">450</span>,   <span style="color: #000000;">841</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>x<span style="color: #7a0874; font-weight: bold;">&#40;</span>   <span style="color: #000000;">498</span>,   <span style="color: #000000;">875</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>, <span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #007800;">x</span>=<span style="color: #000000;">115.664062</span>,<span style="color: #007800;">y</span>=<span style="color: #000000;">21.289375</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>x<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #007800;">x</span>=<span style="color: #000000;">127.968750</span>,<span style="color: #007800;">y</span>=<span style="color: #000000;">4.565474</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #000000;">2010</span>-08-<span style="color: #000000;">12</span> <span style="color: #000000;">17</span>:<span style="color: #000000;">25</span>:<span style="color: #000000;">03.231</span> map2sqlite<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">14113</span>:<span style="color: #000000;">903</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> zoom level <span style="color: #000000;">11</span>:      <span style="color: #000000;">6762</span> tiles, <span style="color: #7a0874; font-weight: bold;">&#40;</span>   <span style="color: #000000;">900</span>,  <span style="color: #000000;">1683</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>x<span style="color: #7a0874; font-weight: bold;">&#40;</span>   <span style="color: #000000;">997</span>,  <span style="color: #000000;">1751</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>, <span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #007800;">x</span>=<span style="color: #000000;">115.839844</span>,<span style="color: #007800;">y</span>=<span style="color: #000000;">21.289375</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>x<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #007800;">x</span>=<span style="color: #000000;">127.968750</span>,<span style="color: #007800;">y</span>=<span style="color: #000000;">4.565474</span><span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

<p>5. ph-osm-map is 43.9 MB but was compressed to ph-1.0.0.db (13.8 MB)</p>
<p><strong>Part III: Downlaod the route-me code from trunk and run some examples.</strong><br />
- Follow this <a href="/wordpress/2009/12/iphone-dev-note-19-route-me-an-opensource-mapkit-for-the-iphone/">previous tutorial</a></p>
<p><strong>Part IV: Patch the trunk to incorporate the RMDBMapSource from Frank Schroder</strong></p>
<p>1. What we need to add to the trunk. Download <a href="/wordpress/wp-content/uploads/2010/08/RMDBMapSource.zip" title="RMDBMapSource.zip">RMDBMapSource.zip</a></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">+ RMDBMapSource.h
+ RMDBMapSource.m
+ RMDBTileImage.h
+ RMDBTileImage.m</pre></div></div>

<p>Copy the files above to the &#8220;Map&#8221; directory.</p>
<p><img src="/wordpress/wp-content/uploads/2010/08/route-me-1.png" alt="route-me-1.png" border="0" width="338" height="403" /></p>
<p>2. Edit RMTileImage.h and RMTileImage.m base on the patch below.</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">Index<span style="color: #339933;">:</span> MapView<span style="color: #339933;">/</span>Map<span style="color: #339933;">/</span>RMTileImage.<span style="color: #202020;">h</span>
<span style="color: #339933;">===================================================================</span>
<span style="color: #339933;">---</span> MapView<span style="color: #339933;">/</span>Map<span style="color: #339933;">/</span>RMTileImage.<span style="color: #202020;">h</span>	<span style="color: #009900;">&#40;</span>revision <span style="color: #0000dd;">605</span><span style="color: #009900;">&#41;</span>
<span style="color: #339933;">+++</span> MapView<span style="color: #339933;">/</span>Map<span style="color: #339933;">/</span>RMTileImage.<span style="color: #202020;">h</span>	<span style="color: #009900;">&#40;</span>working copy<span style="color: #009900;">&#41;</span>
@@ <span style="color: #339933;">-</span><span style="color: #0000dd;">37</span><span style="color: #339933;">,</span><span style="color: #0000dd;">8</span> <span style="color: #339933;">+</span><span style="color: #0000dd;">37</span><span style="color: #339933;">,</span><span style="color: #0000dd;">10</span> @@
 <span style="color: #339933;">#import &quot;RMNotifications.h&quot;</span>
 <span style="color: #339933;">#import &quot;RMTile.h&quot;</span>
 <span style="color: #339933;">#import &quot;RMTileProxy.h&quot;</span>
<span style="color: #339933;">+</span><span style="color: #339933;">#import &quot;FMDatabase.h&quot;</span>
&nbsp;
 @class RMTileImage<span style="color: #339933;">;</span>
<span style="color: #339933;">+</span>@class NSData<span style="color: #339933;">;</span>
&nbsp;
 @interface RMTileImage <span style="color: #339933;">:</span> NSObject <span style="color: #009900;">&#123;</span>
 	<span style="color: #666666; font-style: italic;">// I know this is a bit nasty.</span>
@@ <span style="color: #339933;">-</span><span style="color: #0000dd;">64</span><span style="color: #339933;">,</span><span style="color: #0000dd;">6</span> <span style="color: #339933;">+</span><span style="color: #0000dd;">66</span><span style="color: #339933;">,</span><span style="color: #0000dd;">7</span> @@
 <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>RMTileImage<span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>imageForTile<span style="color: #339933;">:</span> <span style="color: #009900;">&#40;</span>RMTile<span style="color: #009900;">&#41;</span> tile withURL<span style="color: #339933;">:</span> <span style="color: #009900;">&#40;</span>NSString<span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>url<span style="color: #339933;">;</span>
 <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>RMTileImage<span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>imageForTile<span style="color: #339933;">:</span> <span style="color: #009900;">&#40;</span>RMTile<span style="color: #009900;">&#41;</span> tile fromFile<span style="color: #339933;">:</span> <span style="color: #009900;">&#40;</span>NSString<span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>filename<span style="color: #339933;">;</span>
 <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>RMTileImage<span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>imageForTile<span style="color: #339933;">:</span> <span style="color: #009900;">&#40;</span>RMTile<span style="color: #009900;">&#41;</span> tile withData<span style="color: #339933;">:</span> <span style="color: #009900;">&#40;</span>NSData<span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>data<span style="color: #339933;">;</span>
<span style="color: #339933;">++</span> <span style="color: #009900;">&#40;</span>RMTileImage<span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>imageForTile<span style="color: #339933;">:</span> <span style="color: #009900;">&#40;</span>RMTile<span style="color: #009900;">&#41;</span> tile fromDB<span style="color: #339933;">:</span> <span style="color: #009900;">&#40;</span>FMDatabase<span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>db<span style="color: #339933;">;</span>
&nbsp;
 <span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span>moveBy<span style="color: #339933;">:</span> <span style="color: #009900;">&#40;</span>CGSize<span style="color: #009900;">&#41;</span> delta<span style="color: #339933;">;</span>
 <span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span>zoomByFactor<span style="color: #339933;">:</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">float</span><span style="color: #009900;">&#41;</span> zoomFactor near<span style="color: #339933;">:</span><span style="color: #009900;">&#40;</span>CGPoint<span style="color: #009900;">&#41;</span> center<span style="color: #339933;">;</span>
Index<span style="color: #339933;">:</span> MapView<span style="color: #339933;">/</span>Map<span style="color: #339933;">/</span>RMTileImage.<span style="color: #202020;">m</span>
<span style="color: #339933;">===================================================================</span>
<span style="color: #339933;">---</span> MapView<span style="color: #339933;">/</span>Map<span style="color: #339933;">/</span>RMTileImage.<span style="color: #202020;">m</span>	<span style="color: #009900;">&#40;</span>revision <span style="color: #0000dd;">605</span><span style="color: #009900;">&#41;</span>
<span style="color: #339933;">+++</span> MapView<span style="color: #339933;">/</span>Map<span style="color: #339933;">/</span>RMTileImage.<span style="color: #202020;">m</span>	<span style="color: #009900;">&#40;</span>working copy<span style="color: #009900;">&#41;</span>
@@ <span style="color: #339933;">-</span><span style="color: #0000dd;">29</span><span style="color: #339933;">,</span><span style="color: #0000dd;">6</span> <span style="color: #339933;">+</span><span style="color: #0000dd;">29</span><span style="color: #339933;">,</span><span style="color: #0000dd;">7</span> @@
 <span style="color: #339933;">#import &quot;RMWebTileImage.h&quot;</span>
 <span style="color: #339933;">#import &quot;RMTileLoader.h&quot;</span>
 <span style="color: #339933;">#import &quot;RMFileTileImage.h&quot;</span>
<span style="color: #339933;">+</span><span style="color: #339933;">#import &quot;RMDBTileImage.h&quot;</span>
 <span style="color: #339933;">#import &quot;RMTileCache.h&quot;</span>
 <span style="color: #339933;">#import &quot;RMPixel.h&quot;</span>
 <span style="color: #339933;">#import &lt;QuartzCore/QuartzCore.h&gt;</span>
@@ <span style="color: #339933;">-</span><span style="color: #0000dd;">108</span><span style="color: #339933;">,</span><span style="color: #0000dd;">6</span> <span style="color: #339933;">+</span><span style="color: #0000dd;">109</span><span style="color: #339933;">,</span><span style="color: #0000dd;">11</span> @@
 	<span style="color: #b1b100;">return</span> <span style="color: #009900;">&#91;</span>image autorelease<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #339933;">++</span> <span style="color: #009900;">&#40;</span>RMTileImage<span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>imageForTile<span style="color: #339933;">:</span><span style="color: #009900;">&#40;</span>RMTile<span style="color: #009900;">&#41;</span> _tile fromDB<span style="color: #339933;">:</span> <span style="color: #009900;">&#40;</span>FMDatabase<span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>db
<span style="color: #339933;">+</span><span style="color: #009900;">&#123;</span>
<span style="color: #339933;">+</span>	<span style="color: #b1b100;">return</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#91;</span>RMDBTileImage alloc<span style="color: #009900;">&#93;</span> initWithTile<span style="color: #339933;">:</span> _tile fromDB<span style="color: #339933;">:</span>db<span style="color: #009900;">&#93;</span> autorelease<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">+</span><span style="color: #009900;">&#125;</span>
<span style="color: #339933;">+</span>
 <span style="color: #339933;">-</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span> cancelLoading
 <span style="color: #009900;">&#123;</span>
 	<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#91;</span>NSNotificationCenter defaultCenter<span style="color: #009900;">&#93;</span> postNotificationName<span style="color: #339933;">:</span>RMMapImageLoadingCancelledNotification</pre></div></div>

<p>We just need to add these lines on RMTileImage.h:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">+<span style="color: #666666; font-style: italic;">#import &quot;FMDatabase.h&quot;</span>
...
++ <span style="color: #7a0874; font-weight: bold;">&#40;</span>RMTileImage<span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>imageForTile: <span style="color: #7a0874; font-weight: bold;">&#40;</span>RMTile<span style="color: #7a0874; font-weight: bold;">&#41;</span> tile fromDB: <span style="color: #7a0874; font-weight: bold;">&#40;</span>FMDatabase<span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>db;</pre></div></div>

<p>do the same for RMTileImage.m:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">+<span style="color: #666666; font-style: italic;">#import &quot;RMDBTileImage.h&quot;</span>
...
++ <span style="color: #7a0874; font-weight: bold;">&#40;</span>RMTileImage<span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>imageForTile:<span style="color: #7a0874; font-weight: bold;">&#40;</span>RMTile<span style="color: #7a0874; font-weight: bold;">&#41;</span> _tile fromDB: <span style="color: #7a0874; font-weight: bold;">&#40;</span>FMDatabase<span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>db
+<span style="color: #7a0874; font-weight: bold;">&#123;</span>
+	<span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span>RMDBTileImage alloc<span style="color: #7a0874; font-weight: bold;">&#93;</span> initWithTile: _tile fromDB:db<span style="color: #7a0874; font-weight: bold;">&#93;</span> autorelease<span style="color: #7a0874; font-weight: bold;">&#93;</span>;
+<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

<p>UPDATE (OCT 15, 2010): I am attaching my current RMTileImage.h and RMTileImage.m so you guys could double-check the changes I made. <a href="/wordpress/wp-content/uploads/2010/10/RMTileImage.zip" title="RMTileImage.zip">RMTileImage.zip</a></p>
<p>4. Still with me? Comment NSAssert on 609 on RMMapContents.m<br />
<img src="/wordpress/wp-content/uploads/2010/08/rmcontents.png" alt="rmcontents.png" border="0" width="838" height="336" /></p>
<p><strong>Part V: RouteMeSampleMapDBOffline code</strong><br />
1. Download <a href="/wordpress/wp-content/uploads/2010/08/RouteMeSampleMapDBOffline.zip" title="RouteMeSampleMapDBOffline.zip">RouteMeSampleMapDBOffline.zip</a></p>
<p>2. Drop the project in the samples directory.<br />
<img src="/wordpress/wp-content/uploads/2010/08/sample_proj.png" alt="sample_proj.png" border="0" width="311" height="379" /></p>
<p>3. Build. You should be able to build this since the header path is relative to the route-me trunk.<br />
<img src="/wordpress/wp-content/uploads/2010/08/build-config.png" alt="build-config.png" border="0" width="480" height="338" /></p>
<p>4. Run from the simulator<br />
<img src="/wordpress/wp-content/uploads/2010/08/finish.png" alt="finish.png" border="0" width="393" height="733" /></p>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2010/08/iphone-dev-note-21-route-me-offline-mapping-from-database/feed/</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
		<item>
		<title>iPhone Note #8: Exporting Oracle to SQLite3</title>
		<link>/wordpress/2009/08/iphone-note-7-exporting-oracle-to-sqlite3/</link>
		<comments>/wordpress/2009/08/iphone-note-7-exporting-oracle-to-sqlite3/#comments</comments>
		<pubDate>Sun, 16 Aug 2009 12:31:09 +0000</pubDate>
		<dc:creator>Rupert</dc:creator>
				<category><![CDATA[iphone]]></category>
		<category><![CDATA[oracle]]></category>
		<category><![CDATA[sqlite3]]></category>

		<guid isPermaLink="false">http://gismobiledev.wordpress.com/?p=92</guid>
		<description><![CDATA[Since I&#8217;ve been working most of my time with iPhone Dev for the last couple of months, I thought it will be worthwile to post how to import files to SQLite3. In a nutshell, use MesaSQLite&#8217;s IMPORT function. It will save you a lot of time. Now it is up to you how to export [...]]]></description>
			<content:encoded><![CDATA[<p>Since I&#8217;ve been working most of my time with iPhone Dev for the last couple of months, I thought it will be worthwile to post how to import files to SQLite3. In a nutshell, use  <a href="http://www.mesamysql.com/?realmesa_home">MesaSQLite&#8217;s</a> IMPORT function. It will save you a lot of time. Now it is up to you how to export into a CSV or TAB delimited file. For Oracle, I used <a href="http://www.oracle.com/technology/products/database/sql_developer/index.html">SQLDeveloper</a>. For other databases, such as MySQL or Postgres, I&#8217;ve used <a href="http://www.navicat.com">Navicat.</a><span id="more-369"></span></p>
<p>1. Using <a href="http://www.oracle.com/technology/products/database/sql_developer/index.html">SQLDeveloper</a> -&gt; Right Click on the Table from the left pane -&gt; Export</p>
<p><img src="/wordpress/wp-content/uploads/2009/08/oracle-sqldeveloper-left.gif" alt="oracle-sqldeveloper-left.gif" border="0" width="278" height="377" /></p>
<p><img src="/wordpress/wp-content/uploads/2009/08/oracle-sqldeveloper.gif" alt="oracle-sqldeveloper.gif" border="0" width="467" height="409" /></p>
<p>2. Choose TEXT since we are going to use that when importing using <a href="http://www.mesamysql.com/?realmesa_home">MesaSQLite.</a> Note, SQLDeveloper does not export CLOB columns. You need to change your column from CLOB to VARCHAR. A workaround is to add a column and then update that column aferwards.</p>
<pre>
ALTER TABLE poi ADD en_desc VARCHAR(2000);
UPDATE poi SET en_desc = en_short_desc;
</pre>
<p>3. In <a href="http://www.mesamysql.com/?realmesa_home">MesaSQLite,</a> FILE -&gt; IMPORT -&gt; CSV/TAB</p>
<p><img src="/wordpress/wp-content/uploads/2009/08/mesa-1.gif" alt="mesa-1.gif" border="0" width="274" height="127" /></p>
<p>4. Choose the table which you want to import.</p>
<p>5. Choose your exported TAB delimited file from SQLDeveloper.</p>
<p>6. Afterwards, map the corresponding fields to your database. Note, that I added an extra column &#8220;dummy&#8221; in the file because it seems I can only match n-1 columns, thus the extra column.</p>
<p><img src="/wordpress/wp-content/uploads/2009/08/mesa-2.gif" alt="mesa-2.gif" border="0" width="344" height="349" /></p>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2009/08/iphone-note-7-exporting-oracle-to-sqlite3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPhone Note #5: SQLite3</title>
		<link>/wordpress/2009/08/iphone-note-sqlite3-tutorial/</link>
		<comments>/wordpress/2009/08/iphone-note-sqlite3-tutorial/#comments</comments>
		<pubDate>Wed, 12 Aug 2009 09:44:13 +0000</pubDate>
		<dc:creator>Rupert</dc:creator>
				<category><![CDATA[iphone]]></category>
		<category><![CDATA[sqlite3]]></category>

		<guid isPermaLink="false">http://gismobiledev.wordpress.com/?p=64</guid>
		<description><![CDATA[Note this tutorial will be updated in the near future&#8230; 1. The code below (based from the SQLiteBooks Example) will copy the database from your bundle to the &#8220;Documents&#8221; directory. You don&#8217;t have to do this every time your app launches, so there is a check at &#8220;success&#8221; below. To check this, in the iPhone [...]]]></description>
			<content:encoded><![CDATA[<p>Note this tutorial will be updated in the near future&#8230;</p>
<p>1. The code below (based from the <a href="">SQLiteBooks Example</a>) will copy the database from your bundle to the &#8220;Documents&#8221; directory. You don&#8217;t have to do this every time your app launches, so there is a check at &#8220;success&#8221; below. To check this, in the iPhone Simulator navigate to the Documents directory:</p>
<p><span id="more-360"></span></p>
<p><strong>/Users/rupert/Library/Application\ Support/iPhone\ Simulator/User/Applications/unique_number_of_the_application/Documents/sample.db</strong></p>
<pre>
// Creates a writable copy of the bundled default database in the application Documents directory.
- (void)createEditableCopyOfDatabaseIfNeeded {
    // First, test for existence.
    BOOL success;
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSError *error;

	//Documents Database Path
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *writableDBPath = [documentsDirectory stringByAppendingPathComponent:kDatabaseName];

	success = [fileManager fileExistsAtPath:writableDBPath];
    if (success) return;

    // The writable database does not exist, so copy the default to the appropriate location.
    NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:kDatabaseName];
    success = [fileManager copyItemAtPath:defaultDBPath toPath:writableDBPath error:&amp;error];
    if (!success) {
        NSLog(@"Failed to create writable database file with message '%@'.", [error localizedDescription]);
    }
}
</pre>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2009/08/iphone-note-sqlite3-tutorial/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQLite3 Cheatsheet</title>
		<link>/wordpress/2009/08/sqlite3-cheatsheet-2/</link>
		<comments>/wordpress/2009/08/sqlite3-cheatsheet-2/#comments</comments>
		<pubDate>Wed, 12 Aug 2009 02:08:24 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[sqlite3]]></category>

		<guid isPermaLink="false">/wordpress/?p=974</guid>
		<description><![CDATA[Tools 1. MesaSQLite for MacOSX. SQL 1. Getting the current time MySQL = Now(); SQLite3 = CURRENT_TIMESTAMP; insert into jobstemp(full_address, datecreated, dateupdated) VALUES("9 Bishop Street", CURRENT_TIMESTAMP, CURRENT_TIMESTAMP); 2. Getting the local current time SELECT datetime(dateupdated, 'localtime') 3. Trim SELECT trim(name) FROM table 4. Vacuum rupert:Desktop rupert$ sqlite3 photos-2.0.0.db SQLite version 3.6.12 Enter ".help" for instructions [...]]]></description>
			<content:encoded><![CDATA[<h2><strong>Tools</strong></h2>
<p>1. MesaSQLite for MacOSX.</p>
<h2><strong>SQL</strong></h2>
<p><strong>1. Getting the current time</strong></p>
<p>MySQL = Now();</p>
<p>SQLite3 = CURRENT_TIMESTAMP;</p>
<pre>
insert into jobstemp(full_address, datecreated, dateupdated)
VALUES("9 Bishop Street", CURRENT_TIMESTAMP, CURRENT_TIMESTAMP);
</pre>
<p><strong>2. Getting the local current time</strong></p>
<pre>
SELECT datetime(dateupdated, 'localtime')
</pre>
<p><strong>3. Trim</strong></p>
<pre>
SELECT trim(name) FROM table
</pre>
<p><strong>4. Vacuum</strong></p>
<pre>
rupert:Desktop rupert$ sqlite3 photos-2.0.0.db
SQLite version 3.6.12
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> vacuum;
sqlite> .quit;
</pre>
<p><strong>5. Quit</strong></p>
<pre>
rupert:Desktop rupert$ sqlite3 photos-2.0.0.db
SQLite version 3.6.12
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> .quit;
</pre>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2009/08/sqlite3-cheatsheet-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

