<?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>Love web applications &#187; GeoJSON</title>
	<atom:link href="http://blog.hitsuji.me/tag/geojson/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.hitsuji.me</link>
	<description>Webアプリつくるの楽しい！つくるネタ、使うネタ、あとは雑談です。</description>
	<lastBuildDate>Sun, 25 Jan 2015 12:49:45 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.1.41</generator>
	<item>
		<title>GeoJSONからTopoJSON形式に変換して地図を表示する</title>
		<link>http://blog.hitsuji.me/make-topojson-file-and-show-map/</link>
		<comments>http://blog.hitsuji.me/make-topojson-file-and-show-map/#comments</comments>
		<pubDate>Mon, 26 May 2014 03:48:47 +0000</pubDate>
		<dc:creator><![CDATA[kapibarawebmaster1515]]></dc:creator>
				<category><![CDATA[可視化]]></category>
		<category><![CDATA[D3.js]]></category>
		<category><![CDATA[GeoJSON]]></category>
		<category><![CDATA[TopoJSON]]></category>

		<guid isPermaLink="false">http://blog.hitsuji.me/?p=35</guid>
		<description><![CDATA[前回記事で作成したGeoJSONファイルから、TopoJSONファイルを作成して、地図を表示するところまでやってみます。 &#160; TopoJSONファイルに変換する GeoJSONファイルをTo・・・<a class="readon" href="http://blog.hitsuji.me/make-topojson-file-and-show-map/">続きを読む</a>]]></description>
				<content:encoded><![CDATA[<p><a title="ShapeファイルからGeoJsonファイルを作成する" href="http://blog.hitsuji.me/make-shape-file/">前回記事</a>で作成したGeoJSONファイルから、TopoJSONファイルを作成して、地図を表示するところまでやってみます。</p>
<p>&nbsp;</p>
<h4>TopoJSONファイルに変換する</h4>
<p>GeoJSONファイルをTopoJSONファイルに変換します。GeoJSONとTopoJSONの違いは何？という方は、前回ご紹介したサイト</p>
<p>＊D3.jsとTopoJSONで地図を作る　<a title="D3.jsとTopoJSONで地図を作る" href="http://ja.d3js.node.ws/blocks/mike/map/" target="_blank">http://ja.d3js.node.ws/blocks/mike/map/</a></p>
<p>の&#8221;データの変換&#8221;の章に簡単に書いてあります。</p>
<p>&nbsp;</p>
<p>さて、ターミナルを開きます。</p>
<pre class="command">topojson -p name=N03_004 -p name -o yokohama_topo.json yokohama.geojson</pre>
<p>ここでは、&#8221;yokohama.geojson&#8221; というGeoJSONファイルを、&#8221;yokohama_topo.json&#8221;というTopoJSONファイルに変換しつつ、N03_004というフィールドをnameという名前に変更・付与しています。QGISで開くと分かりますが、N03_004フィールドに区名が入っているので、それをTopoJSONファイルに属性値として出力します。</p>
<p>&nbsp;</p>
<h4>TopoJSONファイルを読み込み、横浜市地図を表示する</h4>
<p>いよいよ地図を表示します。下の画像をクリックすると、地図のページに飛びます。</p>
<p><a href="http://static.hitsuji.me/map-yokohama02/" target="_blank"><img class="alignnone" src="http://blog.hitsuji.me/app/wp-content/uploads/2014/05/yokohama_map02-452x600.png" alt="yokohama_map02" width="226" height="300" /></a></p>
<p>&nbsp;</p>
<p>ソースコードはこんな感じです。</p>
<h6>index.html</h6>
<script src="https://gist.github.com/d693035582291061e644.js"></script><noscript><pre><code class="language-html html">&lt;!DOCTYPE html&gt;
&lt;html lang=&quot;ja&quot;&gt;
&lt;head&gt;
&lt;meta charset=&quot;utf-8&quot;&gt;
&lt;script src=&quot;http://d3js.org/d3.v3.min.js&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;http://d3js.org/topojson.v0.min.js&quot;&gt;&lt;/script&gt;
&lt;style type=&quot;text/css&quot;&gt;
h1 {
    font-size: 16px;
}
svg {
    border: 1px solid #aaaaaa;
}
.subunit-boundary {
  fill: none;
  stroke: #777;
  stroke-dasharray: 2,2;
  stroke-linejoin: round;
}
&lt;/style&gt;
&lt;title&gt;Yokohama city map&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;Yokohama city map&lt;/h1&gt;
&lt;div id=&quot;map&quot;&gt;&lt;/div&gt;

&lt;script type=&quot;text/javascript&quot;&gt;
    var map_width = 500;
    var map_height = 650;
    var svg;
    
    d3.json(&quot;yokohama_topo.json&quot;, function(error, json) {
        if( !error ) {
            main(json);
        }
        return;
    });
    
    function main(topo) {
        
        var labelLineHight = 16;
         // svgを追加
        svg = d3.select(&quot;body #map&quot;).append(&quot;svg&quot;)
                .attr(&quot;width&quot;, map_width)
                .attr(&quot;height&quot;, map_height);
                
        // 横浜市のmapを描画する
        var yokohama = topojson.object(topo, topo.objects.yokohama);
        console.log(yokohama);
        
        // 横浜市を中心に指定したメルカトル図法で10万分の1で描画する
        var projection = d3.geo.mercator()
                .center([139.59,35.45])
                .scale(100000)
                .translate([map_width / 2, map_height / 2]);
        
        // pathを作成する
        var path = d3.geo.path().projection(projection);
        svg.append(&quot;path&quot;)
          .datum(yokohama)
          .attr(&quot;d&quot;, path);
        
        // 色を塗る
        svg.selectAll(&quot;path&quot;).attr(&quot;fill&quot;, &quot;#bee59e&quot;);
        
        // 内部境界に線を引く
        svg.append(&quot;path&quot;)
           .datum(topojson.mesh(topo, topo.objects.yokohama, function(a, b) { return a !== b; }))
           .attr(&quot;d&quot;, path)
           .attr(&quot;class&quot;, &quot;subunit-boundary&quot;);
           
    }
&lt;/script&gt;

&lt;/body&gt;
&lt;/html&gt;</code></pre></noscript>
<p>&nbsp;</p>
<p>JSONファイルを読み込む関数d3.jsonは非同期処理になります。読み込み完了したら第2引数のfunction(error,json) {&#8230;} が呼び出される仕組みなので、そのCallback関数の中にjsonファイルを使った処理、すなわち地図を描く処理を書いています。</p>
<p>&nbsp;</p>
<p>d3.geo.mercator().center([139.59,35.45])&#8230; center()で、地図中心を経度と緯度で指定しています。経度と緯度はGoogle Mapで調べてから調整しました。</p>
<p>&nbsp;</p>
<p>今回は、地図を表示することろまで！</p>
<p>それではまた〜</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.hitsuji.me/make-topojson-file-and-show-map/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ShapeファイルからGeoJsonファイルを作成する</title>
		<link>http://blog.hitsuji.me/make-shape-file/</link>
		<comments>http://blog.hitsuji.me/make-shape-file/#comments</comments>
		<pubDate>Thu, 22 May 2014 06:19:29 +0000</pubDate>
		<dc:creator><![CDATA[kapibarawebmaster1515]]></dc:creator>
				<category><![CDATA[可視化]]></category>
		<category><![CDATA[GeoJSON]]></category>
		<category><![CDATA[qgis]]></category>
		<category><![CDATA[shape]]></category>

		<guid isPermaLink="false">http://blog.hitsuji.me/?p=23</guid>
		<description><![CDATA[国土数値情報DLサービスから地図データを入手し、QJISというソフトを使ってGeoJsonファイルを作成するところまでやってみます。 参考サイト 地図作製手順は D3.jsとTopoJSONで地図を作・・・<a class="readon" href="http://blog.hitsuji.me/make-shape-file/">続きを読む</a>]]></description>
				<content:encoded><![CDATA[<p>国土数値情報DLサービスから地図データを入手し、QJISというソフトを使ってGeoJsonファイルを作成するところまでやってみます。</p>
<h4>参考サイト</h4>
<p>地図作製手順は</p>
<p>D3.jsとTopoJSONで地図を作る　<a title="D3.jsとTopoJSONで地図を作る" href="http://ja.d3js.node.ws/blocks/mike/map/" target="_blank">http://ja.d3js.node.ws/blocks/mike/map/</a></p>
<p>に概ね従って作って行きます。このサイトはとても親切なチュートリアル形式なので、一度UKの地図を描いてみるのをオススメします^-^</p>
<p>&nbsp;</p>
<h4>地図データを入手する</h4>
<p>最初に地図データを入手します。</p>
<p><a href="http://nlftp.mlit.go.jp/ksj/">http://nlftp.mlit.go.jp/ksj/</a></p>
<p>今回は横浜市の地図を描くので、行政区域=&gt;神奈川県を選択=&gt;現時点最新であるH25データをダウンロードします。７ファイルぐらいが一括ダウンロードされますが、今回利用するのは拡張子がshpのファイルのみです。</p>
<p>&nbsp;</p>
<h4>QGISを入手する</h4>
<p>ShapeファイルからJsonファイルへの変換アプリを調べたところ、</p>
<p>QGIS　<a title="QGIS" href="http://www.qgis.org" target="_blank">http://www.qgis.org</a></p>
<p>オープンソースだが高性能らしい、ということで使ってみました。</p>
<p>インストール手順はQGISサイトに書いてありますが、私のMacの場合ですが</p>
<ul>
<li>GDAL Completeおよび同梱されていたNumPy</li>
<li>GSL framework</li>
<li>Matplotlib</li>
<li>QGIS本体</li>
</ul>
<p>の順に入れました。全てインストーラ付きで楽々インストールです。</p>
<p>&nbsp;</p>
<h4>QGISからShapeファイルを読み込む</h4>
<p>QGISを起動して、先ほどダウンロードしたShapeファイルを読み込みます。</p>
<p>QGISの基本操作は、次のサイトを参考にしました。</p>
<p>QGIS入門　<a title="QGIS入門" href="https://sites.google.com/site/qgisnoiriguchi/home" target="_blank">https://sites.google.com/site/qgisnoiriguchi/home</a></p>
<p>とても分かりやすいです。感謝、感謝です☆</p>
<p>簡単な手順だけ書くと</p>
<ul>
<li>ベクタレイヤを追加ボタンを押す</li>
<li>ソースタイプ：ファイル、エンコード：shift_jis、データセット：DLしたshpファイルを指定する</li>
<li>Openボタンを押す</li>
<li>空間参照システムのダイアログが（たぶん）自動的に出るので、JGD2000を選択してOKボタンを押す</li>
</ul>
<p>神奈川県の地図が現れました^-^v</p>
<p><img class="alignnone size-large wp-image-26" src="http://blog.hitsuji.me/app/wp-content/uploads/2014/05/kanagawa_map_qgis-1024x651.png" alt="kanagawa_map_qgis" width="512" height="325" /></p>
<p>上図の状態だとレイヤーパネルが開いていないので、 ビュー&gt;パネル&gt;レイヤーをクリックして、レイヤーパネルを表示します。描画中の地図のレイヤーを右クリックして、フィルターを選択。下のようにフィルターを設定します。</p>
<p><a href="http://blog.hitsuji.me/app/wp-content/uploads/2014/05/yokohama_filter_qgis.png"><img src="http://blog.hitsuji.me/app/wp-content/uploads/2014/05/yokohama_filter_qgis-598x600.png" alt="yokohama_filter_qgis" width="299" height="300" /></a></p>
<p>&nbsp;</p>
<p>OKボタンを押すと・・・横浜市のみが表示できました！</p>
<p><img class="alignnone" src="http://blog.hitsuji.me/app/wp-content/uploads/2014/05/yokohama_map_qgis-1200x763.png" alt="yokohama_map_qgis" width="600" height="381" /></p>
<p>&nbsp;</p>
<p>また、描画中のレイヤーを右クリックして、今度は「名前をつけて保存」をクリック。エンコードだけUTF-8に修正して、GeoJSON形式で保存します。</p>
<p>これで、ShapeファイルからGeoJsonファイルへの変換が出来ました♪</p>
<p>それでは、続きはまた次回に！</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.hitsuji.me/make-shape-file/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
