<?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/category/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>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>
	</channel>
</rss>

