<?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>fromthepantothefire &#187; mapnik</title>
	<atom:link href="http://fromthepantothefire.com/tag/mapnik/feed/" rel="self" type="application/rss+xml" />
	<link>http://fromthepantothefire.com</link>
	<description>&#34;...we are not pans and barrows, nor even porters of the fire and torchbearers, but children of the fire, made of it...&#34; -- Ralph Waldo Emerson, The Poet</description>
	<lastBuildDate>Mon, 02 Jan 2023 06:32:48 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.1.41</generator>
	<item>
		<title>Using Mapnik to render custom colored Map images</title>
		<link>http://fromthepantothefire.com/2012/11/24/using-mapnik-to-render-custom-colored-map-images/</link>
		<comments>http://fromthepantothefire.com/2012/11/24/using-mapnik-to-render-custom-colored-map-images/#comments</comments>
		<pubDate>Sat, 24 Nov 2012 17:05:01 +0000</pubDate>
		<dc:creator><![CDATA[Zia]]></dc:creator>
				<category><![CDATA[Maps]]></category>
		<category><![CDATA[mapnik]]></category>
		<category><![CDATA[pyshp]]></category>

		<guid isPermaLink="false">http://fromthepantothefire.com/?p=255</guid>
		<description><![CDATA[Say I want my output map of the world to be colored with a customer specified set of specific colors for countries, water etc.  I also want to output a specific resolution for publication. Natural Earth shapfiles have a the built in &#8220;mapcolor&#8221; attribute to group countries appropriately for this purpose, that will be helpful! [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Say I want my output map of the world to be colored with a customer specified set of specific colors for countries, water etc.  I also want to output a specific resolution for publication.</p>
<div id="attachment_265" style="width: 310px" class="wp-caption alignnone"><a href="http://fromthepantothefire.com/wp-content/uploads/2012/11/baselineMap.png"><img class="size-medium wp-image-265" title="baselineMap" src="http://fromthepantothefire.com/wp-content/uploads/2012/11/baselineMap-300x150.png" alt="" width="300" height="150" /></a><p class="wp-caption-text">Map of World rendered in Mapnik</p></div>
<p>Natural Earth shapfiles have a the built in &#8220;mapcolor&#8221; attribute to group countries appropriately for this purpose, that will be helpful!</p>
<p>Q-GIS has some nice functionality for playing around with the shapefile and exploring the data. But for a final output image it doesn&#8217;t meet the following requirements:</p>
<ul>
<li>Controlling output image resolution and cropping (you can save to .png or .jpg, but there are no other options regarding resolution or dimensions to save).</li>
<li>Configuring colors and color ranges to use can be done (quick and dirty demonstration that the mapcolors attribute is what I expect is easy). But using Q-GIS quickly becomes a super manual process, you have to specify colors via separate RGB fields, ugh. You can specify an attribute to use for the color categories, but seems hard in that mode to configure specific colors to use.</li>
<li>Must reload modified shapefiles and re-configure them anytime the source file changes.</li>
</ul>
<p>I don&#8217;t doubt that there are plugins for saving files (say if you want a vector image!!) and I could probably create my own symbology configuration for the colors I want, but since I am only catering to myself and don&#8217;t want to become an expert in some RSI inducing graphical interface&#8230; time to find a scriptable way to generate high quality output images.</p>
<p><a href="http://mapnik.org/">Mapnik</a> is a map renderer that has bindings for lots of languages including python. I started with <a href="https://github.com/mapnik/mapnik/wiki/GettingStartedInPython">Getting started with mapnik in python</a>, which walks through a simple example in no time. First problem solved: simply specify the image size when you declare the map:</p>
<pre>m = mapnik.Map(600,300)</pre>
<p>And specify the area you want to display when you save it:</p>
<pre>m.zoom_to_box(mapnik.Box2d(-180, -90, 180, 90)) # or m.zoom_all()  
mapnik.render_to_file(m,'world.png', 'png')</pre>
<p>Unfortunately, coloring the country groups is not trivial. Mapnik doesn&#8217;t current have the ability to set the PolygonSymbolizer&#8217;s fill color based on a shapefile attribute (feature in the works). However, as I am now an expert at <a title="Adding custom data to a shapefile using pyshp 1.1.4" href="http://fromthepantothefire.com/2012/11/22/adding-custom-data-to-a-shapefile-using-pyshp-1-1-4/">manipulating shapefiles with pyshp</a>, I hacked together an ugly but straightforward solution in a few minutes.</p>
<ol>
<li>Using pyshp, read in the shapefile to render and spit out n new files, one for each mapcolor group. See <a href="http://fromthepantothefire.com/maps/morphine/cartogram/split_mapColors.py">split_mapColors.py</a></li>
<li>Create a unique mapnik style for each country color group and add each new shapefile to the map with the appropriate style layer. See <a href="http://fromthepantothefire.com/maps/morphine/cartogram/renderCommon.py">renderCommon.py</a></li>
</ol>
<div><span style="line-height: 24px;">Putting it all together, I used the script <a href="http://fromthepantothefire.com/maps/morphine/cartogram/">renderBaseline.py and other utility functions</a> to generate the colored map of the world above. </span></div>
<div></div>
<p>Using the same techniques <a title="Generating a cartogram of access to pain medication around the world." href="http://fromthepantothefire.com/2012/11/24/generating-a-cartogram-of-access-to-pain-medication-around-the-world/">morphed shapefiles</a> can be rendered in the same color pallet, change your mind about  the colors? No problem.</p>
<p><a href="http://fromthepantothefire.com/wp-content/uploads/2012/11/MorphPerDeathMassPiecedTogetherByContinent.png"><img class="alignnone size-medium wp-image-266" title="MorphPerDeathMassPiecedTogetherByContinent" src="http://fromthepantothefire.com/wp-content/uploads/2012/11/MorphPerDeathMassPiecedTogetherByContinent-300x141.png" alt="" width="300" height="141" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://fromthepantothefire.com/2012/11/24/using-mapnik-to-render-custom-colored-map-images/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mapnik experiments</title>
		<link>http://fromthepantothefire.com/2012/10/21/mapnik-experiments/</link>
		<comments>http://fromthepantothefire.com/2012/10/21/mapnik-experiments/#comments</comments>
		<pubDate>Mon, 22 Oct 2012 00:41:32 +0000</pubDate>
		<dc:creator><![CDATA[Zia]]></dc:creator>
				<category><![CDATA[Maps]]></category>
		<category><![CDATA[Hubway]]></category>
		<category><![CDATA[mapnik]]></category>

		<guid isPermaLink="false">http://fromthepantothefire.wordpress.com/?p=84</guid>
		<description><![CDATA[After a day of working with mapnik, I have my first supremely ugly plot, which shows Hubway station locations around Boston, the colors are by station name prefix, which is roughly by area, but not that logical outside Cambridge and Somerville&#8230; Ha! Decided to try to add some color to these water bodies myself in [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>After a day of working with mapnik, I have my first supremely ugly plot, which shows Hubway station locations around Boston, the colors are by station name prefix, which is roughly by area, but not that logical outside Cambridge and Somerville&#8230;</p>
<p><a href="http://fromthepantothefire.com/wp-content/uploads/2012/10/firstmapnikplot.png"><img class="alignnone size-full wp-image-85" title="firstmapnikplot" alt="" src="http://fromthepantothefire.com/wp-content/uploads/2012/10/firstmapnikplot.png" height="456" width="625" /></a></p>
<p>Ha! Decided to try to add some color to these water bodies myself in the sytlesheet. Ended up coloring all of the following:</p>
<p>&lt;Filter&gt;[natural] = &#8216;water&#8217; or [natural] = &#8216;lake&#8217; or [natural] = &#8216;bay&#8217; or [natural] = &#8216;wetland&#8217; or [natural] = &#8216;marsh&#8217; or [gnis:feature_type] = &#8216;Bay&#8217; or [landuse] = &#8216;reservoir&#8217; or [landuse] = &#8216;basin&#8217; or [waterway] &#8216;canal&#8217; or [waterway] = &#8216;boatyard&#8217; or [wetland] = &#8216;wet_meadow&#8217; or [wetland] = &#8216;tidalflat&#8217; or [wetland] = &#8216;saltmarsh&#8217; or [wetland] = &#8216;swamp&#8217;<br />
&lt;/Filter&gt;</p>
<p>Which still didn&#8217;t manage to get any of the Boston Harbor or the Mystic River, however, I am tabling it for a while.<a href="http://fromthepantothefire.com/wp-content/uploads/2012/10/hubway_some_color.png"><img class="alignnone size-full wp-image-95" title="hubway_some_color" alt="" src="http://fromthepantothefire.com/wp-content/uploads/2012/10/hubway_some_color.png" height="423" width="625" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://fromthepantothefire.com/2012/10/21/mapnik-experiments/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
