<?xml version='1.0' encoding='UTF-8'?><rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/" xmlns:blogger="http://schemas.google.com/blogger/2008" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" version="2.0"><channel><atom:id>tag:blogger.com,1999:blog-3120553115257874322</atom:id><lastBuildDate>Mon, 06 Oct 2025 07:04:05 +0000</lastBuildDate><category>spatial data</category><category>GIS</category><category>QGIS</category><category>environment</category><category>science</category><category>misc</category><category>R</category><category>Russia</category><category>St. Petersburg</category><category>waste</category><category>Python</category><category>anticapitalism</category><category>corruption</category><category>illegal dumps and landfills</category><category>sustainable development</category><category>GIS-Lab</category><category>Leningrad region</category><category>openSUSE</category><category>disaster</category><category>OSM</category><category>art</category><category>economy</category><category>religion</category><category>NGO</category><category>education</category><category>LiDAR</category><category>environmental risk</category><category>DEM</category><category>DSM</category><category>Dungeons and Dragons</category><category>GDAL</category><category>Moscow</category><category>OTB</category><category>PostGIS</category><category>SEXTANTE</category><category>maps</category><category>mass media</category><category>rasters</category><category>symbols</category><category>Dota 2</category><category>Finland</category><category>Peewee</category><category>Processing</category><category>Russian Geographical Society</category><category>SAGA</category><category>development</category><category>graph</category><category>imagery</category><category>pansharpening</category><category>repressions</category><category>travel</category><category>Django</category><category>ESRI</category><category>GeoServer</category><category>Greenpeace</category><category>HowTo</category><category>Karelia</category><category>MOSKitt Geo</category><category>Optics</category><category>PyQGIS</category><category>Qt</category><category>Rosreestr</category><category>SQL</category><category>SQLite</category><category>SRTM</category><category>TSP</category><category>USSR</category><category>bokeh</category><category>disturbed land</category><category>environmental monitoring</category><category>iPad</category><category>lamps</category><category>monitoring</category><category>pandas</category><category>president</category><category>spatial planning</category><title>Misanthrope&#39;s Thoughts</title><description>&lt;p align=&quot;right&quot;&gt; What is the cause for the degradation of environment?&lt;br&gt; Capitalism, corruption, consuming society? - OVERPOPULATION!&lt;br&gt;&#xa;Please, save the Planet - kill yourself... &lt;p align=&quot;right&quot;&gt;&lt;/p&gt;&lt;/p&gt;</description><link>http://ssrebelious.blogspot.com/</link><managingEditor>noreply@blogger.com (Yury Ryabov)</managingEditor><generator>Blogger</generator><openSearch:totalResults>164</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3120553115257874322.post-6412425448779682248</guid><pubDate>Tue, 16 Oct 2018 15:10:00 +0000</pubDate><atom:updated>2018-10-16T19:10:07.352+04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Django</category><category domain="http://www.blogger.com/atom/ns#">HowTo</category><category domain="http://www.blogger.com/atom/ns#">Python</category><title>Chaining AND operators in Django</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Sometimes in Dango you need to compose query with several&amp;nbsp; `Q(query) &amp;amp; Q(other_query) &amp;amp;...` and the number of such queries changes dynamically. Here is a quick example how to solve it:&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-color: #2b2b2b; color: #a9b7c6; font-family: &#39;Source Code Pro Semibold&#39;; font-size: 12.0pt;&quot;&gt;&lt;span style=&quot;color: #cc7832;&quot;&gt;import &lt;/span&gt;operator

ids = [&lt;span style=&quot;color: #6897bb;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #cc7832;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #6897bb;&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #cc7832;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #6897bb;&quot;&gt;3&lt;/span&gt;]
queries = [Q(&lt;span style=&quot;color: #aa4926;&quot;&gt;some_m2m_relation__pk&lt;/span&gt;=pk) &lt;span style=&quot;color: #cc7832;&quot;&gt;for &lt;/span&gt;pk &lt;span style=&quot;color: #cc7832;&quot;&gt;in &lt;/span&gt;&lt;span style=&quot;color: #8888c6;&quot;&gt;id&lt;/span&gt;]
result = SomeModel.objects.filter(
    reduce(operator.and_&lt;span style=&quot;color: #cc7832;&quot;&gt;, &lt;/span&gt;queries)
)&lt;/pre&gt;
&lt;br /&gt;&lt;/div&gt;
</description><link>http://ssrebelious.blogspot.com/2018/10/chaining-and-operators-in-django.html</link><author>noreply@blogger.com (Yury Ryabov)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3120553115257874322.post-6160772304026425542</guid><pubDate>Tue, 07 Feb 2017 18:41:00 +0000</pubDate><atom:updated>2017-06-25T10:39:03.892+04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">openSUSE</category><title>How to Configure Pulseaudio to Work With Subwoofer</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
What I hate about Pulseaudio is its crappy default configuration. After fresh installation of SUSE Leap 42.2 I encountered an issue that subwoofer didn&#39;t work with Amarok... again((( Lucky me, the first link that google provided me with was link to &lt;a href=&quot;https://forums.opensuse.org/showthread.php/468546-Pulseaudio-and-Amarok-in-12-1&quot; target=&quot;_blank&quot;&gt;my own(!!!) thread&lt;/a&gt; that I started about 6 years ago (sick!!!). In 2011 I encountered the same issue, asked for help, but solved on my own and answered for my own request. And now future me was able to find that long forgotten thread of mine. That&#39;s so sweet to recieve a messege to miself )))&lt;br /&gt;
&lt;br /&gt;
This time I will put the answer here to remember it better ;-)&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;background-color: #fefefe; color: #333333; font-family: &amp;quot;verdana&amp;quot; , &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;calibri&amp;quot; , &amp;quot;geneva&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;The problem solved, tnx to&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;http://forum.ubuntu.ru/index.php?topic=112310.msg837930#msg837930&quot; style=&quot;background: rgb(254, 254, 254); border: 0px; color: #336699; cursor: pointer; font-family: Verdana, Arial, Tahoma, Calibri, Geneva, sans-serif; font-size: 13px; margin: 0px; outline: 0px; padding: 0px; text-decoration: none;&quot; target=&quot;_blank&quot;&gt;this post&lt;/a&gt;&lt;span style=&quot;background-color: #fefefe; color: #333333; font-family: &amp;quot;verdana&amp;quot; , &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;calibri&amp;quot; , &amp;quot;geneva&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: #fefefe; color: #333333; font-family: &amp;quot;verdana&amp;quot; , &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;calibri&amp;quot; , &amp;quot;geneva&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;In /etс/pulse/daemon.conf I&#39;ve made following changes:&lt;/span&gt;&lt;br /&gt;
&lt;br style=&quot;background-color: #fefefe; color: #333333; font-family: Verdana, Arial, Tahoma, Calibri, Geneva, sans-serif; font-size: 13px;&quot; /&gt;
&lt;div class=&quot;bbcode_container&quot; style=&quot;background: rgb(254, 254, 254); border: 0px; color: #333333; font-family: Verdana, Arial, Tahoma, Calibri, Geneva, sans-serif; font-size: 13px; margin: 5px 20px 20px; outline: 0px; padding: 0px;&quot;&gt;
&lt;div class=&quot;bbcode_description&quot; style=&quot;background: transparent; border: 0px; margin: 0px; outline: 0px; padding: 0px;&quot;&gt;
Code:&lt;/div&gt;
&lt;pre class=&quot;bbcode_code&quot; style=&quot;background: none repeat-x rgb(242, 246, 248); border: 1px inset; direction: ltr; font-size: 12px; height: 60px; line-height: 12px; outline: 0px; overflow: scroll; padding: 6px; white-space: pre-wrap; word-wrap: break-word;&quot;&gt; 
enable-lfe-remixing = yes
default-channel-map = front-left,front-right,rear-left,rear-right,front-center,lfe&lt;/pre&gt;
&lt;/div&gt;
&lt;/blockquote&gt;
&lt;/div&gt;
</description><link>http://ssrebelious.blogspot.com/2017/02/how-to-configure-pulseaudio-to-work.html</link><author>noreply@blogger.com (Yury Ryabov)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3120553115257874322.post-332870984030963578</guid><pubDate>Fri, 23 Sep 2016 19:16:00 +0000</pubDate><atom:updated>2016-09-23T23:22:16.268+04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">bokeh</category><category domain="http://www.blogger.com/atom/ns#">environment</category><category domain="http://www.blogger.com/atom/ns#">environmental monitoring</category><category domain="http://www.blogger.com/atom/ns#">monitoring</category><category domain="http://www.blogger.com/atom/ns#">pandas</category><category domain="http://www.blogger.com/atom/ns#">Peewee</category><category domain="http://www.blogger.com/atom/ns#">Python</category><category domain="http://www.blogger.com/atom/ns#">Qt</category><category domain="http://www.blogger.com/atom/ns#">R</category><category domain="http://www.blogger.com/atom/ns#">SQL</category><title>Environmental Monitoring App</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Python, R, Qt, peewee, bokeh, pandas, SQLite plus couple of sleepless nights and here you are a сute app for the environmental monitoring needs )))&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj7Low6e1DWY4EAoS3c5Z6uAu2G618-CFtKzMdetFM-iyt2KHSDwmC8SU6xPjrc0oanWXI__epBjYKto3g9oAAfMN-2IYfw2R5pr13cJPcE-qrSSFexC7bfN1o2rSZziHeGNURGv9i4eDc/s1600/main_window.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;336&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj7Low6e1DWY4EAoS3c5Z6uAu2G618-CFtKzMdetFM-iyt2KHSDwmC8SU6xPjrc0oanWXI__epBjYKto3g9oAAfMN-2IYfw2R5pr13cJPcE-qrSSFexC7bfN1o2rSZziHeGNURGv9i4eDc/s640/main_window.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Main window of the application&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; font-family: , &amp;quot;blinkmacsystemfont&amp;quot; , &amp;quot;roboto&amp;quot; , &amp;quot;open sans&amp;quot; , &amp;quot;helvetica neue&amp;quot; , sans-serif; font-size: 13px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
</description><link>http://ssrebelious.blogspot.com/2016/09/environmental-monitoring-app.html</link><author>noreply@blogger.com (Yury Ryabov)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj7Low6e1DWY4EAoS3c5Z6uAu2G618-CFtKzMdetFM-iyt2KHSDwmC8SU6xPjrc0oanWXI__epBjYKto3g9oAAfMN-2IYfw2R5pr13cJPcE-qrSSFexC7bfN1o2rSZziHeGNURGv9i4eDc/s72-c/main_window.png" height="72" width="72"/><thr:total>1</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3120553115257874322.post-2668068324610982816</guid><pubDate>Tue, 23 Aug 2016 22:41:00 +0000</pubDate><atom:updated>2016-08-24T02:41:26.211+04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Peewee</category><category domain="http://www.blogger.com/atom/ns#">Python</category><category domain="http://www.blogger.com/atom/ns#">SQLite</category><title>UUID Field for the Peewee ORM</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
I wanted to have UUID fields in my &lt;a href=&quot;http://docs.peewee-orm.com/&quot; target=&quot;_blank&quot;&gt;Peewee&lt;/a&gt;-bsead models for the SQLite database. I quickly found ready-to-use code, but it lacked one important thing - automatic uuid generation. Here is the solution:&lt;/div&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-color: #2b2b2b; color: #a9b7c6; font-family: &#39;Source Code Pro&#39;; font-size: 12,0pt;&quot;&gt;&lt;span style=&quot;color: #cc7832; font-weight: bold;&quot;&gt;import &lt;/span&gt;uuid
&lt;span style=&quot;color: #cc7832; font-weight: bold;&quot;&gt;from &lt;/span&gt;peewee &lt;span style=&quot;color: #cc7832; font-weight: bold;&quot;&gt;import &lt;/span&gt;Field


&lt;span style=&quot;color: #cc7832; font-weight: bold;&quot;&gt;class &lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;UIDField&lt;/span&gt;(Field):
    db_field = &lt;span style=&quot;color: teal;&quot;&gt;&#39;uid&#39;&lt;/span&gt;&lt;span style=&quot;color: teal;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color: teal;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #cc7832; font-weight: bold;&quot;&gt;def &lt;/span&gt;&lt;span style=&quot;color: #b200b2;&quot;&gt;__init__&lt;/span&gt;(&lt;span style=&quot;color: #94558d;&quot;&gt;self&lt;/span&gt;&lt;span style=&quot;color: #cc7832;&quot;&gt;, &lt;/span&gt;*args&lt;span style=&quot;color: #cc7832;&quot;&gt;, &lt;/span&gt;**kwargs):
        &lt;span style=&quot;color: #8888c6;&quot;&gt;super&lt;/span&gt;().&lt;span style=&quot;color: #b200b2;&quot;&gt;__init__&lt;/span&gt;(*args&lt;span style=&quot;color: #cc7832;&quot;&gt;, &lt;/span&gt;**kwargs)
        &lt;span style=&quot;color: #94558d;&quot;&gt;self&lt;/span&gt;.default = uuid.uuid4

    &lt;span style=&quot;color: #cc7832; font-weight: bold;&quot;&gt;def &lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;db_value&lt;/span&gt;(&lt;span style=&quot;color: #94558d;&quot;&gt;self&lt;/span&gt;&lt;span style=&quot;color: #cc7832;&quot;&gt;, &lt;/span&gt;value):
        &lt;span style=&quot;color: #cc7832; font-weight: bold;&quot;&gt;return &lt;/span&gt;&lt;span style=&quot;color: #8888c6;&quot;&gt;str&lt;/span&gt;(value)  &lt;span style=&quot;color: grey;&quot;&gt;# convert UUID to str&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #cc7832; font-weight: bold;&quot;&gt;def &lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;python_value&lt;/span&gt;(&lt;span style=&quot;color: #94558d;&quot;&gt;self&lt;/span&gt;&lt;span style=&quot;color: #cc7832;&quot;&gt;, &lt;/span&gt;value):
        &lt;span style=&quot;color: #cc7832; font-weight: bold;&quot;&gt;return &lt;/span&gt;uuid.UUID(value)  &lt;span style=&quot;color: grey;&quot;&gt;# convert str to UUID&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
</description><link>http://ssrebelious.blogspot.com/2016/08/uuid-field-for-peewee-orm.html</link><author>noreply@blogger.com (Yury Ryabov)</author><thr:total>2</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3120553115257874322.post-7394850343663331700</guid><pubDate>Sun, 08 Nov 2015 23:33:00 +0000</pubDate><atom:updated>2015-11-09T03:36:51.574+04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Python</category><category domain="http://www.blogger.com/atom/ns#">QGIS</category><title>A satisfied customer</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Recently I did a QGIS scripting job and here is the feedback from an extremly satisfied customer:&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;em class=&quot;o-break-word o-white-space-pre-line ng-binding ng-scope&quot; data-ng-if=&quot;item.feedback.comment&quot;&gt;It was fantastic to work with Yury. He provided an excellent product, that went far beyond what I was expecting. I will certainly be contacting Yury in the future for any jobs that relate to GIS and python scripting. Communication was excellent and his ability to understand the job requirement was very impressive. A+++&lt;/em&gt;&lt;/blockquote&gt;
&lt;br /&gt;
Guys, if you are in need of geoprocessing tool for your project - don&#39;t hesitate to contact me ;-)&amp;nbsp;&lt;/div&gt;
</description><link>http://ssrebelious.blogspot.com/2015/11/a-satisfied-customer.html</link><author>noreply@blogger.com (Yury Ryabov)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3120553115257874322.post-8192191374156337836</guid><pubDate>Thu, 22 Oct 2015 21:38:00 +0000</pubDate><atom:updated>2015-10-23T01:38:44.221+04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Python</category><category domain="http://www.blogger.com/atom/ns#">QGIS</category><category domain="http://www.blogger.com/atom/ns#">R</category><title>My QGIS Processing Scripts at GitHub </title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
This is probably my shortest post ever.&lt;br /&gt;
&lt;br /&gt;
All my QGIS processing scripts (R and Python) and models that I already blogged about, plus some extra are now &lt;a href=&quot;https://github.com/ssrebelious/QGIS_processing_scripts&quot; target=&quot;_blank&quot;&gt;available at GitHub&lt;/a&gt;.&lt;/div&gt;
</description><link>http://ssrebelious.blogspot.com/2015/10/my-qgis-processing-scripts-at-github.html</link><author>noreply@blogger.com (Yury Ryabov)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3120553115257874322.post-8761762221184495438</guid><pubDate>Thu, 18 Jun 2015 16:27:00 +0000</pubDate><atom:updated>2015-06-18T20:27:36.298+04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">GIS</category><category domain="http://www.blogger.com/atom/ns#">maps</category><category domain="http://www.blogger.com/atom/ns#">OSM</category><category domain="http://www.blogger.com/atom/ns#">QGIS</category><title>A Quick Map With QGIS and OSM</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
What I love about QGIS is that one is able to create a nice map quickly. The other day I was asked to make a situation map for the project we are working on to include it into presentation. Аll I had was a laptop with no relevant spatial data at all, but with QGIS installed (I even had no mouse to draw something). Though it was more than enough: I loaded OSM as a base layer and used annotation tool to add more sense to it. Voilà:&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgAXx6xP6eOXqvoOSGXmgm13ZMRwVcM8VG9ypznnPk3MfTdZPF_Jqhtl-YHF9gKCMctgAKqVIsnXHz-hxR46H7w6Ld5lr2wCHEtLvf4tsmtNh5r6sFtlKUUB2uH8F90XFKJQvGuTKfYESE/s1600/%25D0%259A%25D0%25B0%25D1%2580%25D1%2582%25D0%25B0_%25D0%25BA%25D1%2580%25D0%25BE%25D0%25BD%25D1%2588%25D1%2582%25D0%25B0%25D0%25B4%25D1%2582%25D0%25B0.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;398&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgAXx6xP6eOXqvoOSGXmgm13ZMRwVcM8VG9ypznnPk3MfTdZPF_Jqhtl-YHF9gKCMctgAKqVIsnXHz-hxR46H7w6Ld5lr2wCHEtLvf4tsmtNh5r6sFtlKUUB2uH8F90XFKJQvGuTKfYESE/s640/%25D0%259A%25D0%25B0%25D1%2580%25D1%2582%25D0%25B0_%25D0%25BA%25D1%2580%25D0%25BE%25D0%25BD%25D1%2588%25D1%2582%25D0%25B0%25D0%25B4%25D1%2582%25D0%25B0.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
</description><link>http://ssrebelious.blogspot.com/2015/06/a-quick-map-with-qgis-and-osm.html</link><author>noreply@blogger.com (Yury Ryabov)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgAXx6xP6eOXqvoOSGXmgm13ZMRwVcM8VG9ypznnPk3MfTdZPF_Jqhtl-YHF9gKCMctgAKqVIsnXHz-hxR46H7w6Ld5lr2wCHEtLvf4tsmtNh5r6sFtlKUUB2uH8F90XFKJQvGuTKfYESE/s72-c/%25D0%259A%25D0%25B0%25D1%2580%25D1%2582%25D0%25B0_%25D0%25BA%25D1%2580%25D0%25BE%25D0%25BD%25D1%2588%25D1%2582%25D0%25B0%25D0%25B4%25D1%2582%25D0%25B0.png" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3120553115257874322.post-2400332083022455800</guid><pubDate>Wed, 10 Jun 2015 21:03:00 +0000</pubDate><atom:updated>2015-06-27T21:22:44.884+04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">PostGIS</category><category domain="http://www.blogger.com/atom/ns#">PyQGIS</category><category domain="http://www.blogger.com/atom/ns#">Python</category><category domain="http://www.blogger.com/atom/ns#">QGIS</category><title>How to Import Layer into PostGIS Database Using PyQGIS</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
This is strange, but I was unable to find instruction about importing QGIS layers into PostGIS database with PyQGIS API. The PyQGIS cookbook has the example of exporting layers as .shp-files via&amp;nbsp;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;QgsVectorFileWriter.writeAsVectorFormat()&lt;/span&gt; function&amp;nbsp;and says that the other other OGR-supported formats are available to use in this function as well. PostGIS is supported by OGR so &lt;a href=&quot;http://gis.stackexchange.com/q/87404/5666&quot; target=&quot;_blank&quot;&gt;people got confused and try to use this function to import data to the PostGIS&lt;/a&gt;&amp;nbsp;with no success and have to write generic import functions.&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
After of couple of hours of searching the internet for the solution I gave up and decided to find the answer the hard way: started to search through the source code for the &lt;i&gt;DB Manager&lt;/i&gt; plugin that has this nice &quot;import layer&quot; feature. It took about 20 minuets to trace down the function that was in charge of the import and it was&amp;nbsp;&lt;span style=&quot;text-align: left;&quot;&gt;&lt;a href=&quot;http://qgis.org/api/2.8/classQgsVectorLayerImport.html&quot; target=&quot;_blank&quot;&gt;QgsVectorLayerImport.importLayer()&lt;/a&gt;. But the quest wasn&#39;t over yet! The documentation says nothing about provider names that are accepted by this function. &quot;PostgreSQL&quot; would be the obvious name for the provider as it is the name for the &lt;i&gt;PostgeSQL&lt;/i&gt; provider in OGR, but it is not the case. I had to go through the source code of &lt;i&gt;DB Manager&lt;/i&gt; again and&amp;nbsp;luckily&amp;nbsp;in comments (and there are quite a few of them in &lt;i&gt;DB Manager&lt;/i&gt;: I didn&#39;t find a single&amp;nbsp;doc-string&amp;nbsp;there) the author wrote that it is &quot;postgres&quot; for the &lt;i&gt;PostgreSQL&lt;/i&gt;. &lt;b&gt;UPD&lt;/b&gt;: the function to list available providers is &lt;span style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;QgsProviderRegistry.instance().providerList().&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;text-align: left;&quot;&gt;Now here is the very basic example code of importing QGIS layer into PostGIS:&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;pre class=&quot;brush: python&quot;&gt;uri = &quot;dbname=&#39;test&#39; host=localhost port=5432 user=&#39;user&#39; password=&#39;password&#39; key=gid type=POINT table=\&quot;public\&quot;.\&quot;test\&quot; (geom) sql=&quot;
crs = None
# layer - QGIS vector layer
error = QgsVectorLayerImport.importLayer(layer, uri, &quot;postgres&quot;, crs, False, False)
if error[0] != 0:
    iface.messageBar().pushMessage(u&#39;Error&#39;, error[1], QgsMessageBar.CRITICAL, 5)
&lt;/pre&gt;
&lt;/div&gt;
</description><link>http://ssrebelious.blogspot.com/2015/06/how-to-import-layer-into-postgis.html</link><author>noreply@blogger.com (Yury Ryabov)</author><thr:total>3</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3120553115257874322.post-3211172020343896405</guid><pubDate>Wed, 01 Apr 2015 13:07:00 +0000</pubDate><atom:updated>2015-04-01T17:07:17.504+04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">OTB</category><category domain="http://www.blogger.com/atom/ns#">QGIS</category><title>A Note About a &quot;#IND&quot;-Error in OfreoToolbox Classification Algorithms</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
One of the optional input for the creation of the classification models in OrfeoToolbox is XML image statistic file that is produced by Compute Image Second Order Statistics tool. If you opt to calculate this statistics - necessarily check the created XML file. If you will see &quot;#INF&quot; record in band statistics (i.e. &quot;1.#INF&quot;) - replace &quot;#INF&quot; with something like &quot;0e+32&quot; (&quot;1.#INF&quot; -&amp;gt; &quot;1.0e+32&quot;), or (a better solution) - calculate the statistics for this problematic band independently (probably with another tool) and completely replace the value.&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
If you leave &quot;#INF&quot; record in XML file, models for classification that will be created based on it will have &quot;#IND&quot; records and when you will try to run classification based upon these models - the process will be terminated complaining about unrecognised &quot;#IND&quot;-values, because values must be numeric and not characters.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
I don&#39;t know what causes the &quot;#INF&quot; records to appear in the first place, maybe not properly defined no-data values? In some cased it is impossible to provide correct no-data value due to limitations of the input field (I use OTB from within Processing module for QGIS).&amp;nbsp;&lt;/div&gt;
&lt;/div&gt;
</description><link>http://ssrebelious.blogspot.com/2015/04/a-note-about-ind-error-in-ofreotoolbox.html</link><author>noreply@blogger.com (Yury Ryabov)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3120553115257874322.post-676345647119008242</guid><pubDate>Thu, 26 Mar 2015 10:57:00 +0000</pubDate><atom:updated>2015-03-26T14:57:39.862+04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">disaster</category><category domain="http://www.blogger.com/atom/ns#">economy</category><category domain="http://www.blogger.com/atom/ns#">environment</category><category domain="http://www.blogger.com/atom/ns#">sustainable development</category><title>Why are natural environments often degraded in the name of economic progress even when this invites disaster, and how can this be overcome?</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
This was one of discussion questions of the Disasters and Ecosystems MOOC.&lt;br /&gt;
&lt;br /&gt;
Actually the answer is simple. The formula for successful environmental degradation consists of 2 variables - overpopulation and capitalism.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
When there are a lot of people - most of them a poor, uneducated and hungry. When you are hungry you will do everything to &lt;i&gt;become less hungry&lt;/i&gt;&amp;nbsp;&lt;b&gt;today&lt;/b&gt;&amp;nbsp;even if it can potentially lead to negative consequences &lt;b&gt;tomorrow&lt;/b&gt;, which you may not even foresee if you are uneducated.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Humans are good in adaptation. When the adaptation is strong enough it leads to abuse (for example, if you are well adopted at the stock market you start abusing it to increase your profit even if it will cost dearly to the other stakeholders - people value their own well-being much more than the other&#39;s and of course much more than the well-being of environment especially when they know that their own impact seems negligible compared to impact of the entire population). &amp;nbsp;When you live in condition of free market of capitalistic world - you are your only hope for &lt;i&gt;not being hungry&lt;/i&gt;&amp;nbsp;(or &lt;i&gt;being more wealthy&lt;/i&gt;) &lt;b&gt;now&lt;/b&gt;. And as you know from the economic theory - the capitalist economy needs a constant grows of consumption and production - so you need more and more resources to just sustain the economy. In conditions of capitalist market people value &lt;b&gt;today&#39;s&lt;/b&gt; profit much more than losses of &lt;b&gt;tomorrow&lt;/b&gt;.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
You see - the capitalist economy needs people to consume more and more; more people - more consumption; more people - more poverty and lack of education; more hungry uneducated people people - more people willing to do anything to survive &lt;b&gt;now&lt;/b&gt; and don&#39;t even bother themselves about the future.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Overpopulation and a consumption society (created by capitalist economy) inter-stimulate each other and destroy the environment for the &lt;b&gt;today&#39;s&lt;/b&gt; profits or food and doesn&#39;t care much of the consequences of &lt;b&gt;tomorrow&lt;/b&gt; because most are either uneducated or doesn&#39;t care at all plus you have to live through &lt;b&gt;today&lt;/b&gt;&amp;nbsp;to face consequences of your actions &lt;b&gt;tomorrow&lt;/b&gt; (a day-by-day living).&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Obviously there are 3 steps to improve the situation:&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;Decrease the population.&lt;/li&gt;
&lt;li&gt;Educate people.&lt;/li&gt;
&lt;li&gt;Create new sustainable economy model that would equally value &lt;b&gt;tomorrow&#39;s&lt;/b&gt; losses and &lt;b&gt;today&#39;s &lt;/b&gt;profits, and would not rely on constantly increasing consumption.&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
</description><link>http://ssrebelious.blogspot.com/2015/03/why-are-natural-environments-often.html</link><author>noreply@blogger.com (Yury Ryabov)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3120553115257874322.post-5487672515051107829</guid><pubDate>Sun, 08 Feb 2015 14:39:00 +0000</pubDate><atom:updated>2015-02-08T18:39:54.395+04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">imagery</category><category domain="http://www.blogger.com/atom/ns#">OTB</category><category domain="http://www.blogger.com/atom/ns#">pansharpening</category><category domain="http://www.blogger.com/atom/ns#">R</category><category domain="http://www.blogger.com/atom/ns#">spatial data</category><title>Pan-sharpening Using R</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
In my previous post I described how to perform &lt;a href=&quot;http://ssrebelious.blogspot.com/2015/01/pansharpening-in-qgis-using-qtb.html&quot; target=&quot;_blank&quot;&gt;pan-sharpening using OrfeoToolbox and QGIS&lt;/a&gt;. This time I will show you how to do this in R. At the bottom you will find several functions I wrote on top of the &#39;raster&#39; package that allow a convenient pan-sharpening in R.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h3 style=&quot;text-align: justify;&quot;&gt;
Motivation&lt;/h3&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
You may wonder why I even bothered myself with pan-sharpening in R when I already have a nice model for pan-sharpening in QGIS. See, one can&#39;t control the data-type of the imagery returned by pan-sharpening that involves OTB. This leads to some unpleasant consequences: during pan-sharpening one will get floating point pixel values even if in initial values were integers. So for example a 600 MiB multi-spectral imagery (with integer pixel values) after pan-sharpening will grow to 5.2 GB. But if we will change datatype of the resulting imagery to force it store only integers it size will be reduced from 5.2 to 2.8 GB which is a huge difference. &#39;raster&#39; package in R allows to control output datatype. Plus using R you can play with different filtering options to play with.&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h3 style=&quot;text-align: justify;&quot;&gt;
The Theory&lt;/h3&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;div&gt;
In OTB pan-sharpening is performed&amp;nbsp;&lt;a href=&quot;http://www.orfeo-toolbox.org/CookBook/CookBooksu36.html#x57-770004.2.2&quot; target=&quot;_blank&quot;&gt;using following well-known formula&lt;/a&gt;:&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjC8bsPKNnR0A4fIZDinb9759fyB1wQ_QT3oYzjy1FJ5JncM8UFRj8FEgy_kNVJo0aMSgyetdky-Vh2Gw1ySBkj5lKpkwoRCzTIYgSmMiY6ui0FIDzAlmzyIbMHSPYG7hDVcIsyepjCDmY/s1600/Formula_OTB_pansharpening.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjC8bsPKNnR0A4fIZDinb9759fyB1wQ_QT3oYzjy1FJ5JncM8UFRj8FEgy_kNVJo0aMSgyetdky-Vh2Gw1ySBkj5lKpkwoRCzTIYgSmMiY6ui0FIDzAlmzyIbMHSPYG7hDVcIsyepjCDmY/s1600/Formula_OTB_pansharpening.png&quot; height=&quot;64&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;-webkit-text-stroke-width: 0px; font-family: &#39;Times New Roman&#39;; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px;&quot;&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;text-align: start;&quot;&gt;Where&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;zptmcmrm-&quot; style=&quot;text-align: start;&quot;&gt;i&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;text-align: start;&quot;&gt;and&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;zptmcmrm-&quot; style=&quot;text-align: start;&quot;&gt;j&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;text-align: start;&quot;&gt;are pixels indices,&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;zptmcmrm-&quot; style=&quot;text-align: start;&quot;&gt;PAN&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;text-align: start;&quot;&gt;is the panchromatic image,&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;zptmcmrm-&quot; style=&quot;text-align: start;&quot;&gt;XS&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;text-align: start;&quot;&gt;is the multi-spectral image and&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;zptmcmrm-&quot; style=&quot;text-align: start;&quot;&gt;PAN&lt;/span&gt;&lt;sub style=&quot;text-align: start;&quot;&gt;&lt;span class=&quot;zptmcmrm-x-x-74&quot; style=&quot;font-size: 12px;&quot;&gt;smooth&lt;/span&gt;&lt;/sub&gt;&lt;span style=&quot;text-align: start;&quot;&gt;&amp;nbsp;is the panchromatic image smoothed with a kernel to fit the multi-spectral image scale.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;text-align: start;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
We will implement exact the same approach using &#39;raster&#39; package for R.&lt;br /&gt;
&lt;span style=&quot;text-align: start;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;h3&gt;
&lt;span style=&quot;text-align: start;&quot;&gt;Code Usage and Result&lt;/span&gt;&lt;/h3&gt;
&lt;div&gt;
As pan-sharpening is the type of procedure that will reoccur over some time I decided to write generic functions for pan-sharpening itself and for saving the results to have easier time in future.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
The usage is as simple as:&lt;/div&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;pan &amp;lt;- raster(&#39;pan.tif&#39;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;multi &amp;lt;- brick(&#39;multi.tif&#39;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;pansharp &amp;lt;- processingPansharp(pan, multi)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;output_path &amp;lt;- &#39;path_and_filename_without_extention&#39; &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;saveResult(pansharp, output_path)&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Here you are the example results from the script and from the OTB model for one of the illegal landfills in Russia:&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiGvDpAINrRM3wgQzSiob6X3zV6_CdWX-_lMIO9NYnYst7lcd20jWBrkUFoGU5iw6lTQr9TO6snIBfHcyT9c_7Y6CpMaG8DI3TBYnE6akF56lSKFer07QM8rcEXKBgXpdvuL1fnOdg7uzk/s1600/initial_multi.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;Initial multi-band raster&quot; border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiGvDpAINrRM3wgQzSiob6X3zV6_CdWX-_lMIO9NYnYst7lcd20jWBrkUFoGU5iw6lTQr9TO6snIBfHcyT9c_7Y6CpMaG8DI3TBYnE6akF56lSKFer07QM8rcEXKBgXpdvuL1fnOdg7uzk/s1600/initial_multi.png&quot; height=&quot;426&quot; title=&quot;Initial multi-band raster&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Initial multi-band raster&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjqVN-NO-4O4_wGQ8odmH6kCQMG4EBRdQtIP4ZIc1sjna7GcmbGL82Z84dbTE5K2PGEhO5gRxPYFEBCLBS40IpSN7gdAPeZ0WpbXv9rohAPETpNpCutaUa3GgR2uvwZ71heSutOpV_moQs/s1600/initial_panchrome.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;Initial panchromatic raster&quot; border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjqVN-NO-4O4_wGQ8odmH6kCQMG4EBRdQtIP4ZIc1sjna7GcmbGL82Z84dbTE5K2PGEhO5gRxPYFEBCLBS40IpSN7gdAPeZ0WpbXv9rohAPETpNpCutaUa3GgR2uvwZ71heSutOpV_moQs/s1600/initial_panchrome.png&quot; height=&quot;426&quot; title=&quot;Initial panchromatic raster&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Initial panchromatic raster&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5A6DbDEgNLTN1A06ois1DTPB_R52yXfC52G3aDZoyhpu7GQfFYyCBiV2RV3DFfGRLczR1iM6H2qLScOKf91m6RRUKBG7YJj3NdhOuAa2q4pqlfBtcarxuUZzSPImkeeSDl2QydDqAe-E/s1600/R_pansharp_result.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;Result of pan-sharpening using R script&quot; border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5A6DbDEgNLTN1A06ois1DTPB_R52yXfC52G3aDZoyhpu7GQfFYyCBiV2RV3DFfGRLczR1iM6H2qLScOKf91m6RRUKBG7YJj3NdhOuAa2q4pqlfBtcarxuUZzSPImkeeSDl2QydDqAe-E/s1600/R_pansharp_result.png&quot; height=&quot;426&quot; title=&quot;Result of pan-sharpening using R script&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Result of pan-sharpening using R script&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;span style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;Result of pan-sharpening using OTB&quot; border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhyUn89Dp2UupPq_x_kgAAluW8qtlhoD_Hgjv2FFQDzjRrT9-40qJvxIXH8BSPFAWUdiUPeykYBczR8Tx4UhyogkNTcY8-gQsTnVRhux-Tt76jzz7JFsImfb51AA7JmlY4c3Q_eATO__3I/s1600/OTB_pansharp_result.png&quot; height=&quot;426&quot; title=&quot;Result of pan-sharpening using OTB&quot; width=&quot;640&quot; /&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Result of pan-sharpening using OTB&lt;br /&gt;
&lt;br /&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Which output do you like better: from OTB or R? Comparing both output results you can notice that the output from R bears heavier filtering markings than the one from OTB. On the other hand R output has more hues of the green colours which actually helps in distinguishing different types of vegetation. As you will see in the code - one can easily adjust or modify procedure of filtering panchromatic raster (&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;extractLPF()&lt;/span&gt; function) in order to get desired output.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h3 style=&quot;text-align: justify;&quot;&gt;
The code&lt;/h3&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;/div&gt;
&lt;pre class=&quot;brush: r&quot;&gt;
library(raster)


# Create needed functions -------------------------------------------------

pansharpFun &lt;- function(raster){
    &#39;
    This function pansharpens a raster
    &#39; 
    # @param raster - Raster object with 3 bands (to-be-pansharpened, high-res and low-frequency component of the high-res image)
    # @param band - band numver, integer
    # @return pansharpened_raster - pansharpened Raster object
    # pansharp = Lowres * Highres / LPF[Highres]
    
    pansharpened_raster &lt;- (raster[,1] * raster[,2]) / raster[,3]
}

extractLPF &lt;- function(pan, multi, filter = &#39;auto&#39;, fun = mean) {
    &#39;
    Returns a low-frequency component of the high-resolution raster by the
        filter adjusted to the low-resolution raster
    &#39;
    # @param pan - a high-resolution panchromatic raster - Raster object
    # @param multi - low-resolution raster to be pansharpened - Raster object
    # @param filter - a smoothing wondow - matrix
    # @param fun - a function to process filter (part of the focal() function)
    # @return LPF - a low-frequency component of the high-resolution raster - Raster object
    
    # Adjust filter size 
    if (filter == &#39;auto&#39;) {
        pan_res &lt;- res(pan) # (x, y) resolution of the panchromatic raster in CRS units (?)
        multi_res &lt;- res(multi) # (x, y) resolution of the lowres raster in CRS units (?)
        x_res_ratio &lt;- round(multi_res[1]/pan_res[1])
        y_res_ratio &lt;- round(multi_res[2]/pan_res[2])
        total &lt;- x_res_ratio + y_res_ratio
        filter &lt;- matrix(1, nc = x_res_ratio, nr = y_res_ratio)
        
        # Enshure that the matrix has an uneven number of colums and rows (needed by focal())
        if (nrow(filter)%%2 == 0) {
            filter &lt;- rbind(filter, 0)
        } 
        if (ncol(filter)%%2 == 0) {
            filter &lt;- cbind(filter, 0)
        }
        
    LPF &lt;- focal(pan, w = filter, fun = fun) # low-frequency component
    
}  


processingPansharp &lt;- function(pan, multi, filter = &#39;auto&#39;, fun = mean){
    &#39; 
    Pansharpening routine
    &#39;
    # @param pan - a high-resolution panchromatic raster - Raster object
    # @param multi - low-resolution raster to be pansharpened - Raster object
    # @param filter - a smoothing wondow - matrix
    # @param fun - a function to process filter (part of the focal() function)
    # @return pansharp - pansharpened &#39;multi&#39; raster - Raster object

    # Check if input parameters are valid - we can loose a lot of time if some of the inputs is wrong
      
    LPF &lt;- extractLPF(pan, multi, filter, fun)
        
    multi &lt;- resample(multi, pan) # resample low-resolution image to match high-res one
        
    all &lt;- stack(multi, pan, LPF)
    
    bands &lt;- nbands(multi)
    pan_band &lt;- bands + 1
    lpf_band &lt;- bands + 2
    
    # Pansharpen layers from low-resolution raster one by one
    pansharp_bands &lt;- list()
    for (band in 1:bands) {
        subset &lt;- all[[c(band, pan_band, lpf_band)]]
        raster &lt;- calc(subset, pansharpFun)
        pansharp_bands[[band]] &lt;- raster
    }
    
    pansharp &lt;- stack(pansharp_bands)
}

saveResult &lt;- function(raster, path, format = &#39;GTiff&#39;, datatype = &#39;INT2S&#39;){
    &#39;
    Saves Raster object to location
    &#39;
    # @param raster - raster to be saved - Raser object
    # @param path - path including filename without extention - string
    # @param format - format of the output raster accordingly to writeRaster() function - string
    # @param datatype - datatype of the raster accordingly to writeRaster() - string
    
    writeRaster(raster, 
                path, 
                format = format, 
                datatype = datatype, 
                overwrite = T)
}


# Do pansharpening --------------------------------------------------------


pan &lt;- raster(&#39;pan.tif&#39;)
multi &lt;- brick(&#39;multi.tif&#39;)
pansharp &lt;- processingPansharp(pan, multi)
output_path &lt;- &#39;r_pansharp-new&#39; # includes path and filename but not the extention
saveResult(pansharp, output_path)

&lt;/pre&gt;
&lt;/div&gt;
</description><link>http://ssrebelious.blogspot.com/2015/02/pan-sharpening-using-r.html</link><author>noreply@blogger.com (Yury Ryabov)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjC8bsPKNnR0A4fIZDinb9759fyB1wQ_QT3oYzjy1FJ5JncM8UFRj8FEgy_kNVJo0aMSgyetdky-Vh2Gw1ySBkj5lKpkwoRCzTIYgSmMiY6ui0FIDzAlmzyIbMHSPYG7hDVcIsyepjCDmY/s72-c/Formula_OTB_pansharpening.png" height="72" width="72"/><thr:total>4</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3120553115257874322.post-4262793002548621378</guid><pubDate>Sat, 31 Jan 2015 16:25:00 +0000</pubDate><atom:updated>2015-02-09T01:43:14.001+04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">imagery</category><category domain="http://www.blogger.com/atom/ns#">OTB</category><category domain="http://www.blogger.com/atom/ns#">pansharpening</category><category domain="http://www.blogger.com/atom/ns#">Processing</category><category domain="http://www.blogger.com/atom/ns#">QGIS</category><title>Pansharpening in QGIS Using QTB</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;UPD:&lt;/b&gt; also you may want to check out my post on &lt;a href=&quot;http://ssrebelious.blogspot.com/2015/02/pan-sharpening-using-r.html&quot; target=&quot;_blank&quot;&gt;Pansharpening using R&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
For a long time I wanted to play with the &lt;a href=&quot;http://www.orfeo-toolbox.org/otb/&quot; target=&quot;_blank&quot;&gt;OrfeoToolBox&lt;/a&gt; instruments (and its GUI named Monteverdi) - a set of powerfull tools to process remote-sensing imagery. Finally I got the opportunity - I needed to perform pansharpening of the World-View-2 scene and I decided to make it using OTB modules available via QGIS &lt;i&gt;Processing&lt;/i&gt; toolbox.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
To make OTB modules available in QGIS you need to install it on your system. Official site provides good &lt;a href=&quot;http://www.orfeo-toolbox.org/otb/download.html&quot; target=&quot;_blank&quot;&gt;instructions&lt;/a&gt; on how to do it. When you have OTB installed you need to enable it in QGIS. Go &lt;i&gt;Processing&lt;/i&gt; -&amp;gt; &lt;i&gt;Options and configuration&lt;/i&gt; -&amp;gt; &lt;i&gt;Providers&lt;/i&gt;, activate OTB and provide folder information if needed:&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiHnHrwXYATEQeleUPDUEZQJjw71oZtivNRlcqW_mWYqP0MiRnvBtaLEWgXIsgaCaVtjghyphenhyphenvTYafNuYd4K33MmkEiIPM3x7SCFZ78bsA1ngXMjIpyuvZaKumZOK_p4GgUK04kqMh2W8oO0/s1600/enable_OTB.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;A dialogue to enable OTB modules in QGIS&quot; border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiHnHrwXYATEQeleUPDUEZQJjw71oZtivNRlcqW_mWYqP0MiRnvBtaLEWgXIsgaCaVtjghyphenhyphenvTYafNuYd4K33MmkEiIPM3x7SCFZ78bsA1ngXMjIpyuvZaKumZOK_p4GgUK04kqMh2W8oO0/s1600/enable_OTB.png&quot; height=&quot;312&quot; title=&quot;OTB Processing activation&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Pansharpening is made in two steps: 1) resampling of the low resolution raster via &lt;i&gt;Superimpose sensor&lt;/i&gt; tool; 2) pansharpening using &lt;i&gt;Pansharpening&lt;/i&gt; tool. Alternatively you can do it using one command line (no QGIS or other GUI needed) in your OS&#39;s console:&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;background-color: #eeeeee; color: #222222; font-family: Consolas, Menlo, Monaco, &#39;Lucida Console&#39;, &#39;Liberation Mono&#39;, &#39;DejaVu Sans Mono&#39;, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, monospace, serif; font-size: 14.3999996185303px; line-height: 18px; text-align: left; white-space: pre-wrap;&quot;&gt;otbcli_BundleToPerfectSensor -inp pan_image -inxs xs_image -out output_image&lt;/span&gt;. &amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Performing two steps instead of just one is super-boring! Lets create a model that will allow us to perform pansharpening in QGIS in one step (virtually). Go to Processing &lt;i&gt;Toolbox&lt;/i&gt; -&amp;gt; &lt;i&gt;Models&lt;/i&gt; -&amp;gt; &lt;i&gt;Tools&lt;/i&gt; and start creating new model:&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjbX7vNPWZSD-7Qk4V_bnNj7aGYdMxJZjKt6yFUudwr7FbKK26KND68QTnwRVTf91vEyzArXH46DsEDuRrl53zhsdp1Oux1FGB0us4QlwBgfZbWr-GJ_XsHTqJoQJRnJk0u4hvNpdCdisU/s1600/create_new_model.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Processing toolbox location of &#39;Create new model tool&#39;&quot; border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjbX7vNPWZSD-7Qk4V_bnNj7aGYdMxJZjKt6yFUudwr7FbKK26KND68QTnwRVTf91vEyzArXH46DsEDuRrl53zhsdp1Oux1FGB0us4QlwBgfZbWr-GJ_XsHTqJoQJRnJk0u4hvNpdCdisU/s1600/create_new_model.png&quot; height=&quot;201&quot; title=&quot;Create new model&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
In the model creation window fill the fields of the model name and group name. Then add two rasters as inputs and name them:&amp;nbsp;&lt;i&gt;High_resolution_panchrom_raster&lt;/i&gt; and&amp;nbsp;&lt;i&gt;Low_resolution_raster&lt;/i&gt;. Now add the module named &lt;i&gt;Superimpose sensor&lt;/i&gt;&amp;nbsp;(&lt;i&gt;Orfeo Toolbox -&amp;gt; Geomentry -&amp;gt; Superimpose sensor&lt;/i&gt;)&amp;nbsp;and configure it to resample the &lt;i&gt;Low_resolution raster&lt;/i&gt;: use&amp;nbsp;&lt;i&gt;High_resolution_panchrom_raster&lt;/i&gt; as input in Reference input field and&amp;nbsp;&lt;i&gt;Low_resolution_raster&lt;/i&gt;&amp;nbsp;as input in &lt;i&gt;The image to reproject&lt;/i&gt; field&lt;i&gt;.&lt;/i&gt;&amp;nbsp;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhl0X1WMYzcToviRX92j8PYIBMGtFmdo83GTnZHivQcRc21QtbSPUCQbsxJ9UzhwJVviOHAiuf9U7U97nVn1dBjoig_ukvGXYNsW_9YnaoVzDaMYuQUEwYhTKjFf5vpFdPloz5KlBi8HeM/s1600/superimpose_sensor.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Superimpose sensor dialogue window&quot; border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhl0X1WMYzcToviRX92j8PYIBMGtFmdo83GTnZHivQcRc21QtbSPUCQbsxJ9UzhwJVviOHAiuf9U7U97nVn1dBjoig_ukvGXYNsW_9YnaoVzDaMYuQUEwYhTKjFf5vpFdPloz5KlBi8HeM/s1600/superimpose_sensor.png&quot; height=&quot;400&quot; title=&quot;Superimpose sensor&quot; width=&quot;343&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Add &lt;i&gt;Pansharpening (rsc)&lt;/i&gt; (&lt;i&gt;Orfeo Toolbox -&amp;gt; Geomentry -&amp;gt;&amp;nbsp;&lt;/i&gt;&lt;i&gt;Superimpose sensor&lt;/i&gt;) module to model. Use&amp;nbsp;&lt;i&gt;High_resolution_panchrom_raster&lt;/i&gt;&amp;nbsp;as input in the &lt;i&gt;Input PAN Image&lt;/i&gt; and output of the &lt;i&gt;Superimpose sensor&lt;/i&gt; as the input in the &lt;i&gt;Input XS Image&lt;/i&gt; field. Give a name (&lt;i&gt;pansharpened_OTB&lt;/i&gt;) for the &lt;i&gt;Output image&lt;/i&gt; to let model know that this is the final stage of the processing.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiw3eGLg6E3PYPi1-BYNAFDqXz1ucQI6gRrtKwErqkS5G5M1Mnn3WhHtCVNnRFMLQX0j3hgqFBJQRBdP8sORNutfApxzTmk0apu08GaFKrXPt6Si4dzePhYsGKPyfcfQ2Cci0BYTshPcSs/s1600/Pansharp_dialogue.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Pansharpening (rsc) dialogue window&quot; border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiw3eGLg6E3PYPi1-BYNAFDqXz1ucQI6gRrtKwErqkS5G5M1Mnn3WhHtCVNnRFMLQX0j3hgqFBJQRBdP8sORNutfApxzTmk0apu08GaFKrXPt6Si4dzePhYsGKPyfcfQ2Cci0BYTshPcSs/s1600/Pansharp_dialogue.png&quot; height=&quot;400&quot; title=&quot;Pansharpening (rsc)&quot; width=&quot;366&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Here how our model looks like in &lt;i&gt;Model builder&lt;/i&gt;:&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgR9ByiRBZVHUEL2kipbY04wBiOyalIKf3bJ9v2_GUxfn_lJVlyjO8X8v1e1Vgd8bdEZ1LUlqZbcLiT8elKe-CdeAmOhwRiygPFQYPoGuJsj0eEEOLUem6OnxEYINiObaobR2qWVnSSD5E/s1600/Model_pansharp_OTB.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Overview of the Pan-sharpening model in model builder&quot; border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgR9ByiRBZVHUEL2kipbY04wBiOyalIKf3bJ9v2_GUxfn_lJVlyjO8X8v1e1Vgd8bdEZ1LUlqZbcLiT8elKe-CdeAmOhwRiygPFQYPoGuJsj0eEEOLUem6OnxEYINiObaobR2qWVnSSD5E/s1600/Model_pansharp_OTB.png&quot; height=&quot;402&quot; title=&quot;Modeller window&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
And this is how it looks like when you launch it:&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhaLqv9xD76mXmsUhBD1d_NzJoMWFtgUHoIUGWFV6WgYMkPxVvTQ1X9vBV3CYvaDybDmqb020QTo5VR8W9nyHlbUBkruQoD4mRsZYAtsZYwktsraRT9pm5FkkItew6OcJMAXOvo77FgDJ8/s1600/Pansharp_model_dialogue.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Pan-sharpening model window&quot; border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhaLqv9xD76mXmsUhBD1d_NzJoMWFtgUHoIUGWFV6WgYMkPxVvTQ1X9vBV3CYvaDybDmqb020QTo5VR8W9nyHlbUBkruQoD4mRsZYAtsZYwktsraRT9pm5FkkItew6OcJMAXOvo77FgDJ8/s1600/Pansharp_model_dialogue.png&quot; height=&quot;336&quot; title=&quot;Pan-sharpening model window&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Also you can skip model creation process and just&amp;nbsp;&lt;a href=&quot;https://mega.co.nz/#!g9QlAT7A!Z-G2LKFILvQqBTDsbIOLV7hf8-_MvRfEAJhzMjyl1jc&quot; target=&quot;_blank&quot;&gt;download&lt;/a&gt; model that I created. You need to paste files from archive&#39;s &lt;i&gt;models&lt;/i&gt; folder into your &lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;/.qgis2/processing/models&lt;/span&gt; directory.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
If you will have issues running OTB Pansharpening it is likely that they will be covered in following gis.stackexchange topics:&amp;nbsp;&lt;a href=&quot;http://gis.stackexchange.com/q/124275/5666&quot; target=&quot;_blank&quot;&gt;OTB Pansharpening Error: Adapter for adaptPansharpening-bayes not found&lt;/a&gt; and&amp;nbsp;&lt;a href=&quot;http://gis.stackexchange.com/q/126374/5666&quot; target=&quot;_blank&quot;&gt;What causes OTB pansharpening ERROR: Inputs do not occupy the same physical space?&lt;/a&gt;&amp;nbsp;&lt;/div&gt;
&lt;/div&gt;
</description><link>http://ssrebelious.blogspot.com/2015/01/pansharpening-in-qgis-using-qtb.html</link><author>noreply@blogger.com (Yury Ryabov)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiHnHrwXYATEQeleUPDUEZQJjw71oZtivNRlcqW_mWYqP0MiRnvBtaLEWgXIsgaCaVtjghyphenhyphenvTYafNuYd4K33MmkEiIPM3x7SCFZ78bsA1ngXMjIpyuvZaKumZOK_p4GgUK04kqMh2W8oO0/s72-c/enable_OTB.png" height="72" width="72"/><thr:total>12</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3120553115257874322.post-5171376607127435199</guid><pubDate>Wed, 28 Jan 2015 22:13:00 +0000</pubDate><atom:updated>2015-01-29T02:13:16.688+04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">misc</category><title>A Dialogue With Bot</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Back in the days when ICQ was popular spam bots added you to their contact lists dozens times a day. But they were brute and ugly. At first they spew their spam links at your face when you added them, then they simply started to insert spam links in the body of the invitation. ICQ is long dead and spam-bots never bothered me in modern protocols... until some time ago.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;/div&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
A contact with the nick-name &lt;b&gt;dazzling.chick9&lt;/b&gt;&amp;nbsp;(according to the profile - a 22 (or so) years old girl) added my on skype. Well, I felt it was bot, but added it anyway. For reasons unknown it was unable to chat with me several times. It sent me messages like &#39;hi&#39; or &#39;hello&#39;, but didn&#39;t respond to me further. These greetings were sent the second I connected to the skype - it was obvious that these messages could be sent only by bot. But I waited patiently and today it finally started to talk to me:&lt;/div&gt;
&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: red;&quot;&gt;[13:51:52]&lt;/span&gt; &lt;span style=&quot;color: red;&quot;&gt;Amanda:&lt;/span&gt; hi&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: lime;&quot;&gt;[13:52:26] Me:&lt;/span&gt; hi&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: red;&quot;&gt;[13:52:55] Amanda:&lt;/span&gt; how are you? i&#39;m Amanda, I saw your Skype in the skype directory. &amp;nbsp;wanna chat ?&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: lime;&quot;&gt;[13:53:26] Me:&lt;/span&gt; chat about what?&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: red;&quot;&gt;[13:53:56] Amanda:&lt;/span&gt; I cannot wait until the summer is actually here, i can tone up my body more&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: lime;&quot;&gt;[13:55:46] Me:&lt;/span&gt; wow, you really think you can pass &lt;a href=&quot;http://en.wikipedia.org/wiki/Turing_test&quot; target=&quot;_blank&quot;&gt;turing test&lt;/a&gt;?&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: lime;&quot;&gt;[13:55:53] Me:&lt;/span&gt; lol&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: red;&quot;&gt;[13:56:14] Amanda:&lt;/span&gt; i love too show what i have, i love the attention from guys&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: red;&quot;&gt;[13:56:15] Amanda:&lt;/span&gt; what should i wear? yoga pants or spandex?&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: lime;&quot;&gt;[13:58:48] Me:&lt;/span&gt; a spanch bob outfit maybe? this bot is lame cause it doesn&#39;t attempt to understand what I&#39;m talking about&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: red;&quot;&gt;[13:59:18] Amanda:&lt;/span&gt; well, i sort of have my just a top on atm so you wanna c how it looks?&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: lime;&quot;&gt;[14:00:06] Me:&lt;/span&gt; yeah baby, send me that spam/scam/fishing link you prepared for me&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: red;&quot;&gt;[14:00:38] Amanda:&lt;/span&gt; my brothers computer does have a cam all you have 2 do is go two http://goo.gl/scam_or_virus_link&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: lime;&quot;&gt;[14:00:55] Me:&lt;/span&gt; bingo!&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: red;&quot;&gt;[14:01:27] Amanda: &lt;/span&gt;I love this way because its always works + its free. this way no one else sees. If my mom saw what i want too show you i would kill myself.&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: lime;&quot;&gt;[14:01:50] Me:&lt;/span&gt; I would love to see that&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: lime;&quot;&gt;[14:02:03] Me:&lt;/span&gt; (how you kill yourself)&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: red;&quot;&gt;[14:02:22] Amanda:&lt;/span&gt; i sorta want you two chat to me kinda dirty. i love being talked down to.&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: lime;&quot;&gt;[14:03:17] Me:&lt;/span&gt; Am I not dirty enough, stupid bot?&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: red;&quot;&gt;[14:03:49] Amanda:&lt;/span&gt; you make me really wet, listen i got it all ready, i will b there 4 you&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: lime;&quot;&gt;[14:05:05] Me:&lt;/span&gt; great! You know, I knew you are bot before you asked me &quot;how are you?&quot;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: red;&quot;&gt;[14:05:21] Amanda:&lt;/span&gt; k&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: lime;&quot;&gt;[14:05:31] Me:&lt;/span&gt; do you want to know how I knew it?&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: lime;&quot;&gt;[14:06:33] Me:&lt;/span&gt; if you want - just ask me ;-)&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: lime;&quot;&gt;[14:07:26] Me:&lt;/span&gt; Any way it was fun, dude)))&lt;/blockquote&gt;
&lt;/blockquote&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
I wonder how stupid people could be to sink that some random chick would approach them with a free striptease offer? Though I was amused with participation in the real-life Turing test. This bot imitated typing: it inserted message and waited about 30 second to actually send it so I would see &#39;typing...&#39; indication in chat window, though this disguise was ruined in its 4-th and 5-th messages which had only a second between them. Also the story told in conversation does not correspond to age indicated in profile - only a teenagerwould be concerned about her mom and use a brother&#39;s computer, not a 22+ woman. Amanda stopped responding and I blocked her and reported abuse. Also I never dared to follow the link despite I&#39;m using Linux, what if I really missed a free striptease? ;-)&lt;/div&gt;
&lt;/div&gt;
</description><link>http://ssrebelious.blogspot.com/2015/01/a-dialogue-with-bot.html</link><author>noreply@blogger.com (Yury Ryabov)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3120553115257874322.post-3700856070373275421</guid><pubDate>Sun, 18 Jan 2015 20:23:00 +0000</pubDate><atom:updated>2015-01-19T16:27:21.304+04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">disaster</category><category domain="http://www.blogger.com/atom/ns#">graph</category><category domain="http://www.blogger.com/atom/ns#">R</category><category domain="http://www.blogger.com/atom/ns#">science</category><category domain="http://www.blogger.com/atom/ns#">spatial data</category><title>How to Predict Where Will Next Disaster Strike?</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
It is amusing coincidence that another &lt;a href=&quot;http://en.wikipedia.org/wiki/MOOC&quot; target=&quot;_blank&quot;&gt;MOOC&lt;/a&gt; that I took this week (&lt;a href=&quot;https://www.coursera.org/course/geoint&quot; target=&quot;_blank&quot;&gt;Geospatial Intelligence &amp;amp; the Geospatial revolution&lt;/a&gt;) mentioned [natural] disasters. About the other course see my recent &lt;a href=&quot;http://ssrebelious.blogspot.ru/2015/01/disasters-myth-or-reality.html&quot; target=&quot;_blank&quot;&gt;Disasters: Myth or the Reality&lt;/a&gt; post.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
In Geospatial Intelligence they gave a weird assignment: one need to mark the location on the world map where the next international natural disaster will occur O_o. This is not and easy task by any means and the lecturer suggested to use one&#39;s &#39;gut feeling&#39; if one&#39;s knowledge is insufficient (I suppose it is close to impossible to find someone who can make such a prediction taking into account all the types of the disasters). Though the link to the &lt;a href=&quot;http://www.emdat.be/&quot; target=&quot;_blank&quot;&gt;International Disasters Database&lt;/a&gt; was given, so I accepted the challenge (to make a data-driven prediction). To predict the&amp;nbsp;&lt;i&gt;exact location&lt;/i&gt;&amp;nbsp;of the next disaster one would need a lot of data - far more that you can get out of that database so my goal was to make prediction at the country level. (BTW the graphs from my &lt;a href=&quot;http://ssrebelious.blogspot.ru/2015/01/disasters-myth-or-reality.html&quot; target=&quot;_blank&quot;&gt;post about disasters&lt;/a&gt; seems to be based on the data from this database - I saw one of them at that site)&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
I passed a query to the database and saved the output to process it with &lt;a href=&quot;http://en.wikipedia.org/wiki/CRAN_%28R_programming_language%29&quot; target=&quot;_blank&quot;&gt;R&lt;/a&gt;. The dataframe looks like this:&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEil4XeyaR9dHXRxJ9SAHB03mbf3WaBuiy3jkWfV3OVZwSTvo4gCgvoTgiFaaheX7_OcFoipsr9eEyaZG65V6gAIpSIr7Ro6vI6x2K9k-x7iwnVUhlimUt2w56V5xYrO2Q773DwMt3EWtjg/s1600/disasters_data_example.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;year | country | continent | occurrence | deaths | injured | homeless | total_affected | total_damage&quot; border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEil4XeyaR9dHXRxJ9SAHB03mbf3WaBuiy3jkWfV3OVZwSTvo4gCgvoTgiFaaheX7_OcFoipsr9eEyaZG65V6gAIpSIr7Ro6vI6x2K9k-x7iwnVUhlimUt2w56V5xYrO2Q773DwMt3EWtjg/s1600/disasters_data_example.png&quot; height=&quot;306&quot; title=&quot;Example of disasters dataset&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Example of disasters dataset&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
So how to predict the country with the next disaster? I came up with the idea to calculate cumulative average occurrence of disasters per country per year and plot it on the graph to see the trends. If I would just calculate average occurrence of disasters per country for the whole time of the observations I would have significant issues choosing from countries that would have close numbers. Plus the total average disasters per year can be misleading by itself due to it can be high because of high amount of disasters in the beginning of XX century but relatively low number in XXI. &amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The formula for the calculation of the cumulative average for the given year that I used was:&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Cumulative_Average = Total_Occurences / ( Given_Year - (Starting_Year - 1) ) ,&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;where:&lt;/span&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt; Total_Occurrences &lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;is the sum of occurrences of disasters for given country in time interval between the starting year and the given year (inclusive).&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;Here is the plot I got for the short-list countries (plotting the results for all the 180 countries from the dataset makes plot&amp;nbsp;&lt;/span&gt;unreadable&lt;span style=&quot;font-family: inherit;&quot;&gt;):&lt;/span&gt;&lt;/div&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjiwbGBCdfLrkA8ql7Ly-EN-7oU307GtVanVnfZa0650qL_Nw9iCGQ7d3oTpSpUz0IDY6qYUhNd2fY7iwx1xw6mvyM4PkAVniW5sjIU58x_OPyNCcu03DVYFmzAORkayHD7J9_1Z5dRet4/s1600/Cumulative_average_disasters.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;Cumulative average is growing rapidly since 1970s for Indonesia and China&quot; border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjiwbGBCdfLrkA8ql7Ly-EN-7oU307GtVanVnfZa0650qL_Nw9iCGQ7d3oTpSpUz0IDY6qYUhNd2fY7iwx1xw6mvyM4PkAVniW5sjIU58x_OPyNCcu03DVYFmzAORkayHD7J9_1Z5dRet4/s1600/Cumulative_average_disasters.png&quot; height=&quot;480&quot; title=&quot;Cumulative average number of disasters&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Cumulative average number of disasters&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
It is clear that China and Indonesia are the two most likely candidates for the next disaster to strike, with a China having a lead. I&#39;m not ready to provide insight on the reasons of the increasing number of natural disasters in the countries at the plot now (especially for Turkey and Iran). Maybe it is just that the events become documented more often?... It should be investigated further.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h3 style=&quot;text-align: justify;&quot;&gt;
The code&lt;/h3&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Here is the code to create the plot above. &lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&#39;sqldf&#39;&lt;/span&gt; package was really helpful for divide data for the short list countries from the rest of 180 countries.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;pre class=&quot;brush: r&quot;&gt;
library(ggplot2)
library(sqldf)
library(grid)
#library(gridExtra)


# Load natural disasters data ---------------------------------------------

dis &lt;- read.csv(&quot;~/R/Disasters/Natural_disasters.csv&quot;)

# Create data frame with average number of disasters per year -------------

average_events &lt;- data.frame(country = character(),
                             year = numeric(),
                             disasters_per_year = numeric(),
                             stringsAsFactors = F)

countries &lt;- unique(dis$country)

starting_year &lt;- min(dis$year) - 1 # we subtract 1 year to have numbers greater than 0 further on

for (country in countries) {
    data &lt;- dis[dis$country == country,] # we need data for one country at a time
    disasters_count &lt;- 0
    years &lt;- unique(data$year)
    
    for (year in years) {
        total_years &lt;- year - starting_year 
        y_data &lt;- data[data$year == year,]
        n_disasters &lt;- sum(y_data$occurrence)
        disasters_count &lt;- disasters_count + n_disasters
        average_disasters &lt;- disasters_count / total_years
        row &lt;- data.frame(country = country, year = year, disasters_per_year = average_disasters)
        average_events &lt;- rbind(average_events, row)
    }
    
}


# Plot data about average number of disasters per country per year --------


# Data for 180 countries is hard to plot, lets filter mots affected.
# Let&#39;s use SQL to query data: subset data for countries that had more than 0.6 disasters per year
# in any year after 2000
danger &lt;- sqldf(&#39;SELECT * FROM average_events WHERE country IN 
      (SELECT DISTINCT country FROM average_events WHERE disasters_per_year &gt;= 0.6 AND year &gt; 2000)&#39;)

p &lt;- ggplot(danger, aes (x = year, y = disasters_per_year)) + 
            geom_line(size = 1.2, aes(colour = country,  linetype = country)) +
            labs(title = &#39;Cumulative average number of disasters per year&#39;,
                 x = &#39;Year&#39;,
                 y = &#39;Average number of disasters cumulative&#39;) +
            guides(guide_legend(keywidth = 3, keyheight = 1)) +
            theme(axis.text.x = element_text(angle=0, hjust = NULL),
                  axis.title = element_text(face = &#39;bold&#39;, size = 14),
                  title = element_text(face = &#39;bold&#39;, size = 16),
                  legend.position = &#39;right&#39;,
                  legend.title = element_blank(),
                  legend.text = element_text(size = 12),
                  legend.key.width = unit(1.5, &#39;cm&#39;),
                  legend.key.height = unit(1, &#39;cm&#39;))
           
plot(p)
&lt;/pre&gt;
&lt;/div&gt;</description><link>http://ssrebelious.blogspot.com/2015/01/how-to-predict-where-will-next-disaster.html</link><author>noreply@blogger.com (Yury Ryabov)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEil4XeyaR9dHXRxJ9SAHB03mbf3WaBuiy3jkWfV3OVZwSTvo4gCgvoTgiFaaheX7_OcFoipsr9eEyaZG65V6gAIpSIr7Ro6vI6x2K9k-x7iwnVUhlimUt2w56V5xYrO2Q773DwMt3EWtjg/s72-c/disasters_data_example.png" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3120553115257874322.post-2106002734556565389</guid><pubDate>Fri, 16 Jan 2015 20:56:00 +0000</pubDate><atom:updated>2015-01-17T00:56:44.848+04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">disaster</category><category domain="http://www.blogger.com/atom/ns#">economy</category><category domain="http://www.blogger.com/atom/ns#">education</category><category domain="http://www.blogger.com/atom/ns#">environment</category><category domain="http://www.blogger.com/atom/ns#">environmental risk</category><category domain="http://www.blogger.com/atom/ns#">science</category><category domain="http://www.blogger.com/atom/ns#">sustainable development</category><title>Disasters: Myth or the Reality?</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
I enrolled a MOOC titled &quot;Disasters and Ecosystems: Resilience in a Changing Climate&quot; which is organised by the UNEP (and other organisations... which names I&#39;m going to learn by heart cause they have like 2 minutes of credits after each lecture O_o ). Not that I know nothing about disasters, risks or climate change (I&#39;m a geographer and ecologist after all), but I was curious about the product that was made by organisation of this class.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The third video (and first video that is not an introduction) they teach us about the disasters; differences between hazard and disaster; and risks. Well... the thing they told, the graphs they showed - that what inspired the title of this post.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h3 style=&quot;text-align: justify;&quot;&gt;
Terminology&lt;/h3&gt;
&lt;div&gt;
Here see some definitions they use.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;b&gt;Disaster&lt;/b&gt;.&amp;nbsp;&lt;span style=&quot;text-align: justify;&quot;&gt;When they say &quot;disaster&quot; they mean &quot;natural disaster&quot; that was enhanced by human [mismanagement].&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Risk&lt;/b&gt; - a potential losses due to disasters.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;Hazard &lt;/b&gt;- A dangerous phenomenon, substance, human activity or condition that may cause loss of life, injury or other health impacts, property damage, loss of livelihoods and services, social and economic disruption, or environmental damage.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;Exposure&lt;/b&gt; - People, property, systems, or other elements present in hazard zones that are thereby subject to potential losses.&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;b&gt;Vulnerability&lt;/b&gt; - the characteristics and circumstances of a community, system or asset that make it susceptible to the damaging effects of a hazard&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h3 style=&quot;text-align: justify;&quot;&gt;
Fails&lt;/h3&gt;
&lt;h4 style=&quot;text-align: justify;&quot;&gt;
The risk&lt;/h4&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
They presented a &quot;great&quot; formula for (a disaster) risk evaluation that they use in the UN:&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Risk = Hazard * Exposure * Vulnerability&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
where: &lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Exposure = People * ExposureTime&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Vulnarability&lt;/span&gt;&amp;nbsp;- succeptability to hazard.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Well these characteristics do correspond to the risk, but the formula is stupid! I &lt;a href=&quot;http://ssrebelious.blogspot.ru/2011/08/about-risks.html&quot; target=&quot;_blank&quot;&gt;already wrote&lt;/a&gt;&amp;nbsp;about that:&amp;nbsp;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Risk = Probability * Damage&lt;/span&gt;. And this formula actually corresponds to the definition they give (see Terminology section). We can&#39;t get a monetary outcome from their formula. We can&#39;t get numeric numeric output out of that formula at all: can you multiply &lt;b&gt;flood&lt;/b&gt; by &lt;b&gt;people&lt;/b&gt;? Can you???!!!&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h4 style=&quot;text-align: left;&quot;&gt;
A Disaster with Disasters&lt;/h4&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The fail with the risk evaluation is a common mistake, but the fail with disaster - that is what really cool!&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Take a look at this plot (which is from reading materials from the course):&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhs_eM6KqXQUVfK5sDtgZ_RtA8nEe18JeEixYDIIR86_2fxfFApzucdbWeexKTdWhO5HNZ9qF4REPVatDm4OvN0GOoIY_AH-wbOi6qeD-LI6zMOCF1efahyphenhyphenTEZm0dIm_cTv3aS2Ap2fJps/s1600/Exposure_graph.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhs_eM6KqXQUVfK5sDtgZ_RtA8nEe18JeEixYDIIR86_2fxfFApzucdbWeexKTdWhO5HNZ9qF4REPVatDm4OvN0GOoIY_AH-wbOi6qeD-LI6zMOCF1efahyphenhyphenTEZm0dIm_cTv3aS2Ap2fJps/s1600/Exposure_graph.png&quot; height=&quot;410&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
What can you conclude from this plot? That the world is doing to hell and we all will fall to disaster? Let&#39;s look closer. The exposure is growing faster for poorer countries (and it is the only conclusion they make in lecture)... but the total number of people exposed (and for each type of countries) seems to be the almost unchanged! Interesting... This means (see the definition for the exposure) that there are just a 150% increase of property value in the dangerous area of the poorer countries (and 25% for the richest) on a span of 30 years. Does this graph shows us only the economic grows? I think it does... (reminds me of &lt;a href=&quot;http://ssrebelious.blogspot.ru/2015/01/do-you-know-what-you-show-at-your-map.html&quot; target=&quot;_blank&quot;&gt;my previous post&lt;/a&gt;).&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Now to the most delicious part. Take a look at this two graphs from the lecture readings:&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiVpqQo5xZUbVsGNKvdgiNFdNcPZhdgGEuBHzU-5a6rKnGHtA5T4eMQKWW6T8RJNbult238g3VtYvRz-zq5keyWQGZGiLsKxXNyZZTkjNrR8V1GwY9JzNeNkaTvTXRxIN21hq28MrHt1jU/s1600/People_killed.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiVpqQo5xZUbVsGNKvdgiNFdNcPZhdgGEuBHzU-5a6rKnGHtA5T4eMQKWW6T8RJNbult238g3VtYvRz-zq5keyWQGZGiLsKxXNyZZTkjNrR8V1GwY9JzNeNkaTvTXRxIN21hq28MrHt1jU/s1600/People_killed.png&quot; height=&quot;504&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Deaths dynamics&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi37X6F9mXBY5nT7sXGwjXxVYORXbY27-SzWtZ_5y0Oj_8JxcI2iKQumBhZGNiU6EzsxddisYBTWlWdj1gn9EZz7XBmPQxKusAvKAOJVumkauDjIDWw-n-GPTfp9uNDrGJE4yu-G8IxLB8/s1600/Damage_dealt.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi37X6F9mXBY5nT7sXGwjXxVYORXbY27-SzWtZ_5y0Oj_8JxcI2iKQumBhZGNiU6EzsxddisYBTWlWdj1gn9EZz7XBmPQxKusAvKAOJVumkauDjIDWw-n-GPTfp9uNDrGJE4yu-G8IxLB8/s1600/Damage_dealt.png&quot; height=&quot;526&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Damage dynamics&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
This is interesting. Despite the population growth and all that questionable &quot;climate change&quot; staff people die less (in total numbers), see fig. 1, but the damage increases, see fig. 2. Did they take inflation into account for the damage graph? Do not know... I think they didn&#39;t, otherwise they would use &quot;discounted damage&quot; term instead of just &quot;damage&quot; and would indicate the base year. So the second graph seems to demonstrate inflation and may be the economic grows.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Clearly disasters are not that disastrous. Despite the new on the TV on the subject the nature&#39;s wrath even enhanced by human is less and less dangerous for human lives. The pockets are to suffer: the storm in port wrecking the humble fisherman&#39;s boat or a trawler - that&#39;s the difference.&lt;/div&gt;
&lt;h3 style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/h3&gt;
&lt;h3 style=&quot;text-align: justify;&quot;&gt;
Conclusion&lt;/h3&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
From these graphs I can conclude one thing - it is safer to live now than in the past, a disaster should not be feared as a deadly havoc. To my mind the disaster nowadays is entirely economic issue. See, if we loose less people and (maybe) more money - we should just develop more advanced insurance techniques to cover economic damage and relax. The disasters should just be studied as phenomena to develop cheap early warning systems, let the property be destroyed (just cover the losses with insurance) and additional employment to be created (rebuilding).&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
This is my conclusion form the graphs I showed here: disasters are an ancient myth! Just buy insurance! LOL&lt;/div&gt;
&lt;/div&gt;
</description><link>http://ssrebelious.blogspot.com/2015/01/disasters-myth-or-reality.html</link><author>noreply@blogger.com (Yury Ryabov)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhs_eM6KqXQUVfK5sDtgZ_RtA8nEe18JeEixYDIIR86_2fxfFApzucdbWeexKTdWhO5HNZ9qF4REPVatDm4OvN0GOoIY_AH-wbOi6qeD-LI6zMOCF1efahyphenhyphenTEZm0dIm_cTv3aS2Ap2fJps/s72-c/Exposure_graph.png" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3120553115257874322.post-2610251261188203422</guid><pubDate>Sat, 10 Jan 2015 11:28:00 +0000</pubDate><atom:updated>2015-01-10T15:28:22.742+04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">maps</category><category domain="http://www.blogger.com/atom/ns#">R</category><category domain="http://www.blogger.com/atom/ns#">spatial data</category><title>Do You Know What You Show at Your Map?</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
As access to the GIS and mapping is becoming easier every year the more people and companies create maps. Unfortunately often they just do not know what they are actually showing at their maps. This issue is being mentioned over and over again. &amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Here is the example that I discovered recently: &lt;a href=&quot;http://cybermap.kaspersky.com/&quot; target=&quot;_blank&quot;&gt;Cyberthreat Real-Time Map&lt;/a&gt; by Kaspersky antivirus company. Here how it looks like:&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhdqJ4DVMmWYT2HevWtHpRqwNdro9_QAomS7SAnXQrOSzZomeRP4Bw5ib_em8QxpNnBE94H-V4m6Fxhq2E03FerlhP16Rlv8-kdO_KCDxgHsbdvpP6s8eWYN4sh4ToNiqx_2wOdKNWKBwU/s1600/kaspersky_map.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhdqJ4DVMmWYT2HevWtHpRqwNdro9_QAomS7SAnXQrOSzZomeRP4Bw5ib_em8QxpNnBE94H-V4m6Fxhq2E03FerlhP16Rlv8-kdO_KCDxgHsbdvpP6s8eWYN4sh4ToNiqx_2wOdKNWKBwU/s1600/kaspersky_map.png&quot; height=&quot;294&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Amongst the other info they show the Infection rank for each country... based on total threats detected.... You may have already guessed what is the fail, but I let me explain it anyway.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
See, the №1 infected country is Russia, which is the home country for Kaspersky and where this antivirus is quite popular. So we can conclude that the rankings that supposed to demonstrate the severity of virus activities merely demonstrates &lt;i&gt;the number of Kaspersky software installations&lt;/i&gt; across the globe.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Lets test this hypothesis. I don&#39;t have the data about the number of installation of Kaspersky software per country, but it is safe to assume that this number is proportional to the population of the given country. Also it is easier to get infection rankings for countries from the map than the number of the threats detected. If I had total threats data per country I would compare it to the population. Having &lt;i&gt;infection rankings&lt;/i&gt; it is more rational to compare it to the &lt;i&gt;population rankings&lt;/i&gt; instead. So I picked 27 random countries and compared their infection and population rankings. The result is demonstrated at the plot below:&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgwpkhK5bSQoI5kxZV_LCYj4r8xa3L0Xb2sod-VIdtZYLH6b-OrSD1_w4G54pYxdc0QnIlRBUS705R-KydoBA_KBaKnyfLJdnFDd_idQrlKFcFKRzTHkI1k8-U15el-pr4n6sVGZhyphenhypheni7ek/s1600/Infection_vs_population.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgwpkhK5bSQoI5kxZV_LCYj4r8xa3L0Xb2sod-VIdtZYLH6b-OrSD1_w4G54pYxdc0QnIlRBUS705R-KydoBA_KBaKnyfLJdnFDd_idQrlKFcFKRzTHkI1k8-U15el-pr4n6sVGZhyphenhypheni7ek/s1600/Infection_vs_population.png&quot; height=&quot;442&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Infection rank vs. Population rank&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The linear model is fairly close to &lt;i&gt;Inrection rank&lt;/i&gt; = &lt;i&gt;Population rank.&lt;/i&gt; It is clear that the phenomena that is presented as an &lt;i&gt;Infection rank&lt;/i&gt;&amp;nbsp;just reflects a total software installations per country and not the severity of the &#39;cyberthreat&#39;. In order to get the &lt;i&gt;actual&lt;/i&gt; Infection rank the number of detected threats have to be normalised by the number of software installations.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
</description><link>http://ssrebelious.blogspot.com/2015/01/do-you-know-what-you-show-at-your-map.html</link><author>noreply@blogger.com (Yury Ryabov)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhdqJ4DVMmWYT2HevWtHpRqwNdro9_QAomS7SAnXQrOSzZomeRP4Bw5ib_em8QxpNnBE94H-V4m6Fxhq2E03FerlhP16Rlv8-kdO_KCDxgHsbdvpP6s8eWYN4sh4ToNiqx_2wOdKNWKBwU/s72-c/kaspersky_map.png" height="72" width="72"/><thr:total>3</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3120553115257874322.post-64459400285822159</guid><pubDate>Sun, 14 Dec 2014 10:35:00 +0000</pubDate><atom:updated>2014-12-14T14:35:47.941+04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">QGIS</category><title>How to Get Accurate Measurements in QGIS</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
This post is mainly &lt;a href=&quot;http://gis.stackexchange.com/a/126538/5666&quot; target=&quot;_blank&quot;&gt;my answer&lt;/a&gt; to the corresponding question.&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The main rule for accurate measurements is to define correct CRS for your layers and project. This is somewhat wide theme to talk about so I won&#39;t ;-)&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Lets just discuss what you should do when the project CRS can&#39;t be easily used for measurement (like Web Mercator) and you want to use &lt;i&gt;Measure tool&lt;/i&gt; to calculate distance or area. Go &lt;i&gt;Settings&lt;/i&gt; -&amp;gt; &lt;i&gt;Project Properties&lt;/i&gt;, in &lt;i&gt;CRS&lt;/i&gt; tab enable on the fly transformation; in &lt;i&gt;General&lt;/i&gt; tab in &lt;i&gt;Measure tool&lt;/i&gt; menu choose ellipsoid for distance calculations. See picture:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgHln0X-0vsnPSUVjMfSaPzRKl3XtMeDZurr8JaBSQMfILxPgOGuB6HBu0XxBXkZD0BuBec_sSd7jE_l89iPiwtJUPJePX_fO8F8m5E3oj1pN3rBI-t6Q3LSWWNu6UXZXB8AXl661eyE0k/s1600/project_settings.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgHln0X-0vsnPSUVjMfSaPzRKl3XtMeDZurr8JaBSQMfILxPgOGuB6HBu0XxBXkZD0BuBec_sSd7jE_l89iPiwtJUPJePX_fO8F8m5E3oj1pN3rBI-t6Q3LSWWNu6UXZXB8AXl661eyE0k/s1600/project_settings.png&quot; height=&quot;362&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
When you start measurements with the&amp;nbsp;&lt;i&gt;Measure&lt;/i&gt; tool move your cursor over the &lt;i&gt;Measure&lt;/i&gt; window - an information about measurement settings will pop up just like that:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEguFY1QtWTE88E5kG6wty-Tuqa9csy1ZvdWKRNZ3H0ank4XksMe8I1fswqeL3IeccvtlzCK6cnkBQlaqjZMU3eGF7_kWF2TDbUkzuk6k3JPJaxwCh9098rF6Solkr3C8bVogm-xfFOHQEg/s1600/distance_tip.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEguFY1QtWTE88E5kG6wty-Tuqa9csy1ZvdWKRNZ3H0ank4XksMe8I1fswqeL3IeccvtlzCK6cnkBQlaqjZMU3eGF7_kWF2TDbUkzuk6k3JPJaxwCh9098rF6Solkr3C8bVogm-xfFOHQEg/s1600/distance_tip.png&quot; height=&quot;243&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Now you can make your measurements and be sure that they are accurate. &lt;b&gt;NOTE&lt;/b&gt;&amp;nbsp;that you should always check &lt;i&gt;Measure tool&lt;/i&gt; settings like it shown at the picture above because &lt;i&gt;Ellipsoid&lt;/i&gt; settings for the &lt;i&gt;Measure tool&lt;/i&gt; are not always stored or displayed in &lt;i&gt;Project&lt;/i&gt; &lt;i&gt;settings&lt;/i&gt; correctly (QGIS 2.6.1).&lt;/div&gt;
&lt;/div&gt;
</description><link>http://ssrebelious.blogspot.com/2014/12/how-to-get-accurate-measurements-in-qgis.html</link><author>noreply@blogger.com (Yury Ryabov)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgHln0X-0vsnPSUVjMfSaPzRKl3XtMeDZurr8JaBSQMfILxPgOGuB6HBu0XxBXkZD0BuBec_sSd7jE_l89iPiwtJUPJePX_fO8F8m5E3oj1pN3rBI-t6Q3LSWWNu6UXZXB8AXl661eyE0k/s72-c/project_settings.png" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3120553115257874322.post-5818120814477082433</guid><pubDate>Sun, 30 Nov 2014 18:02:00 +0000</pubDate><atom:updated>2014-11-30T22:04:38.780+04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">science</category><category domain="http://www.blogger.com/atom/ns#">TSP</category><title>A Flawed Research on a TSP Algorithm</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
A &lt;a href=&quot;http://en.wikipedia.org/wiki/Travelling_salesman_problem&quot; target=&quot;_blank&quot;&gt;Travelling Salesman Problem&lt;/a&gt; (TSP) is a well known computational challenge. A lot of algorithms were developed to solve it or its special cases.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
I came around an article authored by Fang Liu&amp;nbsp;&#39;A dual population parallel ant colony optimization algorithm for solving the travelling salesman problem&#39;. In this article he proposed a modification of an Ant Colony System algorithm for solving TSP and presented results obtained by his algorithm. In the table with results all looked fine - his algorithm was able to provide very good solutions for the TSP instances from &lt;a href=&quot;http://comopt.ifi.uni-heidelberg.de/software/TSPLIB95/&quot; target=&quot;_blank&quot;&gt;TSPLIB&lt;/a&gt;&amp;nbsp;(which is the common testing ground for TSP algorithms).&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
So the researcher presented good results... it seems. But then he decided to show &lt;b&gt;&lt;u&gt;the best routes&lt;/u&gt;&lt;/b&gt; his algorithm was able to find and annotated them with the corresponding route costs. Lets take a look at one of them. Here you are his&amp;nbsp;&lt;b&gt;&lt;u&gt;best route&lt;/u&gt;&lt;/b&gt;&amp;nbsp;for the &#39;att48&#39; instance from the TSPLIB:&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEge-a24qf79I-j4rI5gq2Bc2k-btc8DXm_b3T1iWSwEODenlJT-lr_OYtGogKPc6IqorbHyDtjx1PVz87dhcBD5lzBrT6fU1ytWiZDZaSDahAIPaLTCt6-1AFTHkQEl9gMNA315EosrNls/s1600/FangLiu_fail_att48.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEge-a24qf79I-j4rI5gq2Bc2k-btc8DXm_b3T1iWSwEODenlJT-lr_OYtGogKPc6IqorbHyDtjx1PVz87dhcBD5lzBrT6fU1ytWiZDZaSDahAIPaLTCt6-1AFTHkQEl9gMNA315EosrNls/s1600/FangLiu_fail_att48.png&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Route that claims to be optimal (but the cost is very wrong)&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The optimal route for &#39;att48&#39; and its cost is well-known (it applies to all TSPLIB instanses). Its cost is approximately 33523 (there are different approaches to rounding distances between points). So what we see at the picture above should be the optimal route (or extremely close to it). But dear reader, do you think that you see optimal route? Humans are able to provide very good solutions to TSP instances that consists of not too many points. I bet you can draw far better route yourself. The route from this picture is&amp;nbsp;&lt;span style=&quot;text-align: left;&quot;&gt;1, 8, 46, 33, 20, 17, 43, 27, 19, 37, 6, 30, 36, 28, 7, 18, 44, 31, 38, 9, 40, 15, 12, 11, 47, 21, 13, 25, 14, 23, 3, 22, 16, 41, 34, 2, 29, 5, 48, 39, 32, 24, 42, 10, 45, 35, 4, 26, 1 and its cost is 41052 which is whooping 22% far from optimal! The same story for another illustration in the article.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;text-align: left;&quot;&gt;Here take a look at the optimal route which cost is really 33523:&lt;/span&gt;&lt;/div&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgDkcGFaBi6Q-HOsfPlOyKuaOLsNQ7PLjFjtUrO-DP2Mc-W9jbU7vk5LyEf1ONumnmLDZn69qB2R74nj-booCUdFKnKBc6tCDThN3a3fL-fmE4UvSmXSrKOhayNSMOndFETypR_km6X3MA/s1600/att48_optimal_route.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgDkcGFaBi6Q-HOsfPlOyKuaOLsNQ7PLjFjtUrO-DP2Mc-W9jbU7vk5LyEf1ONumnmLDZn69qB2R74nj-booCUdFKnKBc6tCDThN3a3fL-fmE4UvSmXSrKOhayNSMOndFETypR_km6X3MA/s1600/att48_optimal_route.png&quot; height=&quot;480&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Actually optimal route for &#39;att48&#39; with Cost = 33523&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;text-align: left;&quot;&gt;So what we can conclude? I do believe that the routes demonstrated in the article are the best routes found by given algorithm, but costs are put-up for the routes and for the table of results in the article as well. I think that author developed an algorithm that wasn&#39;t able to find good solutions and provided fraud table with the put-up testing results. And clearly this article wasn&#39;t&amp;nbsp;reviewed&amp;nbsp;by scientist that have knowledge in TSP area&amp;nbsp;because&amp;nbsp;these plots are so&amp;nbsp;obviously&amp;nbsp;flawed that one can&#39;t overlook it!&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;text-align: left;&quot;&gt;No one usually shows plots of the routes they find with their algorithms. I wonder if there are more modern algorithms with the put-up results?&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
</description><link>http://ssrebelious.blogspot.com/2014/11/a-flawed-research-on-tsp-algorithm.html</link><author>noreply@blogger.com (Yury Ryabov)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEge-a24qf79I-j4rI5gq2Bc2k-btc8DXm_b3T1iWSwEODenlJT-lr_OYtGogKPc6IqorbHyDtjx1PVz87dhcBD5lzBrT6fU1ytWiZDZaSDahAIPaLTCt6-1AFTHkQEl9gMNA315EosrNls/s72-c/FangLiu_fail_att48.png" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3120553115257874322.post-8639964804350936963</guid><pubDate>Sun, 02 Nov 2014 17:27:00 +0000</pubDate><atom:updated>2014-11-02T21:27:58.574+04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">GIS</category><category domain="http://www.blogger.com/atom/ns#">graph</category><category domain="http://www.blogger.com/atom/ns#">Python</category><category domain="http://www.blogger.com/atom/ns#">science</category><category domain="http://www.blogger.com/atom/ns#">spatial data</category><title>How to Create Delauney Triangulation Graph from a .shp-file Using NetworkX</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
For my own project I needed to create a graph based on a Delauney triangulation using &lt;a href=&quot;http://networkx.github.io/documentation/networkx-1.9.1/index.html&quot; target=&quot;_blank&quot;&gt;NetworkX&lt;/a&gt; python library. And a special condition was that all the edges must be unique. Points for triangulation stored in a .shp-file.&lt;br /&gt;
&lt;br /&gt;
I was lucky enough to find &lt;a href=&quot;https://groups.google.com/forum/#!topic/networkx-discuss/D7fMmuzVBAw&quot; target=&quot;_blank&quot;&gt;this tread&lt;/a&gt; on Delauney triangulation using NetworkX graphs. I made a nice function out of it for point NetworkX graphs processing. This function preserves nodes attributes (which are lost after triangulation) and calculates lengths of the edges. It can be further improved (and most likely will be) but even at the current state it is very handy.&lt;br /&gt;
&lt;br /&gt;
Example of use:&lt;br /&gt;
&lt;pre class=&quot;brush: py&quot;&gt;
import networkx as nx
import scipy.spatial
import matplotlib.pyplot as plt

path = &#39;/directory/&#39;
f_path = path + &#39;filename.shp&#39;
G = nx.read_shp(f_path)

GD = createTINgraph(G, show = True)&lt;/pre&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhKL6x9rISlkjmboumzmgVJ6Ijo07FUjOPks8a23ybWsf0ncsJLXBihRChNyE-EF_GyPoAjwzEmh3iBlATmUjkRZ5o4Qq-cGASrjLIFQ4hGghivAxzMdHXHUEwNMArzpI7RQpUcVgDHoLo/s1600/TINgraph.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhKL6x9rISlkjmboumzmgVJ6Ijo07FUjOPks8a23ybWsf0ncsJLXBihRChNyE-EF_GyPoAjwzEmh3iBlATmUjkRZ5o4Qq-cGASrjLIFQ4hGghivAxzMdHXHUEwNMArzpI7RQpUcVgDHoLo/s1600/TINgraph.png&quot; height=&quot;300&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Code for the function: &lt;br /&gt;
&lt;pre class=&quot;brush: py&quot;&gt;
import networkx as nx
import scipy.spatial
import matplotlib.pyplot as plt

def createTINgraph(point_graph, show = False, calculate_distance = True):
  &#39;&#39;&#39;
  Creates a graph based on Delaney triangulation

  @param point_graph: either a graph made by read_shp() from another NetworkX&#39;s point graph
  @param show: whether or not resulting graph should be shown, boolean
  @param calculate_distance: whether length of edges should be calculated
  @return - a graph made from a Delauney triangulation

  @Copyright notice: this code is an improved (by Yury V. Ryabov, 2014, riabovvv@gmail.com) version of
                    Tom&#39;s code taken from this discussion
                    https://groups.google.com/forum/#!topic/networkx-discuss/D7fMmuzVBAw
  &#39;&#39;&#39;

  TIN = scipy.spatial.Delaunay(point_graph)
  edges = set()
  # for each Delaunay triangle
  for n in xrange(TIN.nsimplex):
      # for each edge of the triangle
      # sort the vertices
      # (sorting avoids duplicated edges being added to the set)
      # and add to the edges set
      edge = sorted([TIN.vertices[n,0], TIN.vertices[n,1]])
      edges.add((edge[0], edge[1]))
      edge = sorted([TIN.vertices[n,0], TIN.vertices[n,2]])
      edges.add((edge[0], edge[1]))
      edge = sorted([TIN.vertices[n,1], TIN.vertices[n,2]])
      edges.add((edge[0], edge[1]))


  # make a graph based on the Delaunay triangulation edges
  graph = nx.Graph(list(edges))

  #add nodes attributes to the TIN graph from the original points
  original_nodes = point_graph.nodes(data = True)
  for n in xrange(len(original_nodes)):
    XY = original_nodes[n][0] # X and Y tuple - coordinates of the original points
    graph.node[n][&#39;XY&#39;] = XY
    # add other attributes
    original_attributes = original_nodes[n][1]
    for i in original_attributes.iteritems(): # for tuple i = (key, value)
      graph.node[n][i[0]] = i[1]


  # calculate Euclidian length of edges and write it as edges attribute
  if calculate_distance:
    edges = graph.edges()
    for i in xrange(len(edges)):
      edge = edges[i]
      node_1 = edge[0]
      node_2 = edge[1]
      x1, y1 = graph.node[node_1][&#39;XY&#39;]
      x2, y2 = graph.node[node_2][&#39;XY&#39;]
      dist = sqrt( pow( (x2 - x1), 2 ) + pow( (y2 - y1), 2 ) )
      dist = round(dist, 2)
      graph.edge[node_1][node_2][&#39;distance&#39;] = dist


  # plot graph
  if show:
    pointIDXY = dict(zip(range(len(point_graph)), point_graph))
    nx.draw(graph, pointIDXY)
    plt.show()

  return graph
&lt;/pre&gt;
&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;</description><link>http://ssrebelious.blogspot.com/2014/11/how-to-create-delauney-triangulation.html</link><author>noreply@blogger.com (Yury Ryabov)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhKL6x9rISlkjmboumzmgVJ6Ijo07FUjOPks8a23ybWsf0ncsJLXBihRChNyE-EF_GyPoAjwzEmh3iBlATmUjkRZ5o4Qq-cGASrjLIFQ4hGghivAxzMdHXHUEwNMArzpI7RQpUcVgDHoLo/s72-c/TINgraph.png" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3120553115257874322.post-5412804136231476272</guid><pubDate>Tue, 30 Sep 2014 20:57:00 +0000</pubDate><atom:updated>2014-10-01T00:57:07.120+04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">illegal dumps and landfills</category><category domain="http://www.blogger.com/atom/ns#">Leningrad region</category><category domain="http://www.blogger.com/atom/ns#">R</category><category domain="http://www.blogger.com/atom/ns#">science</category><category domain="http://www.blogger.com/atom/ns#">St. Petersburg</category><category domain="http://www.blogger.com/atom/ns#">waste</category><title>Interactive Visualisation of the Profitable Amount of Waste to Dispose Illegally</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&quot;Wow!&quot; - I said to myself after reading &lt;a href=&quot;http://blog.revolutionanalytics.com/2014/04/r-helps-with-employee-churn.html&quot; target=&quot;_blank&quot;&gt;R Helps With Employee Churn&lt;/a&gt; post - &quot;I can create interactive plots in R?!!! I have to try it out!&quot;&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
I quickly came up with an idea of creating interactive plot for my simple model for assessment of the profitable ratio between the volume waste that could be illegally disposed and costs of illegal disposal [&lt;i&gt;Ryabov Y. (2013) Rationale of mechanisms for the land protection from illegal dumping (an example from the St.-Petersburg and Leningrad region). Regional Researches. №1 (39), p. 49-56&lt;/i&gt;]. The conditions for profitable illegal dumping can be describes as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEip6lAsMXEM3wtj65whz8OjbtU_dU3afKZoXnxS9IMpbF-GU3mTQvmAKvQLsQqQ9muR2on-E8LU3Yq_d1pNpS1wwexp7hkLN8moY9B_3J5jr2dRyx_r9IWMZ8qpvRJRMhzCUjXwGHXYQDI/s1600/formula1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEip6lAsMXEM3wtj65whz8OjbtU_dU3afKZoXnxS9IMpbF-GU3mTQvmAKvQLsQqQ9muR2on-E8LU3Yq_d1pNpS1wwexp7hkLN8moY9B_3J5jr2dRyx_r9IWMZ8qpvRJRMhzCUjXwGHXYQDI/s1600/formula1.png&quot; height=&quot;141&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;
Here: &lt;i&gt;k&lt;/i&gt; - the probability of being fined for illegal disposal of waste;&lt;br /&gt;
&lt;i&gt;P&lt;/i&gt; - maximum fine for illegal disposal of waste (illegal dumping);&lt;br /&gt;
&lt;i&gt;V&lt;/i&gt; - volume of waste to be [illegally] disposed by the waste owner;&lt;br /&gt;
&lt;i&gt;E&lt;/i&gt; - costs of illegal disposal of waste per unit;&lt;br /&gt;
&lt;i&gt;T&lt;/i&gt; - official tax for waste disposal per unit.&lt;br /&gt;
&lt;br /&gt;
The conditions for the profitable landfilling can be described as follows:&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgfe-Fi7bx5mctk_6zAG9udYm-y8twpsQYzjr70_6AYTuJitKuhlxStPjURECv3-ns0Fa7ikl3Pw5tbfO0o3gou8ttSvn7AFUYVJz2QKi60-qQJnFti0v0nuEy1CTGQHlLQ5stSZFakLrE/s1600/formula2.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgfe-Fi7bx5mctk_6zAG9udYm-y8twpsQYzjr70_6AYTuJitKuhlxStPjURECv3-ns0Fa7ikl3Pw5tbfO0o3gou8ttSvn7AFUYVJz2QKi60-qQJnFti0v0nuEy1CTGQHlLQ5stSZFakLrE/s1600/formula2.png&quot; height=&quot;140&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
Here: &lt;i&gt;V&lt;span style=&quot;font-size: xx-small;&quot;&gt;1&lt;/span&gt;&lt;/i&gt; - total volume of waste that is supposed to be disposed at illegal landfill;&lt;br /&gt;
&lt;i&gt;T&lt;span style=&quot;font-size: x-small;&quot;&gt;c&lt;/span&gt;&lt;/i&gt; - tax for disposal of waste at illegal landfill per unit;&lt;br /&gt;
&lt;i&gt;P&lt;span style=&quot;font-size: xx-small;&quot;&gt;1&lt;/span&gt;&lt;/i&gt; - maximum fine for illegal landfilling;&lt;br /&gt;
&lt;i&gt;E&lt;span style=&quot;font-size: xx-small;&quot;&gt;1&lt;/span&gt;&lt;/i&gt; - expenditures of the illegal landfill owner for disposal of waste per unit.&lt;br /&gt;
&lt;br /&gt;
Lets plot the graphs (with some random numbers (except for fines) for a nice looking representation) to have a clue how it looks like.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSpIEMM3E3tWDNI7PyFKRcbPIXmx8ZVyYEFhYZhSC3hj07xZ__vhrA9vOwgAXsEy4DYitdmbh5bf1sA1pw8YcmM8Hmr4HWLMawZRDnZysqeA1Y3PkoOgZZohw_nqwKi338CDt8CnUWxQs/s1600/original_plot.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSpIEMM3E3tWDNI7PyFKRcbPIXmx8ZVyYEFhYZhSC3hj07xZ__vhrA9vOwgAXsEy4DYitdmbh5bf1sA1pw8YcmM8Hmr4HWLMawZRDnZysqeA1Y3PkoOgZZohw_nqwKi338CDt8CnUWxQs/s1600/original_plot.png&quot; height=&quot;440&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Note that there is a footnote (&lt;a href=&quot;http://bigdata-analyst.com/best-way-to-add-a-footnote-to-a-plot-created-with-ggplot2.html&quot; target=&quot;_blank&quot;&gt;this post&lt;/a&gt; provides nice examples on how to do it) with the values used for plotting - it is important to have to have this kind of indication if we want to create a series of plots.&lt;br /&gt;
&lt;br /&gt;
Now I will show you the result and then will provide the code and some tips.&lt;br /&gt;
&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjeDCHlFZNEeJtmsxIOfr1eBz3J8yAm_s3osXdCzdG-tFqkSbGzIjr_3MVNZA0LYXuxIh1yjBQFFr815A-GlI_NYtxag5Vc8zEsY3rChXfE7HULgbV78zw2c0Y_1xDqcNcbD_JWUY6yl8k/s1600/plot.gif&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjeDCHlFZNEeJtmsxIOfr1eBz3J8yAm_s3osXdCzdG-tFqkSbGzIjr_3MVNZA0LYXuxIh1yjBQFFr815A-GlI_NYtxag5Vc8zEsY3rChXfE7HULgbV78zw2c0Y_1xDqcNcbD_JWUY6yl8k/s1600/plot.gif&quot; height=&quot;336&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Playing with the plot&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;h3&gt;
Tips and Tricks&lt;/h3&gt;
&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Before I will show you code I want to share my hardly earned knowledge about nuances of the &lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;manipulate&lt;/span&gt; library. There are several ways to get &lt;b&gt;static&lt;/b&gt; plot like that using &lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;ggplot&lt;/span&gt;, but some of them will fail to be interactive with&amp;nbsp;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;manipulate&lt;/span&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;All the data for the plot must be stored in one dataframe.&lt;/li&gt;
&lt;li&gt;All data for plots must be derived from the dataframe (avoid passing single variables to &lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;ggplot&lt;/span&gt;).&lt;/li&gt;
&lt;li&gt;Do not use &lt;a href=&quot;http://docs.ggplot2.org/0.9.3.1/geom_hline.html&quot; target=&quot;_blank&quot;&gt;geom_hline()&lt;/a&gt;&amp;nbsp;for the horizontal line - generate values for this line and store them inside dataframe and draw as a regular graph.&lt;/li&gt;
&lt;li&gt;To create a footnote (to know exactly which parameters were used for the current graph) use &lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;arrangeGrob()&lt;/span&gt;&amp;nbsp;function from the &lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;gridExtra&lt;/span&gt; library.&lt;/li&gt;
&lt;li&gt;Always use $ inside aes() settings to address columns of your dataframe if you want plots to be interactive&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;
The Code&lt;/h3&gt;
&lt;div&gt;
&lt;pre class=&quot;brush: r&quot;&gt;
library(ggplot2)
library(grid)
library(gridExtra)
library(manipulate)
library(scales)
library(reshape2)

## Ta --- official tax for waste utilisation per tonne or cubic metre.
## k --- probability of getting fined for illegal dumping the waste owner (0&lt;k&lt;=1).
## P --- maximum fine for the waste owner if he got cought.
## V --- waste wolume (tonns or cubic meters).
## E --- waste owner expenditures for waste utilisation / removal.
## x &lt;=&gt; V, y &lt;=&gt; E

max_waste_volume &lt;- 2000 
Illegal_dumping_fine_P &lt;- 300000
Illigal_landfilling_fine_P1 &lt;- 500000
Fine_probability_k &lt;- 0.5
Official_tax_Ta &lt;- 600

# mwv = max_waste_volume
# P = Illegal_dumping_fine_P
# P1 = Illigal_landfilling_fine_P1
# k = Fine_probability_k
# Ta = Official_tax_Ta

updateData &lt;- function(mwv, k, P1, P, Ta){
    
    # creates and(or) updates global data frame to provide data for the plot
    
    new_data &lt;&lt;- NULL
    new_data &lt;&lt;- as.data.frame(0:mwv)
    names(new_data) &lt;&lt;- &#39;V&#39;
    new_data$IlD &lt;&lt;- k*P1/new_data$V
    new_data$IlD_fill &lt;&lt;- new_data$IlD
    new_data$IlD_fill[new_data$IlD_fill &gt; Ta] &lt;&lt;- NA # we don&#39;t want ribbon to fill area above Official tax 
    new_data$IlL &lt;&lt;- Ta-k*P/new_data$V
    
    new_data$Ta &lt;&lt;- Ta
    new_data$zero &lt;&lt;- 0
    dta &lt;&lt;- melt(new_data, id.vars=&quot;V&quot;, measure.vars=c(&quot;IlD&quot;, &quot;IlL&quot;, &quot;Ta&quot;))
    dta.lower &lt;&lt;- melt(new_data, id.vars=&quot;V&quot;, measure.vars=c(&quot;IlD_fill&quot;, &quot;zero&quot;, &quot;Ta&quot;))
    dta.upper &lt;&lt;- melt(new_data, id.vars=&quot;V&quot;, measure.vars=c(&quot;Ta&quot;, &quot;IlL&quot;, &quot;Ta&quot;))
    dta &lt;&lt;- cbind(dta, lower=dta.lower$value, upper=dta.upper$value)
    dta$name &lt;&lt;- factor(NA, levels=c(&quot;Illegal landfill owner&#39;s\nprofitable ratio&quot;,
                                    &quot;Waste owner&#39;s\nprofitable ratio&quot;, 
                                    &quot;Official tax&quot;))
    dta$name[dta$variable==&quot;IlD&quot;] &lt;&lt;- &quot;Illegal landfill owner&#39;s\nprofitable ratio&quot;
    dta$name[dta$variable==&quot;IlL&quot;] &lt;&lt;- &quot;Waste owner&#39;s\nprofitable ratio&quot;
    dta$name[dta$variable==&quot;Ta&quot;] &lt;&lt;- &quot;Official tax&quot;
}

updateLabels &lt;- function(k, P1, P, Ta){
    
    ### creates footnote caption for the plot
    
    prob &lt;- paste(&#39;Fining probability = &#39;, k, sep = &#39;&#39;)
    landfilling_fine &lt;- paste(&#39;Illegal landfilling fine = &#39;, P1, sep = &#39;&#39;)
    dumping_fine &lt;- paste(&#39;Illegal dumping fine = &#39;, P, sep = &#39;&#39;)
    tax &lt;- paste(&#39;Official tax = &#39;, Ta, sep = &#39;&#39;)
    note &lt;&lt;- paste(prob, landfilling_fine, sep = &#39;; &#39;)
    note &lt;&lt;- paste(note, dumping_fine, sep = &#39;; &#39;)
    note &lt;&lt;- paste(note, tax, sep = &#39;; &#39;)
    note
}


plotDumping &lt;- function(mwv, P, P1, k, Ta){
    
    ### this function draws the plot
    
   # initialise plot data
    updateData(mwv, k, P1, P, Ta)
    updateLabels(k, P1, P, Ta)
    
    # draw the plot
    profit &lt;- ggplot(dta, aes(x=dta$V, y=dta$value, ymin=dta$lower, ymax=dta$upper, 
                              color=dta$name, fill=dta$name, linetype=dta$name)) +
        geom_line(size=1.2) + 
        geom_ribbon(alpha=.25, linetype=0) +
        theme(axis.text.x = element_text(angle=0, hjust = 0),
              axis.title = element_text(face = &#39;bold&#39;, size = 14),
              title = element_text(face = &#39;bold&#39;, size = 16),
              legend.position = &#39;right&#39;,
              legend.title = element_blank(),
              legend.text = element_text(size = 12),
              legend.key.width = unit(2, &#39;cm&#39;),
              legend.key.height = unit(1.2, &#39;cm&#39;))+
        scale_linetype_manual(values=c(4, 5, 1)) +
        scale_fill_manual(values = c(&quot;#F8766D&quot;,&quot;#00BFC4&quot;,NA)) +
        scale_color_manual(values = c(&quot;#F8766D&quot;,&quot;#00BFC4&quot;, &#39;#66CD00&#39;)) + 
        labs(title=&quot;Profitable ratio between the volume \nof illegally disposed waste \nand costs of illegal disposal of waste&quot;,
             x=&quot;Waste volume, cubic meters&quot;,
             y=&quot;Cost per cubic meter, RUB&quot;) +
        xlim(c(0, max(new_data$V)))+
        ylim(c(0, Ta*1.5))
        
    
    # add a footnote about paramaters used for the current plot
    profit &lt;- arrangeGrob(profit, 
                          sub = textGrob(note, 
                                         x = 0, 
                                         hjust = -0.1, 
                                         vjust=0.1, 
                                         gp = gpar(fontface = &quot;italic&quot;, fontsize = 12)))
    
    # show plot
    print(profit)

}


simDumping &lt;- function(max_waste_volume = 2000, 
                       Illegal_dumping_fine_P = 300000,
                       Illigal_landfilling_fine_P1 = 500000,
                       Fine_probability_k = 0.5,
                       Official_tax_Ta = 600) {
    
    ### this function creates interactive plot
    
    max_waste_volume &lt;&lt;- max_waste_volume 
    Illegal_dumping_fine_P &lt;&lt;- Illegal_dumping_fine_P
    Illigal_landfilling_fine_P1 &lt;&lt;- Illigal_landfilling_fine_P1
    Fine_probability_k &lt;&lt;- Fine_probability_k
    Official_tax_Ta &lt;&lt;- Official_tax_Ta
    
    manipulate(suppressWarnings(plotDumping(max_waste_volume, 
                           Illegal_dumping_fine_P,
                           Illigal_landfilling_fine_P1,
                           Fining_probability_k,
                           Official_tax_Ta)
                           ),
               
               # set up sliders
               max_waste_volume = slider(0, 50000, 
                                         initial = max_waste_volume, 
                                         step = 100,
                                         label = &#39;X axis range&#39;),
               Illegal_dumping_fine_P = slider(0, 5000000, 
                                               initial = Illegal_dumping_fine_P,
                                               step = 10000, 
                                               label = &#39;Illegal dumping fine (P)&#39;),
               Illigal_landfilling_fine_P1 = slider(0, 5000000, 
                                                    initial = Illigal_landfilling_fine_P1, 
                                                    step = 10000,
                                                    label = &#39;Illegal landfilling fine (P1)&#39;),
               Fining_probability_k = slider(0, 1, 
                                             initial = 0.5,
                                             step = 0.01,
                                             label = &#39;Probability of being fined (k)&#39;),
               Official_tax_Ta = slider(0, 3000, 
                                        initial = Official_tax_Ta, 
                                        step = 50,
                                        label = &#39;Official waste disposal tax (T)&#39;)
    )
}

simDumping() # for reasons unknown I have to run this function twice to get proper interactive plot
&lt;/pre&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;</description><link>http://ssrebelious.blogspot.com/2014/10/interactive-visualisation-of-profitable.html</link><author>noreply@blogger.com (Yury Ryabov)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEip6lAsMXEM3wtj65whz8OjbtU_dU3afKZoXnxS9IMpbF-GU3mTQvmAKvQLsQqQ9muR2on-E8LU3Yq_d1pNpS1wwexp7hkLN8moY9B_3J5jr2dRyx_r9IWMZ8qpvRJRMhzCUjXwGHXYQDI/s72-c/formula1.png" height="72" width="72"/><thr:total>1</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3120553115257874322.post-2738796091580472142</guid><pubDate>Fri, 12 Sep 2014 22:22:00 +0000</pubDate><atom:updated>2014-09-13T02:22:53.563+04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">QGIS</category><title>The Most Hilarious Rendering &quot;Bug&quot; I&#39;ve Ever Seen</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Can you guess the projection that I used to display a world map at the picture below (EPSG code is left there because I doubt someone would recall it anyway)?&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjqz8zjjZO1ABctyxRMAuHe4lsLoaUzAxvKrRUzNEjmdX4aKRREic8XwEdz9R94lK5w91fX9ArMwMD1kCruSHeKmrogKOJ5ZKczBVtE7YtRgUB_7RFwl42h8qkWjeX99lbL1Go8rnbvt7Q/s1600/Bonne_world.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjqz8zjjZO1ABctyxRMAuHe4lsLoaUzAxvKrRUzNEjmdX4aKRREic8XwEdz9R94lK5w91fX9ArMwMD1kCruSHeKmrogKOJ5ZKczBVtE7YtRgUB_7RFwl42h8qkWjeX99lbL1Go8rnbvt7Q/s1600/Bonne_world.png&quot; height=&quot;400&quot; width=&quot;377&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;
It is the World Bonne projection in QGIS (original shp&#39;s CRS is EPSG:4326). I already had some fun with Bonne in &lt;a href=&quot;http://ssrebelious.blogspot.ru/2011/03/georeferencing-of-maps-with-weird.html&quot; target=&quot;_blank&quot;&gt;this post&lt;/a&gt;. The world got torn apart at scale 1:75 000 000. At bigger scales map renders normally:&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgNzweKQ2j0Zjfsk5nIjRg9QTir5xQWt_18lPBm6ZkIV4j1HNNwZ0AKhd35TfV4aKyhsoTBafS414lHbZcSolj_04CiBP8U343XfFVqQ_72Zvd6BNEZB-itzyQF95VWtSQAyZ_zcjyViwQ/s1600/Bonne_world1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgNzweKQ2j0Zjfsk5nIjRg9QTir5xQWt_18lPBm6ZkIV4j1HNNwZ0AKhd35TfV4aKyhsoTBafS414lHbZcSolj_04CiBP8U343XfFVqQ_72Zvd6BNEZB-itzyQF95VWtSQAyZ_zcjyViwQ/s1600/Bonne_world1.png&quot; height=&quot;396&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;
Fortunately this issue can be easily resolved by disabling &quot;feature simplification by default for newly added layers&quot; under Settings -&amp;gt; Options -&amp;gt; Rendering.&amp;nbsp;&lt;/div&gt;
&lt;/div&gt;
</description><link>http://ssrebelious.blogspot.com/2014/09/the-most-hilarious-rendering-bug-ive.html</link><author>noreply@blogger.com (Yury Ryabov)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjqz8zjjZO1ABctyxRMAuHe4lsLoaUzAxvKrRUzNEjmdX4aKRREic8XwEdz9R94lK5w91fX9ArMwMD1kCruSHeKmrogKOJ5ZKczBVtE7YtRgUB_7RFwl42h8qkWjeX99lbL1Go8rnbvt7Q/s72-c/Bonne_world.png" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3120553115257874322.post-6513499159807349016</guid><pubDate>Sun, 07 Sep 2014 22:27:00 +0000</pubDate><atom:updated>2014-09-08T02:27:52.535+04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">environment</category><category domain="http://www.blogger.com/atom/ns#">GIS</category><category domain="http://www.blogger.com/atom/ns#">Leningrad region</category><category domain="http://www.blogger.com/atom/ns#">maps</category><category domain="http://www.blogger.com/atom/ns#">OSM</category><category domain="http://www.blogger.com/atom/ns#">QGIS</category><category domain="http://www.blogger.com/atom/ns#">spatial data</category><title>Schema of the Conservation Areas in Leningradskaya Region: Some Notes for Beginner Mappers</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjqVZ0b0fHVKWu_48ssXubhYWQEaaLKEVRJ1PLsnLG1HisrOk-kE09NpZh5e6UvtzjJfk-D59dLW3MEQ-4Mhagj4lZOrIq_KwjYeAnTMa6uajaMCzodIABCLE78SzhdUdBjKshsnZHYlw4/s1600/%D0%9E%D0%9E%D0%9F%D0%A2.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjqVZ0b0fHVKWu_48ssXubhYWQEaaLKEVRJ1PLsnLG1HisrOk-kE09NpZh5e6UvtzjJfk-D59dLW3MEQ-4Mhagj4lZOrIq_KwjYeAnTMa6uajaMCzodIABCLE78SzhdUdBjKshsnZHYlw4/s1600/%D0%9E%D0%9E%D0%9F%D0%A2.png&quot; height=&quot;450&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Schema of the Conservation Areas in Leningradskaya Region&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
About a year ago I was asked to create a small (a B5 size) and simple schema of the conservation areas in Leningradskaya region. I did it using QGIS. Here you are the author version of the schema and several notes that might be helpful for a beginner map-maker.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
There was a huge disproportion between areas of different objects and both polygon and point markers were needed to show them. I decided to use Centroid Fill option in polygon style to be able to use only one layer (polygon) instead of two (polygon and point). Using Centroid Fill makes points in centres of the small polygons overlap and mask these tiny polygons.&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
All the administrative borers were stored in one layer (and there are far more borders than one see here). They are drawn using rule-based symbology so I didn&#39;t even need to subset this layer to get rid of the rest of the polygons in this layer.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
All the names of the surrounding countries, regions, city and the water bodies are not labels derived from layers, but labels created inside the map composer. It was quicker and their position was more precise which is crucial for such a small schema.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
There was a lack of space for the legend so I had to utilise every bit of canvas to place it. I had to use 3 legend items here. One of them is actually overlapping the other and setting a transparent background for the legends was helping with that.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Finally labels for the conservation areas (numbers) were outlined with white colour to be perfectly readable. Some of them were moved manually (with storing coordinates in special columns of the layer) to prevent overlapping with other labels and data.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;P.S.&lt;/b&gt; Don&#39;t be afraid to argue with the client about the workflow. Initially I was asked it manually digitise a 20 000 x 15 000 pixels raster map of the Leningrad region to extract the most precise borders of the conservation areas (and districts of the region). Of course I could do it and charge more money for the job, but what&#39;s the point if some of that borders are not even to be seen at this small schema? So I convinced client to use data from OSM and saved myself a lot of time.&lt;/div&gt;
&lt;/div&gt;
</description><link>http://ssrebelious.blogspot.com/2014/09/schema-of-conservation-areas-in.html</link><author>noreply@blogger.com (Yury Ryabov)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjqVZ0b0fHVKWu_48ssXubhYWQEaaLKEVRJ1PLsnLG1HisrOk-kE09NpZh5e6UvtzjJfk-D59dLW3MEQ-4Mhagj4lZOrIq_KwjYeAnTMa6uajaMCzodIABCLE78SzhdUdBjKshsnZHYlw4/s72-c/%D0%9E%D0%9E%D0%9F%D0%A2.png" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3120553115257874322.post-641376771546740593</guid><pubDate>Sun, 31 Aug 2014 13:32:00 +0000</pubDate><atom:updated>2014-08-31T17:35:45.303+04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">OSM</category><title>Donetsk Label at OpenStreetMap</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Now, when Donetsk became the hot spot of the civil war at the Ukraine I decided to take a glance at the map of the war zone. Of course I used OSM for this. But despite I knew the approximate location of the city I couldn&#39;t find it for several minuets. I was confused... The reason was that &quot;Donetsk&quot; label (label of the city which is the administrative center of the Donetskaya region BTW) at the scales smaller than 10 km is suppressed by the label of adjusted town &quot;Makeevka&quot;. WTF?!&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiWjA9ieExD3wjiOJxC1vwyeQnDH-AoYdrerazce6v0EQxZ6uR3RqNZppiPYdA4uj8Ky6wGKbXy53_3B111Fc0l4LcCFWWxNlunX625a1QTHAQGlX4WYuqlnZXUMgcl1CW9qbZ9IBO-1QI/s1600/Donetsk.gif&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiWjA9ieExD3wjiOJxC1vwyeQnDH-AoYdrerazce6v0EQxZ6uR3RqNZppiPYdA4uj8Ky6wGKbXy53_3B111Fc0l4LcCFWWxNlunX625a1QTHAQGlX4WYuqlnZXUMgcl1CW9qbZ9IBO-1QI/s1600/Donetsk.gif&quot; height=&quot;295&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&quot;Donetsk&quot; (&quot;Донецьк&quot;) label at OSM is suppressed by the label of adjusted town&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
</description><link>http://ssrebelious.blogspot.com/2014/08/donetsk-label-at-openstreetmap.html</link><author>noreply@blogger.com (Yury Ryabov)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiWjA9ieExD3wjiOJxC1vwyeQnDH-AoYdrerazce6v0EQxZ6uR3RqNZppiPYdA4uj8Ky6wGKbXy53_3B111Fc0l4LcCFWWxNlunX625a1QTHAQGlX4WYuqlnZXUMgcl1CW9qbZ9IBO-1QI/s72-c/Donetsk.gif" height="72" width="72"/><thr:total>3</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3120553115257874322.post-2250894305614470879</guid><pubDate>Wed, 28 May 2014 20:25:00 +0000</pubDate><atom:updated>2014-05-29T00:25:41.030+04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Dota 2</category><category domain="http://www.blogger.com/atom/ns#">Python</category><title>Random VS Pseudo Random PROC or Why Does Axe&#39;s Win Rate Dropped in 6.81 Patch (Dota 2)</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;h2 style=&quot;text-align: justify;&quot;&gt;
Introduction&lt;/h2&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Here is an &lt;a href=&quot;http://dotabuff.com/blog?page=3&quot;&gt;interesting post&lt;/a&gt; about 6.81 patch influence on heroes win rate in Dota 2. One point caught my attention: a drastic change in Axe win rate: from 52% to 48%; see image below.&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;img align=&quot;middle&quot; src=&quot;http://i.imgur.com/pSf8gMH.png&quot; height=&quot;166&quot; style=&quot;margin-left: auto; margin-right: auto;&quot; width=&quot;640&quot; /&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;Axe&#39;s win rate before and after 6.81 patch (29-th of April)&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;figure&gt;&lt;div style=&quot;text-align: center;&quot;&gt;
 &lt;/div&gt;
&lt;/figure&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The only change Axe get in this patch was implementation of the preudo random approach for the determination of &lt;a href=&quot;http://dotabuff.com/heroes/axe/abilities&quot;&gt; Counter Helix&lt;/a&gt; skill  triggering instead of random. As was guessed in the article: &amp;nbsp;&lt;/div&gt;
&lt;blockquote class=&quot;tr_bq&quot; style=&quot;text-align: justify;&quot;&gt;
&quot;...where you manage to Berserker&#39;s Call several enemies, you only have 3.2 seconds of being unconditionally hit by the enemy. In this time frame, the amount of successful Counter Helixes that use PRD is probably lower than with a true random. Hence the decrease in damage output and Win Rate.&quot;&amp;nbsp;&lt;/blockquote&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp;Ok, nice guess! Lets test it!&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h2 style=&quot;text-align: justify;&quot;&gt;
Create a simulation to test the hypothesis&lt;/h2&gt;
&lt;div&gt;
Import needed modules&lt;br /&gt;&lt;/div&gt;
&lt;pre class=&quot;brush: python&quot;&gt;
import random
import numpy
from tabulate import tabulate
import collections
&lt;/pre&gt;
&lt;div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Lets create functions to calculate number of Counter Helix PROCs for given number of hits using random and pseudo random approaches. First one will be using random approach (notice that random.randrange() actually generates pseudo random set of values)&lt;/div&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush: python&quot;&gt;
def randHelixProc(hits):
  &#39;&#39;&#39;
  checks if Counter Helix PROCs (chance = 17%) using random approach
  @param hits: number of times Axe was hit
  @return procs: number of times Counter Helix PROCs
  &#39;&#39;&#39;
  procs = 0

  for i in xrange(hits):
    chance = random.randrange(1, 101)
    if chance &lt; 18:
      procs += 1
    else:
      continue

  return procs
&lt;/pre&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
I don&#39;t know how exactly pseudo random PROCs are designed for Axe or for Dota 2 in general, but they say that the probability of the pseudo random event in Dota 2 in it initial state has lower chance to proc than the stated probability for the event and each time the event is not triggered when it could the chance for this event to occur is increased. Lets say some event triggers with the 50% chance. Suggested pseudo random approach can be realised with 3 consecutive checks that have different chances: 0%, 50% and 100% (average is 50%). When event finally triggers it reset chance for the event to initial value (0% in this case) and it all starts over again.&lt;/div&gt;
&lt;pre class=&quot;brush: python&quot;&gt;
def pseudoRandHelixProc(hits):
  &#39;&#39;&#39;
  checks if Counter Helix PROCs (chance = 17%) using pseudo random approach
  @param hits: number of times Axe was hit
  @return procs: number of times Counter Helix PROCs
  &#39;&#39;&#39;
  treshold = 0
  prob_list = [2, 5, 9, 14, 23, 47] # ~17% on average
  procs = 0
  for i in xrange(hits):
    chance = random.randrange(1, 101)
    try:
      success = prob_list[treshold]
    except:
      success = prob_list[5]
    if chance &gt;= success:
      treshold += 1
    else:
      procs += 1
      treshold = 0
  return procs
&lt;/pre&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Check if the chances for PROCs are the same for the both functions. We should have 1700 procs of Counter Helix for 10000 attacs on Axe. Launch 100 simulations of 10000 hits for each function and compute average procs for random and pseudo random approaches.&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;pre class=&quot;brush: python&quot;&gt;
rhelix_list = []
for i in xrange(100):
  value = randHelixProc(10000)
  rhelix_list.append(value)
numpy.mean(rhelix_list)

&gt;&gt;&gt;1702.79

p_rhelix_list = []
for i in xrange(100):
  value = pseudoRandHelixProc(10000)
  p_rhelix_list.append(value)
numpy.mean(p_rhelix_list)

&gt;&gt;&gt;1702.3
&lt;/pre&gt;
Output difference is negligible for random and pseudo random implementations.&lt;br /&gt;
Now its time to create a simulation function.&lt;br /&gt;
&lt;pre class=&quot;brush: python&quot;&gt;
def simulation(times, hits):
  &#39;&#39;&#39;
  Computes average number of PROCs for given hits for random and pseudo random
  approaches and difference between them.

  @param times: number of times simulation will run
  @param hits: number of hits to simulate
  @return: average difference in pocs between random and pseudo random approaches;
           table of simul results
  &#39;&#39;&#39;
  # create lists of results
  diff_list = []
  rand_mean_list = []
  p_rand_mean_list = []

  # run simulation
  for hit in xrange(1, hits + 1):

    rand_list = []
    pseudo_rand_list = []

    for t in xrange(times):
      rand = randHelixProc(hit)
      p_rand = pseudoRandHelixProc(hit)
      rand_list.append(rand)
      pseudo_rand_list.append(p_rand)

    # compute statistics and populate lists of results
    rand_mean = numpy.mean(rand_list)
    rand_mean_list.append(rand_mean)
    p_rand_mean = numpy.mean(pseudo_rand_list)
    p_rand_mean_list.append(p_rand_mean)
    diff = rand_mean - p_rand_mean
    diff = round(diff, 2)
    diff_list.append(diff)

  # print average difference in PROCs
  total_diff = sum(diff_list)
  l = len(diff_list)
  print &#39;average difference:&#39;, total_diff/l
  print &#39;#######################################################################################################&#39;

  # create table output for simulation results
  out_dict = {}
  out_dict[&#39;(1) cumulative hits&#39;] = range(1, l + 1)
  out_dict[&#39;(2) random mean PROCs&#39;] = rand_mean_list
  out_dict[&#39;(3) pseudo random mean PROCs&#39;] = p_rand_mean_list
  out_dict[&#39;(4) difference&#39;] = diff_list
  out_dict = collections.OrderedDict(sorted(out_dict.items()))
  print tabulate(out_dict, headers = &#39;keys&#39;, tablefmt=&quot;orgtbl&quot;)
&lt;/pre&gt;
Lets run 100 simulations of 100 consecutive hits. Of course it is possible to run 10000 hits but it is unnecessary since every time the Counter Helix is triggered we jump back to the first row from the table below (result of the simulation). As was already mentioned:&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&quot;[if] ...you manage to Berserker&#39;s Call several enemies, you only have 3.2 seconds of being unconditionally hit by the enemy&quot;&lt;/blockquote&gt;
If Axe was able to catch 3 enemies, together they will hit him about 9-12 times. This means that with the pseudo random approach he will spin 0.3-0.4 times less than with random approach. It will cause him to deal ~(205*0.35)*3 = 215,25 (or 71.75 per hero) less damage in engagement.&lt;br /&gt;
&lt;br /&gt;
So the hypothesis was true - pseudo random approach caused the decrease in damage output on the short time interval even if total number of PROCs during the game stayed the same.&lt;br /&gt;
&lt;pre class=&quot;brush: python&quot;&gt;
average difference: 0.34
#######################################################################################################
|   (1) cumulative hits |   (2) random mean PROCs |   (3) pseudo random mean PROCs |   (4) difference |
|-----------------------+-------------------------+--------------------------------+------------------|
|                     1 |                    0.17 |                           0    |             0.17 |
|                     2 |                    0.45 |                           0.09 |             0.36 |
|                     3 |                    0.56 |                           0.12 |             0.44 |
|                     4 |                    0.71 |                           0.26 |             0.45 |
|                     5 |                    0.81 |                           0.36 |             0.45 |
|                     6 |                    1.06 |                           0.75 |             0.31 |
|                     7 |                    1.37 |                           0.88 |             0.49 |
|                     8 |                    1.35 |                           0.97 |             0.38 |
|                     9 |                    1.47 |                           1.22 |             0.25 |
|                    10 |                    1.64 |                           1.33 |             0.31 |
|                    11 |                    1.95 |                           1.65 |             0.3  |
|                    12 |                    2.1  |                           1.68 |             0.42 |
|                    13 |                    2.36 |                           1.79 |             0.57 |
|                    14 |                    2.56 |                           2.16 |             0.4  |
|                    15 |                    2.61 |                           2.26 |             0.35 |
|                    16 |                    2.61 |                           2.37 |             0.24 |
|                    17 |                    2.87 |                           2.43 |             0.44 |
|                    18 |                    2.77 |                           2.83 |            -0.06 |
|                    19 |                    3.22 |                           2.84 |             0.38 |
|                    20 |                    3.03 |                           2.84 |             0.19 |
|                    21 |                    3.6  |                           3.22 |             0.38 |
|                    22 |                    3.71 |                           3.32 |             0.39 |
|                    23 |                    3.68 |                           3.68 |             0    |
|                    24 |                    3.93 |                           3.72 |             0.21 |
|                    25 |                    4.54 |                           3.92 |             0.62 |
|                    26 |                    4.65 |                           4.04 |             0.61 |
|                    27 |                    4.47 |                           4.27 |             0.2  |
|                    28 |                    4.83 |                           4.39 |             0.44 |
|                    29 |                    4.78 |                           4.48 |             0.3  |
|                    30 |                    4.93 |                           4.8  |             0.13 |
|                    31 |                    5.3  |                           4.92 |             0.38 |
|                    32 |                    5.1  |                           5.04 |             0.06 |
|                    33 |                    5.79 |                           5.34 |             0.45 |
|                    34 |                    5.82 |                           5.54 |             0.28 |
|                    35 |                    6.04 |                           5.52 |             0.52 |
|                    36 |                    5.67 |                           5.7  |            -0.03 |
|                    37 |                    6.64 |                           5.98 |             0.66 |
|                    38 |                    6.4  |                           6.03 |             0.37 |
|                    39 |                    6.72 |                           6.41 |             0.31 |
|                    40 |                    7.07 |                           6.46 |             0.61 |
|                    41 |                    7.04 |                           6.59 |             0.45 |
|                    42 |                    7.18 |                           6.81 |             0.37 |
|                    43 |                    7.08 |                           6.9  |             0.18 |
|                    44 |                    7.61 |                           7.09 |             0.52 |
|                    45 |                    7.72 |                           7.21 |             0.51 |
|                    46 |                    7.73 |                           7.66 |             0.07 |
|                    47 |                    8    |                           7.68 |             0.32 |
|                    48 |                    8.41 |                           7.7  |             0.71 |
|                    49 |                    8.57 |                           7.93 |             0.64 |
|                    50 |                    8.54 |                           8.11 |             0.43 |
|                    51 |                    8.16 |                           8.31 |            -0.15 |
|                    52 |                    9    |                           8.4  |             0.6  |
|                    53 |                    9.01 |                           8.79 |             0.22 |
|                    54 |                    8.98 |                           8.88 |             0.1  |
|                    55 |                    9.54 |                           8.99 |             0.55 |
|                    56 |                    9.4  |                           9.13 |             0.27 |
|                    57 |                    9.75 |                           9.08 |             0.67 |
|                    58 |                   10.1  |                           9.42 |             0.68 |
|                    59 |                    9.71 |                           9.64 |             0.07 |
|                    60 |                   10.31 |                           9.87 |             0.44 |
|                    61 |                   10.19 |                          10.31 |            -0.12 |
|                    62 |                   10.29 |                          10.21 |             0.08 |
|                    63 |                   10.76 |                          10.55 |             0.21 |
|                    64 |                   10.82 |                          10.48 |             0.34 |
|                    65 |                   10.7  |                          10.77 |            -0.07 |
|                    66 |                   11.27 |                          10.94 |             0.33 |
|                    67 |                   11.81 |                          11.06 |             0.75 |
|                    68 |                   11.54 |                          11.34 |             0.2  |
|                    69 |                   11.98 |                          11.26 |             0.72 |
|                    70 |                   12.26 |                          11.66 |             0.6  |
|                    71 |                   11.35 |                          12.01 |            -0.66 |
|                    72 |                   12.03 |                          11.64 |             0.39 |
|                    73 |                   12.37 |                          11.94 |             0.43 |
|                    74 |                   12.74 |                          12.16 |             0.58 |
|                    75 |                   13.16 |                          12.66 |             0.5  |
|                    76 |                   12.77 |                          12.59 |             0.18 |
|                    77 |                   13.1  |                          12.65 |             0.45 |
|                    78 |                   13.2  |                          12.95 |             0.25 |
|                    79 |                   13.59 |                          13.06 |             0.53 |
|                    80 |                   13.32 |                          13.27 |             0.05 |
|                    81 |                   13.74 |                          13.25 |             0.49 |
|                    82 |                   13.98 |                          13.47 |             0.51 |
|                    83 |                   14.86 |                          13.74 |             1.12 |
|                    84 |                   14.53 |                          13.8  |             0.73 |
|                    85 |                   14.54 |                          14.29 |             0.25 |
|                    86 |                   14.49 |                          14.22 |             0.27 |
|                    87 |                   15.03 |                          14.46 |             0.57 |
|                    88 |                   15.49 |                          14.55 |             0.94 |
|                    89 |                   15.51 |                          14.8  |             0.71 |
|                    90 |                   15.58 |                          15    |             0.58 |
|                    91 |                   16.17 |                          15.01 |             1.16 |
|                    92 |                   14.89 |                          15.43 |            -0.54 |
|                    93 |                   15.73 |                          15.4  |             0.33 |
|                    94 |                   16.16 |                          15.67 |             0.49 |
|                    95 |                   16.11 |                          16.17 |            -0.06 |
|                    96 |                   16.03 |                          16.17 |            -0.14 |
|                    97 |                   16.41 |                          16.07 |             0.34 |
|                    98 |                   17.26 |                          16.27 |             0.99 |
|                    99 |                   15.65 |                          16.7  |            -1.05 |
|                   100 |                   16.15 |                          16.96 |            -0.81 |
&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;</description><link>http://ssrebelious.blogspot.com/2014/05/random-vs-pseudo-random-proc-or-why.html</link><author>noreply@blogger.com (Yury Ryabov)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3120553115257874322.post-5592666620296093298</guid><pubDate>Thu, 08 May 2014 17:02:00 +0000</pubDate><atom:updated>2014-05-08T21:30:48.939+04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">LiDAR</category><category domain="http://www.blogger.com/atom/ns#">QGIS</category><category domain="http://www.blogger.com/atom/ns#">R</category><category domain="http://www.blogger.com/atom/ns#">rasters</category><category domain="http://www.blogger.com/atom/ns#">spatial data</category><title>Classification of the Hyper-Spectral and LiDAR Imagery using R (mostly). Part 3: Shadow Removal</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
This is my third post in this series, here are the links to the &lt;a href=&quot;http://ssrebelious.blogspot.com/2013/07/classification-of-hyper-spectral-and.html&quot; target=&quot;_blank&quot;&gt;Part 1&lt;/a&gt; and &lt;a href=&quot;http://ssrebelious.blogspot.com/2013/08/classification-of-hyper-spectral-and.html&quot; target=&quot;_blank&quot;&gt;Part 2&lt;/a&gt;. Sorry for the delay, but at that time I got completely consumed with my PhD thesis and this story just went out of my mind.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
To the point. There were 2 types of shadows I had to deal with: cloud shadows and cast shadows (from building and trees). In scientific literature you can find several relatively complicated algorithms to deal with them (including DEM usage for cast shadow detection) and I definitely should have used some of them, but... I was too lazy to implement them when there were couple of quick&#39;n&#39;dirty workarounds available.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h3 style=&quot;text-align: justify;&quot;&gt;
Cloud shadow removal&lt;/h3&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
To remove cloud shadows I decided to calculate ratio between mean pixel value of the lighted up and shadowed parts of the raster for each band and multiply shadowed pixels by this ratio. &amp;nbsp;I manually created a mask for shadowed areas. There were 3 areas and their borders were quite distinct in NIR channels:&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEifRcFJF3FDP88KehgW-97i0XtP5SJTjV5nIglDI-SxerWaFewxAlCzHQG99n2Z4fMahDg-gEXhurKsFsd8uAb1lxnYd4rm3kGYFVY5xIgiJ3Ci3XYRq9dRVZUw-WPnekL_zfDf1oz181Q/s1600/clouds_shadow.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEifRcFJF3FDP88KehgW-97i0XtP5SJTjV5nIglDI-SxerWaFewxAlCzHQG99n2Z4fMahDg-gEXhurKsFsd8uAb1lxnYd4rm3kGYFVY5xIgiJ3Ci3XYRq9dRVZUw-WPnekL_zfDf1oz181Q/s1600/clouds_shadow.png&quot; height=&quot;242&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Cloud shadows in one of the NIR bands&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
I drew several polygons over shadows in QGIS and converted them to raster (Raster -&amp;gt; Conversion -&amp;gt; Rasterise). Now everything was ready for patching:&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;

&lt;pre class=&quot;brush: r&quot;&gt;
library(raster)
library(rgdal)

# load rasters
image &lt;- stack(&#39;2013_IEEE_GRSS_DF_Contest_CASI.tif&#39;) # hyper spectral imagery
s_mask &lt;- raster(&#39;shadow_mask.tif&#39;) # mask for cloud shadow

# extract shadowed area
m_cloud &lt;- s_mask
m_cloud[m_cloud &lt; 1] &lt;- NA
shadowed &lt;- mask(image, m_cloud)

# calculate zonal statistics
zd &lt;- zonal(image, s_mask, fun = &#39;mean&#39;, na.rm = T)
zd &lt;- as.data.frame(zd)

# calculate ratio between lighted up and shadowed zones
zd[3,] &lt;- zd[1,] / zd[2,] 

# recalculae data in shadows
multiplyer &lt;- zd[3,]
multiplyer &lt;- multiplyer[,2:ncol(zd)]
multiplyer &lt;- as.numeric(multiplyer)
enlight &lt;- shadowed*multiplyer # patch layer
restored &lt;- cover(enlight, image, progress = &#39;text&#39;)

# save result
wr &lt;- writeRaster(restored, 
                  filename = &#39;restored.tif&#39;, 
                  datatype = &#39;GTiff&#39;, overwrite = TRUE)

&lt;/pre&gt;

&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Now it&#39;s time to check out results:&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjw9u0MDve-zMB3yxnFYVXafHKp5YD3NIFlIyAN5SBcQhSZykaHvD5E-cFTmEnNwb_AoyUyiyz0lElY75xHKEbS_cpC7-CuptdTWeypExMIEwc8cXOaLhsWra7M7_43YSCG1PEhFJlOOaU/s1600/clouds_shadow_patched.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjw9u0MDve-zMB3yxnFYVXafHKp5YD3NIFlIyAN5SBcQhSZykaHvD5E-cFTmEnNwb_AoyUyiyz0lElY75xHKEbS_cpC7-CuptdTWeypExMIEwc8cXOaLhsWra7M7_43YSCG1PEhFJlOOaU/s1600/clouds_shadow_patched.png&quot; height=&quot;242&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;The same NIR band after cloud shadow removal&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Yes, we can easily find patched areas, but overall result is good for such simple approach.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h3 style=&quot;text-align: justify;&quot;&gt;
Cast shadow removal&lt;/h3&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Shadows from buildings can be processed the same way as cloud shadows as shown above except mask creation approach is different. In case of cast shadows they have to be detected automatically (for there are a bit more than 3 as in case with clouds). Using one of the NIR bands I created a learning sample of points and passed it to Random Forest algorithm to classify imagery into shadowed and non-shadowed areas. I will not describe here this classification process for Random Forest was used for overall classification of the imagery and it is the subject of my next post of this series.&lt;/div&gt;

&lt;/div&gt;</description><link>http://ssrebelious.blogspot.com/2014/05/classification-of-hyper-spectral-and.html</link><author>noreply@blogger.com (Yury Ryabov)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEifRcFJF3FDP88KehgW-97i0XtP5SJTjV5nIglDI-SxerWaFewxAlCzHQG99n2Z4fMahDg-gEXhurKsFsd8uAb1lxnYd4rm3kGYFVY5xIgiJ3Ci3XYRq9dRVZUw-WPnekL_zfDf1oz181Q/s72-c/clouds_shadow.png" height="72" width="72"/><thr:total>0</thr:total></item></channel></rss>