<?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; google</title>
	<atom:link href="http:///wordpress/tag/google/feed/" rel="self" type="application/rss+xml" />
	<link>/wordpress</link>
	<description>by rupert</description>
	<lastBuildDate>Wed, 08 Feb 2012 22:26:15 +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>Nominatim (Reverse Geocoder) via PL/PYTHON for RubyOnRails Mapping App</title>
		<link>/wordpress/2012/01/nominatim-reverse-geocoder-via-plpython-for-rubyonrails-app/</link>
		<comments>/wordpress/2012/01/nominatim-reverse-geocoder-via-plpython-for-rubyonrails-app/#comments</comments>
		<pubDate>Fri, 06 Jan 2012 04:16:17 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[geocoding]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[nominatim]]></category>

		<guid isPermaLink="false">/wordpress/?p=1190</guid>
		<description><![CDATA[Even google maps enterprise have restrictions on their geocoding/reverse-geocoding services, 100k if my memory serves me correctly. So, I have to rollout our own service to allow millions of lonlats for reverse geocoding. Have a look at Nominatim, yes it&#8217;s opensource. If you need to get it up and running, have a read of my [...]]]></description>
			<content:encoded><![CDATA[<p>Even google maps enterprise have restrictions on their geocoding/reverse-geocoding services, 100k if my memory serves me correctly.  So, I have to rollout our own service to allow millions of lonlats for reverse geocoding.  Have a look at <a href="http://wiki.openstreetmap.org/wiki/Nominatim">Nominatim</a>, yes it&#8217;s opensource. If you need to get it up and running, have a read of my <a href="/wordpress/2011/11/nominatim-on-osx/">nominatim installation via homebrew on OSX.</a></p>
<p>The nominatim www interface which spits out <a href="http://open.mapquestapi.com/nominatim/v1/reverse?format=xml&#038;lat=-37.856206&#038;lon=145.233980" target="_blank"><code>xml/json</code></a> depending on the format parameter is done in php. </p>
<p>Anyway, I wanted to expose/use this webservice for our Rails3 app. It will also be good if we don&#8217;t use the nominatim webservice all the time if the lonlat was already requested&#8211;caching.</p>
<p><strong>Python-Nominatim</strong> <a href="https://github.com/rdeguzman/python-nominatim">https://github.com/rdeguzman/python-nominatim</a></p>
<p>This project was forked from <a href="https://github.com/agabel/python-nominatim.git">Austin&#8217;s Gabels python-nominatim. </a>  I added the ability to pass a <code>base_url</code> to the classes and added <code>reverse_geocode.py</code>. So assuming you have Python installed, you can do a reverse geocode like this&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> nominatim <span style="color: #ff7700;font-weight:bold;">import</span> ReverseGeocoder
client = ReverseGeocoder<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;http://127.0.0.1/nominatim/reverse.php?format=json&quot;</span><span style="color: black;">&#41;</span>
response = client.<span style="color: black;">geocode</span><span style="color: black;">&#40;</span>-<span style="color: #ff4500;">37.856206</span>, <span style="color: #ff4500;">145.233980</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">print</span> response<span style="color: black;">&#91;</span><span style="color: #483d8b;">'full_address'</span><span style="color: black;">&#93;</span>
<span style="color: #808080; font-style: italic;">#Amesbury Avenue, Wantirna, City of Knox, 3152, Australia</span></pre></div></div>

<p><strong>PL/PYTHON</strong><br />
Now we wrap this python code via PL/PYTHON so Postgres can call it. Checkout <a href="https://github.com/rdeguzman/python-nominatim/blob/master/setup.sql">setup.sql</a></p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">PROCEDURAL</span> <span style="color: #993333; font-weight: bold;">LANGUAGE</span> <span style="color: #ff0000;">'plpythonu'</span> HANDLER plpython_call_handler;
&nbsp;
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">OR</span> <span style="color: #993333; font-weight: bold;">REPLACE</span> <span style="color: #993333; font-weight: bold;">FUNCTION</span> reverse_geocode<span style="color: #66cc66;">&#40;</span>geocoding_url text<span style="color: #66cc66;">,</span> latitude float<span style="color: #66cc66;">,</span> longitude float<span style="color: #66cc66;">&#41;</span> RETURNS
  text
  <span style="color: #993333; font-weight: bold;">AS</span>
  $$
    import nominatim
    client <span style="color: #66cc66;">=</span> nominatim<span style="color: #66cc66;">.</span>ReverseGeocoder<span style="color: #66cc66;">&#40;</span>geocoding_url<span style="color: #66cc66;">&#41;</span>
    response <span style="color: #66cc66;">=</span> client<span style="color: #66cc66;">.</span>geocode<span style="color: #66cc66;">&#40;</span>latitude<span style="color: #66cc66;">,</span> longitude<span style="color: #66cc66;">&#41;</span>
    <span style="color: #993333; font-weight: bold;">RETURN</span> response<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'full_address'</span><span style="color: #66cc66;">&#93;</span>
  $$
  <span style="color: #993333; font-weight: bold;">LANGUAGE</span> <span style="color: #ff0000;">'plpythonu'</span>;</pre></div></div>

<p>With the snippet above, we can now call this with a regular SELECT statement&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> reverse_geocode<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'http://127.0.0.1/nominatim/reverse.php?format=json'</span><span style="color: #66cc66;">,</span> <span style="color: #66cc66;">-</span><span style="color: #cc66cc;">37.856206</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">145.233980</span><span style="color: #66cc66;">&#41;</span>; 
                       reverse_geocode
  <span style="color: #808080; font-style: italic;">----------------------------------------------------------</span>
   Amesbury Avenue<span style="color: #66cc66;">,</span> Wantirna<span style="color: #66cc66;">,</span> City of Knox<span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">3152</span><span style="color: #66cc66;">,</span> Australia
  <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span> row<span style="color: #66cc66;">&#41;</span></pre></div></div>

<p><strong>Rails ActiveRecord</strong></p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">    create_table <span style="color:#ff3333; font-weight:bold;">:locations</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>t<span style="color:#006600; font-weight:bold;">|</span>
      t.<span style="color:#CC0066; font-weight:bold;">float</span>    <span style="color:#ff3333; font-weight:bold;">:latitude</span>
      t.<span style="color:#CC0066; font-weight:bold;">float</span>    <span style="color:#ff3333; font-weight:bold;">:longitude</span>
      t.<span style="color:#9900CC;">text</span>     <span style="color:#ff3333; font-weight:bold;">:address</span>
    <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>In AR, I created a <code>location</code> model above and exposed a <code>reverse_geocode</code> method below</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> Location <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">reverse_geocode</span><span style="color:#006600; font-weight:bold;">&#40;</span>geocode_url, lat, lon<span style="color:#006600; font-weight:bold;">&#41;</span>
    sql_string = <span style="color:#996600;">&quot;SELECT reverse_geocode('#{geocode_url}', #{lat}, #{lon}) as address, #{lat} as latitude, #{lon} as longitude&quot;</span>
    loc_array = <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">find_by_sql</span> sql_string
    loc_array<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>So now, in one of my models, I could simply do..</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> ActiveSession <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>
...
  <span style="color:#9966CC; font-weight:bold;">def</span> location_address
    <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">has_gps</span>?
      loc = Location.<span style="color:#9900CC;">reverse_geocode</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'http://path/to/reverse.php?format=json'</span>, <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">gps_latitude</span>, <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">gps_longitude</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      loc.<span style="color:#9900CC;">address</span>
    <span style="color:#9966CC; font-weight:bold;">else</span>
      <span style="color:#0000FF; font-weight:bold;">nil</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
...
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>In the view, we can simple call <code>model.location_address</code> to retrieve the location details. Below is a code snippet which creates a google marker and adds the location details in the infoWindow.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;%</span> location <span style="color: #339933;">=</span> active_session.<span style="color: #660066;">location_address</span> <span style="color: #339933;">%&gt;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> latlong <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> google.<span style="color: #660066;">maps</span>.<span style="color: #660066;">LatLng</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">&lt;%=</span> active_session.<span style="color: #660066;">gps_latitude</span> <span style="color: #339933;">%&gt;,</span> <span style="color: #339933;">&lt;%=</span> active_session.<span style="color: #660066;">gps_longitude</span> <span style="color: #339933;">%&gt;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> content <span style="color: #339933;">=</span> <span style="color: #3366CC;">'&lt;div style=&quot;width: 300px;&quot;&gt;'</span><span style="color: #339933;">;</span>
content <span style="color: #339933;">=</span> content <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;p&gt;&lt;%= escape_javascript location %&gt;&lt;/p&gt;'</span><span style="color: #339933;">;</span>
content <span style="color: #339933;">=</span> content <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;p&gt;&lt;%= active_session.gps_longitude %&gt;,&lt;%= active_session.gps_latitude %&gt;&lt;/p&gt;'</span><span style="color: #339933;">;</span></pre></div></div>

<p><img src="/wordpress/wp-content/uploads/2012/01/marker.png" alt="marker.png" border="0" width="413" height="373" /></p>
<p><strong>Caching</strong><br />
Our last step is to improve performance via caching. I have opted to do this from the PL/PYTHON end but using a Rails activerecord model/table.  This way, the Rails activerecord has no idea that it is cached when it calls <code>model.location_address</code>. Below, I wrap the new <code>reverse_geocode PL/PYTHON function</code> in a rails migration.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> CreateFunctionReverseGeocoder <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Migration</span>
  <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>.<span style="color:#9900CC;">connection</span>.<span style="color:#9900CC;">schema_search_path</span> = <span style="color:#996600;">&quot;public&quot;</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">up</span>
    execute <span style="color:#996600;">'CREATE OR REPLACE FUNCTION reverse_geocode(geocoding_url text, latitude float, longitude float) RETURNS
      text
      AS
      $$
        plan = plpy.prepare(&quot;SELECT address FROM locations WHERE latitude = $1 AND longitude = $2&quot;, [ &quot;float&quot;, &quot;float&quot; ])
        rv = plpy.execute(plan, [ latitude, longitude ], 1)
&nbsp;
        if rv.nrows() &gt; 0:
          result = rv[0][&quot;address&quot;]
        else:
          import nominatim
          client = nominatim.ReverseGeocoder(geocoding_url)
          response = client.geocode(latitude, longitude)
          result = response[&quot;full_address&quot;]
          insert_plan = plpy.prepare(&quot;INSERT INTO locations(latitude, longitude, address) VALUES($1, $2, $3)&quot;, [&quot;float&quot;, &quot;float&quot;, &quot;text&quot;])
          plpy.execute(insert_plan, [ latitude, longitude, result ])
&nbsp;
        return result
      $$
      language plpythonu;'</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">down</span>
    execute <span style="color:#996600;">'DROP FUNCTION IF EXISTS reverse_geocode(text, double precision, double precision);'</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p><strong>Benchmarks</strong><br />
I plotted 1000 records on my MBP (old core2duo early 2009 4GB RAM). Initial launch takes 108 seconds to load, ~ 2 minutes? But subsequent requests loads < 2 secs.</p>

<div class="wp_syntax"><div class="code"><pre class="terminal" style="font-family:monospace;">For 1000 records:
Completed 200 OK in 110478ms (Views: 1608.8ms | ActiveRecord: 108674.6ms)
Completed 200 OK in 1744ms (Views: 1110.7ms | ActiveRecord: 443.3ms)</pre></div></div>

<p>Below is an architecture diagram of how the systems talk to each other. The locations cache is inside the geo_app_development db. Ofcourse, the nominatim database (gazetteer_au) is separate from our domain so it goes into a different db/server whereever.<br />
<img src="/wordpress/wp-content/uploads/2012/01/archi.png" alt="archi.png" border="0" width="604" height="534" /></p>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2012/01/nominatim-reverse-geocoder-via-plpython-for-rubyonrails-app/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>Google Reader Links to your Blogroll</title>
		<link>/wordpress/2008/02/google-reader-links-to-your-blogroll/</link>
		<comments>/wordpress/2008/02/google-reader-links-to-your-blogroll/#comments</comments>
		<pubDate>Thu, 14 Feb 2008 11:21:21 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[google]]></category>

		<guid isPermaLink="false">/wordpress/index.php/2008/02/14/google-reader-links-to-your-blogroll/</guid>
		<description><![CDATA[It is so eeeassy to publish blog links in your WordPress Blog from Google Reader using an OPML file. OPML is a file type that is widely used to distribute lists of RSS/newsfeeds. You could also grab other feeds and see it in Google Reader. 1. Login to your Google Reader with your Google Account. [...]]]></description>
			<content:encoded><![CDATA[<p>It is so eeeassy to publish blog links in your WordPress Blog from Google Reader using an OPML file. OPML is a file type that is widely used to distribute lists of RSS/newsfeeds. <a href="http://www.google.com/support/reader/bin/answer.py?hl=en&amp;answer=70572">You could also grab other feeds and see it in Google Reader.</a></p>
<p>1. Login to your Google Reader with your Google Account.<br />
2. Click on Settings.<br />
3. Then Import/Export.<br />
4. You will see &#8220;Export your subscriptions as an OPML file.&#8221;<br />
5. Import to WordPress.</p>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2008/02/google-reader-links-to-your-blogroll/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Reviving an old web map with Google Maps via OpenLayers</title>
		<link>/wordpress/2008/01/reviving-an-old-web-map-with-google-maps-via-openlayers/</link>
		<comments>/wordpress/2008/01/reviving-an-old-web-map-with-google-maps-via-openlayers/#comments</comments>
		<pubDate>Tue, 22 Jan 2008 01:10:09 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[openlayers]]></category>
		<category><![CDATA[google]]></category>

		<guid isPermaLink="false">/wordpress/?p=136</guid>
		<description><![CDATA[An old coworker and I worked on a travel portal for the Philippines called travelsite.ph about 4 years ago. We are now given a task of reviving the old web application and even adding mapping functionalities. Back then, the application was using ColdFusion 4.5 and MySQL 3. Fingers crossed we dropped the app in a [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.gisnotes.com/wordpress/wp-content/uploads/2008/01/travelsite.jpg" title="Travelsite.ph with Google"><img src="http://www.gisnotes.com/wordpress/wp-content/uploads/2008/01/travelsite.jpg" alt="Travelsite.ph with Google" /></a></p>
<p>An old coworker and I worked on a travel portal for the Philippines called travelsite.ph about 4 years ago. We are now given a task of reviving the old web application and even adding mapping functionalities.  Back then, the application was using ColdFusion 4.5 and MySQL 3.</p>
<p>Fingers crossed we dropped the app in a ColdFusion 6/7/8 environment with no changes at all. The app still works! Awesome.. how CF really progressed through the years with backward compatibility.  The only changes we made was removing the registration/sign up for a quick demo. I just laughed at the oddities and the no brainer features (pertaining to security) that I made when I was starting out.</p>
<p>The database was also intact and have UTM coordinates. We dropped it to a Debian mysql 5 and works flawlessly since its MyISAM. I had the coordinates exported to lon/lat, so I could directly inject it to OpenLayers/Google.  After two hours of fiddling around, I got mapping embedded.. hehe.. courtesy of OpenLayers ofcourse.</p>
<p>Here&#8217;s a quick reminder to myself&#8230;</p>
<p>A. Google WGS 84 Example.</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: #3366CC;">&quot;EPSG:4326&quot;</span><span style="color: #339933;">,</span>
					numZoomLevels<span style="color: #339933;">:</span> <span style="color: #CC0000;">19</span><span style="color: #339933;">,</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: #CC0000;">120.8774</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">14.3684</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">121.1628</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">14.7931</span><span style="color: #009900;">&#41;</span>
&nbsp;
				<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #006600; font-style: italic;">// avoid pink tiles</span>
		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>
		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>
		sat_wms <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;">Google</span><span style="color: #009900;">&#40;</span>
					<span style="color: #3366CC;">&quot;Layer&quot;</span><span style="color: #339933;">,</span>
					<span style="color: #009900;">&#123;</span>type<span style="color: #339933;">:</span> G_SATELLITE_MAP<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		map.<span style="color: #660066;">addLayer</span><span style="color: #009900;">&#40;</span>sat_wms<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		map.<span style="color: #660066;">addControl</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">new</span> OpenLayers.<span style="color: #660066;">Control</span>.<span style="color: #660066;">MousePosition</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		map.<span style="color: #660066;">addControl</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">new</span> OpenLayers.<span style="color: #660066;">Control</span>.<span style="color: #660066;">LayerSwitcher</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		map.<span style="color: #660066;">addControl</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">new</span> OpenLayers.<span style="color: #660066;">Control</span>.<span style="color: #660066;">Scale</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #003366; font-weight: bold;">var</span> center <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> OpenLayers.<span style="color: #660066;">LonLat</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">121.06504</span><span style="color: #339933;">,</span><span style="color: #CC0000;">14.65495</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		map.<span style="color: #660066;">setCenter</span><span style="color: #009900;">&#40;</span>center<span style="color: #339933;">,</span> <span style="color: #CC0000;">16</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span></pre></div></div>

<p>B. Google Mercator Projection</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: #3366CC;">&quot;EPSG:900913&quot;</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>
						maxResolution<span style="color: #339933;">:</span> <span style="color: #CC0000;">156543.0339</span><span style="color: #339933;">,</span>
						numZoomLevels<span style="color: #339933;">:</span> <span style="color: #CC0000;">19</span><span style="color: #339933;">,</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: #CC0000;">12823075.86334</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">4800551.12375</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">13101918.14248</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">5021301.26141</span><span style="color: #009900;">&#41;</span>
					<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #006600; font-style: italic;">// avoid pink tiles</span>
			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>
			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>
			sat_wms <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;">Google</span><span style="color: #009900;">&#40;</span>
						<span style="color: #3366CC;">&quot;Layer&quot;</span><span style="color: #339933;">,</span>
						<span style="color: #009900;">&#123;</span>type<span style="color: #339933;">:</span> G_SATELLITE_MAP<span style="color: #339933;">,</span><span style="color: #3366CC;">'sphericalMercator'</span><span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#125;</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>sat_wms<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<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>
				<span style="color: #3366CC;">&quot;http://127.0.0.1/cgi-bin/mapserv&quot;</span><span style="color: #339933;">,</span>
				<span style="color: #009900;">&#123;</span>
					layers<span style="color: #339933;">:</span> <span style="color: #3366CC;">'beijing_all'</span><span style="color: #339933;">,</span>
					map<span style="color: #339933;">:</span> <span style="color: #3366CC;">'/home/map/beijing/new/beijing_google.map'</span><span style="color: #339933;">,</span>
					format<span style="color: #339933;">:</span> <span style="color: #3366CC;">'AGG'</span><span style="color: #339933;">,</span>
					<span style="color: #3366CC;">'transparent'</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'true'</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;">false</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>	
&nbsp;
			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>
&nbsp;
			map.<span style="color: #660066;">addControl</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">new</span> OpenLayers.<span style="color: #660066;">Control</span>.<span style="color: #660066;">MousePosition</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			map.<span style="color: #660066;">addControl</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">new</span> OpenLayers.<span style="color: #660066;">Control</span>.<span style="color: #660066;">LayerSwitcher</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			map.<span style="color: #660066;">addControl</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">new</span> OpenLayers.<span style="color: #660066;">Control</span>.<span style="color: #660066;">Scale</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #003366; font-weight: bold;">var</span> center <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> OpenLayers.<span style="color: #660066;">LonLat</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">12956625.68367</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">4852316.90682</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			map.<span style="color: #660066;">setCenter</span><span style="color: #009900;">&#40;</span>center<span style="color: #339933;">,</span> <span style="color: #CC0000;">18</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span></pre></div></div>

<p>What&#8217;s the difference between both snippets? Obviously projection is one. Since most of my point data is in lon/lat, then the WGS84 example is good if I don&#8217;t want to overlay custom precise data.  Remember the x shift problem in Google with Openlayers. The Google Mercator example is used when I want to overlay more custom data, particularly polygons/line that needs to fit on Google Layers. For more details, please see my previous <a href="/wordpress/?p=129">blog post</a>.</p>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2008/01/reviving-an-old-web-map-with-google-maps-via-openlayers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>OpenLayers + Google Spherical Mercator Example</title>
		<link>/wordpress/2007/12/openlayers-google-spherical-mercator-example/</link>
		<comments>/wordpress/2007/12/openlayers-google-spherical-mercator-example/#comments</comments>
		<pubDate>Sat, 22 Dec 2007 11:42:18 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[GIS]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[openlayers]]></category>

		<guid isPermaLink="false">/wordpress/?p=129</guid>
		<description><![CDATA[I&#8217;ve been a dormant user of OpenLayers for months (4 months?) now and it was a surprise that the svn trunk had huge differences from what I remember OL (2.4/5?) to be. One of the cool features that and the OpenLayers community contributed was the Google Speherical Mercator hack. Below is a quick step tutorial [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.gisnotes.com/wordpress/wp-content/uploads/2007/12/openlayers_google.jpg" title="Road Overlay on Google Vector in Forbidden City and Tiananmen, Beijing, China"><img src="http://www.gisnotes.com/wordpress/wp-content/uploads/2007/12/openlayers_google.jpg" alt="Road Overlay on Google Vector in Forbidden City and Tiananmen, Beijing, China" /></a></p>
<p>I&#8217;ve been a dormant user of OpenLayers for months (4 months?) now and it was a surprise that the <a href="http://svn.openlayers.org/trunk/openlayers/">svn trunk</a> had huge differences from what I remember OL (2.4/5?) to be. One of the cool features that <a href="http://labs.metacarta.com/"></a> and the <a href="http://trac.openlayers.org/">OpenLayers</a> community contributed was the Google Speherical Mercator hack. Below is a quick step tutorial on how I was able to overlay a custom WMS to Google (set as the baselayer). For this tutorial, I want to overlay a road layer on top of Google.</p>
<p>1. We need to convert our data to <a href="http://trac.osgeo.org/gdal/ticket/1868">Google Projection (Spatial Reference System: 900913)</a>. This applies to whatever kind of data (mine is vector stored both in Mapinfo and PostGis) we have.  For PostGis, we need to:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> spatial_ref_sys <span style="color: #66cc66;">&#40;</span>srid<span style="color: #66cc66;">,</span> auth_name<span style="color: #66cc66;">,</span> auth_srid<span style="color: #66cc66;">,</span> proj4text<span style="color: #66cc66;">,</span> srtext<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">900913</span><span style="color: #66cc66;">,</span> 
&nbsp;
<span style="color: #ff0000;">'spatialreference.org'</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">900913</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 
&nbsp;
+x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext  +no_defs'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'PROJCS
&nbsp;
[&quot;unnamed&quot;,GEOGCS[&quot;unnamed ellipse&quot;,DATUM[&quot;unknown&quot;,SPHEROID[&quot;unnamed&quot;,6378137,0]],PRIMEM
&nbsp;
[&quot;Greenwich&quot;,0],UNIT[&quot;degree&quot;,0.0174532925199433]],PROJECTION[&quot;Mercator_2SP&quot;],PARAMETER
&nbsp;
[&quot;standard_parallel_1&quot;,0],PARAMETER[&quot;central_meridian&quot;,0],PARAMETER
&nbsp;
[&quot;false_easting&quot;,0],PARAMETER[&quot;false_northing&quot;,0],UNIT[&quot;Meter&quot;,1],EXTENSION
&nbsp;
[&quot;PROJ4&quot;,&quot;+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 
&nbsp;
+units=m +nadgrids=@null +wktext  +no_defs&quot;]]'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #993333; font-weight: bold;">SELECT</span> AddGeometryColumn<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'public'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'roads'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'the_geom_google'</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">900913</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'LINESTRING'</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span>; 
&nbsp;
<span style="color: #993333; font-weight: bold;">UPDATE</span> roads <span style="color: #993333; font-weight: bold;">SET</span> the_geom_google <span style="color: #66cc66;">=</span> Transform<span style="color: #66cc66;">&#40;</span>the_geom<span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">900913</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>2. MapFile Settings courtesy of <a href="http://spatialreference.org/ref/user/google-projection/">SpatialReference: Google Projection</a></p>

<div class="wp_syntax"><div class="code"><pre class="conf" style="font-family:monospace;">WEB
    #Other Web Config Settings goes here...
    &quot;wms_srs&quot;              &quot;EPSG:900913&quot;
END
&nbsp;
PROJECTION
    &quot;+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext  +no_defs&quot;
END</pre></div></div>

<p>3. By ensuring that Mapserver has the new 900913 projection, problems such as <em>&#8220;msWMSLoadGetMapParams(): WMS server error. Invalid SRS given : SRS must be valid for all requested layers.&#8221;</em> or <em><a href="http://mapserver.gis.umn.edu/docs/error/proj-init-file">&#8220;msProcessProjection(): Projection library error. no options found in &#8216;init&#8217; file&#8221;</a></em> will be avoided.</p>

<div class="wp_syntax"><div class="code"><pre class="conf" style="font-family:monospace;">cd /ms4w/proj/nad/
gvim epsg
# GCS Voirol 1875 Degree
&amp;lt;104304&amp;gt; +proj=longlat +a=6378249.2 +b=6356514.999904194  no_defs &amp;lt;&amp;gt;
# GCS Voirol Unifie 1960 Degree
&amp;lt;104305&amp;gt; +proj=longlat +ellps=clrk80  no_defs &amp;lt;&amp;gt;
# Google Spherical Mercator
. . .
&amp;lt;900913&amp;gt; +proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext  +no_defs</pre></div></div>

<p>4. Below is an example WMS Request. Note: &#8220;SRS=EPSG 900913&#8243; is added; TRANSPARENT=true not TRANSPARENT=on; Check your BBOX settings for the correct extent.</p>

<div class="wp_syntax"><div class="code"><pre class="conf" style="font-family:monospace;">http://127.0.0.1/cgi-bin/mapserv?
LAYERS=beijing_all
&amp;amp;MAP=%2Fhome%2Fmap%2Fbeijing%2Fnew%2Fbeijing_google.map
&amp;amp;FORMAT=AGG
&amp;amp;TRANSPARENT=true
&amp;amp;SERVICE=WMS&amp;amp;VERSION=1.1.1&amp;amp;REQUEST=GetMap
&amp;amp;STYLES=
&amp;amp;EXCEPTIONS=application%2Fvnd.ogc.se_inimage
&amp;amp;SRS=EPSG%3A900913
&amp;amp;BBOX=12956687.788758555,4852222.554861524,12956993.536871642,4852528.30297461
&amp;amp;WIDTH=256&amp;amp;HEIGHT=256</pre></div></div>

<p>5. Requesting the WMS from OpenLayers.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">	<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: #3366CC;">&quot;EPSG:900913&quot;</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>
			<span style="color: #006600; font-style: italic;">//maxResolution: 156543.0339,</span>
			numZoomLevels<span style="color: #339933;">:</span> <span style="color: #CC0000;">18</span><span style="color: #339933;">,</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: #CC0000;">12823075.86334</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">4800551.12375</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">13101918.14248</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">021301.26141</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">// avoid pink tiles</span>
	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>
	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>
	sat_wms <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;">Google</span><span style="color: #009900;">&#40;</span>
				<span style="color: #3366CC;">&quot;Layer&quot;</span><span style="color: #339933;">,</span>
				<span style="color: #009900;">&#123;</span>type<span style="color: #339933;">:</span> G_SATELLITE_MAP<span style="color: #339933;">,</span><span style="color: #3366CC;">'sphericalMercator'</span><span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#125;</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>sat_wms<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<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>
		<span style="color: #3366CC;">&quot;http://127.0.0.1/cgi-bin/mapserv&quot;</span><span style="color: #339933;">,</span>
		<span style="color: #009900;">&#123;</span>
			layers<span style="color: #339933;">:</span> <span style="color: #3366CC;">'beijing_all'</span><span style="color: #339933;">,</span>
			map<span style="color: #339933;">:</span> <span style="color: #3366CC;">'/home/map/beijing/new/beijing_google.map'</span><span style="color: #339933;">,</span>
			format<span style="color: #339933;">:</span> <span style="color: #3366CC;">'AGG'</span><span style="color: #339933;">,</span>
			<span style="color: #3366CC;">'transparent'</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'true'</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;">false</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>	
&nbsp;
        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>
	map.<span style="color: #660066;">addControl</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">new</span> OpenLayers.<span style="color: #660066;">Control</span>.<span style="color: #660066;">MousePosition</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	map.<span style="color: #660066;">addControl</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">new</span> OpenLayers.<span style="color: #660066;">Control</span>.<span style="color: #660066;">LayerSwitcher</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	map.<span style="color: #660066;">addControl</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">new</span> OpenLayers.<span style="color: #660066;">Control</span>.<span style="color: #660066;">Scale</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;">var</span> center <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> OpenLayers.<span style="color: #660066;">LonLat</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">12956625.68367</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">4852316.90682</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	map.<span style="color: #660066;">setCenter</span><span style="color: #009900;">&#40;</span>center<span style="color: #339933;">,</span> <span style="color: #CC0000;">17</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>/wordpress/2007/12/openlayers-google-spherical-mercator-example/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Downloading Google Videos</title>
		<link>/wordpress/2007/08/downloading-google-videos/</link>
		<comments>/wordpress/2007/08/downloading-google-videos/#comments</comments>
		<pubDate>Sat, 11 Aug 2007 15:29:22 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[google]]></category>

		<guid isPermaLink="false">/wordpress/?p=96</guid>
		<description><![CDATA[Having troubles downloading google videos in china. I found this excellent post, http://www.isaacmao.com/meta/2006/07/how-to-view-google-video-locally-in.html&#8221;. Trick here, is for your browser to use anonymous access. This is where TOR comes to the picture. Follow the steps above in setting up TOR. You should see two (2) icons on your system tray&#8211;[1] Privoxy and [2]Tor. Go to D:\Vidalia [...]]]></description>
			<content:encoded><![CDATA[<p>Having troubles downloading google videos in china. I found this excellent post, <a href="http://www.isaacmao.com/meta/2006/07/how-to-view-google-video-locally-in.html">http://www.isaacmao.com/meta/2006/07/how-to-view-google-video-locally-in.html&#8221;</a>.</p>
<p>Trick here, is for your browser to use anonymous access. This is where <a href="http://tor.eff.org/docs/tor-doc-win32.html.en">TOR</a> comes to the picture.</p>
<ol>
<li>Follow the steps above in setting up TOR.</li>
<li>You should see two (2) icons on your system tray&#8211;[1] Privoxy and [2]Tor.</li>
<li>Go to D:\Vidalia Bundle\Torbutton\ and drag torbutton-1.0.4-fx+tb.xpi to Firefox to install the plugin. Restart Firefox.</li>
<li>To test your settings: Go to <a href="http://torcheck.xenobite.eu/">tor detector</a>.</li>
</ol>
<p>TOR-disabled:<br />
<em>219.142.136.4 (4.136.142.219.broad.bj.bj.dynamic.163data.com.cn)</em></p>
<p>TOR:<br />
<em>88.84.142.165 (v29465.1blu.de)</em></p>
<ol>
<li>Now we can view google video from China.</li>
<li>To download the video, view source the file after the flash video has initialized</li>
<li>Look for: &#8220;<em>googleplayer.swf?&amp;videoUrl</em>&#8220;, copy and paste the URL until you see &#8220;<em>&amp;messagesUrl\u003</em>&#8220;</li>
<li>Now fire up your PL of choice and unescape the string</li>
</ol>

<div class="wp_syntax"><div class="code"><pre class="cf" style="font-family:monospace;">&lt;cfset temp=&quot;http%3A%2F%2Fvp.video.google.com%2Fvideodownload%3Fversion%3D0%26secureurl%3DtwAAAJXmdl7RAbyfYcDwHzBiBVKQtqUQSoSZfAnVXGhsGvKxwTGSF0kNuXRAvMyVxKs6uXkGf3muen2mfnv_D21e3Wkw89ngl9-GEELOIiKHZtJsfUc_kYbKHHMieqsUs92S5ALoyWiWZBeX3SaNdyNTNuc6h1aPjG9EBrGIK4sf0s9Zrl5npjJiUZJ8j_mKWj9YQFhnHOkL-t7XUBBxJuXGeK2ORTrfBPecXPAC-ql_GlIwWIDkAWP6bVCeej0uFln-EA%26sigh%3Dyt6dfQtoXjSdikbv9o9y5YADjj8%26begin%3D0%26len%3D6009275%26docid%3D1135114630744003385&quot;&gt;
&nbsp;
&lt;cfoutput&gt;
&lt;a href=&quot;#URLDecode(temp)#&quot;&gt;#URLDecode(temp)#&lt;/a&gt;
&lt;/cfoutput&gt;
&lt;/cfset&gt;</pre></div></div>

<p>Once downloaded, you can view it from google&#8217;s video player. GoogleVideoPlayerSetup.exe</p>
]]></content:encoded>
			<wfw:commentRss>/wordpress/2007/08/downloading-google-videos/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>OpenLayers and Google Layer Zoom fix</title>
		<link>/wordpress/2007/02/openlayers-and-google-layer-zoom-fix/</link>
		<comments>/wordpress/2007/02/openlayers-and-google-layer-zoom-fix/#comments</comments>
		<pubDate>Tue, 20 Feb 2007 11:32:18 +0000</pubDate>
		<dc:creator>rupert</dc:creator>
				<category><![CDATA[openlayers]]></category>
		<category><![CDATA[google]]></category>

		<guid isPermaLink="false">/wordpress/?p=38</guid>
		<description><![CDATA[I have finally fixed the disappearing layer on the layer switch when we try to overlay the layer on top of Google. I edited Google.js to reflect the ff: &#160; MAX_ZOOM_LEVEL: 22, &#160; /** Hardcode these resolutions so that they are more closely * tied with the standard wms projection * * @final @type Array(float) [...]]]></description>
			<content:encoded><![CDATA[<p>I have finally fixed the disappearing layer on the layer switch when we try to overlay the layer on top of Google. I edited Google.js to reflect the ff:</p>

<div class="wp_syntax"><div class="code"><pre class="js" style="font-family:monospace;">&nbsp;
    MAX_ZOOM_LEVEL: 22,
&nbsp;
    /** Hardcode these resolutions so that they are more closely
     *   tied with the standard wms projection
     *
     * @final @type Array(float) */
/*    RESOLUTIONS: [1.40625,0.703125,0.3515625,0.17578125,0.087890625,0.0439453125,0.02197265625,0.010986328125,0.0054931640625,0.00274658203125,0.001373291015625,0.0006866455078125,0.00034332275390625,0.000171661376953125,0.0000858306884765625,0.00004291534423828125],*/
&nbsp;
RESOLUTIONS:[1.40625,0.703125,0.3515625,0.17578125,0.087890625,0.0439453125,0.02197265625,0.010986328125,0.0054931640625,0.00274658203125,0.001373291015625,0.0006866455078125,0.00034332275390625,0.000171661376953125,0.0000858306884765625,0.00004291534423828125,0.0000214576721191140625,0.000107288360595703125,0.0000053644182978515625,0.000002682209014892578125,0.0000013411045074462890625,0.00000067055225372314453125],</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>/wordpress/2007/02/openlayers-and-google-layer-zoom-fix/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

