<?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>ItOpen - Soluzioni WebGIS Open Source &#187; Python</title>
	<atom:link href="http://www.itopen.it/category/programmazione/python/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.itopen.it</link>
	<description>[lang_en]Open Web Solutions: WebGis, Open Source development[/lang_en][lang_it]Soluzioni WebGIS e sviluppo software Open Source[lang_it]</description>
	<lastBuildDate>Tue, 31 Jan 2012 14:19:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Serving your map tiles 30 times faster</title>
		<link>http://www.itopen.it/2012/01/17/serving-your-map-tiles-30-times-faster/</link>
		<comments>http://www.itopen.it/2012/01/17/serving-your-map-tiles-30-times-faster/#comments</comments>
		<pubDate>Tue, 17 Jan 2012 18:03:45 +0000</pubDate>
		<dc:creator>Alessandro Pasotti</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[GIS]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Sysadmin]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[WebGis]]></category>

		<guid isPermaLink="false">http://www.itopen.it/?p=716</guid>
		<description><![CDATA[Recently I&#8217;ve been experimenting with TileStache tiles caching system, which is similar to TileCache and other tile caching systems in scope. TileStache revealed itself as a powerful and flexible product and was very good to cache tiles generated with my Django-backed mapscript-powered WMS server. Caching and serving tiles with TileStache was by far faster then [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I&#8217;ve been experimenting with <a href="http://tilestache.org">TileStache</a> tiles caching system, which is similar to TileCache and other tile caching systems in scope.</p>
<p>TileStache revealed itself as a powerful and flexible product and was very good to cache tiles generated with my Django-backed mapscript-powered WMS server. Caching and serving tiles with TileStache was by far faster then running the whole mapscript WMS machinery.</p>
<p>But I wanted to do more: if I could just convince nginx to serve the tiles directly from disk, this would have been even faster. Of course for this to work, TileStache must be configured to cache tiles on disk, which is what you normally want.</p>
<p>nginx is really good at serving static files and it is luckily wery flexible and easy to configure (once you know what to do).</p>
<p>The following configuration uses named regular expression captures and a <strong>try_files</strong> instruction to check for the tile existance, if found, the tile is served directly, if not found the internal redirect to the @django named location takes place.<br />
The 404 trick in the base location (/) was necessary to avoid duplication of the @django location content, but there might be a better way.</p>
<h2>nginx configuration file</h2>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">server <span style="color: #009900;">&#123;</span>
    listen   <span style="color: #CC0000;">88</span> <span style="color: #003366; font-weight: bold;">default</span><span style="color: #339933;">;</span>
    server_name  localhost<span style="color: #339933;">;</span>
    access_log  <span style="color: #339933;">/</span><span style="color: #003366; font-weight: bold;">var</span><span style="color: #339933;">/</span>log<span style="color: #339933;">/</span>nginx<span style="color: #339933;">/</span>access.<span style="color: #660066;">log</span><span style="color: #339933;">;</span>
    rewrite  <span style="color: #3366CC;">&quot;^/[a-z]{2}/(static|media)/(.*)$&quot;</span>  <span style="color: #009966; font-style: italic;">/$1/</span>$2<span style="color: #339933;">;</span>
    root <span style="color: #339933;">/</span>www<span style="color: #339933;">/</span>django_app<span style="color: #339933;">/;</span>
&nbsp;
    location  <span style="color: #009966; font-style: italic;">/media/</span> <span style="color: #009900;">&#123;</span>
        alias <span style="color: #339933;">/</span>www<span style="color: #339933;">/</span>django<span style="color: #339933;">/</span>contrib<span style="color: #339933;">/</span>admin<span style="color: #339933;">/</span>media<span style="color: #339933;">/;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    location  <span style="color: #009966; font-style: italic;">/static/</span> <span style="color: #009900;">&#123;</span>
        alias <span style="color: #339933;">/</span>www<span style="color: #339933;">/</span>django_app<span style="color: #339933;">/</span>site_media<span style="color: #339933;">/;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    location ~ <span style="color: #339933;">^/</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">?&lt;</span>lang_code<span style="color: #339933;">&gt;</span>..<span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span>resource<span style="color: #339933;">/</span>tiles<span style="color: #339933;">/</span><span style="color: #CC0000;">1</span>\.0\.0<span style="color: #339933;">/</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">?&lt;</span>tile_path<span style="color: #339933;">&gt;</span>.<span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>$ <span style="color: #009900;">&#123;</span>
        alias <span style="color: #339933;">/</span>tmp<span style="color: #339933;">/</span>stache<span style="color: #339933;">/;</span>
        add_header X<span style="color: #339933;">-</span>Static <span style="color: #003366; font-weight: bold;">super</span><span style="color: #339933;">;</span>
        try_files $http_host<span style="color: #339933;">/</span>$lang_code<span style="color: #339933;">/</span>$tile_path <span style="color: #339933;">@</span>django<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    location <span style="color: #339933;">/</span> <span style="color: #009900;">&#123;</span>
        add_header X<span style="color: #339933;">-</span>Static hit<span style="color: #339933;">;</span>
        error_page <span style="color: #CC0000;">404</span> <span style="color: #339933;">=</span> <span style="color: #339933;">@</span>django<span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #CC0000;">404</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    location <span style="color: #339933;">@</span>django <span style="color: #009900;">&#123;</span>
        add_header X<span style="color: #339933;">-</span>Static miss<span style="color: #339933;">;</span>
        proxy_pass http<span style="color: #339933;">:</span><span style="color: #006600; font-style: italic;">//127.0.0.1:8000;</span>
        proxy_set_header Host $http_host<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h2>Results</h2>
<p>niginx is listening on port 88 and the dev server (I&#8217;m using werkzeug in this case) is listening on port 8080.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">ab <span style="color: #660033;">-c</span> <span style="color: #000000;">100</span> <span style="color: #660033;">-n</span> <span style="color: #000000;">1000</span> http:<span style="color: #000000; font-weight: bold;">//</span>localhost:<span style="color: #000000;">88</span><span style="color: #000000; font-weight: bold;">/</span>it<span style="color: #000000; font-weight: bold;">/</span>resource<span style="color: #000000; font-weight: bold;">/</span>tiles<span style="color: #000000; font-weight: bold;">/</span>1.0.0<span style="color: #000000; font-weight: bold;">/</span>track_4<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">0</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">0</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">0</span>.png
&nbsp;
Concurrency Level:      <span style="color: #000000;">100</span>
Time taken <span style="color: #000000; font-weight: bold;">for</span> tests:   <span style="color: #000000;">0.084</span> seconds
Complete requests:      <span style="color: #000000;">1000</span>
Failed requests:        <span style="color: #000000;">0</span>
Write errors:           <span style="color: #000000;">0</span>
Total transferred:      <span style="color: #000000;">7553744</span> bytes
HTML transferred:       <span style="color: #000000;">7302912</span> bytes
Requests per second:    <span style="color: #000000;">11902.92</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #666666; font-style: italic;">#/sec] (mean)</span>
Time per request:       <span style="color: #000000;">8.401</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>ms<span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>mean<span style="color: #7a0874; font-weight: bold;">&#41;</span>
Time per request:       <span style="color: #000000;">0.084</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>ms<span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>mean, across all concurrent requests<span style="color: #7a0874; font-weight: bold;">&#41;</span>
Transfer rate:          <span style="color: #000000;">87804.31</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>Kbytes<span style="color: #000000; font-weight: bold;">/</span>sec<span style="color: #7a0874; font-weight: bold;">&#93;</span> received</pre></div></div>

<p>With TileStache only:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">ab <span style="color: #660033;">-c</span> <span style="color: #000000;">100</span> <span style="color: #660033;">-n</span> <span style="color: #000000;">1000</span> http:<span style="color: #000000; font-weight: bold;">//</span>localhost:<span style="color: #000000;">8000</span><span style="color: #000000; font-weight: bold;">/</span>track_4<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">0</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">0</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">0</span>.png
&nbsp;
Concurrency Level:      <span style="color: #000000;">100</span>
Time taken <span style="color: #000000; font-weight: bold;">for</span> tests:   <span style="color: #000000;">2.944</span> seconds
Complete requests:      <span style="color: #000000;">1000</span>
Failed requests:        <span style="color: #000000;">0</span>
Write errors:           <span style="color: #000000;">0</span>
Non-2xx responses:      <span style="color: #000000;">1000</span>
Total transferred:      <span style="color: #000000;">145000</span> bytes
HTML transferred:       <span style="color: #000000;">0</span> bytes
Requests per second:    <span style="color: #000000;">339.63</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #666666; font-style: italic;">#/sec] (mean)</span>
Time per request:       <span style="color: #000000;">294.438</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>ms<span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>mean<span style="color: #7a0874; font-weight: bold;">&#41;</span>
Time per request:       <span style="color: #000000;">2.944</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>ms<span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>mean, across all concurrent requests<span style="color: #7a0874; font-weight: bold;">&#41;</span>
Transfer rate:          <span style="color: #000000;">48.09</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>Kbytes<span style="color: #000000; font-weight: bold;">/</span>sec<span style="color: #7a0874; font-weight: bold;">&#93;</span> received</pre></div></div>

<h2>Conclusions</h2>
<p>Unsurprisingly, the solution with files served directly is several times faster: 35 in this test case.</p>
<p>In a production environment, using <strong>mod_wsgi</strong> or <strong>uwsgi</strong>, the fugures may vary, but I&#8217;m confident that the overall speed boost is guaranteed.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.itopen.it/2012/01/17/serving-your-map-tiles-30-times-faster/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>TileStache Vector simplify provider</title>
		<link>http://www.itopen.it/2012/01/11/tilestache-vector-simplify-provider/</link>
		<comments>http://www.itopen.it/2012/01/11/tilestache-vector-simplify-provider/#comments</comments>
		<pubDate>Wed, 11 Jan 2012 17:19:57 +0000</pubDate>
		<dc:creator>Alessandro Pasotti</dc:creator>
				<category><![CDATA[GIS]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[WebGis]]></category>

		<guid isPermaLink="false">http://www.itopen.it/?p=703</guid>
		<description><![CDATA[This is the third part of the story that I started with part 1: Polymaps, TileStache and SVG CSS styling issues part 2: TileStache Django tiny wrapper during my experiments I wanted to reach the goal of minimize both the bandwith consuption and the number of vector coordinates that the browser needs to handle, this means that [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">This is the third part of the story that I started with</p>
<ul>
<li>part 1: <a title="Permanent Link to Polymaps, TileStache and SVG CSS styling issues" href="http://www.itopen.it/2012/01/05/polymaps-tilestache-and-svg-css-styling-issues/" rel="bookmark">Polymaps, TileStache and SVG CSS styling issues</a></li>
<li>part 2: <a title="Permanent Link to TileStache Django tiny wrapper" href="http://www.itopen.it/2012/01/09/tilestache-django-tiny-wrapper/" rel="bookmark">TileStache Django tiny wrapper</a></li>
</ul>
<p>during my experiments I wanted to reach the goal of minimize both the bandwith consuption and the number of vector coordinates that the browser needs to handle, this means that if we need to show complex geometries, for example a set of mountain hiking paths for an overall of 250000 point, we absolutely need a way to simplify features at lower zoom levels.</p>
<p>TileStache doesn&#8217;t support this out-of-the box, so I started playing with a clone of the Vector provider and ended up with a <a title="My branch on github" href="https://github.com/elpaso/TileStache/tree/vector-simplify" target="_blank">vector-simplify branch in my fork</a>.</p>
<p>What I&#8217;ve done was basically to add a new &#8220;simplify&#8221; provider configuration parameter, where you can enter the tolerance for <a href="http://en.wikipedia.org/wiki/Ramer%E2%80%93Douglas%E2%80%93Peucker_algorithm">Douglas-Peucker simplification algorhitm</a> in pixel unit. The paramer can be set in TileStache config file as shown here:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">  <span style="color: #3366CC;">&quot;layers&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #3366CC;">&quot;pmcollection&quot;</span><span style="color: #339933;">:</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #3366CC;">&quot;provider&quot;</span><span style="color: #339933;">:</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #3366CC;">&quot;name&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;vector&quot;</span><span style="color: #339933;">,</span>
            <span style="color: #3366CC;">&quot;driver&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;PostgreSQL&quot;</span><span style="color: #339933;">,</span>
            <span style="color: #3366CC;">&quot;parameters&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #3366CC;">&quot;dbname&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;polymaps_test&quot;</span><span style="color: #339933;">,</span>
                <span style="color: #3366CC;">&quot;user&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;xxx&quot;</span><span style="color: #339933;">,</span>
                <span style="color: #3366CC;">&quot;port&quot;</span> <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;5433&quot;</span><span style="color: #339933;">,</span>                
                <span style="color: #3366CC;">&quot;table&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;pm_points_pmcollection&quot;</span>
            <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
            <span style="color: #3366CC;">&quot;verbose&quot;</span> <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;true&quot;</span><span style="color: #339933;">,</span>
            <span style="color: #3366CC;">&quot;simplify&quot;</span> <span style="color: #339933;">:</span> <span style="color: #CC0000;">0.5</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        <span style="color: #3366CC;">&quot;allowed origin&quot;</span> <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;*&quot;</span>
    <span style="color: #009900;">&#125;</span>
 <span style="color: #009900;">&#125;</span></pre></div></div>

<h3>A picture is worth a thousand words</h3>
<p>Some pictures might be the best way to show how this parameter affects the generated geometries:</p>
<div id="attachment_704" class="wp-caption " style="width: 458px"><img class="size-full wp-image-704  " title="tilestache_simplify_tile" src="http://www.itopen.it/wp-content/uploads/2012/01/tilestache_simplify_tile.png" alt="" width="448" height="227" /><p class="wp-caption-text">This is a single tile, the original geometry is in red, the simplified geometry in green/yellow and an over-simplified geometry in blue.</p></div>
<p>The following overall views show all the details:</p>
<div id="attachment_705" class="wp-caption " style="width: 310px"><a href="http://www.itopen.it/wp-content/uploads/2012/01/tilestache_simplify_None.png"><img class="size-medium wp-image-705" title="tilestache_simplify_None" src="http://www.itopen.it/wp-content/uploads/2012/01/tilestache_simplify_None-300x201.png" alt="" width="300" height="201" /></a><p class="wp-caption-text">Original geometry</p></div>
<div id="attachment_708" class="wp-caption " style="width: 310px"><a href="http://www.itopen.it/wp-content/uploads/2012/01/tilestache_simplify_50.png"><img class="size-medium wp-image-708" title="tilestache_simplify_50" src="http://www.itopen.it/wp-content/uploads/2012/01/tilestache_simplify_50-300x201.png" alt="" width="300" height="201" /></a><p class="wp-caption-text">Over-simplified with tolerance 50</p></div>
<div id="attachment_706" class="wp-caption " style="width: 310px"><a href="http://www.itopen.it/wp-content/uploads/2012/01/tilestache_simplify_0.5.png"><img class="size-medium wp-image-706" title="tilestache_simplify_0.5" src="http://www.itopen.it/wp-content/uploads/2012/01/tilestache_simplify_0.5-300x201.png" alt="" width="300" height="201" /></a><p class="wp-caption-text">Simplified with tolerance 0.5</p></div>
<h3>Open issues</h3>
<p>The biggest issue I&#8217;ve encountered was about getting the tolerance in lat-lon WGS84 starting from pixel units, but let me explain why I choose pixel units in the first place: I think that pixel units are are the best choice because normally we don&#8217;t care about feature details which are below 1 pixel, we simply cannot see them. Using pixel units we also get the advantage of using a single number for all zoom levels, a more complicated approach would consist in using separate values for each zoom level. Translating pixel units to decimal degrees is not possible without approximations, I just hope that my approach works in most situations.</p>
<p>Another strange thing I noted in the library is that the bounding box used for clipping (which is a rectangle) is built using 16 points instead of 4. This means that after clipping we end up with a geometry that have many more points that it needs. I&#8217;m still waiting for a clarification I&#8217;ve asked in the TileStache ML, but in the meantime I patched my branch to use a normal 4 points rectangle and everything seems to work fine (and with smaller geojson responses).</p>
<h3>Conclusions</h3>
<p>TileStache confirmed to be a valuable tool for web GIS developers, it&#8217;s well written and supported and easily expandable, absolutely worths a try.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.itopen.it/2012/01/11/tilestache-vector-simplify-provider/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>TileStache Django tiny wrapper</title>
		<link>http://www.itopen.it/2012/01/09/tilestache-django-tiny-wrapper/</link>
		<comments>http://www.itopen.it/2012/01/09/tilestache-django-tiny-wrapper/#comments</comments>
		<pubDate>Mon, 09 Jan 2012 17:47:09 +0000</pubDate>
		<dc:creator>Alessandro Pasotti</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[GIS]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Programmazione]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[WebGis]]></category>

		<guid isPermaLink="false">http://www.itopen.it/?p=697</guid>
		<description><![CDATA[This is the second part of the story about my experiments with the wonderful TileStache that I started with TileStache and Polymaps SVG experiments. First, I would like to thank Michal for the quick patch inclusion, the Polymaps patch is still waiting for the pull and the Django admin patch is awating for somebody to [...]]]></description>
			<content:encoded><![CDATA[<p>This is the second part of the story about my experiments with the wonderful TileStache that I started with <a href="http://www.itopen.it/2012/01/05/polymaps-tilestache-and-svg-css-styling-issues/">TileStache and Polymaps SVG experiments</a>.</p>
<p>First, I would like to thank Michal for the quick patch inclusion, the Polymaps patch is still waiting for the pull and the Django admin patch is awating for somebody to take care of that 18-months-old bug.</p>
<p>My experiments have continued with Django integration, I just wanted to see how easy it was (and it was really easy indeed). There aren&#8217;t any clear advantages using a Django app instead of the standalone TileStache server, but writing the wrapper was a nice exercise to learn something more about TileStache and Polymaps, and having all the pieces into one place is always tempting for me (not to mention that you can dribble the <a href="http://en.wikipedia.org/wiki/Cross-Origin_Resource_Sharing">CORS</a> completely).</p>
<p>The wapper consists in a single router rule in urlconf:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">    url<span style="color: black;">&#40;</span>r<span style="color: #483d8b;">'^tiles/(?P&lt;layer_name&gt;[^/]+)/(?P&lt;z&gt;[^/]+)/(?P&lt;x&gt;[^/]+)/(?P&lt;y&gt;[^/]+)<span style="color: #000099; font-weight: bold;">\.</span>(?P&lt;extension&gt;.+)$'</span>, <span style="color: #483d8b;">'pm_points.views.tiles'</span>, name=<span style="color: #483d8b;">'tiles_url'</span><span style="color: black;">&#41;</span>,</pre></div></div>

<p>&#8230; a view for the tiles (get_config implements a singleton to avoid parsing TileStache config every time):</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">&nbsp;
<span style="color: #808080; font-style: italic;"># proper imports go here...</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> tiles<span style="color: black;">&#40;</span>request, layer_name, z, x, y, extension<span style="color: black;">&#41;</span>:
    <span style="color: #483d8b;">&quot;&quot;&quot;
    Proxy to tilestache
    {X} - coordinate column.
    {Y} - coordinate row.
    {B} - bounding box.
    {Z} - zoom level.
    {S} - host.
    &quot;&quot;&quot;</span>
    config = get_config<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    path_info = <span style="color: #483d8b;">&quot;%s/%s/%s/%s.%s&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>layer_name, z, x, y, extension<span style="color: black;">&#41;</span>
    coord, extension = TileStache.<span style="color: black;">splitPathInfo</span><span style="color: black;">&#40;</span>path_info<span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span>:<span style="color: black;">&#93;</span>
    mimetype, content = TileStache.<span style="color: black;">getTile</span><span style="color: black;">&#40;</span>config.<span style="color: black;">layers</span><span style="color: black;">&#91;</span>layer_name<span style="color: black;">&#93;</span>, coord, extension<span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">return</span> HttpResponse<span style="color: black;">&#40;</span>content, mimetype=mimetype<span style="color: black;">&#41;</span></pre></div></div>

<p>&#8230; and a simple view for the map:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> home<span style="color: black;">&#40;</span>request<span style="color: black;">&#41;</span>:
    <span style="color: #483d8b;">&quot;&quot;&quot;
    Pass layers by
    &quot;&quot;&quot;</span>
    config = get_config<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    layer_urls = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span>
    <span style="color: #ff7700;font-weight:bold;">for</span> l <span style="color: #ff7700;font-weight:bold;">in</span> config.<span style="color: black;">layers</span>:
        <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">isinstance</span><span style="color: black;">&#40;</span>config.<span style="color: black;">layers</span><span style="color: black;">&#91;</span>l<span style="color: black;">&#93;</span>.<span style="color: black;">provider</span>, TileStache.<span style="color: black;">Providers</span>.<span style="color: black;">Vector</span>.<span style="color: black;">Provider</span><span style="color: black;">&#41;</span>:
            layer_urls.<span style="color: black;">append</span><span style="color: black;">&#40;</span>reverse<span style="color: black;">&#40;</span><span style="color: #483d8b;">'tiles_url'</span>, args=<span style="color: black;">&#91;</span>l, <span style="color: #483d8b;">'{Z}'</span>, <span style="color: #483d8b;">'{X}'</span>, <span style="color: #483d8b;">'{Y}'</span>, <span style="color: #483d8b;">'geojson'</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>.<span style="color: black;">replace</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'%7B'</span>, <span style="color: #483d8b;">'{'</span><span style="color: black;">&#41;</span>.<span style="color: black;">replace</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'%7D'</span>, <span style="color: #483d8b;">'}'</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">return</span> render_to_response<span style="color: black;">&#40;</span><span style="color: #483d8b;">'home.html'</span>, <span style="color: black;">&#123;</span> <span style="color: #483d8b;">'layer_urls'</span> :  layer_urls<span style="color: black;">&#125;</span>, context_instance=RequestContext<span style="color: black;">&#40;</span>request<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>&#8230; and a template for Polymaps (I paste the js part only):</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">&nbsp;
    <span style="color: #003366; font-weight: bold;">var</span> po <span style="color: #339933;">=</span> org.<span style="color: #660066;">polymaps</span><span style="color: #339933;">,</span>
        map<span style="color: #339933;">,</span>
        layers <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
        stylist<span style="color: #339933;">;</span>
        jQuery<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            map <span style="color: #339933;">=</span> po.<span style="color: #660066;">map</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
                .<span style="color: #660066;">container</span><span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;map&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span>po.<span style="color: #660066;">svg</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;svg&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
                .<span style="color: #660066;">center</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>lat<span style="color: #339933;">:</span> <span style="color: #CC0000;">40</span><span style="color: #339933;">,</span> lon<span style="color: #339933;">:</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
                .<span style="color: #660066;">zoomRange</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">16</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
                .<span style="color: #660066;">zoom</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span>
                .<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span>po.<span style="color: #660066;">interact</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
                .<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span>po.<span style="color: #660066;">hash</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;
            map.<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span>po.<span style="color: #660066;">image</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
                .<span style="color: #660066;">url</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;http://s3.amazonaws.com/com.modestmaps.bluemarble/{Z}-r{Y}-c{X}.jpg&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            stylist <span style="color: #339933;">=</span> po.<span style="color: #660066;">stylist</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
                .<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'class'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>d<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                    <span style="color: #000066; font-weight: bold;">return</span> d.<span style="color: #660066;">geometry</span>.<span style="color: #660066;">type</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'_'</span> <span style="color: #339933;">+</span> d.<span style="color: #660066;">properties</span>.<span style="color: #660066;">id</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
                .<span style="color: #660066;">title</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>d<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #000066; font-weight: bold;">return</span> d.<span style="color: #660066;">properties</span>.<span style="color: #000066;">name</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
                <span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #009900;">&#123;</span><span style="color: #339933;">%</span> <span style="color: #000066; font-weight: bold;">for</span> lay_url <span style="color: #000066; font-weight: bold;">in</span> layer_urls <span style="color: #339933;">%</span><span style="color: #009900;">&#125;</span>
            <span style="color: #003366; font-weight: bold;">var</span> layer <span style="color: #339933;">=</span> po.<span style="color: #660066;">geoJson</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
                .<span style="color: #660066;">url</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;{{ lay_url|safe }}&quot;</span><span style="color: #009900;">&#41;</span>
                .<span style="color: #660066;">zoom</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>z<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                    <span style="color: #000066; font-weight: bold;">return</span> z<span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
                .<span style="color: #660066;">id</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'pmcollection'</span><span style="color: #009900;">&#41;</span>
                .<span style="color: #660066;">on</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;load&quot;</span><span style="color: #339933;">,</span>  stylist<span style="color: #009900;">&#41;</span>
                .<span style="color: #660066;">on</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'show'</span><span style="color: #339933;">,</span> stylist<span style="color: #009900;">&#41;</span>
                <span style="color: #339933;">;</span>
            map.<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span>layer<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            layers.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span>layer<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#123;</span><span style="color: #339933;">%</span> endfor <span style="color: #339933;">%</span><span style="color: #009900;">&#125;</span>
&nbsp;
            map.<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span>po.<span style="color: #660066;">compass</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
                .<span style="color: #660066;">pan</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;none&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            map.<span style="color: #660066;">container</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">setAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;class&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;mymap&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Quick and dirty, it also dynamically adds layers to the Polymap.</p>
<p>This story continues with: <a href="http://www.itopen.it/2012/01/11/tilestache-vector-simplify-provider/">TileStache Vector simplify provider</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.itopen.it/2012/01/09/tilestache-django-tiny-wrapper/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Polymaps, TileStache and SVG CSS styling issues</title>
		<link>http://www.itopen.it/2012/01/05/polymaps-tilestache-and-svg-css-styling-issues/</link>
		<comments>http://www.itopen.it/2012/01/05/polymaps-tilestache-and-svg-css-styling-issues/#comments</comments>
		<pubDate>Thu, 05 Jan 2012 16:38:00 +0000</pubDate>
		<dc:creator>Alessandro Pasotti</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[GIS]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Programmazione]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[WebGis]]></category>

		<guid isPermaLink="false">http://www.itopen.it/?p=682</guid>
		<description><![CDATA[A few days ago I started playing with Polymaps and TileStache, two very promising WebGIS building tools. The final goal of this experiments was the integration with Django. Polymaps Polymaps is a Javascript library aimed to display svg maps in a web page, recently I&#8217;ve watched to an interesting talk about a Django-powered app built [...]]]></description>
			<content:encoded><![CDATA[<p>A few days ago I started playing with <a href="http://polymaps.org/">Polymaps</a> and <a href="http://tilestache.org/">TileStache</a>, two very promising WebGIS building tools.</p>
<p>The final goal of this experiments was the integration with Django.</p>
<h2>Polymaps</h2>
<p>Polymaps is a Javascript library aimed to display svg maps in a web page, recently I&#8217;ve watched to an interesting talk about a Django-powered app built on top of Polymaps: </p>
<p><iframe src="http://blip.tv/play/AYLUmmQC.html?p=1" width="550" height="442" frameborder="0" allowfullscreen></iframe><embed type="application/x-shockwave-flash" src="http://a.blip.tv/api.swf#AYLUmmQC" style="display:none"></embed></p>
<p>The main reason to give Polymaps a try is the interesting support to tiled vector layers, as far as I know a unique feature.</p>
<p>I&#8217;ve found the documentation of Polymaps a bit obscure and still incomplete (I just hope it isn&#8217;t another facade Open Source product where the lack of documentation and community support limits the use to commercial projects).</p>
<p>A quick look in the code shows no comments and rather obscure variable names, debbugging this library would certainly be a nightmare if you&#8217;re not the author, if you compare the source code with OpenLayers&#8217;s code you get the idea.</p>
<p>BTW I managed to make it work in a few hours (with all the server stuff).</p>
<h2>TileStache</h2>
<p>TileStache is a python library aimed to build, cache and manage map tiles. It&#8217;s similar to TileCache in scope and uses the well known Mapnik renderer while the data provider is implemented with shapely and OGR and can read the most widely used formats (postgis, shapefile, geojson).</p>
<p>TileStache is the ideal companion to Polymaps because it can handle and cache vector tiles (geojson) through the Vector class (don&#8217;t even try to use the PostgreSQL class you can find in Goodies, it&#8217;s kind of unofficially deprecated and it will let you waste your time).</p>
<p>I had to fork the project on github and made a pull request to fix the missing &#8220;port&#8221; parameter to the DB connection since I&#8217;m using a not-standard port.</p>
<h2>SVG CSS</h2>
<p>I admit I am a true beginner with SVG and while I was trying to experiment with the stylist features of Polymaps  I discovered some counter-intuitive (at least for me, coming from XHTML CSS) behaviours:</p>
<p>You can define styles in three ways:</p>
<ol>
<li>CSS rules</li>
<li>&#8220;style&#8221; attribute of the SVG element</li>
<li>individual attributes (&#8220;stroke&#8221;, &#8220;fill&#8221; etc. etc.) of the SVG element</li>
</ol>
<p>Strange enough, the priority is top-down, while I would have expected that point 3 had a higher priority.</p>
<p>Another thing worths noting is that what distinguish a polygon from a linestring in the Polymaps generated &#8220;path&#8221; SVG element is just that the &#8220;d&#8221; element (which contains the geometry) ends with a &#8220;Z&#8221;.</p>
<p>This is a linestring:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;path</span> <span style="color: #000066;">d</span>=<span style="color: #ff0000;">&quot;M101.99999715555555,189.9999971369224</span>
<span style="color: #009900;">L75.00000142222234,219.00000190473258</span>
<span style="color: #009900;">L75.00000142222234,242.49999834108655</span>
<span style="color: #009900;">L94.49999928888906,242.99999806558844</span>
<span style="color: #009900;">L102.49999928888906,255.4999976705726</span>
<span style="color: #009900;">L101.99970702222231,256&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>;</pre></div></div>

<p>This is a polygon:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;path</span> <span style="color: #000066;">d</span>=<span style="color: #ff0000;">&quot;M95.07080533333351,256.00000052462633</span>
<span style="color: #009900;">L0,196.67516186124612</span>
<span style="color: #009900;">L0,192.0000022835775</span>
<span style="color: #009900;">L0,128.0000001888236L0,70.92093168072711</span>
<span style="color: #009900;">L175.92470186666674,0.000006325172648757871</span>
<span style="color: #009900;">L192,0.000006325172648757871</span>
<span style="color: #009900;">L256,0.000006325172648757871</span>
<span style="color: #009900;">L256,64.00000444302805</span>
<span style="color: #009900;">L256,128.0000001888236</span>
<span style="color: #009900;">L256,160.99230434784874</span>
<span style="color: #009900;">L113.66593991111131,256.00000052462633Z&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>;</pre></div></div>

<p>Styling the plygon fill without hitting linestring in a GEOMETRYCOLLECTION layer turned out to be quite troublesome.</p>
<p>I ended up with a CSS-3 attribute CSS rule:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.layer</span> path <span style="color: #00AA00;">&#123;</span>
fill<span style="color: #00AA00;">:</span> cyan<span style="color: #00AA00;">;</span>
fill-opacity<span style="color: #00AA00;">:</span> .85<span style="color: #00AA00;">;</span>
stroke<span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#012</span><span style="color: #00AA00;">;</span>
stroke-linecap<span style="color: #00AA00;">:</span> round<span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #6666ff;">.layer</span> <span style="color: #993333;">circle</span> <span style="color: #00AA00;">&#123;</span>
fill<span style="color: #00AA00;">:</span> cyan<span style="color: #00AA00;">;</span>
fill-opacity<span style="color: #00AA00;">:</span> .85<span style="color: #00AA00;">;</span>
stroke<span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#012</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* Don't fill in SVG */</span>
<span style="color: #6666ff;">.layer</span> path<span style="color: #00AA00;">:</span>not<span style="color: #00AA00;">&#40;</span><span style="color: #00AA00;">&#91;</span>d$<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;Z&quot;</span><span style="color: #00AA00;">&#93;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">&#123;</span>
fill<span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
stroke-<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">3px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>I wonder if there is a better way&#8230;</p>
<p>This story continues with: <a href="http://www.itopen.it/2012/01/09/tilestache-django-tiny-wrapper/">TileStache Django tiny wrapper</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.itopen.it/2012/01/05/polymaps-tilestache-and-svg-css-styling-issues/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Meeting di programmatori QGIS a Zurigo</title>
		<link>http://www.itopen.it/2011/12/16/meeting-di-programmatori-qgis-a-zurigo/</link>
		<comments>http://www.itopen.it/2011/12/16/meeting-di-programmatori-qgis-a-zurigo/#comments</comments>
		<pubDate>Fri, 16 Dec 2011 15:45:29 +0000</pubDate>
		<dc:creator>Alessandro Pasotti</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[GIS]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.itopen.it/?p=675</guid>
		<description><![CDATA[Lo scorso mese di novembre 2011, si è tenuto a Zurigo il meeting internazionale di programmatori QGIS. Ho avuto la fortuna di partecipare, dato che mi occupo da diverso tempo della nuova infrastruttura web, basta su Django e sono autore di un paio di plugin QGIS python. È il secondo meeting QGIS al quale partecipo [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_676" class="wp-caption alignright" style="width: 310px"><a href="http://www.itopen.it/wp-content/uploads/2011/12/foto-gruppo-zurigo.jpg"><img class="size-medium wp-image-676" title="foto-gruppo-zurigo" src="http://www.itopen.it/wp-content/uploads/2011/12/foto-gruppo-zurigo-300x123.jpg" alt="" width="300" height="123" /></a><p class="wp-caption-text">Zuerich QGIS hackmeeting</p></div>
<p>Lo scorso mese di novembre 2011, si è tenuto a Zurigo il meeting internazionale di programmatori <a title="QGIS hackmeeting 2011" href="http://www.qgis.org" target="_blank">QGIS</a>.</p>
<p>Ho avuto la fortuna di partecipare, dato che mi occupo da diverso tempo della nuova infrastruttura web, basta su Django e sono autore di un paio di plugin QGIS python.</p>
<p>È il secondo meeting QGIS al quale partecipo ed è stata una bellissima occasione per incontrare gli altri sviluppatori, e confrontarmi con loro sul futuro del più promettente programma GIS libero.</p>
<p>Durante il meeting ho potuto assistere a numerose presentazioni, tra cui le più stimolanti sono state quella sul porting QGIS per android e il nuovo supporto topologico per postgis.</p>
<p>Il mio lavoro durante il meeting è consistito nella correzione di alcuni difetti nella nuova piattaforma web e l&#8217;implementazione di alcune nuove funzionalità, in particolare l&#8217;interfaccia XML-RPC per il caricamento dei plugin, implementata con l&#8217;ottimo pacchetto <a title="RPC4Django home page" href="http://davidfischer.name/rpc4django/" target="_blank">RPC4Django</a>.</p>
<p>Ringrazio l&#8217;associazione <a title="Associazione Italiana per l'informazione geografica libera" href="http://www.gfoss.it" target="_blank">GFOSS</a> che ha contribuito  alla mia trasferta.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.itopen.it/2011/12/16/meeting-di-programmatori-qgis-a-zurigo/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>django deployment with nginx and uwsgi</title>
		<link>http://www.itopen.it/2011/09/09/django-deployment-with-nginx-and-uwsgi/</link>
		<comments>http://www.itopen.it/2011/09/09/django-deployment-with-nginx-and-uwsgi/#comments</comments>
		<pubDate>Fri, 09 Sep 2011 07:11:25 +0000</pubDate>
		<dc:creator>Alessandro Pasotti</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Tech]]></category>

		<guid isPermaLink="false">http://www.itopen.it/?p=559</guid>
		<description><![CDATA[There are many tutorial/procedures on this topic, I just wish to add a few notes on the pieces I&#8217;ve found more obscure and difficult to setup. I&#8217;m running a VM on slicehost and I haven&#8217;t alredy found the resources to perform a full upgrade to something newer than the original Ubuntu Hardy which was installed [...]]]></description>
			<content:encoded><![CDATA[<p>There are many tutorial/procedures on this topic, I just wish to add a few notes on the pieces I&#8217;ve found more obscure and difficult to setup.</p>
<p>I&#8217;m running a VM on slicehost and I haven&#8217;t alredy found the resources to perform a full upgrade to something newer than the original Ubuntu Hardy which was installed at setup time.</p>
<p>Basically, I&#8217;ve compiled latest nginx from sources (older versions did not support uwsgi natively) and installed uwsgi with</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> pip <span style="color: #c20cb9; font-weight: bold;">install</span> uwsgi</pre></div></div>

<p>not running on a virtualenv on this machine <img src='http://www.itopen.it/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
<p>what I&#8217;ve found really hard to fix was the wrong filesystem encoding wich lead to the famous encoding errors:</p>
<pre>UnicodeEncodeError: 'ascii' codec can't encode character u'\xe0' inposition 86: ordinal not in range(128)</pre>
<p>The fix is trivial: you must convince uwsgi that is running in an UTF-8 locale, to do so, you must set environment vars as explained in <a href="https://docs.djangoproject.com/en/dev/howto/deployment/modpython/#if-you-get-a-unicodeencodeerror" target="_blank">django docs </a>  (for apache/mod_python, but the root is the same).</p>
<p>Having had an hard time to set env on upstart, I&#8217;ve switched to a standard init script for uwsgi:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#! /bin/bash</span>
<span style="color: #666666; font-style: italic;"># /etc/init.d/uwsgi</span>
<span style="color: #666666; font-style: italic;">#</span>
&nbsp;
<span style="color: #007800;">daemon</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>uwsgi
<span style="color: #007800;">pid</span>=<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>project-master.pid
<span style="color: #666666; font-style: italic;"># run as www-data</span>
<span style="color: #007800;">args</span>=<span style="color: #ff0000;">&quot;--uid=33 --gid=33 --ini /home/public_html/project/uwsgi.ini --pidfile <span style="color: #007800;">$pid</span>&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Carry out specific functions when asked to by the system</span>
<span style="color: #000000; font-weight: bold;">case</span> <span style="color: #ff0000;">&quot;$1&quot;</span> <span style="color: #000000; font-weight: bold;">in</span>
    start<span style="color: #7a0874; font-weight: bold;">&#41;</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Starting uwsgi&quot;</span>
        <span style="color: #007800;">LC_ALL</span>=<span style="color: #ff0000;">'en_US.UTF-8'</span> <span style="color: #007800;">LANG</span>=<span style="color: #ff0000;">'en_US.UTF-8'</span> start-stop-daemon <span style="color: #660033;">-p</span> <span style="color: #007800;">$pid</span> <span style="color: #660033;">--start</span> <span style="color: #660033;">--exec</span> <span style="color: #007800;">$daemon</span> <span style="color: #660033;">--</span> <span style="color: #007800;">$args</span>
        <span style="color: #000000; font-weight: bold;">;;</span>
    stop<span style="color: #7a0874; font-weight: bold;">&#41;</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Stopping script uwsgi&quot;</span>
        <span style="color: #007800;">LC_ALL</span>=<span style="color: #ff0000;">'en_US.UTF-8'</span> <span style="color: #007800;">LANG</span>=<span style="color: #ff0000;">'en_US.UTF-8'</span> start-stop-daemon <span style="color: #660033;">--signal</span> INT <span style="color: #660033;">-p</span> <span style="color: #007800;">$pid</span> <span style="color: #660033;">--stop</span> <span style="color: #007800;">$daemon</span> <span style="color: #660033;">--</span> <span style="color: #007800;">$args</span>
        <span style="color: #000000; font-weight: bold;">;;</span>
    reload<span style="color: #7a0874; font-weight: bold;">&#41;</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Reloading conf&quot;</span>
        <span style="color: #c20cb9; font-weight: bold;">kill</span> <span style="color: #660033;">-HUP</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #007800;">$pid</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
        <span style="color: #000000; font-weight: bold;">;;</span>
    <span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Usage: /etc/init.d/uwsgi {start|stop|reload}&quot;</span>
        <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
    <span style="color: #000000; font-weight: bold;">;;</span>
<span style="color: #000000; font-weight: bold;">esac</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">0</span></pre></div></div>

<p>Here the trick is to set env vars on the start-stop-daemon line.</p>
<p>The application ini is something like:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#91;</span>uwsgi<span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #007800;">chdir</span>=<span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>public_html<span style="color: #000000; font-weight: bold;">/</span>project<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #007800;">master</span>=True
<span style="color: #007800;">vacuum</span>=True
max-requests=<span style="color: #000000;">5000</span>
<span style="color: #007800;">daemonize</span>=<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>uwsgi<span style="color: #000000; font-weight: bold;">/</span>uwsgi.log
<span style="color: #007800;">socket</span>=127.0.0.1:<span style="color: #000000;">49152</span>
<span style="color: #c20cb9; font-weight: bold;">env</span> = <span style="color: #007800;">DJANGO_SETTINGS_MODULE</span>=settings
module = django.core.handlers.wsgi:WSGIHandler<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>Last missing piece is log rotation:</p>
<p>&nbsp;</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #ff0000;">&quot;/var/log/uwsgi/*.log&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
  copytruncate
  daily
  rotate <span style="color: #000000;">5</span>
  compress
  delaycompress
  missingok
  notifempty
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.itopen.it/2011/09/09/django-deployment-with-nginx-and-uwsgi/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Django DAG: my first reusable app on PyPi</title>
		<link>http://www.itopen.it/2011/02/15/django-dag-my-first-reusable-app-on-pypi/</link>
		<comments>http://www.itopen.it/2011/02/15/django-dag-my-first-reusable-app-on-pypi/#comments</comments>
		<pubDate>Tue, 15 Feb 2011 08:02:41 +0000</pubDate>
		<dc:creator>Alessandro Pasotti</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[Programmazione]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Tech]]></category>

		<guid isPermaLink="false">http://www.itopen.it/?p=501</guid>
		<description><![CDATA[﻿﻿ Django DAG Django-dag is a small reusable app which implements a Directed Acyclic Graph. Usage Django-dag uses abstract base classes, to use it you must create your own concrete classes that inherit from Django-dag classes. The `dag_test` app contains a simple example and a unit test to show you its usage. Example class ConcreteNode&#40;node_factory&#40;'ConcreteEdge'&#41;&#41;: [...]]]></description>
			<content:encoded><![CDATA[<h2>﻿﻿<br />
Django DAG</h2>
<p>Django-dag is a small reusable app which implements a <a href="http://en.wikipedia.org/wiki/Directed_acyclic_graph">Directed Acyclic Graph</a>.</p>
<h2>Usage</h2>
<p>Django-dag uses abstract base classes, to use it you must create your own<br />
concrete classes that inherit from Django-dag classes.</p>
<p>The `dag_test` app contains a simple example and a unit test to show<br />
you its usage.</p>
<h2>Example</h2>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">class</span> ConcreteNode<span style="color: black;">&#40;</span>node_factory<span style="color: black;">&#40;</span><span style="color: #483d8b;">'ConcreteEdge'</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>:
    <span style="color: #483d8b;">&quot;&quot;&quot;
    Test node, adds just one field
    &quot;&quot;&quot;</span>
    name = models.<span style="color: black;">CharField</span><span style="color: black;">&#40;</span>max_length = <span style="color: #ff4500;">32</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> ConcreteEdge <span style="color: black;">&#40;</span>edge_factory<span style="color: black;">&#40;</span>ConcreteNode, concrete = <span style="color: #008000;">False</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>:
    <span style="color: #483d8b;">&quot;&quot;&quot;
    Test edge, adds just one field
    &quot;&quot;&quot;</span>
    name = models.<span style="color: black;">CharField</span><span style="color: black;">&#40;</span>max_length = <span style="color: #ff4500;">32</span>, blank = <span style="color: #008000;">True</span>, null = <span style="color: #008000;">True</span><span style="color: black;">&#41;</span></pre></div></div>

<p><a href="http://pypi.python.org/pypi/django-dag/">Diango DAG on pypi.</a></p>
<p><a href="https://github.com/elpaso/django-dag">Django DAG github code repository with examples and tests.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.itopen.it/2011/02/15/django-dag-my-first-reusable-app-on-pypi/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Italian GFOSS Day 2010</title>
		<link>http://www.itopen.it/2010/11/12/italian-gfoss-day-2010/</link>
		<comments>http://www.itopen.it/2010/11/12/italian-gfoss-day-2010/#comments</comments>
		<pubDate>Fri, 12 Nov 2010 16:48:10 +0000</pubDate>
		<dc:creator>Alessandro Pasotti</dc:creator>
				<category><![CDATA[GIS]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[WebGis]]></category>

		<guid isPermaLink="false">http://www.itopen.it/?p=464</guid>
		<description><![CDATA[Next week, from wednesday 18 to friday 19, I will attend in Foligno to the upcoming GFOSS Day 2010 holding two tutorials on GIS Python development and on a GeoDjango case study. Like previous editions of this event, it will be another fundamental opportunity to meet the other members of the Italian free GIS software community. Don't miss this event, if you can!]]></description>
			<content:encoded><![CDATA[<h1><a href="http://www.itopen.it/wp-content/uploads/2010/11/gfoss_logo.png"><img class="alignright size-medium wp-image-467" title="gfoss_logo" src="http://www.itopen.it/wp-content/uploads/2010/11/gfoss_logo-300x100.png" alt="" width="300" height="100" /></a>About GFOSS:</h1>
<p><a title="GFOSS official site" href="http://www.gfoss.it" target="_blank">GFOSS</a> is the Italian chapter of <a title="OSGEO website" href="http://www.osgeo.org" target="_blank">OSGEO</a> fundation.</p>
<p>I am a proud member from its birth and I participate to almost all events.</p>
<h1>About GFOSS Day:</h1>
<p>GFOSS day is an yearly meeting where all the people interested in geographic open source free sotware can meet to share ideas and experiences.</p>
<p>This year 2010  the event will last two days (18 and 19 november) with conferences, tutorials and workshops.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.itopen.it/2010/11/12/italian-gfoss-day-2010/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>QuickWKT QGIS plugin</title>
		<link>http://www.itopen.it/2010/10/21/wkt-on-the-fly-qgis-plugin/</link>
		<comments>http://www.itopen.it/2010/10/21/wkt-on-the-fly-qgis-plugin/#comments</comments>
		<pubDate>Thu, 21 Oct 2010 07:29:30 +0000</pubDate>
		<dc:creator>Alessandro Pasotti</dc:creator>
				<category><![CDATA[GIS]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.itopen.it/?p=443</guid>
		<description><![CDATA[Un nuovo plugin per QGIS in python permette di visualizzare velocemente le geometrie in formato WKT]]></description>
			<content:encoded><![CDATA[<div id="attachment_292" class="wp-caption alignright" style="width: 193px"><img class="size-full wp-image-292" title="qgis_logo_right" src="http://www.itopen.it/wp-content/uploads/2009/06/qgis_logo_right.gif" alt="QGIS logo" width="183" height="149" /><p class="wp-caption-text">QGIS logo</p></div>
<p>During the last development effort for out GeoDjango-based platform, we&#8217;ve been in the need to test if GIS buffering functions  were working as expected. Since everything was executed on the server without any user interaction, we ended up logging plain <a target="_blank" title="Wikipedia: WKT definition" href="http://en.wikipedia.org/wiki/Well-Known_Text">WKT </a> geometries.</p>
<p>Of course understanding the shape and dimensions of a geometry just reading it coordinates is almost impossible, and we couldn&#8217;t find an easy way to quickly display WKT  geometries in our GIS  software <a title="QGIS official site" href="http://www.qgis.org">QGIS</a>.</p>
<p>This new plugin allows a user to paste WKT geometries into a dialog text field and get it displayed in QGIS inside a temporary (in-memory) layer.</p>
<p>You can find the new plugin named <strong>QuickWKT</strong> on <a href="http://pyqgis.org/admin/contributed/python_plugins/list">QGIS the 3rd parties repository</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.itopen.it/2010/10/21/wkt-on-the-fly-qgis-plugin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Lanciato il nuovo progetto basato su GeoDjango</title>
		<link>http://www.itopen.it/2010/05/28/new-geodjango-platform-launched/</link>
		<comments>http://www.itopen.it/2010/05/28/new-geodjango-platform-launched/#comments</comments>
		<pubDate>Fri, 28 May 2010 15:57:23 +0000</pubDate>
		<dc:creator>Alessandro Pasotti</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[Programmazione]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Realizzazioni]]></category>
		<category><![CDATA[Varie]]></category>

		<guid isPermaLink="false">http://www.itopen.it/?p=407</guid>
		<description><![CDATA[﻿﻿﻿Abbiamo appena lanciato una famiglia di siti internet realizzati attraverso una piattforma basata su GeoDjango. La realizzazione è durata più di sei mesi e ha messo in luce pregi e difetti delle soluzioni tecniche adottate.
]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.itopen.it/wp-content/uploads/2010/05/django_logo.png"><img class="alignright size-full wp-image-409" title="django_logo" src="http://www.itopen.it/wp-content/uploads/2010/05/django_logo.png" alt="" width="117" height="41" /></a>I&#8217;ve spent the last six months learning a new programming language (<a title="Python HP" href="http://www.python.org">Python</a>) and a new framework (<a href="http://www.djangoproject.org">Django</a>). The result is a platform which integrates some state-of-the-art web development and web mapping technologies:</p>
<ul>
<li>Django</li>
<li>postgis</li>
<li>pg_routing</li>
<li>ExtJS</li>
<li>GeoExt</li>
<li>OpenLayers</li>
</ul>
<p>My client is a market leader in GPS wandering and track planning, who needed a complex CMS to publish and promote his activities.</p>
<p>The project&#8217;s goal was to develop a Geographic CMS multi-site, multi-admin (resellable) , multi-language using open source tools. Among other interesting features, we needed to support all well-known mapping providers (Google Maps, Yahoo Maps, OpenStreet Map etc.) plus an internal maps with tracks arc-node network, suitable for routing calculations.</p>
<p>The new website(s) are reachable at <a title="Movimento Lento HP" href="http://www.movimentolento.it">www.movimentolento.it</a> at the time of this writing, the Italian language is the only one with some contents.</p>
<h2>Python vs. PHP</h2>
<p>After more than seven years of PHP programming, the language switch was a risky move, but I rapidly fell in love with Python and its vibrant users community. I usually avoid flame wars about programming languages, but I&#8217;m now deeply convinced that Python is far more advanced than PHP, even if PHP has its own advantages, expecially when deployment time comes.</p>
<h2>(Geo)Django a powerful framework</h2>
<p>The choice of Django as the barebone framework was dictated by Django being the one having an advanced support of Geographic extensions (GeoDjango) and by its beautiful documentation. Of course the ideal framework does not exists (yet) and is maybe impossible to create since they are always a compromise between ready-to-use functionalities and flexibility. Django authors must have had a good time providing (almost) all the necessary hooks for customization.</p>
<p>I&#8217;ve found Django a very interesting project for many reasons:</p>
<h3>Lack of &#8220;magic&#8221;</h3>
<p>While most widespread principles like DRY and convention over configuration are valuable, I&#8217;ve often found confusing for first time users the lot of under the hood features that are are triggered because you&#8217;ve named a function or a class in a certain way, I think Django has wisely chose to not implement too much of this outside of the ORM DB design phase. The result is a clean application design flow without too many conventions that you must have in the top of your head.</p>
<h3>Powerful ORM</h3>
<p>I really like the way you can build complex queries and retrieve related object in Django, even M2M relations can be handled in an understandable way. If you need multi-class (multi-table) references you can build them quite easily with the ContenType contribution classes.</p>
<h3>Flexible templates</h3>
<p>This is maybe what I love much in Django: the templating engine is so powerful and flexible that it can really save you a lot of work allowing you to put presentation logic inside the template itself. I agree that separating concerns in a pure MVC patterns (presentation and controller logic) is a must but think of Django templates like they were the presentation part of the view component and you&#8217;ve got the point.</p>
<h3>Reusable apps</h3>
<p>&#8220;Reusable apps&#8221; are ready to use applications that you should be able to drop into your applications, and they are reusable indeed. Even if I probably had to modify most of them in order to add multilingual and multi-site support, reusable apps can save you a lot of time.</p>
<h2>Missing features</h2>
<p>This is a short description of the main problems I&#8217;ve encountered when developing missing features in Django. I ended up without core modifications and with a single real patch, so it wasn&#8217;t that bad after all.</p>
<h3>Multisite</h3>
<p>Django comes with the &#8220;Sites&#8221; framework, it allows you to share the same DB from different websites, but you are supposed to run each website into a different Django instance. While this remains the recommended way, my clients required new sites to be added from the control panel in  an easy way.</p>
<p>Site ID is hardcoded in the settings and due to the fact that static class methods are shared among processes (and moreover among threads, of course) you cannot use it directly without modifications. I&#8217;ve had to modify queryst managers and to create a middleware to change Site ID on the fly based on the requested domain. A catch-all DNS record allows to create third level domains within the control panel having them online within minutes.</p>
<p>Something similar is available as reusable app:<a href="http://github.com/shestera/django-multisite"> django-multisite</a>.</p>
<h3>Multilingual</h3>
<p>Django does not support multiple language for the content (it does for the interface static strings).  I started from a reusable app (<a href="http://http://code.google.com/p/django-transmeta/">transmeta</a>) and did some modifications to allow for optional translations and to easy control panel interface development and presentation. FTS integrations was also added.</p>
<h3>Full text search (FTS)</h3>
<p>DB is Postgresql which now comes with integrated FTS, I added some triggers and management commands  to support multilanguage FTS. Django doesn&#8217;t provide any utility to handle FTS.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.itopen.it/2010/05/28/new-geodjango-platform-launched/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

