<?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>Tales From The Cloud &#187; overlay</title>
	<atom:link href="http://blog.newsplore.com/tag/overlay/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.newsplore.com</link>
	<description>Everything beta</description>
	<lastBuildDate>Sun, 05 Feb 2012 09:03:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Spincloud Labs: Political boundaries overlay in Google maps (Part 2)</title>
		<link>http://blog.newsplore.com/2009/03/01/political-boundaries-overlay-google-maps-2</link>
		<comments>http://blog.newsplore.com/2009/03/01/political-boundaries-overlay-google-maps-2#comments</comments>
		<pubDate>Mon, 02 Mar 2009 01:43:15 +0000</pubDate>
		<dc:creator>Florin</dc:creator>
				<category><![CDATA[home]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[tools]]></category>
		<category><![CDATA[UNIX]]></category>
		<category><![CDATA[gis]]></category>
		<category><![CDATA[google maps]]></category>
		<category><![CDATA[overlay]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://blog.newsplore.com/?p=737</guid>
		<description><![CDATA[Update Sep.21.2011: I took the code in the two parts and made a github project off of it called Gborders. The code is simpler and there are more options to generate the borders overlay based on geographic regions. Happy forks! In Part 1 we imported world political borders into a database table. In this second [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="padding-right:0;margin-top:3px"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.newsplore.com%2F2009%2F03%2F01%2Fpolitical-boundaries-overlay-google-maps-2"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.newsplore.com%2F2009%2F03%2F01%2Fpolitical-boundaries-overlay-google-maps-2" height="61" width="51" /></a></div><p><i>Update Sep.21.2011: I took the code in the two parts and made a github project off of it called <a href='https://github.com/florind/Gborders'>Gborders</a>. The code is simpler and there are more options to generate the borders overlay based on geographic regions. Happy forks!</i><br />
</p>
<p align="justify">In <a href="http://blog.newsplore.com/?p=531">Part 1</a> we imported world political borders into a database table. In this second part we&#8217;ll use the table and generate a script that will be used to add the borders overlay to Google Maps. We&#8217;ll use the cool Ruby and some fancy GIS words along the way.</p>
<p align="justify">We left-off with a database table containing all borders. The goal today is to produce a Javascript file that will be used for overlaying polygons representing countries, over a map using the <a href="http://code.google.com/apis/maps/">Google Maps API.</a></p>
<p>Let&#8217;s examine the table data first (I&#8217;m using mysql through the command line):</p>
<pre>mysql&gt; desc world_boundaries;
+-----------+--------------+------+-----+---------+-------+
| Field     | Type         | Null | Key | Default | Extra |
+-----------+--------------+------+-----+---------+-------+
| ID        | int(11)      | NO   | PRI | NULL    |       |
| FIPS      | varchar(255) | YES  |     | NULL    |       |
| ISO2      | varchar(255) | YES  |     | NULL    |       |
| ISO3      | varchar(255) | YES  |     | NULL    |       |
| UN        | int(11)      | YES  |     | NULL    |       |
| NAME      | varchar(255) | YES  |     | NULL    |       |
| AREA      | int(11)      | YES  |     | NULL    |       |
| POP2005   | bigint(20)   | YES  |     | NULL    |       |
| REGION    | int(11)      | YES  |     | NULL    |       |
| SUBREGION | int(11)      | YES  |     | NULL    |       |
| LON       | double       | YES  |     | NULL    |       |
| LAT       | double       | YES  |     | NULL    |       |
| ogc_geom  | geometry     | YES  |     | NULL    |       |
+-----------+--------------+------+-----+---------+-------+</pre>
<p>A lot of information here but we&#8217;ll need just these fields: name (country name), iso2 (two letter <a href="http://www.iso.org/iso/english_country_names_and_code_elements">country codes</a>) the_geom, iso2 (border geometry) and region (grouping countries by regions). To check the data-set let&#8217;s examine a small country. I&#8217;ll pick the tiny <a href="http://en.wikipedia.org/wiki/Vatican_City">State of Vatican</a> for its size:</p>
<pre>mysql&gt; select iso2, AsText(ogc_geom), region from world_boundaries where iso2='VA';
+------+---------------------------------------------------------------------------------------------------------------------------------------------------+--------+
| iso2 | AsText(ogc_geom)                                                                                                                                  | region |
+------+---------------------------------------------------------------------------------------------------------------------------------------------------+--------+
| VA   | MULTIPOLYGON(((12.445090330889 41.903117521785,12.451653339581 41.907989033391,12.456660170954 41.901426024699,12.445090330889 41.903117521785))) |    150 |
+------+---------------------------------------------------------------------------------------------------------------------------------------------------+--------+
1 row in set (0.00 sec)</pre>
<p>The only surprise here is that the country border is described as a <a href="http://dev.mysql.com/doc/refman/5.0/en/gis-class-multipolygon.html">MULTIPLOYGON</a> spatial type which describe a collection of polygons that don&#8217;t interset. This is in order to accommodate countries that have islands under ownership.</p>
<p>Let&#8217;s see how these points look on the map. We&#8217;ll use the excellent polygon <a href="http://facstaff.unca.edu/mcmcclur/GoogleMaps/EncodePolyline/encodeForm.html">encoder utility</a> written by Mark McClure. Copy Vatican&#8217;s point set in the &#8220;Input Text&#8221; input box (choose lng/lat option):</p>
<pre>12.445090330889, 41.903117521785
12.451653339581, 41.907989033391
12.456660170954, 41.901426024699
12.445090330889, 41.903117521785</pre>
<p>Here&#8217;s the result:<br />
<img class="alignnone size-full wp-image-628" src="/wp-content/uploads/2009/02/va_polygon.png" alt="va_polygon" width="229" height="176" /><br />
Not very accurate but we&#8217;ll have to live with it, it&#8217;s a free data set after all&#8230;<br />
<span id="more-737"></span><br />
We can also get a glimpse of how the Javascript code containing the encoded polygon looks like  by using the same utility. Click on the &#8220;Show Code&#8221; button; you should see this:</p>
<pre>...
var polyline1_1 = new GPolyline.fromEncoded({
  color: "#0000ff",
  weight: 4,
  opacity: 0.8,
  points: "mew~Fyt}jAm]_h@~g@i^qIhgA",
  levels: "PHIP",
  zoomFactor: 2,
  numLevels: 18
});
map.addOverlay(polyline1_1);</pre>
<p>The last line adds this polygon (i.e. is a polyline but more on that later) to the map.<br />
The &#8220;points&#8221; property of the GPolyline is an encoded string which we&#8217;ll have to generate. The full documentation on how the encoding is performed read <a href="http://code.google.com/apis/maps/documentation/overlays.html#Polylines_Overview">Google&#8217;s polyline documentation</a>.<br />
Let&#8217;s use a bit of pseudocode to describe the steps we want performed:</p>
<pre>for each ogc_geom of countries fetched from DB
  generate encoded points
  create GPolygon Javascript code snippet
  collect snippet to Javascript file
end</pre>
<p>First things first. Since I&#8217;m learning Ruby, I&#8217;m going to use it to implement these requirements. The extras I&#8217;m gonna need are Mysql (for DB connectivity) and <a href="http://georuby.rubyforge.org/">GeoRuby</a> (for processing spatial data types). Installing MySql gem to Ruby is easy (sudo gem install mysql) that is if you don&#8217;t want to get into using 64bit Mysql distributions (you don&#8217;t) so let&#8217;s skip that. Install GeoRuby with a&#8221;sudo gem install GeoRuby&#8221; command.<br />
To verify if both mysql and GeoRuby are enabled, open an irb session then type:</p>
<pre>&gt;&gt; require 'mysql'
=&gt; true
&gt;&gt; require 'geo_ruby'
=&gt; true</pre>
<p>They should both render true.<br />
A word about encoding polygons. Google&#8217;s encoded polyline/polygon API optimizes the rendering by enabling encoding more or less points giving different zoom levels (higher zoom, more points will be used). A well known optimization method is described by the <a href="http://mappinghacks.com/code/PolyLineReduction/">Douglas-Peucker</a> algorithm. However, to make my life easy I devised a simpler algorithm for dealing with this; I term it the <em>straight point reduction algorithm</em> and it replaces the D-P algorithm by uniformly reducing all points up-front and encoding the polygons always using the same number of points for all zoom levels. The rendering of the polygons is not impacted and the actual looks of the country borders is virtually unchanged at all zoom levels. I have found that using one in five points yields respectable performance and doesn&#8217;t impact the shape of the borders. Finally the algorithm used to encode coordinates is described <a href="http://code.google.com/apis/maps/documentation/polylinealgorithm.html">here</a>. The generated javascript has three functions: initializing the overlay (initOverlay) and adding/removing  (addBordersOverlay/removeBordersOverlay)</p>
<p><i>Update Aug/05/2011:</i> I originally wrote the script below for the Google Maps API v2.0. In the mean time Google upgraded their API to v3.1 and <a href='https://gist.github.com/Ivesvdf'>Ivesdf</a> has written an updated Ruby script for the new Google Maps API v3.0 <a href='https://gist.github.com/1124959'>here</a>. Thanks Ives!</p>
<p>To check out the code <a href="/wp-content/uploads/2009/02/gen_encpolygons.rb">download</a> the .rb file or <a style="display:none;" id="ddetlink1890781817" href="javascript:expand(document.getElementById('ddet1890781817'))">click to expand.</a>
<div class="ddet_div" id="ddet1890781817"><script language="JavaScript" type="text/javascript">expand(document.getElementById('ddet1890781817'));expand(document.getElementById('ddetlink1890781817'))</script></p>
<pre>
require 'mysql'
require 'geo_ruby'

include GeoRuby::SimpleFeatures

def generate_js_border_overlay(output_file)
  factory = GeometryFactory.new
  wkt_parser = EWKTParser.new(factory)

  borderDB = Mysql::new('localhost', 'root', '', 'bordersdb')
  #region 150 is Europe
  res = borderDB.query("select name, iso2, AsText(ogc_geom), region from
                world_boundaries where region=150")
  encoded_polygon_desc = "";
  remove_warnings_layer = "function removeBordersOverlay() {n"
  add_warnings_layer = "function addBordersOverlay() {n"
  init_borders = "function initBorders() {n"
  res.each do |row|
    name, iso2, multi_polygon, region = *row
    processed_polygon = wkt_parser.parse(multi_polygon);
    encoded_polygon_desc &lt;&lt; "var encodedPolygon_#{iso2};n"
    add_warnings_layer &lt;&lt; "map.addOverlay(encodedPolygon_#{iso2});n"
    remove_warnings_layer &lt;&lt; "map.removeOverlay(encodedPolygon_#{iso2});n"
    init_borders &lt;&lt; "encodedPolygon_#{iso2} =
      new GPolygon.fromEncoded({n
      polylines: ["
    factory.geometry.each do |landmass|
      landmass.rings.each do |ring|
        encoded = encode_by_reducing_pointcount(ring.points)
        init_borders &lt;&lt; "{color: "white",n
        weight: 5,n
        points: '"
        init_borders &lt;&lt; encoded[0].gsub(/\/, '&amp;&amp;') + "',n
        levels: '#{encoded[1]}',n
        zoomFactor: 2,n numLevels: 2}"
        init_borders &lt;&lt; "," unless ring == landmass.rings.last
                 &amp;&amp; landmass == factory.geometry.last
        init_borders &lt;&lt; "n"
      end
    end
    init_borders &lt;&lt; "],nfill:true,n
    opacity:0.7,n
    color: 'white'n
    });"
  end

  add_warnings_layer &lt;&lt; "n}"
  remove_warnings_layer &lt;&lt; "n}"
  init_borders &lt;&lt; "n}"
  File.open(output_file, 'w') {|f|
    f.write(encoded_polygon_desc + "n")
    f.write(add_warnings_layer + "n")
    f.write(remove_warnings_layer + "n")
    f.write(init_borders)
  }
end

def encode_by_reducing_pointcount(points)
  dlat = plng = plat = dlng = 0
  res = ["",""]
  index = -1
  for point in points
    index += 1
    #straight point reduction algorithm: use every 5th point only
    #use all points if their total count is less than 16
    next if index.modulo(5) != 0 &amp;&amp; points.size &gt; 16
    late5 = (point.y * 1e5).floor
    lnge5 = (point.x * 1e5).floor
    dlat = late5 - plat;
    dlng = lnge5 - plng;
    plat = late5;
    plng = lnge5;
    res[0] &lt;&lt; encode_signed_number(dlat)
    res[0] &lt;&lt; encode_signed_number(dlng)
    res[1] &lt;&lt; encode_number(3)
  end
  return res
end

def encode_signed_number(num)
  sig_num = num &lt;&lt; 1
  sig_num = ~sig_num if sig_num &lt; 0
  encode_number(sig_num)
end

def encode_number(num)
  res = ""
  while num  &gt;= 0x20 do
    res &lt;&lt; ((0x20 | (num &amp; 0x1f)) + 63).chr
    num &gt;&gt;= 5
  end
  res &lt;&lt; (num + 63).chr
  return res
end

generate_js_border_overlay("/tmp/bordersOverlay.js")
</pre>
<p></div><br />
I gotta give it to Ruby: it took less than 100 lines to write it all. I choose to skip all exception handling for simplification.<br />
Running program generates a file called bordersOverlay.js in the /tmp folder. You can change the file location by changing the last line of code.<br />
You can also modify the script to filter certain countries based on different criteria by changing the SQL statement at line 11. The line colors, fill colors or opacity can also be changed as needed.<br />
Let&#8217;s put this file to work. I&#8217;m going to generate the border overlay for a single country; I&#8217;ll go with Spain my sunny country of choice. To prepare the script, I&#8217;m changing the SQL query to filter only Spain:</p>
<pre>select name, iso2, AsText(ogc_geom), region from world_boundaries where iso2='ES'")</pre>
<p>I&#8217;m picking a nicely colored background too, electric lime that is; in the ruby script I&#8217;ll update the two occurrences of &#8220;color: &#8221; to &#8220;color: #CCFF00&#8243;.After the script is ran, the file /tmp/bordersOverlay.js is created.</p>
<p>Let&#8217;s put it all together. This is a live embedded map that uses the generated JS script:<br />
<iframe frameborder="0" src="http://blog.newsplore.com//wp-content/uploads/2009/03/embedmap.html" width="520" scrolling="no" height="440"></iframe><br />
The usage is straightforward: include the JS file in the HTML snippet</p>
<pre> &lt;script type="text/javascript" src="bordersOverlay.js"&gt;&lt;/script&gt;</pre>
<p>then call these two functions in your JS code after initializing the GMap2 object:</p>
<pre>initBorders();
addBordersOverlay();</pre>
<p>You can also peek at the source code <a href='/wp-content/uploads/2009/03/embedmap.html'>here</a>.<br />
If you zoom-in towards a border area you can observe how approximate the true border is followed. This is due to the straight point reduction algorithm detailed earlier. Spain&#8217;s islands are also colored correctly (Balearic islands to the East of the mainland and the Canary Islands which become visible if you browse off the West coast of Africa).<br />
You can also dynamically change the polygon colors as needed. For the above case we&#8217;ll use the following code:</p>
<pre>encodedPolygon_ES.setFillStyle({color:blue",opacity:1})');</pre>
<p>That&#8217;s all.<br />
The only concern is client-side performance. If there are many polygons to render, the browser may take a long time to render the countries overlay. This is quite apparent when trying <a href="http://spincloud.com">Spincloud</a>&#8216;s Europe weather warnings (Meteoalarm) overlay by using Internet Explorer. Position the map over Europe and click the Meteoalarm button located in the top-left corner of the map. Rendering may take a long time (Chrome handles this the best, it&#8217;s mighty fast).<br />
I&#8217;ll close this tutorial with some colorful maps created using variations of the above code.</p>
<p>All countries in the Mediterranean Basin colored by region:<br />
<img src="http://blog.newsplore.com/wp-content/uploads/2009/03/mediterranean_basin.png" alt="mediterranean_basin" width="460" height="300" /></p>
<p>Countries in <a href="http://en.wikipedia.org/wiki/G7">G7</a>:<br />
<img src="http://blog.newsplore.com/wp-content/uploads/2009/03/g7.png" alt="g7" width="460" height="180" /></p>
<p>Finally, all <a href="http://www.opec.org/">OPEC</a> member countries:<br />
<img class="alignnone size-full wp-image-693" src="http://blog.newsplore.com/wp-content/uploads/2009/03/opec.png" alt="opec" width="460" height="200" /></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.newsplore.com/2009/03/01/political-boundaries-overlay-google-maps-2/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Spincloud Labs: Political boundaries overlay in Google maps (Part 1)</title>
		<link>http://blog.newsplore.com/2009/02/22/spincloud-labs-political-boundaries-overlay-in-google-maps-part-1</link>
		<comments>http://blog.newsplore.com/2009/02/22/spincloud-labs-political-boundaries-overlay-in-google-maps-part-1#comments</comments>
		<pubDate>Sun, 22 Feb 2009 21:34:41 +0000</pubDate>
		<dc:creator>Florin</dc:creator>
				<category><![CDATA[scripting]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[tools]]></category>
		<category><![CDATA[UNIX]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[gis]]></category>
		<category><![CDATA[overlay]]></category>

		<guid isPermaLink="false">http://blog.newsplore.com/?p=531</guid>
		<description><![CDATA[Update Sep.21.2011: I took the code in this post and part deux and made a github project off of it called Gborders. The code is simpler and there are more options to generate the borders overlay based on geographic regions. Happy forks! One thing I needed when designing the Meteoalarm mashup for Spincloud were the [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="padding-right:0;margin-top:3px"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.newsplore.com%2F2009%2F02%2F22%2Fspincloud-labs-political-boundaries-overlay-in-google-maps-part-1"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.newsplore.com%2F2009%2F02%2F22%2Fspincloud-labs-political-boundaries-overlay-in-google-maps-part-1" height="61" width="51" /></a></div><p><i>Update Sep.21.2011: I took the code in this post and <a href='http://blog.newsplore.com/2009/03/01/political-boundaries-overlay-google-maps-2'>part deux</a> and made a github project off of it called <a href='https://github.com/florind/Gborders'>Gborders</a>. The code is simpler and there are more options to generate the borders overlay based on geographic regions. Happy forks!</i><br />
</p>
<p align="justify">One thing I needed when designing the <a href="http://blog.newsplore.com/?p=382">Meteoalarm mashup</a> for <a href="http://spincloud.com">Spincloud</a> were the political boundaries for all European countries. With them at hand, I would use the <a href="http://code.google.com/apis/maps/documentation/overlays.html#Polygons_Overview">polygon overlay</a> from the Coogle API and fill the country polygons with the respective weather warning colors.</p>
<p>This first part is a tutorial on how to import world political borders into a MySQL database table.<br />
The second part in these series will use this table to create a script that will add the country borders overlay to Google Maps.</p>
<p>So after learning that Google Maps API doesn&#8217;t give programatic access to the political boundaries I moved on to doing it myself. I read about the <a href="http://code.google.com/apis/maps/documentation/polylineutility.html">encoded polylines</a> and figured that I only missed the country boundaries as encoded polygons so I started searching for readily-available resources. Sure enough there were nowhere to be found.</p>
<p>The next best thing was to find the country boundaries in some GIS format and generate the polyligons myself. The information seems to be sparse but after a bit of research I found was the <a href="http://www.evl.uic.edu/pape/data/WDB/">CIA World Databank</a> but the format is incomplete, it only defines the polygons with no country names or any other administrative hook that I would be able to use.  I then spent hours trying to find a better resource until I remembered that <a href="http://mappinghacks.com/">Mapping Hacks</a> (an excellent book by the way) has data set for the examples in the book. I had the first breakthrough, the website makes available updated world borders files <a href="http://mappinghacks.com/data/">here</a>, they are mirrored from <a href="http://thematicmapping.org/downloads/world_borders.php">thematicmapping.org</a>.</p>
<p>We&#8217;ll use a utility called <a href="http://kartoweb.itc.nl/RIMapper/code/shp2mysql_0_4.zip">shp2mysql</a> to export the boundaries to SQL. I&#8217;m on a MacBook and no shp2mysql binaries for my platform were available in the original package so we&#8217;ll have to compile it first then run it to be able to export the shapefile to SQL.</p>
<p>Below are detailed all steps needed to to produce the borders SQL file on Leopard 10.5.x (note that you have to have the <a href="http://developer.apple.com/Tools/">Developer Tools</a> installed). In short, copy and run the following script on your mac in a file called process_boundaries.sh. The script creates a file called wb_dump.sql which is ready to be imported into database:<br />
<span id="more-531"></span></p>
<pre>mkdir borders
cd borders
wget http://mappinghacks.com/data/TM_WORLD_BORDERS-0.2.zip
mkdir boundaries_shp
unzip TM_WORLD_BORDERS-0.2.zip -d boundaries_shp
wget http://kartoweb.itc.nl/RIMapper/code/shp2mysql_0_4.zip
unzip shp2mysql_0_4.zip -d shp2mysql_04
wget http://dl.maptools.org/dl/shapelib/shapelib_1_2_10.zip
unzip shapelib_1_2_10.zip
cd shapelib-1.2.10
make
cd ..
rm ./shp2mysql_04/src/*.o
sed 's/^OBJS.*$/OBJS = \.\.\/\.\.\/shapelib-1\.2\.10\/shpopen\.o \.\.\/\.\.\/shapelib-1\.2\.10\/dbfopen\.o/' shp2mysql_04/src/Makefile &gt; shp2mysql_04/src/Makefile2
mv shp2mysql_04/src/Makefile2 shp2mysql_04/src/Makefile
cd shp2mysql_04/src
make
cd ../../
cp shp2mysql_04/src/shp2mysql .
./shp2mysql -d boundaries_shp/TM_WORLD_BORDERS-0.2.shp world_boundaries test_db &gt; wb_dump.sql
rm *.zip
rm -rf shp2mysql_04
rm -rf shapelib-1.2.10
rm -rf boundaries_shp</pre>
<p>Make the above script executable then run it:</p>
<pre>chmod +x process_boundaries.sh
./process_boundaries.sh</pre>
<p>If you&#8217;re interested in the details about this script then read on otherwise <a href="#import-to-DB">happily skip it</a>. The final SQL file is linked at the end of this post.</p>
<p>We&#8217;ll start by bringing the shape files:</p>
<pre>mkdir borders
cd borders
wget http://mappinghacks.com/data/TM_WORLD_BORDERS-0.2.zip
mkdir boundaries_shp
unzip TM_WORLD_BORDERS-0.2.zip -d boundaries_shp</pre>
<p>The files are in ESRI&#8217;s shp format which wasn&#8217;t exactly what I needed. I had to export them in a more usable format, SQL in my case. For this I used the <a href="http://kartoweb.itc.nl/RIMapper/code/shp2mysql_0_4.zip">shp2mysql</a> utility for which I didn&#8217;t find the MacOS executable so we&#8217;ll compile it from source. Since it has a dependency to <a href="http://shapelib.maptools.org/">shapelib</a> we have to download and compile it along:</p>
<pre>mkdir shp2mysql
wget http://kartoweb.itc.nl/RIMapper/code/shp2mysql_0_4.zip
unzip shp2mysql_0_4.zip -d shp2mysql
wget http://dl.maptools.org/dl/shapelib/shapelib_1_2_10.zip
unzip shapelib_1_2_10.zip
cd shapelib-1.2.10
make
cd ..</pre>
<p>Now you should have both shapelib and shp2mysql downloaded with shapelib succesfully compiled.  Now we&#8217;ll compile shp2mysql: we have to delete all .o files (they have been compiled for a different platform), fix the Makefile then issue the <code>make</code> command</p>
<pre>rm shp2mysql/src/*.o
sed 's/^OBJS.*$/OBJS = ../../shapelib-1.2.10/shpopen.o ../../shapelib-1.2.10/dbfopen.o/' shp2mysql/src/Makefile &gt; shp2mysql/src/Makefile2
mv shp2mysql/src/Makefile2 shp2mysql/src/Makefile
cd shp2mysql/src
make
cp shp2mysql/src/shp2mysql .</pre>
<p>which should execute successfully.<br />
We&#8217;re ready to export the world boundaries into SQL format. Switch to the <code>boundaries</code> folder then issue the export command as follows:</p>
<pre>cd ..
./shp2mysql -d boundaries_shp/TM_WORLD_BORDERS-0.2.shp world_boundaries test_db &gt; wb_dump.sql</pre>
<p>this will create a SQL file called wb_dump.sql ready to be loaded into your database.</p>
<p>Running the script will generate a file called wb_dump.sql which is ready to be imported on your spatially enabled database:<br />
<a name="import-to-DB"></a><br />
All we have to do now is to import the sql file into the database. Note that the database has to be spatially enabled (MySQL is by default, I&#8217;m using 5.0). Issue the following command:</p>
<pre>mysql -uroot -p my_database &lt; wb_dump.sql</pre>
<p>Now we should have country borders for the whole world imported in the database.<br />
For convenience, I have made the world boundaries SQL file available for <a href="http://blog.newsplore.com/wp-content/uploads/2009/02/wb_dump.zip">download</a> (4.3 MB).</p>
<p>In the second part of this how-to, we&#8217;ll use this table to create the country borders overlay for Google Maps.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.newsplore.com/2009/02/22/spincloud-labs-political-boundaries-overlay-in-google-maps-part-1/feed</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
	</channel>
</rss>

