<?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>Mattk&#039;s Website &#187; Spatial Tools</title>
	<atom:link href="http://www.mattk.info/tag/spatial-tools/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mattk.info</link>
	<description>Blog d&#039;un développeur .NET</description>
	<lastBuildDate>Sun, 04 Jul 2010 11:04:57 +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>Obtenir les coordonnées géographique d’une région</title>
		<link>http://www.mattk.info/2009/05/obtenir-les-coordonnees-gographique-dune-region/</link>
		<comments>http://www.mattk.info/2009/05/obtenir-les-coordonnees-gographique-dune-region/#comments</comments>
		<pubDate>Thu, 14 May 2009 15:05:04 +0000</pubDate>
		<dc:creator>Mattk</dc:creator>
				<category><![CDATA[Astuces]]></category>
		<category><![CDATA[Spatial Tools]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Virtual Earth]]></category>

		<guid isPermaLink="false">http://www.mattk.info/?p=19</guid>
		<description><![CDATA[Pour les besoins d&#8217;un petit projet, il me faut les coordonnées géographique des régions administratives françaises. Le but final étant de créer des calques sur les maps Virtual Earth. Dans un premier temps, j&#8217;ai cherché un webservice qui me fournirait ces données. Pas de chances, je n&#8217;en ai pas trouvé et me suis donc rabattu]]></description>
			<content:encoded><![CDATA[<p>Pour les besoins d&#8217;un petit projet, il me faut les coordonnées géographique des régions administratives françaises. Le but final étant de créer des calques sur les maps Virtual Earth.</p>
<p>Dans un premier temps, j&#8217;ai cherché un webservice qui me fournirait ces données. Pas de chances, je n&#8217;en ai pas trouvé et me suis donc rabattu sur la solution suivante : une base données sous SQL Server 2008 contenant les calques de mes régions au format Geometry. Voici donc la méthode que j&#8217;ai utilisé.</p>
<p><strong>Etape 1 : Récupérer les régions administratives sur GEO Data Portal</strong></p>
<p>Rien de plus simple :</p>
<ol>
<li> aller sur le site : <a title="Geo Data Portal" href="http://geodata.grid.unep.ch/" target="_blank">http://geodata.grid.unep.ch/</a></li>
<li>dans le formulaire de recherche, taper le mot clé : <em>administrative boundaries</em></li>
<li> sélectionner les données : <em>Administratives Boundaries &#8211; First Level (ESRI)</em>, puis cliquer sur <em>Envoyer</em></li>
<li>une map apparaît, choisir l&#8217;onglet <em>download</em>, puis le format <em>ESRI ShapeFile</em> et lancer le téléchargement (fichier zip)</li>
</ol>
<p><strong>Etape 2 : Ajouter nos données à SQL Server 2008</strong></p>
<p>Là encore c&#8217;est easy :</p>
<ol>
<li>Télécharger les <em>SQL Spatial Tools</em> <a title="SQL Spatial Tools" href="http://www.sharpgis.net/page/SQL-Server-2008-Spatial-Tools.aspx" target="_blank">ici</a></li>
<li>Décompresser le zip contenant notre fichier ESRI Shapefile</li>
<li>Décompresser le zip des <em>SQL Spatial Tools</em> et exécuter le programme <em>Shape2SQL.exe</em></li>
<li>On rentre les données de connexion à notre BDD, puis on va chercher notre fichier .shp contenant nos shapes des régions<br />
<span style="color: #ff0000;">Important : ne pas oublier de cocher <strong>&laquo;&nbsp;Set SRID&nbsp;&raquo;</strong> avec la valeur <strong>4326</strong></span></li>
<li>Les données sont importées dans notre SQL Server 2008</li>
</ol>
<p>Tout ça, c&#8217;est bien mignon, mais je ne veux que les régions administratives françaises.</p>
<p><strong>Etape 3 : Un peu de requêtage SQL</strong></p>
<p>Pour supprimer toutes les régions, hors françaises, nous allons utiliser l&#8217;outils <em>SqlSpatial</em> fournit dans les <em>SQL Spatial Tools</em>. On lance le programme, on se connecte à notre base de données, et on vérifie que nos données soit bien présentes (nom de ma table : <em>adminbound</em>) :</p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">*</span><br />
<span style="color: #993333; font-weight: bold;">FROM</span> adminbound</div></div>
<p>Sur la map, on peut alors voir le découpage régional administratif de tous les pays. Maintenant nous n&#8217;allons conserver que la France. Pour cela, on va créer une vue qui contiendra les ID de toutes les régions non françaises) :</p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">VIEW</span> v1 <span style="color: #993333; font-weight: bold;">AS</span><br />
<span style="color: #993333; font-weight: bold;">SELECT</span> ID <span style="color: #993333; font-weight: bold;">AS</span> my_key<br />
<span style="color: #993333; font-weight: bold;">FROM</span> adminbound<br />
<span style="color: #993333; font-weight: bold;">WHERE</span> CNTRY_NAME &amp;lt;&amp;gt; <span style="color: #ff0000;">'France'</span></div></div>
<p>Puis supprimer toutes les occurences de la vue dans notre table adminbound :</p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">DELETE</span> <span style="color: #993333; font-weight: bold;">FROM</span> adminbound<br />
<span style="color: #993333; font-weight: bold;">WHERE</span> <span style="color: #993333; font-weight: bold;">EXISTS</span> <span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">*</span><br />
<span style="color: #993333; font-weight: bold;">FROM</span> v1<br />
<span style="color: #993333; font-weight: bold;">WHERE</span> adminbound<span style="color: #66cc66;">.</span>ID <span style="color: #66cc66;">=</span> v1<span style="color: #66cc66;">.</span>my_key<span style="color: #66cc66;">&#41;</span></div></div>
<p>On vérifie que nous n&#8217;avons plus que la France avec une requête classique :</p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">*</span> <span style="color: #993333; font-weight: bold;">FROM</span> adminbound</div></div>
<p>Nos régions françaises apparaissent, on peut donc supprimer la vue :</p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">DROP</span> <span style="color: #993333; font-weight: bold;">VIEW</span> v1</div></div>
<div id="attachment_20" class="wp-caption aligncenter" style="width: 310px"><img class="size-medium wp-image-20" title="Régions Françaises" src="http://www.mattk.info/wp-content/uploads/2009/05/regionfr-300x189.png" alt="Régions Françaises" width="300" height="189" /><p class="wp-caption-text">Régions Françaises</p></div>
<p>Et voilà, il ne reste plus qu&#8217;à servir de cela pour le projet <img src='http://www.mattk.info/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><span style="color: #008000;"><span style="color: #008080;">Mise à jour du 20/09/2009 :<br />
Il semblerait que le lien de téléchargement du fichier zip contenant les coordonnées spatiales des régions administratives (cf Etape 1) soit actuellement indisponible. En analysant un peu l&#8217;url, j&#8217;ai pu le récupérer<a title="Fichier ESRI Shapefile" href="http://geodata.grid.unep.ch/download/admin98_li_shp.zip" target="_blank"></a>. Merci Samuel pour cette remarque :</span>)</span></p>
<p><span style="color: #008000;">Mise à jour du 20/10/2009 :<br />
Le fichier est à nouveau disponible<a title="Fichier zip région administrative" href="http://geodata.grid.unep.ch/mod_download/download_geospatial.php?selectedID=290&amp;newFile=download/admin98_li_shp.zip" target="_blank"> ici</a>.</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.mattk.info/2009/05/obtenir-les-coordonnees-gographique-dune-region/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
