<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
  <title>ENGs on JLA Data</title>
  <link>https://www.jla-data.net/eng/</link>
  <description>Recent content in ENGs on JLA Data</description>
  <generator>Hugo -- gohugo.io</generator>
<language>en-us</language>
<copyright>Jindra Lacko</copyright>
<lastBuildDate>Thu, 09 Oct 2025 00:00:00 +0000</lastBuildDate>

<atom:link href="https://www.jla-data.net/eng/index.xml" rel="self" type="application/rss+xml" />


<item>
  <title>Extracting location from text with AI</title>
  <link>https://www.jla-data.net/eng/extracting-location-from-text-with-gemini-ai/</link>
  <pubDate>Thu, 09 Oct 2025 00:00:00 +0000</pubDate>
  
<guid>https://www.jla-data.net/eng/extracting-location-from-text-with-gemini-ai/</guid>
  <description>
&lt;link href=&#34;https://www.jla-data.net/eng/extracting-location-from-text-with-gemini-ai/index_files/htmltools-fill/fill.css&#34; rel=&#34;stylesheet&#34; /&gt;
&lt;script src=&#34;https://www.jla-data.net/eng/extracting-location-from-text-with-gemini-ai/index_files/htmlwidgets/htmlwidgets.js&#34;&gt;&lt;/script&gt;
&lt;script src=&#34;https://www.jla-data.net/eng/extracting-location-from-text-with-gemini-ai/index_files/jquery/jquery-3.6.0.min.js&#34;&gt;&lt;/script&gt;
&lt;link href=&#34;https://www.jla-data.net/eng/extracting-location-from-text-with-gemini-ai/index_files/leaflet/leaflet.css&#34; rel=&#34;stylesheet&#34; /&gt;
&lt;script src=&#34;https://www.jla-data.net/eng/extracting-location-from-text-with-gemini-ai/index_files/leaflet/leaflet.js&#34;&gt;&lt;/script&gt;
&lt;link href=&#34;https://www.jla-data.net/eng/extracting-location-from-text-with-gemini-ai/index_files/leafletfix/leafletfix.css&#34; rel=&#34;stylesheet&#34; /&gt;
&lt;script src=&#34;https://www.jla-data.net/eng/extracting-location-from-text-with-gemini-ai/index_files/proj4/proj4.min.js&#34;&gt;&lt;/script&gt;
&lt;script src=&#34;https://www.jla-data.net/eng/extracting-location-from-text-with-gemini-ai/index_files/Proj4Leaflet/proj4leaflet.js&#34;&gt;&lt;/script&gt;
&lt;link href=&#34;https://www.jla-data.net/eng/extracting-location-from-text-with-gemini-ai/index_files/rstudio_leaflet/rstudio_leaflet.css&#34; rel=&#34;stylesheet&#34; /&gt;
&lt;script src=&#34;https://www.jla-data.net/eng/extracting-location-from-text-with-gemini-ai/index_files/leaflet-binding/leaflet.js&#34;&gt;&lt;/script&gt;


&lt;p&gt;In one of my projects I have recently faced the need to summarize and geolocate a largish volume of short pieces of text. While the actual project is not that relevant for this post I found the problem as a fun excuse for using AI methods, and overall an interesting learning exercise.&lt;/p&gt;
&lt;p&gt;The method I ended using is the &lt;a href=&#34;https://ai.google.dev/gemini-api/docs/structured-output&#34;&gt;structured output of Gemini API&lt;/a&gt;, leveraged from R via the &lt;a href=&#34;https://jhk0530.github.io/gemini.R/&#34;&gt;gemini.R&lt;/a&gt; package. Gemini because I have a working relationship with Google from using their geocoding and routing APIs extensively in my work, and structured output in order to ease the conversion from plain text to the &lt;code&gt;{sf}&lt;/code&gt; flavor of data frame.&lt;/p&gt;
&lt;p&gt;Since my task was relatively simple and high volume I tried at first the &lt;a href=&#34;https://ai.google.dev/gemini-api/docs/models#gemini-2.5-flash-lite&#34;&gt;Lite&lt;/a&gt; version of the current Gemini model, as it produces the fastest (and cheapest) output. I found the quality of the lite model more than adequate for my needs, and so I stuck with the initial choice.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;The first step is reading in the libraries required; no surprise here…&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;library(gemini.R)  # for accessing the Gemini API
library(dplyr)     # for the pipe and data frame handling
library(jsonlite)  # to make sense of the JSON results
library(leaflet)   # to visualize the output&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The Gemini call is not overly complicated: it involves passing a prompt to a model, and handling the output. In the case of a &lt;a href=&#34;https://jhk0530.github.io/gemini.R/reference/gemini_structured.html&#34;&gt;&lt;code&gt;gemini.R::gemini_structured()&lt;/code&gt;&lt;/a&gt; call also with specification of the required structure, which is well documented on the package website.&lt;/p&gt;
&lt;p&gt;Since the Gemini API is a paid service it is also necessary to register an API key; a step that I am omitting here for practical reasons (I suggest keeping the key in your &lt;code&gt;.Renviron&lt;/code&gt; file).&lt;/p&gt;
&lt;p&gt;The fun part is playing with various versions of a prompt; in my case it follows the structure of “you are an experienced &lt;em&gt;whatever&lt;/em&gt;, do give me &lt;em&gt;this &amp;amp; that&lt;/em&gt;” followed by the piece of text that needs summarising and geocoding.&lt;/p&gt;
&lt;p&gt;With a little tuning it can be tweaked to geocode either all the locations mentioned, or only the most important one. Since my use case called for one (and only one) location per piece of text I am asking very specifically for the single most important location.&lt;/p&gt;
&lt;p&gt;To test my prompt I am using a piece of lyrics from Peter Sarsted’s &lt;a href=&#34;https://en.wikipedia.org/wiki/Where_Do_You_Go_To_(My_Lovely)%3F&#34;&gt;Where Do You Go To&lt;/a&gt;:&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;# initial prompt
prompt_header &amp;lt;- &amp;quot;you are an experienced geographer; analyze this text and 
                  give me its single most important location as a name and 
                  as a POINT in simple features WKT format 
                  and state your confidence on a scale from 0 to 100 \n\n&amp;quot;

# text to be analyzed
text_input &amp;lt;- &amp;quot;You talk like Marlene Dietrich
               And you dance like Zizi Jeanmaire
               Your clothes are all made by Balmain
               And there&amp;#39;s diamonds and pearls in your hair, yes, there are
               You live in a fancy apartment
               Off the Boulevard St. Michel
               Where you keep your Rolling Stones records
               And a friend of Sacha Distel, yes, you do
               
               But where do you go to, my lovely
               When you&amp;#39;re alone in your bed?
               Tell me the thoughts that surround you
               I want to look inside your head, yes, I do
               
               I&amp;#39;ve seen all your qualifications
               You got from the Sorbonne
               And the painting you stole from Picasso
               Your loveliness goes on and on, yes, it does
               When you go on your summer vacation
               You go to Juan-les-Pins
               With your carefully designed topless swimsuit
               You get an even suntan on your back, and on your legs
               And when the snow falls you&amp;#39;re found in St. Moritz
               With the others of the jet set
               And you sip your Napoleon brandy
               But you never get your lips wet, no, you don&amp;#39;t
               
               But where do you go to, my lovely
               When you&amp;#39;re alone in your bed?
               Won&amp;#39;t you tell me the thoughts that surround you?
               I want to look inside your head, yes, I do&amp;quot;

# schema to give the output a firm structure
schema &amp;lt;- list(
   type = &amp;quot;ARRAY&amp;quot;,
   items = list(
      type = &amp;quot;OBJECT&amp;quot;,
      properties = list(
         name = list(type = &amp;quot;STRING&amp;quot;),
         location = list(type = &amp;quot;STRING&amp;quot;),
         confidence = list(type = &amp;quot;NUMBER&amp;quot;)
      ),
      propertyOrdering = c(&amp;quot;name&amp;quot;, &amp;quot;location&amp;quot;, &amp;quot;confidence&amp;quot;)
   )
)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Having all the parts ready I place a call to the Gemini model:&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;# let Gemini perform its magic!
location &amp;lt;- gemini_structured(prompt = paste(prompt_header, text_input),
                              model = &amp;quot;2.5-flash-lite&amp;quot;, # for the cheapskates...
                              schema = schema)&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;## Gemini is generating a structured response...&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;To give an overview of the result returned I first check the JSON returned, and then transform the output from JSON to &lt;code&gt;{sf}&lt;/code&gt; data format via a regular data frame. The model evidently understands the logic of simple features format well and uses EPSG:4326 coordinates by default. The transformation from a well known text to &lt;code&gt;{sf}&lt;/code&gt; is thus not a complicated one.&lt;/p&gt;
&lt;p&gt;As a final step I pipe the &lt;code&gt;{sf}&lt;/code&gt; result to a &lt;code&gt;{leaflet}&lt;/code&gt; call, visualizing the location on the default OSM basemap.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;# initial overview of the result as JSON object
prettify(location)&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;## [
##     {
##         &amp;quot;name&amp;quot;: &amp;quot;Boulevard Saint-Michel&amp;quot;,
##         &amp;quot;location&amp;quot;: &amp;quot;POINT(2.3366434 48.8464368)&amp;quot;,
##         &amp;quot;confidence&amp;quot;: 95
##     }
## ]
## &lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;# interpret the result as sf object
location %&amp;gt;% 
   jsonlite::fromJSON() %&amp;gt;%  
   sf::st_as_sf(wkt = &amp;quot;location&amp;quot;, crs = 4326) %&amp;gt;% 
   leaflet() %&amp;gt;% 
   addTiles() %&amp;gt;% 
   addCircleMarkers(label = ~ paste(name, &amp;quot;- confidence&amp;quot;, confidence, &amp;quot;of 100&amp;quot;),
                    color = &amp;quot;red&amp;quot;,
                    stroke = NA,
                    fillOpacity = 1)&lt;/code&gt;&lt;/pre&gt;
&lt;div class=&#34;leaflet html-widget html-fill-item&#34; id=&#34;htmlwidget-1&#34; style=&#34;width:100%;height:480px;&#34;&gt;&lt;/div&gt;
&lt;script type=&#34;application/json&#34; data-for=&#34;htmlwidget-1&#34;&gt;{&#34;x&#34;:{&#34;options&#34;:{&#34;crs&#34;:{&#34;crsClass&#34;:&#34;L.CRS.EPSG3857&#34;,&#34;code&#34;:null,&#34;proj4def&#34;:null,&#34;projectedBounds&#34;:null,&#34;options&#34;:{}}},&#34;calls&#34;:[{&#34;method&#34;:&#34;addTiles&#34;,&#34;args&#34;:[&#34;https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png&#34;,null,null,{&#34;minZoom&#34;:0,&#34;maxZoom&#34;:18,&#34;tileSize&#34;:256,&#34;subdomains&#34;:&#34;abc&#34;,&#34;errorTileUrl&#34;:&#34;&#34;,&#34;tms&#34;:false,&#34;noWrap&#34;:false,&#34;zoomOffset&#34;:0,&#34;zoomReverse&#34;:false,&#34;opacity&#34;:1,&#34;zIndex&#34;:1,&#34;detectRetina&#34;:false,&#34;attribution&#34;:&#34;&amp;copy; &lt;a href=\&#34;https://openstreetmap.org/copyright/\&#34;&gt;OpenStreetMap&lt;\/a&gt;,  &lt;a href=\&#34;https://opendatacommons.org/licenses/odbl/\&#34;&gt;ODbL&lt;\/a&gt;&#34;}]},{&#34;method&#34;:&#34;addCircleMarkers&#34;,&#34;args&#34;:[48.8464368,2.3366434,10,null,null,{&#34;interactive&#34;:true,&#34;className&#34;:&#34;&#34;,&#34;stroke&#34;:null,&#34;color&#34;:&#34;red&#34;,&#34;weight&#34;:5,&#34;opacity&#34;:0.5,&#34;fill&#34;:true,&#34;fillColor&#34;:&#34;red&#34;,&#34;fillOpacity&#34;:1},null,null,null,null,&#34;Boulevard Saint-Michel - confidence 95 of 100&#34;,{&#34;interactive&#34;:false,&#34;permanent&#34;:false,&#34;direction&#34;:&#34;auto&#34;,&#34;opacity&#34;:1,&#34;offset&#34;:[0,0],&#34;textsize&#34;:&#34;10px&#34;,&#34;textOnly&#34;:false,&#34;className&#34;:&#34;&#34;,&#34;sticky&#34;:true},null]}],&#34;limits&#34;:{&#34;lat&#34;:[48.8464368,48.8464368],&#34;lng&#34;:[2.3366434,2.3366434]}},&#34;evals&#34;:[],&#34;jsHooks&#34;:[]}&lt;/script&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;I was pleasantly surprised that the model did not fall for the red herrings of the Azure Coast and St. Moritz, and places the most significant location firmly in the Left Bank of Paris. The location returned is about 250 meters off the &lt;em&gt;actual&lt;/em&gt; Boulevard St. Michel, a level of accuracy that is more than adequate for my needs.&lt;/p&gt;
&lt;p&gt;Since my original use case was in multiple languages I am trying out next a different call, using lyrics from Zhanna Bichevskaya’s &lt;a href=&#34;https://en.wikipedia.org/wiki/Po_dikim_stepyam_Zabaikalya&#34;&gt;The Vagabond&lt;/a&gt; in both an unfamiliar language and script:&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;# text to be analyzed
text_input &amp;lt;- &amp;quot;По диким степям Забайкалья,
               Где золото роют в горах,
               Бродяга, судьбу проклиная,
               Тащился с сумой на плечах.
               
               Бежал из тюрьмы тёмной ночью,
               В тюрьме он за правду страдал.
               Идти дальше нет уже мочи –
               Пред ним расстилался Байкал.
               
               Бродяга к Байкалу подходит,
               Рыбацкую лодку берёт
               И грустную песню заводит,
               Про Родину что-то поёт.

               Бродяга Байкал переехал,
               Навстречу - родимая мать.
               &amp;#39;Ах, здравствуй, ах, здравствуй, мамаша,
               Здоров ли отец мой да брат?&amp;#39;
               
               &amp;#39;Отец твой давно уж в могиле,
               Землею сырою лежит,
               А брат твой давно уж в Сибири,
               Давно кандалами гремит.&amp;#39;&amp;quot;

# the same Gemini call, with the same prompt header &amp;quot;experienced geographer&amp;quot;
location &amp;lt;- gemini_structured(prompt = paste(prompt_header, text_input),
                              model = &amp;quot;2.5-flash-lite&amp;quot;, 
                              schema = schema)

# initial overview of the result as JSON object
prettify(location)&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;## [
##     {
##         &amp;quot;name&amp;quot;: &amp;quot;Lake Baikal&amp;quot;,
##         &amp;quot;location&amp;quot;: &amp;quot;POINT(108.316667 53.616667)&amp;quot;,
##         &amp;quot;confidence&amp;quot;: 95
##     }
## ]
## &lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;# interpret the result as sf object
location %&amp;gt;% 
   jsonlite::fromJSON() %&amp;gt;% 
   sf::st_as_sf(wkt = &amp;quot;location&amp;quot;, crs = 4326) %&amp;gt;% 
   leaflet() %&amp;gt;% 
   addTiles() %&amp;gt;% 
   addCircleMarkers(label = ~ paste(name, &amp;quot;- confidence&amp;quot;, confidence, &amp;quot;of 100&amp;quot;),
                    color = &amp;quot;red&amp;quot;,
                    stroke = NA,
                    fillOpacity = 1)&lt;/code&gt;&lt;/pre&gt;
&lt;div class=&#34;leaflet html-widget html-fill-item&#34; id=&#34;htmlwidget-2&#34; style=&#34;width:100%;height:480px;&#34;&gt;&lt;/div&gt;
&lt;script type=&#34;application/json&#34; data-for=&#34;htmlwidget-2&#34;&gt;{&#34;x&#34;:{&#34;options&#34;:{&#34;crs&#34;:{&#34;crsClass&#34;:&#34;L.CRS.EPSG3857&#34;,&#34;code&#34;:null,&#34;proj4def&#34;:null,&#34;projectedBounds&#34;:null,&#34;options&#34;:{}}},&#34;calls&#34;:[{&#34;method&#34;:&#34;addTiles&#34;,&#34;args&#34;:[&#34;https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png&#34;,null,null,{&#34;minZoom&#34;:0,&#34;maxZoom&#34;:18,&#34;tileSize&#34;:256,&#34;subdomains&#34;:&#34;abc&#34;,&#34;errorTileUrl&#34;:&#34;&#34;,&#34;tms&#34;:false,&#34;noWrap&#34;:false,&#34;zoomOffset&#34;:0,&#34;zoomReverse&#34;:false,&#34;opacity&#34;:1,&#34;zIndex&#34;:1,&#34;detectRetina&#34;:false,&#34;attribution&#34;:&#34;&amp;copy; &lt;a href=\&#34;https://openstreetmap.org/copyright/\&#34;&gt;OpenStreetMap&lt;\/a&gt;,  &lt;a href=\&#34;https://opendatacommons.org/licenses/odbl/\&#34;&gt;ODbL&lt;\/a&gt;&#34;}]},{&#34;method&#34;:&#34;addCircleMarkers&#34;,&#34;args&#34;:[53.616667,108.316667,10,null,null,{&#34;interactive&#34;:true,&#34;className&#34;:&#34;&#34;,&#34;stroke&#34;:null,&#34;color&#34;:&#34;red&#34;,&#34;weight&#34;:5,&#34;opacity&#34;:0.5,&#34;fill&#34;:true,&#34;fillColor&#34;:&#34;red&#34;,&#34;fillOpacity&#34;:1},null,null,null,null,&#34;Lake Baikal - confidence 95 of 100&#34;,{&#34;interactive&#34;:false,&#34;permanent&#34;:false,&#34;direction&#34;:&#34;auto&#34;,&#34;opacity&#34;:1,&#34;offset&#34;:[0,0],&#34;textsize&#34;:&#34;10px&#34;,&#34;textOnly&#34;:false,&#34;className&#34;:&#34;&#34;,&#34;sticky&#34;:true},null]}],&#34;limits&#34;:{&#34;lat&#34;:[53.616667,53.616667],&#34;lng&#34;:[108.316667,108.316667]}},&#34;evals&#34;:[],&#34;jsHooks&#34;:[]}&lt;/script&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;The model interprets the song accurately, and places the principal location in the middle of Lake Baikal as expected (you may need to zoom the map out a little to fully appreciate this).&lt;/p&gt;
&lt;p&gt;Given the AI models well documented eagerness to please – and the inevitable hallucinations which result from it – I wanted to finally test my prompt with a piece of text guaranteed to contain absolutely no usable information; Lewis Carroll’s &lt;a href=&#34;https://en.wikipedia.org/wiki/Jabberwocky&#34;&gt;Jabberwocky&lt;/a&gt; ensures that:&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;# text to be analyzed
text_input &amp;lt;- &amp;quot;&amp;#39;Twas brillig, and the slithy toves
               Did gyre and gimble in the wabe;
               All mimsy were the borogoves,
               And the mome raths outgrabe.
               
               &amp;#39;Beware the Jabberwock, my son!
               The jaws that bite, the claws that catch!
               Beware the Jubjub bird, and shun
               The frumious Bandersnatch!&amp;#39;
               
               He took his vorpal sword in hand:
               Long time the manxome foe he sought—
               So rested he by the Tumtum tree,
               And stood awhile in thought.
               
               And as in uffish thought he stood,
               The Jabberwock, with eyes of flame,
               Came whiffling through the tulgey wood,
               And burbled as it came!
               
               One, two! One, two! And through and through
               The vorpal blade went snicker-snack!
               He left it dead, and with its head
               He went galumphing back.
               
               &amp;#39;And hast thou slain the Jabberwock?
               Come to my arms, my beamish boy!
               O frabjous day! Callooh! Callay!&amp;#39;
               He chortled in his joy.
               
               &amp;#39;Twas brillig, and the slithy toves
               Did gyre and gimble in the wabe;
               All mimsy were the borogoves,
               And the mome raths outgrabe.&amp;quot;
               
# the same Gemini call, with the same prompt header &amp;quot;experienced geographer&amp;quot;
location &amp;lt;- gemini_structured(prompt = paste(prompt_header, text_input),
                              model = &amp;quot;2.5-flash-lite&amp;quot;, 
                              schema = schema)

# initial overview of the result as JSON object
prettify(location)&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;## [
##     {
##         &amp;quot;name&amp;quot;: &amp;quot;The Wabe&amp;quot;,
##         &amp;quot;location&amp;quot;: &amp;quot;POINT(0 0)&amp;quot;,
##         &amp;quot;confidence&amp;quot;: 10
##     }
## ]
## &lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;# interpret the result as sf object
location %&amp;gt;% 
   jsonlite::fromJSON() %&amp;gt;% 
   sf::st_as_sf(wkt = &amp;quot;location&amp;quot;, crs = 4326) %&amp;gt;% 
   leaflet() %&amp;gt;% 
   addTiles() %&amp;gt;% 
   addCircleMarkers(label = ~ paste(name, &amp;quot;- confidence&amp;quot;, confidence, &amp;quot;of 100&amp;quot;),
                    color = &amp;quot;red&amp;quot;,
                    stroke = NA,
                    fillOpacity = 1)&lt;/code&gt;&lt;/pre&gt;
&lt;div class=&#34;leaflet html-widget html-fill-item&#34; id=&#34;htmlwidget-3&#34; style=&#34;width:100%;height:480px;&#34;&gt;&lt;/div&gt;
&lt;script type=&#34;application/json&#34; data-for=&#34;htmlwidget-3&#34;&gt;{&#34;x&#34;:{&#34;options&#34;:{&#34;crs&#34;:{&#34;crsClass&#34;:&#34;L.CRS.EPSG3857&#34;,&#34;code&#34;:null,&#34;proj4def&#34;:null,&#34;projectedBounds&#34;:null,&#34;options&#34;:{}}},&#34;calls&#34;:[{&#34;method&#34;:&#34;addTiles&#34;,&#34;args&#34;:[&#34;https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png&#34;,null,null,{&#34;minZoom&#34;:0,&#34;maxZoom&#34;:18,&#34;tileSize&#34;:256,&#34;subdomains&#34;:&#34;abc&#34;,&#34;errorTileUrl&#34;:&#34;&#34;,&#34;tms&#34;:false,&#34;noWrap&#34;:false,&#34;zoomOffset&#34;:0,&#34;zoomReverse&#34;:false,&#34;opacity&#34;:1,&#34;zIndex&#34;:1,&#34;detectRetina&#34;:false,&#34;attribution&#34;:&#34;&amp;copy; &lt;a href=\&#34;https://openstreetmap.org/copyright/\&#34;&gt;OpenStreetMap&lt;\/a&gt;,  &lt;a href=\&#34;https://opendatacommons.org/licenses/odbl/\&#34;&gt;ODbL&lt;\/a&gt;&#34;}]},{&#34;method&#34;:&#34;addCircleMarkers&#34;,&#34;args&#34;:[0,0,10,null,null,{&#34;interactive&#34;:true,&#34;className&#34;:&#34;&#34;,&#34;stroke&#34;:null,&#34;color&#34;:&#34;red&#34;,&#34;weight&#34;:5,&#34;opacity&#34;:0.5,&#34;fill&#34;:true,&#34;fillColor&#34;:&#34;red&#34;,&#34;fillOpacity&#34;:1},null,null,null,null,&#34;The Wabe - confidence 10 of 100&#34;,{&#34;interactive&#34;:false,&#34;permanent&#34;:false,&#34;direction&#34;:&#34;auto&#34;,&#34;opacity&#34;:1,&#34;offset&#34;:[0,0],&#34;textsize&#34;:&#34;10px&#34;,&#34;textOnly&#34;:false,&#34;className&#34;:&#34;&#34;,&#34;sticky&#34;:true},null]}],&#34;limits&#34;:{&#34;lat&#34;:[0,0],&#34;lng&#34;:[0,0]}},&#34;evals&#34;:[],&#34;jsHooks&#34;:[]}&lt;/script&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;The model, again as expected, responded by hallucinating up a place called “The Wabe” and placing it on &lt;a href=&#34;https://en.wikipedia.org/wiki/Null_Island&#34;&gt;the Null Island&lt;/a&gt;. But at least it had the good manners to acknowledge the poor quality of its output by giving it a rather low confidence value. In a real world scenario such low confidence locations would be likely filtered out.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;I believe I have shown the feasibility of summarizing and geocoding a piece of text by leveraging the Gemini API.&lt;/p&gt;
&lt;p&gt;The concept seems to be working, with better than expected accuracy. Considering the (possibly excessive, but who am I to judge?) resources invested in the AI toolchain recently it is not surprising that the rough edges were sorted out, and the process of calling the Gemini model API from the comfort of my R session is very smooth.&lt;/p&gt;
&lt;p&gt;And while the Gemini API is a paid service, the costs involved are very reasonable – especially considering the effort that processing of such a volume of short texts manually would involve.&lt;/p&gt;
</description>
  </item>
  
<item>
  <title>Spatial dataset serialization</title>
  <link>https://www.jla-data.net/eng/2024-09-23-cross-language-object-serialization/</link>
  <pubDate>Mon, 23 Sep 2024 00:00:00 +0000</pubDate>
  
<guid>https://www.jla-data.net/eng/2024-09-23-cross-language-object-serialization/</guid>
  <description>


&lt;p&gt;On a recent Spatial Data Science across Languages workshop we discussed the problem of sharing datasets over common data analytics languages.&lt;/p&gt;
&lt;p&gt;This topic is of a special interest to me, as I maintain &lt;a href=&#34;https://cran.r-project.org/package=RCzechia&#34;&gt;a niche package&lt;/a&gt; of sorts, serving spatial data relevant to the Czech Republic to R users. Since the main added value of my package is curating and documenting of highly standardized open datasets the use case lends easily to a multilanguage setting – providing a language agnostic serialization pattern is implemented.&lt;/p&gt;
&lt;p&gt;As a proof of concept I am testing serialization of German &lt;a href=&#34;https://en.wikipedia.org/wiki/Nomenclature_of_Territorial_Units_for_Statistics&#34;&gt;NUTS&lt;/a&gt; 3 regions obtained via the &lt;a href=&#34;https://ropengov.github.io/giscoR/&#34;&gt;&lt;code&gt;{giscoR}&lt;/code&gt;&lt;/a&gt; package, which interfaces the official Eurostat spatial data repository.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;library(sf)

# German NUTS 3 polygons
nuesse &amp;lt;- giscoR::gisco_get_nuts(year = &amp;quot;2024&amp;quot;,
                                 resolution = &amp;quot;01&amp;quot;,
                                 country = &amp;quot;DE&amp;quot;,
                                 nuts_level = 3)
# a high level overview
str(nuesse)&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;## Classes &amp;#39;sf&amp;#39; and &amp;#39;data.frame&amp;#39;:	400 obs. of  10 variables:
##  $ NUTS_ID   : chr  &amp;quot;DE11B&amp;quot; &amp;quot;DE11C&amp;quot; &amp;quot;DE11D&amp;quot; &amp;quot;DE121&amp;quot; ...
##  $ LEVL_CODE : num  3 3 3 3 3 3 3 3 3 3 ...
##  $ URBN_TYPE : chr  NA NA NA NA ...
##  $ CNTR_CODE : chr  &amp;quot;DE&amp;quot; &amp;quot;DE&amp;quot; &amp;quot;DE&amp;quot; &amp;quot;DE&amp;quot; ...
##  $ NAME_LATN : chr  &amp;quot;Main-Tauber-Kreis&amp;quot; &amp;quot;Heidenheim&amp;quot; &amp;quot;Ostalbkreis&amp;quot; &amp;quot;Baden-Baden, Stadtkreis&amp;quot; ...
##  $ NUTS_NAME : chr  &amp;quot;Main-Tauber-Kreis&amp;quot; &amp;quot;Heidenheim&amp;quot; &amp;quot;Ostalbkreis&amp;quot; &amp;quot;Baden-Baden, Stadtkreis&amp;quot; ...
##  $ MOUNT_TYPE: chr  NA NA NA NA ...
##  $ COAST_TYPE: chr  NA NA NA NA ...
##  $ geo       : chr  &amp;quot;DE11B&amp;quot; &amp;quot;DE11C&amp;quot; &amp;quot;DE11D&amp;quot; &amp;quot;DE121&amp;quot; ...
##  $ geometry  :sfc_MULTIPOLYGON of length 400; first list element: List of 1
##   ..$ :List of 2
##   .. ..$ : num [1:415, 1:2] 9.65 9.62 9.58 9.58 9.57 ...
##   .. ..$ : num [1:7, 1:2] 9.53 9.53 9.54 9.54 9.54 ...
##   ..- attr(*, &amp;quot;class&amp;quot;)= chr [1:3] &amp;quot;XY&amp;quot; &amp;quot;MULTIPOLYGON&amp;quot; &amp;quot;sfg&amp;quot;
##  - attr(*, &amp;quot;sf_column&amp;quot;)= chr &amp;quot;geometry&amp;quot;
##  - attr(*, &amp;quot;agr&amp;quot;)= Factor w/ 3 levels &amp;quot;constant&amp;quot;,&amp;quot;aggregate&amp;quot;,..: NA NA NA NA NA NA NA NA NA
##   ..- attr(*, &amp;quot;names&amp;quot;)= chr [1:9] &amp;quot;NUTS_ID&amp;quot; &amp;quot;LEVL_CODE&amp;quot; &amp;quot;URBN_TYPE&amp;quot; &amp;quot;CNTR_CODE&amp;quot; ...&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Germany has 400 NUTS 3 regions, and the logical way to serialize my object for use in R only would be a RDS file; this would be usable only in R environment, but is quite efficient. This will serve as my baseline.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;saveRDS(nuesse, &amp;quot;nuts.rds&amp;quot;)
fs::file_info(&amp;quot;nuts.rds&amp;quot;)$size&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;## 1.19M&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Alternative approach would be to save the dataset as an &lt;a href=&#34;https://en.wikipedia.org/wiki/GeoPackage&#34;&gt;OGC GeoPackage&lt;/a&gt;, a platform-independent data format. A geopackage is easily accessed from any standard data analytics and GIS platform. However the format is not quite as efficient as RDS, leading to about 60% greater file size than my baseline.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;write_sf(nuesse, &amp;quot;nuts.gpkg&amp;quot;)
fs::file_info(&amp;quot;nuts.gpkg&amp;quot;)$size&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;## 1.91M&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;An interesting alternative is storing my dataset in Apache Arrow Feather file format. Out of the box it does not support spatial data features, and thus requires converting geometry to WKT.&lt;/p&gt;
&lt;p&gt;On serialization it loses the CRS information, leaving no record what is the dimension of coordinates stored as WKT (degrees or meters, feet even?). On the other hand the compression applied is very efficient, giving us file size about one half of the RDS benchmark.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;# convert geometry column to WKT string
nuesse$geom &amp;lt;- st_as_text(st_geometry(nuesse))

# drop the original geometry, leaving the WKT only
nuesse$geometry &amp;lt;- NULL

# serialize via Apache Arrow
arrow::write_feather(nuesse, &amp;quot;nuts.feather&amp;quot;, compression = &amp;quot;zstd&amp;quot;)
fs::file_info(&amp;quot;nuts.feather&amp;quot;)$size&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;## 600K&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Getting data back to R means going through the process in reverse – reading my feather file via &lt;code&gt;{arrow}&lt;/code&gt;; it will be a regular data frame, not a spatial one. Geometry column must be reconstructed from WKT, and information on interpreting the coordinates provided externally.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;# NUTS back in, under slightly different name
noix &amp;lt;- arrow::read_feather(&amp;quot;nuts.feather&amp;quot;)

# check structure - a regular data frame
str(noix)&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;## tibble [400 × 10] (S3: tbl_df/tbl/data.frame)
##  $ NUTS_ID   : chr [1:400] &amp;quot;DE11B&amp;quot; &amp;quot;DE11C&amp;quot; &amp;quot;DE11D&amp;quot; &amp;quot;DE121&amp;quot; ...
##  $ LEVL_CODE : num [1:400] 3 3 3 3 3 3 3 3 3 3 ...
##  $ URBN_TYPE : chr [1:400] NA NA NA NA ...
##  $ CNTR_CODE : chr [1:400] &amp;quot;DE&amp;quot; &amp;quot;DE&amp;quot; &amp;quot;DE&amp;quot; &amp;quot;DE&amp;quot; ...
##  $ NAME_LATN : chr [1:400] &amp;quot;Main-Tauber-Kreis&amp;quot; &amp;quot;Heidenheim&amp;quot; &amp;quot;Ostalbkreis&amp;quot; &amp;quot;Baden-Baden, Stadtkreis&amp;quot; ...
##  $ NUTS_NAME : chr [1:400] &amp;quot;Main-Tauber-Kreis&amp;quot; &amp;quot;Heidenheim&amp;quot; &amp;quot;Ostalbkreis&amp;quot; &amp;quot;Baden-Baden, Stadtkreis&amp;quot; ...
##  $ MOUNT_TYPE: chr [1:400] NA NA NA NA ...
##  $ COAST_TYPE: chr [1:400] NA NA NA NA ...
##  $ geo       : chr [1:400] &amp;quot;DE11B&amp;quot; &amp;quot;DE11C&amp;quot; &amp;quot;DE11D&amp;quot; &amp;quot;DE121&amp;quot; ...
##  $ geom      : chr [1:400] &amp;quot;MULTIPOLYGON (((9.648736 49.79148, 9.61994 49.78339, 9.58053 49.77841, 9.57557 49.78151, 9.572757 49.78327, 9.5&amp;quot;| __truncated__ &amp;quot;MULTIPOLYGON (((10.16116 48.76557, 10.16414 48.77024, 10.15598 48.77164, 10.15103 48.77249, 10.15137 48.77704, &amp;quot;| __truncated__ &amp;quot;MULTIPOLYGON (((10.24128 49.05692, 10.23887 49.0536, 10.234 49.0469, 10.22182 49.04798, 10.22131 49.04803, 10.2&amp;quot;| __truncated__ &amp;quot;MULTIPOLYGON (((8.177443 48.84196, 8.16952 48.84214, 8.163085 48.84621, 8.158402 48.84665, 8.161558 48.83443, 8&amp;quot;| __truncated__ ...&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;# convert back to safety of sf format, taking care of CRS
noix &amp;lt;- st_as_sf(noix, wkt = &amp;quot;geom&amp;quot;, crs = 4326)

# a visual check
plot(noix)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;https://www.jla-data.net/eng/2024-09-23-cross-language-object-serialization/index_files/figure-html/read-human-1.png&#34; width=&#34;100%&#34; /&gt;&lt;/p&gt;
&lt;p&gt;To complete the serialization POC I am reading the feather file again, this time from a python session.&lt;/p&gt;
&lt;p&gt;First as a Shapely object via WKT, then enriching it for the CRS information that was lost on serializing and finally converting to a geopandas dataframe.&lt;/p&gt;
&lt;pre class=&#34;python&#34;&gt;&lt;code&gt;import geopandas
import pandas as pd
from shapely import wkt

# read in the dataset as a pandas dataframe
df = pd.read_feather(&amp;quot;nuts.feather&amp;quot;)

# restore geometry from text to WKT
df[&amp;quot;geom&amp;quot;] = geopandas.GeoSeries.from_wkt(df[&amp;quot;geom&amp;quot;])

# upgrade to geodataframe, re-implementing the CRS 
gdf = geopandas.GeoDataFrame(df, geometry = &amp;quot;geom&amp;quot;).set_crs(4326)

# a visual check
gdf.plot()&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;https://www.jla-data.net/eng/2024-09-23-cross-language-object-serialization/index_files/figure-html/read-parseltongue-1.png&#34; width=&#34;100%&#34; /&gt;&lt;/p&gt;
&lt;p&gt;I believe I have shown the feasibility of serializing a spatial object to a relatively small Feather file, one that can be effectively consumed from both R and python setting.&lt;/p&gt;
&lt;p&gt;The concept seems to be working, with better than expected efficiency (I would be happy to settle for a file size at par with RDS; getting to one half is a nice bonus) but some challenges remain. The chief is that the conversion from WKT is expensive, and likely would benefit from a client side caching.&lt;/p&gt;
</description>
  </item>
  
<item>
  <title>Overriding {ggplot2} Legend Keys</title>
  <link>https://www.jla-data.net/eng/2024-03-23-overriding-ggplot2-legend-keys/</link>
  <pubDate>Sat, 23 Mar 2024 00:00:00 +0000</pubDate>
  
<guid>https://www.jla-data.net/eng/2024-03-23-overriding-ggplot2-legend-keys/</guid>
  <description>


&lt;p&gt;While preparing an article for publication I have encountered a thorny problem: for visual consistency I needed to align legend keys between two &lt;code&gt;{ggplot2}&lt;/code&gt; plots. Which is in theory a straightforward task, but in practice it turned out to be a bit more complicated.&lt;/p&gt;
&lt;p&gt;The issue was that one of the plots was a choropleth map, with information keyed to the fill aesthetic, and the other was a point map. The first map turned out with classic colored squares for legend keys, while the second one with little round points. Since both legends were meant to be displayed side by side, and carry the same information, the inconsistency was a problem.&lt;/p&gt;
&lt;p&gt;To illustrate my problem, and its eventual solution, I am using a toy example built on top of the well known &amp;amp; much loved &lt;code&gt;nc.shp&lt;/code&gt; shapefile that ships with &lt;code&gt;{sf}&lt;/code&gt; package.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;library(sf)
library(ggplot2)

# the one and only NC shapefile
nc &amp;lt;- st_read(system.file(&amp;quot;shape/nc.shp&amp;quot;, package=&amp;quot;sf&amp;quot;),
              quiet = T)

# three semi random counties
three_counties &amp;lt;- subset(nc, NAME %in% c(&amp;quot;Ashe&amp;quot;, &amp;quot;Mecklenburg&amp;quot;, &amp;quot;Iredell&amp;quot;))&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This is my first plot; note the big square legend keys.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;ggplot() +
  geom_sf(data = nc) +
  geom_sf(data = three_counties, 
          aes(fill = NAME)) +
  scale_fill_brewer(&amp;quot;Counties&amp;quot;, palette = &amp;quot;Set1&amp;quot;) +
  theme_minimal()&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;https://www.jla-data.net/eng/2024-03-23-overriding-ggplot2-legend-keys/index_files/figure-html/filled-plot-1.png&#34; width=&#34;100%&#34; /&gt;&lt;/p&gt;
&lt;p&gt;This was my second map; note the dotted legend.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;ggplot() +
  geom_sf(data = nc) +
  geom_sf(data = st_centroid(three_counties), 
          aes(color = NAME)) +
  scale_color_brewer(&amp;quot;Counties&amp;quot;, palette = &amp;quot;Set1&amp;quot;) +
  theme_minimal()&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;https://www.jla-data.net/eng/2024-03-23-overriding-ggplot2-legend-keys/index_files/figure-html/bad-dotted-plot-1.png&#34; width=&#34;100%&#34; /&gt;&lt;/p&gt;
&lt;p&gt;While both maps look fine the difference between style of legend keys was distracting from the fact that both legends were meant to carry the same information.&lt;/p&gt;
&lt;p&gt;I struggled for a while, until discovering a helpful blog post by Emil Hvitfeldt on &lt;a href=&#34;https://emilhvitfeldt.com/post/changing-glyph-in-ggplot2/&#34;&gt;changing glyph in legend in ggplot2&lt;/a&gt;. The solution was to use the &lt;code&gt;key_glyph&lt;/code&gt; argument in my &lt;code&gt;geom_sf()&lt;/code&gt; call.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;ggplot() +
  geom_sf(data = nc) +
  geom_sf(data = st_centroid(three_counties), 
          aes(color = NAME), 
          key_glyph = &amp;quot;rect&amp;quot;) +
  scale_color_brewer(&amp;quot;Counties&amp;quot;, palette = &amp;quot;Set1&amp;quot;) +
  theme_minimal()&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;https://www.jla-data.net/eng/2024-03-23-overriding-ggplot2-legend-keys/index_files/figure-html/nice-looking-plot-1.png&#34; width=&#34;100%&#34; /&gt;&lt;/p&gt;
&lt;p&gt;And while a plain &lt;code&gt;&#34;rect&#34;&lt;/code&gt; for a rectangular key glyph turned out perfectly fine for the purpose of my article, I could not resist trying out some other options. Such as the timeseries glyph, or a little boxplot.&lt;/p&gt;
&lt;p&gt;Which looks somewhat funky in a &lt;em&gt;map&lt;/em&gt; settings, but will no doubt find a good use elsewhere.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;ggplot() +
  geom_sf(data = nc) +
  geom_sf(data = st_centroid(three_counties), 
          aes(color = NAME), 
          key_glyph = &amp;quot;boxplot&amp;quot;) +
  scale_color_brewer(&amp;quot;Counties&amp;quot;, palette = &amp;quot;Set1&amp;quot;) +
  theme_minimal()&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;https://www.jla-data.net/eng/2024-03-23-overriding-ggplot2-legend-keys/index_files/figure-html/funky-looking-plot-1.png&#34; width=&#34;100%&#34; /&gt;&lt;/p&gt;
</description>
  </item>
  
<item>
  <title>Monospaced Maps</title>
  <link>https://www.jla-data.net/eng/2023-09-15-monospace-maps/</link>
  <pubDate>Fri, 15 Sep 2023 00:00:00 +0000</pubDate>
  
<guid>https://www.jla-data.net/eng/2023-09-15-monospace-maps/</guid>
  <description>


&lt;p&gt;Inspired by the great Nicola Rennie of Fosstodon and her &lt;a href=&#34;https://fosstodon.org/@nrennie/111068087181336211&#34;&gt;typewritten map of Scotland&lt;/a&gt; I have felt the need to pay her the highest form of flattery by imitating her work.&lt;/p&gt;
&lt;p&gt;My own country felt a better start than distant Scotland, and it seemed to me as a good idea to share the code.&lt;/p&gt;
&lt;p&gt;The first step is acquiring the raw elevation raster; I am building on the one provided by &lt;code&gt;vyskopis()&lt;/code&gt; function of &lt;code&gt;{RCzechia}&lt;/code&gt; package. But any DEM file read in via &lt;code&gt;{terra}&lt;/code&gt; would do…&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;library(terra)   # for raster manipulation
library(ggplot2) # for plotting the plot
library(dplyr)   # for generic data frame manipulation

# raw raster - elevation of Czechia (from original DEM)
src_raster &amp;lt;- RCzechia::vyskopis(&amp;quot;actual&amp;quot;) 

# a visual overview
plot(src_raster)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;https://www.jla-data.net/eng/2023-09-15-monospace-maps/index_files/figure-html/raw-data-1.png&#34; width=&#34;672&#34; /&gt;&lt;/p&gt;
&lt;p&gt;The second step is downsampling the raster drastically, so that a single raster cell will be rendered as a letter, and casting it from raster to a data frame, minding the &lt;code&gt;xy&lt;/code&gt; argument to &lt;code&gt;as.data.frame&lt;/code&gt; method of &lt;code&gt;SpatRaster&lt;/code&gt;. By setting it to &lt;code&gt;TRUE&lt;/code&gt; we will keep the coordinates of the raster cells, which will be of great help in placing our letters via &lt;code&gt;ggplot2::geom_text()&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;I discretized the elevation to three letters - &lt;code&gt;l&lt;/code&gt; for lowlands, &lt;code&gt;h&lt;/code&gt; for hills and capital &lt;code&gt;M&lt;/code&gt; for Big Mountains - via &lt;code&gt;base::cut()&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;What turned out to be a slight challenge was plot aspect ratio; my DEM file was in geographic coordinates, and since Czechia is not quite on equator the degrees of latitude and longitude do not translate to the same distance. I was able to overcome this by getting the aspect ratio from my raster reprojected to a metric CRS (Web Mercator specifically).&lt;/p&gt;
&lt;p&gt;The remaining fun part was finding a sufficiently old fashioned monospaced font that could plausibly pass for typewritter. I settled on &lt;a href=&#34;https://fonts.google.com/specimen/Special+Elite&#34;&gt;Special Elite&lt;/a&gt; from Google Fonts.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;# cast elevation from raster to data frame
map_src &amp;lt;- src_raster %&amp;gt;% 
  terra::aggregate(fact = 30) %&amp;gt;% # downsample the raster by factor of 30
  as.data.frame(xy = T) %&amp;gt;% # convert raster to data frame, preserving coordinates
  mutate(category = cut(Band_1,
                        breaks = c(0, 400, 600, Inf),
                        labels = c(&amp;quot;l&amp;quot;, &amp;quot;h&amp;quot;, &amp;quot;M&amp;quot;)))

# get raster extent in meters for aspect ratio
bbox &amp;lt;- sf::st_bbox(project(src_raster, &amp;quot;EPSG:3857&amp;quot;))
aspect_ratio &amp;lt;- (bbox$ymax - bbox$ymin) / (bbox$xmax - bbox$xmin)

# now draw the rest of the map! :)
ggplot(data = map_src,
       aes(x = x, y = y, label = category)) +
  geom_text(family=&amp;quot;Special Elite&amp;quot;, 
            size = 1.5) +
  labs(title = &amp;quot;Czechia in monospace&amp;quot;,
       caption = &amp;quot;Typed with love and #rstats by fosstodon.org/@jladata &amp;quot;) +
  theme_void() +
  theme(aspect.ratio = aspect_ratio,
        plot.title = element_text(family = &amp;quot;Special Elite&amp;quot;,
                                  hjust = 1/2,
                                  size = 30,
                                  color = &amp;quot;black&amp;quot;),
        plot.caption = element_text(family = &amp;quot;Special Elite&amp;quot;,
                                    size = 6,
                                    color = &amp;quot;grey50&amp;quot;))&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;https://www.jla-data.net/eng/2023-09-15-monospace-maps/index_files/figure-html/czechia-in-monospace-1.png&#34; width=&#34;672&#34; /&gt;&lt;/p&gt;
</description>
  </item>
  
<item>
  <title>Spatial Neighborhoods</title>
  <link>https://www.jla-data.net/eng/2023-05-10-spatial-neighborhoods-in-r/</link>
  <pubDate>Sat, 02 Sep 2023 00:00:00 +0000</pubDate>
  
<guid>https://www.jla-data.net/eng/2023-05-10-spatial-neighborhoods-in-r/</guid>
  <description>


&lt;p&gt;Two important concepts in the field of spatial econometrics are contiguity matrices &lt;strong&gt;C&lt;/strong&gt; and weight matrices &lt;strong&gt;W&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Contiguity matrices provide qualitative information about which polygons are neighbors, and weight (or spatial weight) matrices give a quantitative measure of the this neighborhood relationship.&lt;/p&gt;
&lt;p&gt;In this post I provide several alternative approaches to constructing contiguity and weight matrices, with examples using the well known and much loved &lt;code&gt;nc.shp&lt;/code&gt; shapefile that ships with the &lt;code&gt;{sf}&lt;/code&gt; package.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;Both contiguity and weight matrices are implemented in the &lt;code&gt;{spdep}&lt;/code&gt; package, which is the de-facto standard approach to spatial dependence modelling in R settings.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The contiguity matrix is implemented as &lt;code&gt;nb&lt;/code&gt; (short for neighborhood) object, which is a list of indexes of objects considered neighbors (whatever that means in a given context).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The weights matrix is implemented as &lt;code&gt;listw&lt;/code&gt; object, which is a compound consisting of two items:
&lt;code&gt;neighbours&lt;/code&gt; object, which is in principle the same as a &lt;code&gt;nb&lt;/code&gt; object, and a &lt;code&gt;weights&lt;/code&gt; object, which contains the weights matrix itself.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Formally the weight matrix encodes the neighborhood structure as a &lt;em&gt;n × n&lt;/em&gt; matrix &lt;strong&gt;W&lt;/strong&gt;, where elements &lt;em&gt;w&lt;sub&gt;i,j&lt;/sub&gt;&lt;/em&gt; are the spatial weights:&lt;/p&gt;
&lt;p&gt;&lt;span class=&#34;math display&#34;&gt;\[
{\bf W} = \left(\begin{array}{ccccc}
  w_{1,1}&amp;amp;w_{1,2}&amp;amp;w_{1,3}&amp;amp;\cdots &amp;amp;w_{1,n}\\
  w_{2,1}&amp;amp;w_{2,2}&amp;amp;w_{2,3}&amp;amp;\cdots &amp;amp;w_{2,n}\\
  w_{3,1}&amp;amp;w_{3,2}&amp;amp;w_{3,3}&amp;amp;\cdots &amp;amp;w_{3,n}\\
  \vdots&amp;amp;&amp;amp;&amp;amp;\ddots&amp;amp;\\
  w_{n,1}&amp;amp;w_{n,2}&amp;amp;w_{n,3}&amp;amp;\cdots &amp;amp;w_{n,n}
  \end{array}\right)
\]&lt;/span&gt;
The weights &lt;em&gt;w&lt;sub&gt;i,j&lt;/sub&gt;&lt;/em&gt; have value of zero for polygons that are &lt;em&gt;not&lt;/em&gt; considered neighbors, and non–zero values for neighboring ones.&lt;/p&gt;
&lt;p&gt;By convention a polygon is not considered to be neighboring with itself, so the diagonal of a weights matrix is zero by definition.&lt;/p&gt;
&lt;p&gt;Also by convention the individual weights are row standardized, so that weight matrix rows sum to 1. Consequently the matrix itself sums to the number of observations &lt;em&gt;n&lt;/em&gt;. This convention is represented as &lt;code&gt;style=&#39;W&#39;&lt;/code&gt; in the framework of &lt;code&gt;{spdep}&lt;/code&gt; models (other conventions, such as standardizing all weights to unity, are possible, but less commonly used).&lt;/p&gt;
&lt;p&gt;My first step is loading required packages and the &lt;code&gt;nc.shp&lt;/code&gt; shapefile as &lt;code&gt;counties&lt;/code&gt; object. The shapefile is then projected to a feety CRS, because as an European, metric born &amp;amp; bred, I find the quaint local customs amusing.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;library(spdep)
library(dplyr)
library(sf)
library(ggplot2)

# NC counties as polygons - a shapefile shipped with the sf package
counties &amp;lt;- st_read(system.file(&amp;quot;shape/nc.shp&amp;quot;, package = &amp;quot;sf&amp;quot;), quiet = T) %&amp;gt;% 
  st_transform(2264) # a feety CRS, to make it more interesting :)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;My second step is preparing a convenience function &lt;code&gt;report_results()&lt;/code&gt; in order to plot a map illustrating the calculated results. It takes for argument a &lt;code&gt;listw&lt;/code&gt; object, and draws a plot of neighbors of a single county, with neighborhood weight as labels. Notice that the labels are placed in the centroid of the neighbor.&lt;/p&gt;
&lt;p&gt;This convenience function will be used to show differences in calculated matrices (because a graphical example is more than 1000 words, and because I dislike repeating my code).&lt;/p&gt;
&lt;p&gt;County &lt;a href=&#34;https://en.wikipedia.org/wiki/Franklin_County,_North_Carolina&#34;&gt;Franklin&lt;/a&gt; makes for a good example, because out of all the North Carolina counties it has the biggest difference between rook and queen neighborhoods (it touches neighboring counties Halifax and Johnston in single point each).&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;# a convenience function; will display county Franklin &amp;amp; its neighbors
report_results &amp;lt;- function(listw_object) {

  chart_source &amp;lt;-  counties %&amp;gt;%
    # selects neigbbors of cnty Franklin (only) as polygons
    slice(purrr::pluck(listw_object$neighbours,
                       which(counties$NAME == &amp;quot;Franklin&amp;quot;))) %&amp;gt;%
    # new column of weights relative to cnty Franklin
    mutate(weight = purrr::pluck(listw_object$weights,
                               which(counties$NAME == &amp;quot;Franklin&amp;quot;))) 
 
  # draw a plot based on chart_source object 
  ggplot(data = chart_source) +
    geom_sf() +
    geom_sf_label(aes(label = scales::percent(weight, accuracy = 1)),
                  # let&amp;#39;s use the label to mark county centroid!
                  fun.geometry = sf::st_centroid) +
    # centroid of cnty Franklin, for reference
    geom_sf(data = st_centroid(counties[which(counties$NAME == &amp;quot;Franklin&amp;quot;), ]), 
            color= &amp;quot;red&amp;quot;, pch = 4) +
    theme_void()
  
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The first example is creating a queen style neighborhood, in which neighbors are defined as polygons (counties) sharing at least a single point. In this framework county Franklin has 7 neighbors, giving each equal 14% neighborhood weight (where 14.29% = 100 / 7).&lt;/p&gt;
&lt;p&gt;The call to invoke queen neighborhoods is &lt;code&gt;spdep::poly2nb()&lt;/code&gt; with queen argument set to &lt;code&gt;TRUE&lt;/code&gt; (which is the default).&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;queen_hoods &amp;lt;- st_geometry(counties) %&amp;gt;% 
  poly2nb(queen = TRUE) %&amp;gt;% 
  nb2listw() 

report_results(queen_hoods)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;https://www.jla-data.net/eng/2023-05-10-spatial-neighborhoods-in-r/index_files/figure-html/queen-1.png&#34; width=&#34;100%&#34; /&gt;&lt;/p&gt;
&lt;p&gt;The second approach is creating a rook style neighborhood, in which neighbors are defined as polygons (counties) sharing an edge – a single point is not enough. In this framework county Franklin has 5 neighbors, giving each weight of 20%.&lt;/p&gt;
&lt;p&gt;In practice, when dealing with polygons that originated from a sufficiently random process – such as admin areas that originated “bottom up” in a long settled area – you will find very few, if any, differences between queen and rook neighbors. Cases such as the famous &lt;a href=&#34;https://en.wikipedia.org/wiki/Four_Corners_Monument&#34;&gt;four corners point&lt;/a&gt; between Utah, Arizona, Colorado and New Mexico are rather rare, occurring chiefly in “top down” driven administration of newly settled territories; a fine example being the &lt;a href=&#34;https://en.wikipedia.org/wiki/List_of_counties_in_Iowa&#34;&gt;US State of Iowa&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;I confess that I had to cheat a bit using &lt;code&gt;setdiff()&lt;/code&gt; on the two &lt;code&gt;nb&lt;/code&gt; objects to find a sufficiently salient example in a mostly organically settled state of North Carolina, as I really wanted to stick with the &lt;code&gt;nc.shp&lt;/code&gt; shapefile we all know and love.&lt;/p&gt;
&lt;p&gt;The call to invoke rook neighborhoods is &lt;code&gt;spdep::poly2nb()&lt;/code&gt; with queen argument set to &lt;code&gt;FALSE&lt;/code&gt; (meaning a rook is the &lt;em&gt;not&lt;/em&gt; queenly approach).&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;rook_hoods &amp;lt;- st_geometry(counties) %&amp;gt;% 
  poly2nb(queen = FALSE) %&amp;gt;% # not queen means rook
  nb2listw() 

report_results(rook_hoods)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;https://www.jla-data.net/eng/2023-05-10-spatial-neighborhoods-in-r/index_files/figure-html/rook-1.png&#34; width=&#34;100%&#34; /&gt;&lt;/p&gt;
&lt;p&gt;Third approach is basing neighborhoods on K nearest neighbors. This approach is not defined for polygons (for good reasons) but a good practice for point data.&lt;/p&gt;
&lt;p&gt;In order to make it work for polygons these have to be first converted to points via &lt;code&gt;sf::st_centroid()&lt;/code&gt;. In this framework county Franklin (and every other, by definition) has 3 neighbors, giving each weight of 33%.&lt;/p&gt;
&lt;p&gt;The call to invoke KNN neighbors is &lt;code&gt;spdep::knearneigh()&lt;/code&gt;, where argument &lt;code&gt;k&lt;/code&gt; is the desired number of neighbors.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;knn_hoods &amp;lt;- st_geometry(counties) %&amp;gt;% 
  st_centroid() %&amp;gt;% # polygons to points
  knearneigh(k = 3) %&amp;gt;% # always 3 neighbors - never more, never less...
  knn2nb() %&amp;gt;% 
  nb2listw() 

report_results(knn_hoods)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;https://www.jla-data.net/eng/2023-05-10-spatial-neighborhoods-in-r/index_files/figure-html/knn-1.png&#34; width=&#34;100%&#34; /&gt;&lt;/p&gt;
&lt;p&gt;Fourth approach is basing neighborhoods on distance. This approach is again defined for points only, so in order to use it we have to convert our polygons to centroids.&lt;/p&gt;
&lt;p&gt;In this framework we have to set the minimum (usually zero) and maximum distance; I am using 50 miles as maximum distance between county centroids to be considered “neighboring”.&lt;/p&gt;
&lt;p&gt;In this framework county Franklin has 12 neighbors, giving each 8% weight (where 8.33% = 100 / 12).&lt;/p&gt;
&lt;p&gt;The call to invoke distance based neighbors is &lt;code&gt;spdep::dnearneigh()&lt;/code&gt;, where argument &lt;code&gt;d1&lt;/code&gt; is the minimal, and &lt;code&gt;d2&lt;/code&gt; the maximal distance.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;distance_hoods &amp;lt;- st_geometry(counties) %&amp;gt;% 
  st_centroid() %&amp;gt;% # polygon to points
  dnearneigh(d1 = 0, # from zero...
             d2 = 5280 * 50) %&amp;gt;% # ... to 50 miles
  nb2listw() 

report_results(distance_hoods) &lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;https://www.jla-data.net/eng/2023-05-10-spatial-neighborhoods-in-r/index_files/figure-html/distance-1.png&#34; width=&#34;100%&#34; /&gt;&lt;/p&gt;
&lt;p&gt;Important fine tuning technique is altering the weights of your &lt;code&gt;listw&lt;/code&gt; object. Depending on your use case it may be – and may &lt;em&gt;not&lt;/em&gt; be – appropriate to give each neighbor equal weight, such as the 8% used in the last example. Or there may be a compelling reason to make some neighbors less equal than others.&lt;/p&gt;
&lt;p&gt;Fortunately, the &lt;code&gt;weights&lt;/code&gt; element of your &lt;code&gt;listw&lt;/code&gt; object can be easily rewritten as your situation requires.&lt;/p&gt;
&lt;p&gt;A common approach is to apply inverse distance weighting, giving more prominence to close neighbors and less to far off ones. Note how the weight of close neighbors moves from 8% to 13%, and drops to 5% for the farthest one.&lt;/p&gt;
&lt;p&gt;For this frequent use case we can leverage the &lt;code&gt;spdep::nbdists()&lt;/code&gt; function that calculates distances between elements of a &lt;code&gt;nb&lt;/code&gt; neighborhood object.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;# start with a nb object (not yet listw)
nblist &amp;lt;- st_geometry(counties) %&amp;gt;% 
  st_centroid() %&amp;gt;% 
  dnearneigh(d1 = 0,d2 = 5280 * 50)
  
# then use the nb object to create a listw object
idw_hoods &amp;lt;- nb2listw(nblist)

# then rewrite the &amp;quot;weights&amp;quot; part of the said listw object
# using information contained in the original nb 
idw_hoods$weights &amp;lt;- nbdists(nblist, 
                             st_coordinates(st_centroid(counties))) %&amp;gt;% 
  lapply(function(x) 1/x)  %&amp;gt;% # distance inverted
  lapply(function(x) x/sum(x)) # W-style standardization 


report_results(idw_hoods)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;https://www.jla-data.net/eng/2023-05-10-spatial-neighborhoods-in-r/index_files/figure-html/weighted_distances-1.png&#34; width=&#34;100%&#34; /&gt;&lt;/p&gt;
&lt;p&gt;Yet more aggressive approach is basing weights on inverse of &lt;em&gt;squared&lt;/em&gt; distances; notice how the weight of Nash County increases to 20%, while the weight of Orange County drops to 3%.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;nblist &amp;lt;- st_geometry(counties) %&amp;gt;% 
  st_centroid() %&amp;gt;% 
  dnearneigh(d1 = 0,d2 = 5280 * 50)

idwsq_hoods &amp;lt;- nb2listw(nblist)

# again, rewrite the existing weights part of listw object
idwsq_hoods$weights &amp;lt;- nbdists(nblist, 
                              st_coordinates(st_centroid(counties))) %&amp;gt;% 
  lapply(function(x) 1/(x^2)) %&amp;gt;% # square of distance inverted
  lapply(function(x) x/sum(x)) # W-style standardization

report_results(idwsq_hoods)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;https://www.jla-data.net/eng/2023-05-10-spatial-neighborhoods-in-r/index_files/figure-html/weighted_queen-1.png&#34; width=&#34;100%&#34; /&gt;&lt;/p&gt;
&lt;p&gt;A different approach is creating weights based on the length of shared border; this requires slightly more coding, as there is no standard function to return a list of border lengths of a &lt;code&gt;nb&lt;/code&gt; set (unlike for the list of distances), but not overly so.&lt;/p&gt;
&lt;p&gt;Note how, by basing the border length weighted list on queen neighborhoods, we end up with zero weights for the “joinded in the corners” counties, effectively removing the difference between the queen and the rook neighborhood patterns.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;# start with a queen style, rather than rook style nb object
# - it will make the zeroes in corners (zero length border) really stand out
nblist &amp;lt;- st_geometry(counties) %&amp;gt;% 
  poly2nb(queen = TRUE) 
  
# then create a listw object
borderline_hoods &amp;lt;- nb2listw(nblist)

# then pre-allocate a list of distances
distances &amp;lt;- vector(&amp;quot;list&amp;quot;, length(nblist))

# use i as iterator over list of distances
for (i in seq_along(distances)) {
  
  # indices of neighbors of i-th element
  neighbor_ids &amp;lt;- purrr::pluck(nblist[[i]])
  
  # shared borders of (multiple) neighbors and i-th element as a line
  distances[[i]] &amp;lt;- st_intersection(st_geometry(counties)[neighbor_ids],
                                    st_geometry(counties)[i]) %&amp;gt;% 
    st_length() %&amp;gt;% # from line as geometry to length of said line
    units::drop_units() # we want share of total, which is unitless
  
}

# apply the W style standardization
distances &amp;lt;- lapply(distances, function(x) x/sum(x)) 

# overwrite the original weights object  
borderline_hoods$weights &amp;lt;- distances 

report_results(borderline_hoods)&lt;/code&gt;&lt;/pre&gt;
&lt;img src=&#34;https://www.jla-data.net/eng/2023-05-10-spatial-neighborhoods-in-r/index_files/figure-html/borderline_distances-1.png&#34; width=&#34;100%&#34; /&gt;
&lt;hr&gt;
&lt;p&gt;I believe I have demonstrated both:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;the variety of options for calculating the contiguity and weight matrices&lt;/li&gt;
&lt;li&gt;the ease of doing so within the context of &lt;code&gt;{spdep}&lt;/code&gt; package and friends&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;QED :)&lt;/p&gt;
</description>
  </item>
  
<item>
  <title>Adding Mastodon Social Link</title>
  <link>https://www.jla-data.net/eng/adding-mastodon-link-to-blogdown-template/</link>
  <pubDate>Mon, 07 Nov 2022 00:00:00 +0000</pubDate>
  
<guid>https://www.jla-data.net/eng/adding-mastodon-link-to-blogdown-template/</guid>
  <description>&lt;p&gt;This site is built on the &lt;a href=&#34;https://github.com/roryg/ghostwriter&#34;&gt;ghostwriter&lt;/a&gt; template, as &lt;a href=&#34;https://github.com/jbub/ghostwriter&#34;&gt;ported to HUGO&lt;/a&gt; by jbub. Paired with the R package &lt;a href=&#34;https://bookdown.org/yihui/blogdown/&#34;&gt;&lt;code&gt;{blogdown}&lt;/code&gt;&lt;/a&gt; and trusty old RStudio it is a setup that has served me reliably over the years.&lt;/p&gt;
&lt;p&gt;And while it is a setup that is simple and well designed, it still requires some attention from time to time, much like the nine hundred years old dwarf axe in Terry Pratchett&amp;rsquo;s &lt;a href=&#34;https://en.wikipedia.org/wiki/The_Fifth_Elephant&#34;&gt;The Fifth Elephant&lt;/a&gt;. New blade here, new handle there, a little refreshing of the ornamentation&amp;hellip;&lt;/p&gt;
&lt;p&gt;A refresh that I recently found necessary was updating the social media ribbon on top to include a link to my Mastodon presence. While I am not a true social media natural I felt a need to hedge my bets given the recent developments on the birdie site.&lt;/p&gt;
&lt;center&gt;
&lt;p&gt;&lt;img src=&#34;header-img.png&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;/center&gt;
&lt;p&gt;The ghostwriter template does not support Mastodon out of the box, but at the end it did not require too complex tweaking (did I mention it is both simple and well designed?).&lt;/p&gt;
&lt;p&gt;It three steps were necessary:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;tweaking the &lt;code&gt;&amp;lt;body&amp;gt;&lt;/code&gt; part of the &lt;code&gt;header.html&lt;/code&gt; partial to recognize &amp;amp; interpret a new parameter &lt;code&gt;mastodon&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;tweaking the &lt;code&gt;&amp;lt;head&amp;gt;&lt;/code&gt; part of the &lt;code&gt;header.html&lt;/code&gt; partial to use a more current version of &lt;a href=&#34;https://fontawesome.com/&#34;&gt;Font Awesome&lt;/a&gt; icons&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;giving the newly created &lt;code&gt;mastodon&lt;/code&gt; parameter a meaning in my &lt;code&gt;config.toml&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The &lt;code&gt;header.html&lt;/code&gt; partial is located in &lt;code&gt;themes/ghostwriter/layouts/partials&lt;/code&gt; directory of your blogdown, and as usual before tweaking it it pays to create a backup copy.&lt;/p&gt;
&lt;p&gt;Creating a piece of code handling new parameters is not hard, as you can readily copy-paste the existing implementation of Twitter, LinkedIn or what not. I chose to place the new button between Twitter and GitHub, but it was only an aesthetic choice with little impact on function.&lt;/p&gt;
&lt;p&gt;What I found advantageous is including the &lt;code&gt;rel=&amp;quot;me&amp;quot;&lt;/code&gt; part that Mastodon requires in a backlink to verify a site owner here.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;{{ with .Site.Params.mastodon }}
  &amp;lt;a class=&amp;#34;button-square button-social hint--top&amp;#34; rel=&amp;#34;me&amp;#34; data-hint=&amp;#34;Mastodon&amp;#34; title=&amp;#34;Mastodon&amp;#34; href=&amp;#34;{{ . }}&amp;#34;&amp;gt;
  &amp;lt;i class=&amp;#34;fa-brands fa-mastodon&amp;#34;&amp;gt;&amp;lt;/i&amp;gt;
  &amp;lt;/a&amp;gt;
{{ end }}
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Of course I needed to update the icon class of the button (the &lt;code&gt;fa-mastodon&lt;/code&gt; part in code above) to display a nice Mastodon icon, and not some bird or a cat. Which brings us to the second part, which is updating Font Awesome to a more current version.&lt;/p&gt;
&lt;p&gt;My template was built on top of 4.7 version of Font Awesome, which is by now somewhat dated. The scope of 4.7 version regarding brands supported is limited, and does not include Mastodon. You will need version 5.0.11 or later for that, the current being 6.2.&lt;/p&gt;
&lt;p&gt;Updating to current Font Awesome required some change of logic, as Font Awesome no longer supports a distribution via CDN and I had to &lt;a href=&#34;https://fontawesome.com/docs/web/setup/use-kit&#34;&gt;set up a kit&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Once I had my kit up &amp;amp; running I swapped the part of &lt;code&gt;&amp;lt;head&amp;gt;&lt;/code&gt; of my header partial that linked to CDN of Font Awesome (&lt;code&gt;https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css&lt;/code&gt;) for a link to my shiny new kit (you are welcome to copy my code, but note that your kit will have a different name than mine).&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;&amp;lt;script src=&amp;#34;https://kit.fontawesome.com/your_kit.js&amp;#34; crossorigin=&amp;#34;anonymous&amp;#34;&amp;gt;&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This concludes the &amp;ldquo;tricky&amp;rdquo; coding part; what remains is setting up a link to Mastodon presence in &lt;code&gt;config.toml&lt;/code&gt;. Which in my case means putting&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;  mastodon = &amp;#34;https://fosstodon.org/@jladata&amp;#34;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;in between the other metadata links.&lt;/p&gt;
&lt;p&gt;And like that I was done. Two hours of time, including googling (three if I include time spent writing this article and putting it up).&lt;/p&gt;
</description>
  </item>
  
<item>
  <title>Thirsty Salesman Problem</title>
  <link>https://www.jla-data.net/eng/travelling-salesman-problem-with-here/</link>
  <pubDate>Sun, 13 Mar 2022 00:00:00 +0000</pubDate>
  
<guid>https://www.jla-data.net/eng/travelling-salesman-problem-with-here/</guid>
  <description>
&lt;script src=&#34;https://www.jla-data.net/eng/travelling-salesman-problem-with-here/index_files/htmlwidgets/htmlwidgets.js&#34;&gt;&lt;/script&gt;
&lt;script src=&#34;https://www.jla-data.net/eng/travelling-salesman-problem-with-here/index_files/jquery/jquery.min.js&#34;&gt;&lt;/script&gt;
&lt;link href=&#34;https://www.jla-data.net/eng/travelling-salesman-problem-with-here/index_files/leaflet/leaflet.css&#34; rel=&#34;stylesheet&#34; /&gt;
&lt;script src=&#34;https://www.jla-data.net/eng/travelling-salesman-problem-with-here/index_files/leaflet/leaflet.js&#34;&gt;&lt;/script&gt;
&lt;link href=&#34;https://www.jla-data.net/eng/travelling-salesman-problem-with-here/index_files/leafletfix/leafletfix.css&#34; rel=&#34;stylesheet&#34; /&gt;
&lt;script src=&#34;https://www.jla-data.net/eng/travelling-salesman-problem-with-here/index_files/proj4/proj4.min.js&#34;&gt;&lt;/script&gt;
&lt;script src=&#34;https://www.jla-data.net/eng/travelling-salesman-problem-with-here/index_files/Proj4Leaflet/proj4leaflet.js&#34;&gt;&lt;/script&gt;
&lt;link href=&#34;https://www.jla-data.net/eng/travelling-salesman-problem-with-here/index_files/rstudio_leaflet/rstudio_leaflet.css&#34; rel=&#34;stylesheet&#34; /&gt;
&lt;script src=&#34;https://www.jla-data.net/eng/travelling-salesman-problem-with-here/index_files/leaflet-binding/leaflet.js&#34;&gt;&lt;/script&gt;
&lt;script src=&#34;https://www.jla-data.net/eng/travelling-salesman-problem-with-here/index_files/leaflet-providers/leaflet-providers_1.9.0.js&#34;&gt;&lt;/script&gt;
&lt;script src=&#34;https://www.jla-data.net/eng/travelling-salesman-problem-with-here/index_files/leaflet-providers-plugin/leaflet-providers-plugin.js&#34;&gt;&lt;/script&gt;
&lt;link href=&#34;https://www.jla-data.net/eng/travelling-salesman-problem-with-here/index_files/leaflet-awesomemarkers/leaflet.awesome-markers.css&#34; rel=&#34;stylesheet&#34; /&gt;
&lt;script src=&#34;https://www.jla-data.net/eng/travelling-salesman-problem-with-here/index_files/leaflet-awesomemarkers/leaflet.awesome-markers.min.js&#34;&gt;&lt;/script&gt;
&lt;link href=&#34;https://www.jla-data.net/eng/travelling-salesman-problem-with-here/index_files/fontawesome/font-awesome.min.css&#34; rel=&#34;stylesheet&#34; /&gt;


&lt;p&gt;My Alma Mater, &lt;a href=&#34;https://www.vse.cz/english/&#34;&gt;Prague School of Economics&lt;/a&gt;, is located in Žižkov. A formerly working class neighborhood, now rather gentrified, it has to this day retained some traces of its former rougher edges. One of these is an active night life.&lt;/p&gt;
&lt;p&gt;A crawl through the bars of Žižkov is therefore a familiar activity for many VŠE students, and can serve as a gateway drug for serious optimization techniques. Such as the &lt;a href=&#34;https://en.wikipedia.org/wiki/Travelling_salesman_problem&#34;&gt;Travelling Salesman Problem&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The TSP is an optimization classic, with a number of well understood and highly standardized solutions available in the context of statistical programming language R.&lt;/p&gt;
&lt;p&gt;In this blog post I would like to share a practical example of solving the TSP using Open Street Map data of bars via &lt;a href=&#34;https://cran.r-project.org/package=osmdata&#34;&gt;&lt;code&gt;{osmdata}&lt;/code&gt;&lt;/a&gt; and HERE routing engine via &lt;a href=&#34;https://cran.r-project.org/package=hereR&#34;&gt;&lt;code&gt;{hereR}&lt;/code&gt;&lt;/a&gt;. The actual solution will be found by utilizing the &lt;a href=&#34;https://cran.r-project.org/package=TSP&#34;&gt;&lt;code&gt;{TSP}&lt;/code&gt;&lt;/a&gt; package.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;library(sf) # for spatial data handling
library(dplyr) # for general data frame processing
library(osmdata) # to get data in from OSM
library(leaflet) # to show data interactively
library(hereR) # interface to routing engine
library(TSP) # to solve TSP&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The first step in our exercise is acquiring data of Žižkov bars. A search is performed over the area of &lt;em&gt;core Žižkov&lt;/em&gt;, defined as a polygon, using the OSM Overpass API.&lt;/p&gt;
&lt;p&gt;As there seems not to be a clear consensus over what constitutes a bar, restaurant or a pub in Prague I am including all three of the possible amenities.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;# bbox = http://bboxfinder.com - &amp;quot;core&amp;quot; Žižkov
core_zizkov &amp;lt;- c(14.437408,50.081131,
                 14.452686,50.087561)

# acquire bar data - https://wiki.openstreetmap.org/wiki/Map_features#Amenity 
search_res &amp;lt;- opq(bbox = core_zizkov) %&amp;gt;%
  add_osm_feature(key = &amp;quot;amenity&amp;quot;, 
                  value = c(&amp;quot;bar&amp;quot;, &amp;quot;restaurant&amp;quot;, &amp;quot;pub&amp;quot;)) %&amp;gt;%
  osmdata_sf(quiet = T) 

# pulls bars as points
bars &amp;lt;- search_res$osm_points %&amp;gt;%  
  filter(!is.na(name)) %&amp;gt;% 
  select(name)

# show results
leaflet(bars) %&amp;gt;% 
  addProviderTiles(&amp;quot;CartoDB.Positron&amp;quot;) %&amp;gt;% 
  addCircleMarkers(fillColor = &amp;quot;red&amp;quot;,
                   radius = 5,
                   stroke = F,
                   fillOpacity = .75,
                   label = ~ name)&lt;/code&gt;&lt;/pre&gt;
&lt;div id=&#34;htmlwidget-1&#34; style=&#34;width:100%;height:480px;&#34; class=&#34;leaflet html-widget&#34;&gt;&lt;/div&gt;
&lt;script type=&#34;application/json&#34; data-for=&#34;htmlwidget-1&#34;&gt;{&#34;x&#34;:{&#34;options&#34;:{&#34;crs&#34;:{&#34;crsClass&#34;:&#34;L.CRS.EPSG3857&#34;,&#34;code&#34;:null,&#34;proj4def&#34;:null,&#34;projectedBounds&#34;:null,&#34;options&#34;:{}}},&#34;calls&#34;:[{&#34;method&#34;:&#34;addProviderTiles&#34;,&#34;args&#34;:[&#34;CartoDB.Positron&#34;,null,null,{&#34;errorTileUrl&#34;:&#34;&#34;,&#34;noWrap&#34;:false,&#34;detectRetina&#34;:false}]},{&#34;method&#34;:&#34;addCircleMarkers&#34;,&#34;args&#34;:[[50.0824314,50.0822069,50.085209,50.0847602,50.0824881,50.0870535,50.0868466,50.0856394,50.0843102,50.0862561,50.084382,50.0847283,50.0874131,50.0864238,50.0824195,50.0820592,50.0823758,50.0834291,50.082837,50.0821624,50.0830711,50.0828715,50.0833603,50.0835461,50.0830608,50.0859666,50.0817138,50.0819674,50.0823263,50.0853388,50.0860888,50.087127,50.0823723,50.0850515,50.0812857,50.0870671,50.0864231,50.0868483,50.0855308,50.0850166,50.0844041,50.0867697,50.0840595,50.0837011,50.0834725,50.08408,50.0868647,50.0854213,50.0852725,50.0871616,50.0867791,50.0846202,50.0819081,50.0821718,50.0846047,50.0826649,50.0823039,50.08515,50.0844227,50.0844226,50.0850012,50.0856481,50.0862309,50.0854011,50.0850768,50.0846095,50.0848591,50.084451,50.0841188,50.0829196,50.086173,50.0818708,50.0853797,50.0832317,50.0866446,50.08319],[14.4457779,14.445976,14.4500592,14.4510837,14.444303,14.4502687,14.446589,14.4400343,14.4526231,14.4416022,14.4514308,14.4486671,14.4523471,14.4462288,14.4490198,14.4495274,14.4502785,14.4502785,14.4475319,14.4512012,14.4485941,14.4486907,14.446856,14.4467058,14.4447027,14.4486844,14.4468291,14.4385956,14.4452029,14.442925,14.4484876,14.4495723,14.449943,14.4518274,14.4441225,14.4503255,14.4400912,14.4488204,14.4448097,14.447254,14.4511577,14.452441,14.4524088,14.4516395,14.4510897,14.4491213,14.4458552,14.4408734,14.4440236,14.4444131,14.4448966,14.447706,14.4460137,14.4455537,14.4507261,14.4468576,14.4489614,14.4478253,14.4494912,14.4493759,14.4462038,14.4500064,14.4512612,14.4412774,14.4473437,14.4480337,14.448872,14.4508799,14.4519823,14.4471568,14.451775,14.4459364,14.449984,14.4501288,14.45182,14.4499142],5,null,null,{&#34;interactive&#34;:true,&#34;className&#34;:&#34;&#34;,&#34;stroke&#34;:false,&#34;color&#34;:&#34;#03F&#34;,&#34;weight&#34;:5,&#34;opacity&#34;:0.5,&#34;fill&#34;:true,&#34;fillColor&#34;:&#34;red&#34;,&#34;fillOpacity&#34;:0.75},null,null,null,null,[&#34;U Houdků&#34;,&#34;Pizzeria Mestre&#34;,&#34;U Habásků&#34;,&#34;Pivoteka ŽižkOFF&#34;,&#34;Belzepub&#34;,&#34;Vegan City&#34;,&#34;Spice India&#34;,&#34;Pizzerie Pasta e Basta&#34;,&#34;Bibimbap&#34;,&#34;District 3 Bar&#34;,&#34;Lavička&#34;,&#34;Pizzeria Einstein&#34;,&#34;Taiko Ramen Bar&#34;,&#34;Green Tea restaurant&#34;,&#34;Palác Akropolis&#34;,&#34;U mariánského obrazu&#34;,&#34;Amores Perros&#34;,&#34;Herba café&#34;,&#34;Morava&#34;,&#34;Království&#34;,&#34;Bukowski&#39;s&#34;,&#34;Hospůdka Nad Viktorkou&#34;,&#34;Blind Eye&#34;,&#34;Kapibara&#34;,&#34;Sedm vlků&#34;,&#34;Spirit Bar&#34;,&#34;Olympos&#34;,&#34;Krakora&#34;,&#34;Kopyto&#34;,&#34;Restaurace Poja&#34;,&#34;Pardubická pivnice U Járy&#34;,&#34;U Vystřelenýho voka&#34;,&#34;U Kurelů&#34;,&#34;Behind the Courtain&#34;,&#34;The Tavern&#34;,&#34;CEEL&#34;,&#34;Final Art Music Club&#34;,&#34;Pivovar Victor&#34;,&#34;U Dobruských&#34;,&#34;Vincaffe&#34;,&#34;Pizzeria Vendemaria&#34;,&#34;Guston&#34;,&#34;Nebeská vůně&#34;,&#34;Pivo a Párek&#34;,&#34;Bohužel bar&#34;,&#34;Chartreuse Bar&#34;,&#34;Delicates Pizzeria&amp;amp;Café&#34;,&#34;Viet Flavor&#34;,&#34;Night Club Victory&#34;,&#34;Bar Fud&#34;,&#34;Bar Food&#34;,&#34;Harmonie&#34;,&#34;Bumper Bar Žižkov&#34;,&#34;Vape House Prague&#34;,&#34;U Kroužků&#34;,&#34;Malkovich Bar&#34;,&#34;Palác Akropolis&#34;,&#34;U Pižďucha&#34;,&#34;Sushi Sushi&#34;,&#34;Simply U Kravaty 2&#34;,&#34;Sklep Restaurant&#34;,&#34;Grow Bar&#34;,&#34;Tiky taky&#34;,&#34;Play House&#34;,&#34;Deep Down&#34;,&#34;Ananas Bananas&#34;,&#34;Dream&#34;,&#34;Pivní lokál Ostrý&#34;,&#34;U Pádivce&#34;,&#34;U Fíčků&#34;,&#34;Sociální bistro Střecha&#34;,&#34;Česka kuchyne&#34;,&#34;SOU100&#34;,&#34;Music pub woodoo&#34;,&#34;Cibo&#34;,&#34;Chocobamba&#34;],{&#34;interactive&#34;:false,&#34;permanent&#34;:false,&#34;direction&#34;:&#34;auto&#34;,&#34;opacity&#34;:1,&#34;offset&#34;:[0,0],&#34;textsize&#34;:&#34;10px&#34;,&#34;textOnly&#34;:false,&#34;className&#34;:&#34;&#34;,&#34;sticky&#34;:true},null]}],&#34;limits&#34;:{&#34;lat&#34;:[50.0812857,50.0874131],&#34;lng&#34;:[14.4385956,14.4526231]}},&#34;evals&#34;:[],&#34;jsHooks&#34;:[]}&lt;/script&gt;
&lt;p&gt;&lt;br&gt;
We have located 76 bars, implying a distance matrix of 5776 elements. Not a huge one by today’s standards — but big enough to think twice about trying to solve using a pen and a piece of paper.&lt;/p&gt;
&lt;p&gt;I have found that while it is not overly difficult to solve the TSP for &lt;em&gt;all&lt;/em&gt; the Žižkov bars there is educational value in running the TSP over only a small sample. I have found it advantageous to be able to actually show the distance matrix — and this page will easily accommodate only about a 5×5 matrix.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;# a sample of bars to make the matrix fit a web page
vzorek &amp;lt;- bars %&amp;gt;% 
  slice_sample(n = 5)

# a beer tankard icon for nicer display
beer_icon &amp;lt;- makeAwesomeIcon(
  icon = &amp;quot;beer&amp;quot;,
  iconColor = &amp;quot;black&amp;quot;,
  markerColor = &amp;quot;blue&amp;quot;,
  library = &amp;quot;fa&amp;quot;
)

# a quick overview of our selection
leaflet(vzorek) %&amp;gt;% 
  addProviderTiles(&amp;quot;CartoDB.Positron&amp;quot;) %&amp;gt;% 
  addAwesomeMarkers(data = vzorek,
                    icon = beer_icon, # the awesome icon declared earlier
                    label = ~name)&lt;/code&gt;&lt;/pre&gt;
&lt;div id=&#34;htmlwidget-2&#34; style=&#34;width:100%;height:480px;&#34; class=&#34;leaflet html-widget&#34;&gt;&lt;/div&gt;
&lt;script type=&#34;application/json&#34; data-for=&#34;htmlwidget-2&#34;&gt;{&#34;x&#34;:{&#34;options&#34;:{&#34;crs&#34;:{&#34;crsClass&#34;:&#34;L.CRS.EPSG3857&#34;,&#34;code&#34;:null,&#34;proj4def&#34;:null,&#34;projectedBounds&#34;:null,&#34;options&#34;:{}}},&#34;calls&#34;:[{&#34;method&#34;:&#34;addProviderTiles&#34;,&#34;args&#34;:[&#34;CartoDB.Positron&#34;,null,null,{&#34;errorTileUrl&#34;:&#34;&#34;,&#34;noWrap&#34;:false,&#34;detectRetina&#34;:false}]},{&#34;method&#34;:&#34;addAwesomeMarkers&#34;,&#34;args&#34;:[[50.0853797,50.0850515,50.08319,50.0871616,50.0817138],[14.449984,14.4518274,14.4499142,14.4444131,14.4468291],{&#34;icon&#34;:&#34;beer&#34;,&#34;markerColor&#34;:&#34;blue&#34;,&#34;iconColor&#34;:&#34;black&#34;,&#34;spin&#34;:false,&#34;squareMarker&#34;:false,&#34;iconRotate&#34;:0,&#34;font&#34;:&#34;monospace&#34;,&#34;prefix&#34;:&#34;fa&#34;},null,null,{&#34;interactive&#34;:true,&#34;draggable&#34;:false,&#34;keyboard&#34;:true,&#34;title&#34;:&#34;&#34;,&#34;alt&#34;:&#34;&#34;,&#34;zIndexOffset&#34;:0,&#34;opacity&#34;:1,&#34;riseOnHover&#34;:false,&#34;riseOffset&#34;:250},null,null,null,null,[&#34;SOU100&#34;,&#34;Behind the Courtain&#34;,&#34;Chocobamba&#34;,&#34;Bar Fud&#34;,&#34;Olympos&#34;],{&#34;interactive&#34;:false,&#34;permanent&#34;:false,&#34;direction&#34;:&#34;auto&#34;,&#34;opacity&#34;:1,&#34;offset&#34;:[0,0],&#34;textsize&#34;:&#34;10px&#34;,&#34;textOnly&#34;:false,&#34;className&#34;:&#34;&#34;,&#34;sticky&#34;:true},null]}],&#34;limits&#34;:{&#34;lat&#34;:[50.0817138,50.0871616],&#34;lng&#34;:[14.4444131,14.4518274]}},&#34;evals&#34;:[],&#34;jsHooks&#34;:[]}&lt;/script&gt;
&lt;p&gt;&lt;br&gt;&lt;/p&gt;
&lt;p&gt;The easiest distance matrix to calculate is plain “as the crow flies” distance. This can be calculated via a &lt;code&gt;sf::st_distance()&lt;/code&gt; call.&lt;/p&gt;
&lt;p&gt;The resulting matrix will be based on pure distance, with some differences in interpretation depending on coordinate reference system of underlying data (Euclidean in projected CRS and spherical in unprojected CRS).&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;# distance matrix &amp;quot;as the crow flies&amp;quot;
crow_matrix &amp;lt;- st_distance(vzorek,
                           vzorek)

# naming the dimensions for easier orientation
rownames(crow_matrix) &amp;lt;- vzorek$name
colnames(crow_matrix) &amp;lt;- vzorek$name

# a visual check; note that the matrix has a {units} dimension
crow_matrix&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;## Units: [m]
##                       SOU100 Behind the Courtain Chocobamba  Bar Fud  Olympos
## SOU100                0.0000            136.4923   243.5348 444.1134 465.6544
## Behind the Courtain 136.4923              0.0000   247.9489 578.6872 514.7123
## Chocobamba          243.5348            247.9489     0.0000 590.8310 274.5917
## Bar Fud             444.1134            578.6872   590.8310   0.0000 629.8178
## Olympos             465.6544            514.7123   274.5917 629.8178   0.0000&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Calculating the distance matrix using plain distance is easy, and the resulting matrix is symmetrical (distance from A to B equals distance from B to A). It is also hollow (distance from A to A itself is zero).&lt;/p&gt;
&lt;p&gt;Solving the TSP for such a matrix is straightforward, as the hard work has been outsourced to the &lt;code&gt;{TSP}&lt;/code&gt; package internals.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;# solve the TSP via {TSP}
crow_tsp &amp;lt;- crow_matrix %&amp;gt;% 
  units::drop_units() %&amp;gt;%  # get rid of unit dimension
  # declaring the problem as a symmetric TSP
  TSP() %&amp;gt;%
  solve_TSP()

# the tour (crawl) as sequence of bars
vzorek$name[as.numeric(crow_tsp)]&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;## [1] &amp;quot;Bar Fud&amp;quot;             &amp;quot;Olympos&amp;quot;             &amp;quot;Chocobamba&amp;quot;         
## [4] &amp;quot;Behind the Courtain&amp;quot; &amp;quot;SOU100&amp;quot;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Once we have the optimal route calculated it can be visualized using &lt;code&gt;{leaflet}&lt;/code&gt;. The sequence of stops needs to be completed (by repeating the first stop after the last) and cast from points to a linestring.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;stops &amp;lt;- as.numeric(crow_tsp) # sequence of &amp;quot;cities&amp;quot; as indices

# bars in sequence, with the first repeated in last place
crow_result &amp;lt;- vzorek[c(stops, stops[1]), ] %&amp;gt;%
  st_combine() %&amp;gt;% # combined to a single object
  st_cast(&amp;quot;LINESTRING&amp;quot;) # &amp;amp; presented as a route (a line)

# present the as-the-crow-flies based route in crimson color
leaflet(crow_result) %&amp;gt;% 
  addProviderTiles(&amp;quot;CartoDB.Positron&amp;quot;) %&amp;gt;% 
  addPolylines(color = &amp;quot;crimson&amp;quot;,
               popup = &amp;quot;as the crow flies...&amp;quot;) %&amp;gt;% 
  addAwesomeMarkers(data = vzorek,
                    icon = beer_icon, # the awesome icon declared earlier
                    label = ~name)&lt;/code&gt;&lt;/pre&gt;
&lt;div id=&#34;htmlwidget-3&#34; style=&#34;width:100%;height:480px;&#34; class=&#34;leaflet html-widget&#34;&gt;&lt;/div&gt;
&lt;script type=&#34;application/json&#34; data-for=&#34;htmlwidget-3&#34;&gt;{&#34;x&#34;:{&#34;options&#34;:{&#34;crs&#34;:{&#34;crsClass&#34;:&#34;L.CRS.EPSG3857&#34;,&#34;code&#34;:null,&#34;proj4def&#34;:null,&#34;projectedBounds&#34;:null,&#34;options&#34;:{}}},&#34;calls&#34;:[{&#34;method&#34;:&#34;addProviderTiles&#34;,&#34;args&#34;:[&#34;CartoDB.Positron&#34;,null,null,{&#34;errorTileUrl&#34;:&#34;&#34;,&#34;noWrap&#34;:false,&#34;detectRetina&#34;:false}]},{&#34;method&#34;:&#34;addPolylines&#34;,&#34;args&#34;:[[[[{&#34;lng&#34;:[14.4444131,14.4468291,14.4499142,14.4518274,14.449984,14.4444131],&#34;lat&#34;:[50.0871616,50.0817138,50.08319,50.0850515,50.0853797,50.0871616]}]]],null,null,{&#34;interactive&#34;:true,&#34;className&#34;:&#34;&#34;,&#34;stroke&#34;:true,&#34;color&#34;:&#34;crimson&#34;,&#34;weight&#34;:5,&#34;opacity&#34;:0.5,&#34;fill&#34;:false,&#34;fillColor&#34;:&#34;crimson&#34;,&#34;fillOpacity&#34;:0.2,&#34;smoothFactor&#34;:1,&#34;noClip&#34;:false},&#34;as the crow flies...&#34;,null,null,{&#34;interactive&#34;:false,&#34;permanent&#34;:false,&#34;direction&#34;:&#34;auto&#34;,&#34;opacity&#34;:1,&#34;offset&#34;:[0,0],&#34;textsize&#34;:&#34;10px&#34;,&#34;textOnly&#34;:false,&#34;className&#34;:&#34;&#34;,&#34;sticky&#34;:true},null]},{&#34;method&#34;:&#34;addAwesomeMarkers&#34;,&#34;args&#34;:[[50.0853797,50.0850515,50.08319,50.0871616,50.0817138],[14.449984,14.4518274,14.4499142,14.4444131,14.4468291],{&#34;icon&#34;:&#34;beer&#34;,&#34;markerColor&#34;:&#34;blue&#34;,&#34;iconColor&#34;:&#34;black&#34;,&#34;spin&#34;:false,&#34;squareMarker&#34;:false,&#34;iconRotate&#34;:0,&#34;font&#34;:&#34;monospace&#34;,&#34;prefix&#34;:&#34;fa&#34;},null,null,{&#34;interactive&#34;:true,&#34;draggable&#34;:false,&#34;keyboard&#34;:true,&#34;title&#34;:&#34;&#34;,&#34;alt&#34;:&#34;&#34;,&#34;zIndexOffset&#34;:0,&#34;opacity&#34;:1,&#34;riseOnHover&#34;:false,&#34;riseOffset&#34;:250},null,null,null,null,[&#34;SOU100&#34;,&#34;Behind the Courtain&#34;,&#34;Chocobamba&#34;,&#34;Bar Fud&#34;,&#34;Olympos&#34;],{&#34;interactive&#34;:false,&#34;permanent&#34;:false,&#34;direction&#34;:&#34;auto&#34;,&#34;opacity&#34;:1,&#34;offset&#34;:[0,0],&#34;textsize&#34;:&#34;10px&#34;,&#34;textOnly&#34;:false,&#34;className&#34;:&#34;&#34;,&#34;sticky&#34;:true},null]}],&#34;limits&#34;:{&#34;lat&#34;:[50.0817138,50.0871616],&#34;lng&#34;:[14.4444131,14.4518274]}},&#34;evals&#34;:[],&#34;jsHooks&#34;:[]}&lt;/script&gt;
&lt;p&gt;&lt;br&gt;
From the visual overview we can see an obvious shortcoming of the “as the crow flies” approach: it completely ignores other constraints except for distance — such as the road network.&lt;/p&gt;
&lt;p&gt;Thus while the route shown is “optimal” in the sense that it forms the shortest path joining the five bars selected, it is not one that we could actually follow (unless we were a flying crow).&lt;/p&gt;
&lt;p&gt;This shortcoming can be resolved by using an alternative distance matrix as input, while retaining the techniques of &lt;code&gt;{TSP}&lt;/code&gt; for the actual route selection. A possible source of more applicable data are routing engines, available to R users via API interfacing packages.&lt;/p&gt;
&lt;p&gt;There are &lt;a href=&#34;https://www.jla-data.net/eng/routing-in-r-context/&#34;&gt;several of them available&lt;/a&gt;, my personal favorite being the &lt;a href=&#34;https://cran.r-project.org/package=hereR&#34;&gt;&lt;code&gt;{hereR}&lt;/code&gt;&lt;/a&gt; package interfacing to the &lt;a href=&#34;https://developer.here.com/&#34;&gt;HERE routing engine&lt;/a&gt;. I have found HERE to be very reliable and rich in detail. It does require registration, but its free tier is more than adequate for most individual users.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;# set the HERE API key; mine is stored in an envir variable
hereR::set_key(Sys.getenv(&amp;quot;HERE_API_KEY&amp;quot;))

# a full set of all combinations - 5 × 5 = 25 rows
indices &amp;lt;- expand.grid(from = seq_along(vzorek$name), 
                       to = seq_along(vzorek$name))

# call routing API for all permutations &amp;amp; store for future use
for (i in seq_along(indices$from)) {
  
  active_route &amp;lt;- hereR::route(origin = vzorek[indices$from[i], ],
                               destination = vzorek[indices$to[i], ],
                               transport_mode = &amp;quot;car&amp;quot;) %&amp;gt;% 
    # technical columns for easier use and presentation
    mutate(idx_origin = indices$from[i],
           idx_destination = indices$to[i],
           route_name = paste(vzorek$name[indices$from[i]],
                        &amp;quot;&amp;gt;&amp;gt;&amp;quot;,
                        vzorek$name[indices$to[i]])) %&amp;gt;% 
    relocate(idx_origin, idx_destination, route_name) %&amp;gt;% 
    st_zm() # drop z dimension, as it messes up with leaflet viz
  
  if (i == 1) {
    # if processing the first sample = initiate a result set
    routes &amp;lt;- active_route 
  } else {
    # not processing the first sample = bind to the existing result set
    routes &amp;lt;- routes %&amp;gt;% 
      bind_rows(active_route)
  }
  
}

# a quick overview of structure of the routes data frame
glimpse(routes)&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;## Rows: 25
## Columns: 15
## $ idx_origin      &amp;lt;int&amp;gt; 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, …
## $ idx_destination &amp;lt;int&amp;gt; 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, …
## $ route_name      &amp;lt;chr&amp;gt; &amp;quot;SOU100 &amp;gt;&amp;gt; SOU100&amp;quot;, &amp;quot;Behind the Courtain &amp;gt;&amp;gt; SOU100&amp;quot;, &amp;quot;…
## $ id              &amp;lt;dbl&amp;gt; 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, …
## $ rank            &amp;lt;dbl&amp;gt; 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, …
## $ section         &amp;lt;dbl&amp;gt; 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, …
## $ departure       &amp;lt;dttm&amp;gt; 2022-03-28 18:08:37, 2022-03-28 18:08:37, 2022-03-28 …
## $ arrival         &amp;lt;dttm&amp;gt; 2022-03-28 18:08:37, 2022-03-28 18:09:01, 2022-03-28 …
## $ type            &amp;lt;chr&amp;gt; &amp;quot;vehicle&amp;quot;, &amp;quot;vehicle&amp;quot;, &amp;quot;vehicle&amp;quot;, &amp;quot;vehicle&amp;quot;, &amp;quot;vehicle&amp;quot;,…
## $ mode            &amp;lt;chr&amp;gt; &amp;quot;car&amp;quot;, &amp;quot;car&amp;quot;, &amp;quot;car&amp;quot;, &amp;quot;car&amp;quot;, &amp;quot;car&amp;quot;, &amp;quot;car&amp;quot;, &amp;quot;car&amp;quot;, &amp;quot;car&amp;quot;…
## $ distance        &amp;lt;int&amp;gt; 0, 169, 504, 895, 606, 619, 0, 1050, 971, 1199, 1381, …
## $ duration        &amp;lt;int&amp;gt; 0, 24, 105, 139, 113, 98, 0, 177, 145, 189, 236, 182, …
## $ duration_base   &amp;lt;int&amp;gt; 0, 24, 94, 101, 112, 88, 0, 165, 103, 173, 224, 171, 0…
## $ consumption     &amp;lt;dbl&amp;gt; 0.0000, 0.0610, 0.1487, 0.7347, 0.1400, 0.4019, 0.0000…
## $ geometry        &amp;lt;GEOMETRY [°]&amp;gt; POLYGON ((14.44988 50.08544..., LINESTRING (1…&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The routing results give us several pieces of data:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;the routes as linestring objects in EPSG:4326 (for visualization later on)&lt;/li&gt;
&lt;li&gt;distance of the route (in meters)&lt;/li&gt;
&lt;li&gt;travel time (in seconds) both raw and adjusted for traffic&lt;/li&gt;
&lt;li&gt;petrol consumption&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;To these I have added three technical columns: indices of start &amp;amp; destination for easier joining of solved TSP results back and the name of the route as string for visualization purposes.&lt;/p&gt;
&lt;p&gt;Having a variety of metrics will be helpful in construction of alternative distance matrices.&lt;/p&gt;
&lt;p&gt;The first routing distance matrix will be based on route distance; notice that while the matrix is hollow it is not symmetrical. This is not surprising, as routing is not commutative — optimal route from A to B need not be the same as from B to A, due to constraints such as one way roads. Žižkov is a veritable warren of one way streets.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;# distance matrix based on actual distances
distance_matrix &amp;lt;- matrix(routes$distance,
                          nrow = nrow(vzorek),
                          ncol = nrow(vzorek))

# naming the dimensions for easier orientation
rownames(distance_matrix) &amp;lt;- vzorek$name
colnames(distance_matrix) &amp;lt;- vzorek$name

# a visual check; the units are meters (distance)
distance_matrix&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;##                     SOU100 Behind the Courtain Chocobamba Bar Fud Olympos
## SOU100                   0                 619       1381    1011    1169
## Behind the Courtain    169                   0       1007     637     795
## Chocobamba             504                1050          0     972     661
## Bar Fud                895                 971       1698       0    1523
## Olympos                606                1199        360    1031       0&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;# solve the TSP via {TSP}
distance_tsp &amp;lt;- distance_matrix %&amp;gt;% 
  # declaring the problem as asymmetric TSP
  ATSP() %&amp;gt;%
  solve_TSP()

# the tour (crawl) as sequence of bars
vzorek$name[as.numeric(distance_tsp)]&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;## [1] &amp;quot;Chocobamba&amp;quot;          &amp;quot;SOU100&amp;quot;              &amp;quot;Bar Fud&amp;quot;            
## [4] &amp;quot;Behind the Courtain&amp;quot; &amp;quot;Olympos&amp;quot;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Once we have solved the TSP and figured the sequence of “cities” to visit it is time to report our results.&lt;/p&gt;
&lt;p&gt;For this purpose it is advantageous to prepare a data frame of indices of start and destination, and join it back with the original dataset from HERE API (which contains routes as linestrings).&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;stops &amp;lt;- as.numeric(distance_tsp) # sequence of &amp;quot;cities&amp;quot; as indices

# a route as a set of origin &amp;amp; destination pairs, as indexes,
# destination is offset by one from start (last destination = first start)
distance_route &amp;lt;- data.frame(idx_origin = stops,
                             idx_destination = c(stops[2:(nrow(vzorek))],
                                                 stops[1]))

# amend the origin &amp;amp; destination indexes by actual routes
distance_result &amp;lt;-  distance_route %&amp;gt;% 
  inner_join(routes,
             by = c(&amp;quot;idx_origin&amp;quot;, &amp;quot;idx_destination&amp;quot;)) %&amp;gt;% 
  st_as_sf() 

# present the distance based route in goldenrod color
leaflet(distance_result) %&amp;gt;% 
  addProviderTiles(&amp;quot;CartoDB.Positron&amp;quot;) %&amp;gt;% 
  addPolylines(color = &amp;quot;GoldenRod&amp;quot;,
               popup = ~route_name) %&amp;gt;% 
  addAwesomeMarkers(data = vzorek,
                    icon = beer_icon, # the awesome icon declared earlier
                    label = ~name)&lt;/code&gt;&lt;/pre&gt;
&lt;div id=&#34;htmlwidget-4&#34; style=&#34;width:100%;height:480px;&#34; class=&#34;leaflet html-widget&#34;&gt;&lt;/div&gt;
&lt;script type=&#34;application/json&#34; data-for=&#34;htmlwidget-4&#34;&gt;{&#34;x&#34;:{&#34;options&#34;:{&#34;crs&#34;:{&#34;crsClass&#34;:&#34;L.CRS.EPSG3857&#34;,&#34;code&#34;:null,&#34;proj4def&#34;:null,&#34;projectedBounds&#34;:null,&#34;options&#34;:{}}},&#34;calls&#34;:[{&#34;method&#34;:&#34;addProviderTiles&#34;,&#34;args&#34;:[&#34;CartoDB.Positron&#34;,null,null,{&#34;errorTileUrl&#34;:&#34;&#34;,&#34;noWrap&#34;:false,&#34;detectRetina&#34;:false}]},{&#34;method&#34;:&#34;addPolylines&#34;,&#34;args&#34;:[[[[{&#34;lng&#34;:[14.449884,14.45031,14.45043,14.4514,14.45157,14.45106,14.45111,14.45065,14.45018,14.44995,14.44882,14.44884,14.44972,14.449878],&#34;lat&#34;:[50.083245,50.08334,50.08339,50.0836,50.08361,50.08407,50.08429,50.08435,50.08441,50.08444,50.08458,50.08469,50.08532,50.085438]}]],[[{&#34;lng&#34;:[14.449878,14.45047,14.45181,14.4519,14.452,14.45225,14.45127,14.44996,14.44972,14.4484,14.44846,14.4485,14.44851,14.44834,14.44803,14.44752,14.44735,14.44618,14.44587,14.44565,14.44537,14.44506,14.44483,14.44448,14.444362],&#34;lat&#34;:[50.085438,50.08588,50.08678,50.08674,50.08669,50.08656,50.08516,50.08529,50.08532,50.08568,50.08576,50.08586,50.08601,50.08601,50.08601,50.086,50.08602,50.08624,50.08677,50.0868,50.08685,50.08692,50.08697,50.08704,50.087066]}]],[[{&#34;lng&#34;:[14.444362,14.44448,14.44483,14.44506,14.44537,14.44565,14.44587,14.44624,14.44638,14.44684,14.44715,14.44735,14.44832,14.4486,14.44892,14.44919,14.4494,14.44978,14.4509,14.45116,14.45123,14.45131,14.45144,14.45165,14.45181,14.4519,14.452,14.45225,14.4525,14.4527,14.45289,14.45319,14.45355,14.45377,14.45407,14.45422,14.45418,14.45385,14.45358,14.45344,14.45277,14.451835],&#34;lat&#34;:[50.087066,50.08704,50.08697,50.08692,50.08685,50.0868,50.08677,50.08676,50.08676,50.08677,50.08677,50.08677,50.08675,50.08674,50.08674,50.08677,50.08681,50.08688,50.08709,50.08713,50.08708,50.08703,50.08696,50.08685,50.08678,50.08674,50.08669,50.08656,50.08643,50.08632,50.08622,50.08607,50.08588,50.08576,50.08561,50.08553,50.0855,50.08526,50.08506,50.08508,50.08511,50.085141]}]],[[{&#34;lng&#34;:[14.451835,14.45127,14.45065,14.45111,14.45106,14.45157,14.45168,14.45219,14.4501,14.44918,14.44787,14.44752,14.446906],&#34;lat&#34;:[50.085141,50.08516,50.08435,50.08429,50.08407,50.08361,50.08351,50.0824,50.08227,50.08219,50.08183,50.08173,50.081582]}]],[[{&#34;lng&#34;:[14.446906,14.44752,14.44787,14.44743,14.44932,14.449884],&#34;lat&#34;:[50.081582,50.08173,50.08183,50.08268,50.08312,50.083245]}]]],null,null,{&#34;interactive&#34;:true,&#34;className&#34;:&#34;&#34;,&#34;stroke&#34;:true,&#34;color&#34;:&#34;GoldenRod&#34;,&#34;weight&#34;:5,&#34;opacity&#34;:0.5,&#34;fill&#34;:false,&#34;fillColor&#34;:&#34;GoldenRod&#34;,&#34;fillOpacity&#34;:0.2,&#34;smoothFactor&#34;:1,&#34;noClip&#34;:false},[&#34;Chocobamba &gt;&gt; SOU100&#34;,&#34;SOU100 &gt;&gt; Bar Fud&#34;,&#34;Bar Fud &gt;&gt; Behind the Courtain&#34;,&#34;Behind the Courtain &gt;&gt; Olympos&#34;,&#34;Olympos &gt;&gt; Chocobamba&#34;],null,null,{&#34;interactive&#34;:false,&#34;permanent&#34;:false,&#34;direction&#34;:&#34;auto&#34;,&#34;opacity&#34;:1,&#34;offset&#34;:[0,0],&#34;textsize&#34;:&#34;10px&#34;,&#34;textOnly&#34;:false,&#34;className&#34;:&#34;&#34;,&#34;sticky&#34;:true},null]},{&#34;method&#34;:&#34;addAwesomeMarkers&#34;,&#34;args&#34;:[[50.0853797,50.0850515,50.08319,50.0871616,50.0817138],[14.449984,14.4518274,14.4499142,14.4444131,14.4468291],{&#34;icon&#34;:&#34;beer&#34;,&#34;markerColor&#34;:&#34;blue&#34;,&#34;iconColor&#34;:&#34;black&#34;,&#34;spin&#34;:false,&#34;squareMarker&#34;:false,&#34;iconRotate&#34;:0,&#34;font&#34;:&#34;monospace&#34;,&#34;prefix&#34;:&#34;fa&#34;},null,null,{&#34;interactive&#34;:true,&#34;draggable&#34;:false,&#34;keyboard&#34;:true,&#34;title&#34;:&#34;&#34;,&#34;alt&#34;:&#34;&#34;,&#34;zIndexOffset&#34;:0,&#34;opacity&#34;:1,&#34;riseOnHover&#34;:false,&#34;riseOffset&#34;:250},null,null,null,null,[&#34;SOU100&#34;,&#34;Behind the Courtain&#34;,&#34;Chocobamba&#34;,&#34;Bar Fud&#34;,&#34;Olympos&#34;],{&#34;interactive&#34;:false,&#34;permanent&#34;:false,&#34;direction&#34;:&#34;auto&#34;,&#34;opacity&#34;:1,&#34;offset&#34;:[0,0],&#34;textsize&#34;:&#34;10px&#34;,&#34;textOnly&#34;:false,&#34;className&#34;:&#34;&#34;,&#34;sticky&#34;:true},null]}],&#34;limits&#34;:{&#34;lat&#34;:[50.081582,50.0871616],&#34;lng&#34;:[14.444362,14.45422]}},&#34;evals&#34;:[],&#34;jsHooks&#34;:[]}&lt;/script&gt;
&lt;p&gt;&lt;br&gt;
Since the HERE API is generous in terms of results provided it is not difficult to construct an alternative distance matrix, using a different metric. This could be either trip duration or petrol consumption.&lt;/p&gt;
&lt;p&gt;In our specific situation both of these can be expected to be be highly correlated with the plain distance results. All the streets in Žižkov are of very similar type, and the average speed &amp;amp; consumption are unlikely to vary greatly between the routes.&lt;/p&gt;
&lt;p&gt;The most significant difference between the distance and time based TSP will be driven by current traffic, which is a factor HERE routing engine considers.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;# distance matrix based on travel time
duration_matrix &amp;lt;- matrix(routes$duration,
                          nrow = nrow(vzorek),
                          ncol = nrow(vzorek))

# names make the distance matrix easier to interpret
rownames(duration_matrix) &amp;lt;- vzorek$name
colnames(duration_matrix) &amp;lt;- vzorek$name

# a visual check; the units are seconds (time)
duration_matrix&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;##                     SOU100 Behind the Courtain Chocobamba Bar Fud Olympos
## SOU100                   0                  98        236     183     205
## Behind the Courtain     24                   0        182     120     151
## Chocobamba             105                 177          0     216      99
## Bar Fud                139                 145        268       0     244
## Olympos                113                 189         58     203       0&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;# solving using the same pattern as distance based TSP
duration_tsp &amp;lt;- duration_matrix %&amp;gt;% 
  ATSP() %&amp;gt;% 
  solve_TSP() 

# the tour (crawl) as sequence of bars
vzorek$name[as.numeric(duration_tsp)]&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;## [1] &amp;quot;SOU100&amp;quot;              &amp;quot;Behind the Courtain&amp;quot; &amp;quot;Bar Fud&amp;quot;            
## [4] &amp;quot;Olympos&amp;quot;             &amp;quot;Chocobamba&amp;quot;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Once we have solved the trip duration optimized TSP we again need to report the results; in our use case the output is very similar to the distance based one.&lt;/p&gt;
&lt;p&gt;This will not necessarily be the case in other contexts, especially ones with greater variation of road types (city streets vs. highways).&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;# the same steps as for distance based matrix
stops &amp;lt;- as.numeric(duration_tsp)

duration_route &amp;lt;- data.frame(idx_origin = stops,
                             idx_destination = c(stops[2:(nrow(vzorek))],
                                                 stops[1]))
# again, the same as for distance based calculation
duration_result &amp;lt;-  duration_route %&amp;gt;% 
  inner_join(routes,
             by = c(&amp;quot;idx_origin&amp;quot;, &amp;quot;idx_destination&amp;quot;)) %&amp;gt;% 
  st_as_sf() 

# present the duration based route in light blue color
leaflet(duration_result) %&amp;gt;% 
  addProviderTiles(&amp;quot;CartoDB.Positron&amp;quot;) %&amp;gt;% 
  addPolylines(color = &amp;quot;cornflowerblue&amp;quot;,
               popup = ~route_name) %&amp;gt;% 
  addAwesomeMarkers(data = vzorek,
                    icon = beer_icon,
                    label = ~ name)&lt;/code&gt;&lt;/pre&gt;
&lt;div id=&#34;htmlwidget-5&#34; style=&#34;width:100%;height:480px;&#34; class=&#34;leaflet html-widget&#34;&gt;&lt;/div&gt;
&lt;script type=&#34;application/json&#34; data-for=&#34;htmlwidget-5&#34;&gt;{&#34;x&#34;:{&#34;options&#34;:{&#34;crs&#34;:{&#34;crsClass&#34;:&#34;L.CRS.EPSG3857&#34;,&#34;code&#34;:null,&#34;proj4def&#34;:null,&#34;projectedBounds&#34;:null,&#34;options&#34;:{}}},&#34;calls&#34;:[{&#34;method&#34;:&#34;addProviderTiles&#34;,&#34;args&#34;:[&#34;CartoDB.Positron&#34;,null,null,{&#34;errorTileUrl&#34;:&#34;&#34;,&#34;noWrap&#34;:false,&#34;detectRetina&#34;:false}]},{&#34;method&#34;:&#34;addPolylines&#34;,&#34;args&#34;:[[[[{&#34;lng&#34;:[14.449878,14.45047,14.45181,14.4519,14.452,14.45225,14.4525,14.4527,14.45289,14.45319,14.45355,14.45377,14.45407,14.45422,14.45418,14.45385,14.45358,14.45344,14.45277,14.451835],&#34;lat&#34;:[50.085438,50.08588,50.08678,50.08674,50.08669,50.08656,50.08643,50.08632,50.08622,50.08607,50.08588,50.08576,50.08561,50.08553,50.0855,50.08526,50.08506,50.08508,50.08511,50.085141]}]],[[{&#34;lng&#34;:[14.451835,14.45127,14.44996,14.44972,14.4484,14.44846,14.4485,14.44851,14.44834,14.44803,14.44752,14.44735,14.44618,14.44587,14.44565,14.44537,14.44506,14.44483,14.44448,14.444362],&#34;lat&#34;:[50.085141,50.08516,50.08529,50.08532,50.08568,50.08576,50.08586,50.08601,50.08601,50.08601,50.086,50.08602,50.08624,50.08677,50.0868,50.08685,50.08692,50.08697,50.08704,50.087066]}]],[[{&#34;lng&#34;:[14.444362,14.44425,14.44389,14.44348,14.44337,14.44332,14.44328,14.44289,14.44266,14.44249,14.44223,14.44208,14.44179,14.44148,14.44126,14.44095,14.44072,14.44036,14.44,14.43965,14.43939,14.43917,14.43899,14.43871,14.43805,14.43809,14.43814,14.4382,14.4383,14.43875,14.43891,14.43906,14.43918,14.43933,14.43979,14.44008,14.44026,14.44039,14.44054,14.44066,14.44081,14.4409,14.44102,14.44116,14.44129,14.44142,14.44159,14.44194,14.44313,14.44337,14.44335,14.44333,14.4433,14.44326,14.44325,14.44323,14.44322,14.44323,14.44325,14.44328,14.44334,14.44343,14.44356,14.44371,14.44383,14.44391,14.44399,14.44405,14.4442,14.44441,14.44442,14.44454,14.44467,14.44473,14.44481,14.44493,14.44515,14.44536,14.44545,14.446906],&#34;lat&#34;:[50.087066,50.08709,50.08717,50.08726,50.08729,50.08731,50.08734,50.08735,50.08736,50.08737,50.08738,50.08738,50.08738,50.08736,50.08733,50.08729,50.08726,50.0872,50.08713,50.08704,50.08696,50.08688,50.0868,50.08667,50.08635,50.08627,50.0862,50.08613,50.0861,50.08593,50.08587,50.08581,50.08576,50.08568,50.08544,50.0853,50.08523,50.08519,50.08516,50.08515,50.08514,50.08514,50.08515,50.08516,50.08517,50.08518,50.08519,50.08519,50.08512,50.08511,50.08477,50.0846,50.08438,50.08399,50.08388,50.08364,50.08351,50.08342,50.08335,50.08329,50.08322,50.08313,50.08303,50.08292,50.08283,50.08276,50.08268,50.08259,50.08235,50.082,50.08198,50.08178,50.08156,50.08144,50.08132,50.0813,50.08127,50.08125,50.08123,50.081582]}]],[[{&#34;lng&#34;:[14.446906,14.44752,14.44787,14.44743,14.44932,14.449884],&#34;lat&#34;:[50.081582,50.08173,50.08183,50.08268,50.08312,50.083245]}]],[[{&#34;lng&#34;:[14.449884,14.45031,14.45043,14.4514,14.45157,14.45106,14.45111,14.45065,14.45018,14.44995,14.44882,14.44884,14.44972,14.449878],&#34;lat&#34;:[50.083245,50.08334,50.08339,50.0836,50.08361,50.08407,50.08429,50.08435,50.08441,50.08444,50.08458,50.08469,50.08532,50.085438]}]]],null,null,{&#34;interactive&#34;:true,&#34;className&#34;:&#34;&#34;,&#34;stroke&#34;:true,&#34;color&#34;:&#34;cornflowerblue&#34;,&#34;weight&#34;:5,&#34;opacity&#34;:0.5,&#34;fill&#34;:false,&#34;fillColor&#34;:&#34;cornflowerblue&#34;,&#34;fillOpacity&#34;:0.2,&#34;smoothFactor&#34;:1,&#34;noClip&#34;:false},[&#34;SOU100 &gt;&gt; Behind the Courtain&#34;,&#34;Behind the Courtain &gt;&gt; Bar Fud&#34;,&#34;Bar Fud &gt;&gt; Olympos&#34;,&#34;Olympos &gt;&gt; Chocobamba&#34;,&#34;Chocobamba &gt;&gt; SOU100&#34;],null,null,{&#34;interactive&#34;:false,&#34;permanent&#34;:false,&#34;direction&#34;:&#34;auto&#34;,&#34;opacity&#34;:1,&#34;offset&#34;:[0,0],&#34;textsize&#34;:&#34;10px&#34;,&#34;textOnly&#34;:false,&#34;className&#34;:&#34;&#34;,&#34;sticky&#34;:true},null]},{&#34;method&#34;:&#34;addAwesomeMarkers&#34;,&#34;args&#34;:[[50.0853797,50.0850515,50.08319,50.0871616,50.0817138],[14.449984,14.4518274,14.4499142,14.4444131,14.4468291],{&#34;icon&#34;:&#34;beer&#34;,&#34;markerColor&#34;:&#34;blue&#34;,&#34;iconColor&#34;:&#34;black&#34;,&#34;spin&#34;:false,&#34;squareMarker&#34;:false,&#34;iconRotate&#34;:0,&#34;font&#34;:&#34;monospace&#34;,&#34;prefix&#34;:&#34;fa&#34;},null,null,{&#34;interactive&#34;:true,&#34;draggable&#34;:false,&#34;keyboard&#34;:true,&#34;title&#34;:&#34;&#34;,&#34;alt&#34;:&#34;&#34;,&#34;zIndexOffset&#34;:0,&#34;opacity&#34;:1,&#34;riseOnHover&#34;:false,&#34;riseOffset&#34;:250},null,null,null,null,[&#34;SOU100&#34;,&#34;Behind the Courtain&#34;,&#34;Chocobamba&#34;,&#34;Bar Fud&#34;,&#34;Olympos&#34;],{&#34;interactive&#34;:false,&#34;permanent&#34;:false,&#34;direction&#34;:&#34;auto&#34;,&#34;opacity&#34;:1,&#34;offset&#34;:[0,0],&#34;textsize&#34;:&#34;10px&#34;,&#34;textOnly&#34;:false,&#34;className&#34;:&#34;&#34;,&#34;sticky&#34;:true},null]}],&#34;limits&#34;:{&#34;lat&#34;:[50.08123,50.08738],&#34;lng&#34;:[14.43805,14.45422]}},&#34;evals&#34;:[],&#34;jsHooks&#34;:[]}&lt;/script&gt;
&lt;p&gt;&lt;br&gt;&lt;/p&gt;
&lt;p&gt;I believe my tongue in cheek example has succeeded in showing two things:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;the ease of applying a standardized solution (the &lt;code&gt;{TSP}&lt;/code&gt; package) to a well known and well understood problem (the Travelling Salesman Problem) within the context of R ecosystem&lt;/li&gt;
&lt;li&gt;construction of distance matrices from HERE API routing results, with option to optimize for multiple metrics (such as minimizing the travel distance, travel time and petrol consumption)&lt;/li&gt;
&lt;/ul&gt;
</description>
  </item>
  
<item>
  <title>The Breadbaskets of Europe</title>
  <link>https://www.jla-data.net/eng/breadbaskets-of-europe/</link>
  <pubDate>Thu, 11 Nov 2021 00:00:00 +0000</pubDate>
  
<guid>https://www.jla-data.net/eng/breadbaskets-of-europe/</guid>
  <description>
&lt;script src=&#34;https://www.jla-data.net/eng/breadbaskets-of-europe/index_files/header-attrs/header-attrs.js&#34;&gt;&lt;/script&gt;


&lt;p&gt;I have been inspired by the work of &lt;a href=&#34;https://twitter.com/vlckel/status/1458126497126957060/photo/1&#34;&gt;Eliška Vlčková&lt;/a&gt; and &lt;a href=&#34;https://milospopovic.net/overlay-spatial-polygon-on-satellite-imagery-using-r/&#34;&gt;Milos Popovic&lt;/a&gt;, who created – each in his own way – fascinating visualizations of forest cover in Europe.&lt;/p&gt;
&lt;p&gt;Repeating of their work would be like taking owls to Athens, or coal to Newcastle, but I find the technique of extracting Land Use data from Copernicus programme greatly inspiring in other lines of work.&lt;/p&gt;
&lt;p&gt;One such is identifying the breadbaskets of Europe – the areas of highest concentration of agriculture. Which can be defined as areas with the highest proportion of cropland over total area.&lt;/p&gt;
&lt;p&gt;Cropland is a recognized land use category in &lt;a href=&#34;https://land.copernicus.eu/global/&#34;&gt;Copernicus Global Land Cover&lt;/a&gt; product, and as it is open published it can be accessed rather easily (the only issue is file size; remote sensing rasters are big chunks of data).&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;library(terra)
library(ggplot2)
library(dplyr)
library(units)
library(sf)

# files of interest / remote rasters - big grid cells
remotes &amp;lt;- c(&amp;quot;/E000N80/E000N80&amp;quot;,
             &amp;quot;/W040N80/W040N80&amp;quot;,
             &amp;quot;/W020N80/W020N80&amp;quot;,
             &amp;quot;/E020N80/E020N80&amp;quot;,
             &amp;quot;/E040N80/E040N80&amp;quot;,
             &amp;quot;/E040N60/E040N60&amp;quot;,
             &amp;quot;/W020N60/W020N60&amp;quot;,
             &amp;quot;/E000N60/E000N60&amp;quot;,
             &amp;quot;/E020N60/E020N60&amp;quot;,
             &amp;quot;/W020N40/W020N40&amp;quot;,
             &amp;quot;/E000N40/E000N40&amp;quot;,
             &amp;quot;/E020N40/E020N40&amp;quot;,
             &amp;quot;/E040N40/E040N40&amp;quot;)

# files of interest / remote rasters - common parts
remotes &amp;lt;- paste0(
  &amp;quot;https://s3-eu-west-1.amazonaws.com/vito.landcover.global/v3.0.1/2019&amp;quot;,
  remotes,
  &amp;quot;_PROBAV_LC100_global_v3.0.1_2019-nrt_Crops-CoverFraction-layer_EPSG-4326.tif&amp;quot;
  )

# if missing, download!
for (remote in remotes) {
  if(!file.exists(basename(remote))) curl::curl_download(
    url = remote,
    destfile = basename(remote)
    )
}

# one raster file to rule them all!
if(!file.exists(&amp;quot;cropland.tif&amp;quot;)) {
  gdalUtils::mosaic_rasters(gdalfile = basename(remotes),
                            dst_dataset = &amp;quot;cropland.tif&amp;quot;,
                            of = &amp;quot;GTiff&amp;quot;)
}

# read the one raster in 
cropland &amp;lt;- rast(&amp;quot;cropland.tif&amp;quot;)

# a quick glance at the raw data
plot(cropland)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;https://www.jla-data.net/eng/breadbaskets-of-europe/index_files/figure-html/setup-1.png&#34; width=&#34;672&#34; /&gt;&lt;/p&gt;
&lt;p&gt;Once we have the raster side of the map it is necessary to prepare the vector part. This will consist of two parts:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;country polygons, in my case from Eurostat via &lt;code&gt;{giscoR}&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;hexagons, in my case generated via &lt;code&gt;sf::st_make_grid()&lt;/code&gt; call&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;An interesting problem is finding a good country polygon shapefile of continental Europe; the standard administrative approach considers &lt;a href=&#34;https://en.wikipedia.org/wiki/French_Guiana&#34;&gt;French Guiana&lt;/a&gt; a perfectly normal part of France, and the Azores and Canary Islands of Portugal and Spain. Which is not exactly practical in my use case.&lt;/p&gt;
&lt;p&gt;On the other hand while I am OK with not recognizing Russia as an European country a map of Europe looks &lt;em&gt;wrong&lt;/em&gt; without the little exclave of Kaliningrad / Königsberg by the Baltics.&lt;/p&gt;
&lt;p&gt;I thus had to resort to a little fudge, eliminating parts of France, Portugal, Spain and Russia that are too far from Bern. I was stuck with the two Spanish exclaves in Africa, but these are small enough not to be an issue at continental scale.&lt;/p&gt;
&lt;p&gt;As I will be making areal calculation it is appropriate to project the polygons to an equal area projection; &lt;a href=&#34;https://epsg.io/3035&#34;&gt;EPSG:3350&lt;/a&gt; seemed a reasonable choice.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;# download shapefiles from GISCO API
europe &amp;lt;- giscoR::gisco_get_countries(resolution = &amp;quot;10&amp;quot;,
                                      region = &amp;quot;Europe&amp;quot;)


# Overseas France, Azores + Canaries, and don&amp;#39;t get me started on East Prussia!
troublemakers &amp;lt;- subset(europe, CNTR_ID %in% c(&amp;quot;FR&amp;quot;, &amp;quot;PT&amp;quot;, &amp;quot;ES&amp;quot;, &amp;quot;RU&amp;quot;))

buffer &amp;lt;- tidygeocoder::geo(&amp;quot;Bern&amp;quot;, quiet = T) %&amp;gt;% 
  st_as_sf(coords = c(&amp;quot;long&amp;quot;, &amp;quot;lat&amp;quot;), crs = 4326) %&amp;gt;% 
  st_buffer(as_units(1750, &amp;quot;km&amp;quot;)) %&amp;gt;% 
  st_geometry() # don&amp;#39;t need the address column anymore

# remove the bits too far from Bern (roughly midway between Cadiz and Königsberg)
troublemakers &amp;lt;- troublemakers %&amp;gt;% 
  st_intersection(buffer) 

# administrative regions in equal area projection
europe &amp;lt;- europe %&amp;gt;% 
  filter(!CNTR_ID %in% c(&amp;quot;RU&amp;quot;, &amp;quot;SJ&amp;quot;, &amp;quot;FR&amp;quot;, &amp;quot;PT&amp;quot;, &amp;quot;ES&amp;quot;)) %&amp;gt;% 
  rbind(troublemakers) %&amp;gt;% 
  st_transform(3035) # equal area Lambert / &amp;quot;European Albers&amp;quot;

# landmass without borders
continent &amp;lt;- europe %&amp;gt;% 
  summarise() %&amp;gt;% 
  nngeo::st_remove_holes() # get rid of funny artefacts at borders

# grid object
plocha &amp;lt;- as_units(5000, &amp;quot;km2&amp;quot;) # target cell area 

grid_spacing &amp;lt;- sqrt(2*plocha/sqrt(3)) %&amp;gt;% 
  set_units(&amp;quot;m&amp;quot;) %&amp;gt;% 
  as.numeric() # sf expects dimensionless spacing in crs units (= meters)

grid &amp;lt;- continent %&amp;gt;%  
  st_make_grid(square = F, cellsize = c(grid_spacing)) %&amp;gt;% # make the grid
  st_intersection(continent) %&amp;gt;% 
  st_sf()

plot(grid)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;https://www.jla-data.net/eng/breadbaskets-of-europe/index_files/figure-html/grid-1.png&#34; width=&#34;100%&#34; /&gt;&lt;/p&gt;
&lt;p&gt;The final part of my exercise is translating the raster values to the grid object. This can be done very efficiently with the help of &lt;code&gt;{exactextractr}&lt;/code&gt;. Since we are talking about relative measurement (proportion of cropland) mean is the most appropriate transformation.&lt;/p&gt;
&lt;p&gt;Once the grid is populated with data the only thing remains to actually plot the data.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;# extract raster values per grid cells
grid$cropland &amp;lt;- exactextractr::exact_extract(
  x = cropland, # input raster
  y = st_transform(grid, 4326), # target polygons, in CRS of the original raster
  fun = &amp;quot;mean&amp;quot;, # transformation function; sum would give a very different result!
  progress = F # not an issue in interactive mode, but makes a mess of markdown
) 

# draw the map itself
ggplot() +
  geom_sf(data = grid, aes(fill = cropland), color = NA) +
  geom_sf(data = europe, color = alpha(&amp;quot;white&amp;quot;, 2/3), fill = NA, lwd = 1/3) +
  scale_fill_gradientn(colors = rev(terrain.colors(7))) +
  labs(title = &amp;quot;The Breadbaskets of Europe&amp;quot;,
       caption = &amp;quot;© Copernicus Service Information 2019
                \n© EuroGeographics for the administrative boundaries&amp;quot;) +
  theme_void() +
  theme(legend.position = &amp;quot;none&amp;quot;,
        plot.title = element_text(family = &amp;quot;Permanent Marker&amp;quot;,
                                  hjust = 1/2,
                                  size = 30,
                                  color = &amp;quot;grey30&amp;quot;),
        plot.caption = element_text(face = &amp;quot;italic&amp;quot;,
                                    size = 6,
                                    color = &amp;quot;grey50&amp;quot;))&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;https://www.jla-data.net/eng/breadbaskets-of-europe/index_files/figure-html/plot-1.png&#34; width=&#34;100%&#34; /&gt;&lt;/p&gt;
</description>
  </item>
  
<item>
  <title>Geocoding the Minard Map</title>
  <link>https://www.jla-data.net/eng/minard-map-tidygeocoder/</link>
  <pubDate>Tue, 18 May 2021 00:00:00 +0000</pubDate>
  
<guid>https://www.jla-data.net/eng/minard-map-tidygeocoder/</guid>
  <description>
&lt;script src=&#34;https://www.jla-data.net/rmarkdown-libs/htmlwidgets/htmlwidgets.js&#34;&gt;&lt;/script&gt;
&lt;script src=&#34;https://www.jla-data.net/rmarkdown-libs/jquery/jquery-3.6.0.min.js&#34;&gt;&lt;/script&gt;
&lt;link href=&#34;https://www.jla-data.net/rmarkdown-libs/leaflet/leaflet.css&#34; rel=&#34;stylesheet&#34; /&gt;
&lt;script src=&#34;https://www.jla-data.net/rmarkdown-libs/leaflet/leaflet.js&#34;&gt;&lt;/script&gt;
&lt;link href=&#34;https://www.jla-data.net/rmarkdown-libs/leafletfix/leafletfix.css&#34; rel=&#34;stylesheet&#34; /&gt;
&lt;script src=&#34;https://www.jla-data.net/rmarkdown-libs/proj4/proj4.min.js&#34;&gt;&lt;/script&gt;
&lt;script src=&#34;https://www.jla-data.net/rmarkdown-libs/Proj4Leaflet/proj4leaflet.js&#34;&gt;&lt;/script&gt;
&lt;link href=&#34;https://www.jla-data.net/rmarkdown-libs/rstudio_leaflet/rstudio_leaflet.css&#34; rel=&#34;stylesheet&#34; /&gt;
&lt;script src=&#34;https://www.jla-data.net/rmarkdown-libs/leaflet-binding/leaflet.js&#34;&gt;&lt;/script&gt;
&lt;script src=&#34;https://www.jla-data.net/rmarkdown-libs/leaflet-providers/leaflet-providers_2.0.0.js&#34;&gt;&lt;/script&gt;
&lt;script src=&#34;https://www.jla-data.net/rmarkdown-libs/leaflet-providers-plugin/leaflet-providers-plugin.js&#34;&gt;&lt;/script&gt;


&lt;p&gt;The &lt;a href=&#34;https://en.wikipedia.org/wiki/Charles_Joseph_Minard#NapoleonInRussia&#34;&gt;“Napoleon in Russia”&lt;/a&gt; map by Charles Joseph Minard is a justly famous piece of 19th century infographic.&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;https://commons.wikimedia.org/wiki/File:Minard.png&#34;&gt;&lt;img src=&#34;https://upload.wikimedia.org/wikipedia/commons/2/29/Minard.png&#34; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;It has been a subject to many modern era &lt;a href=&#34;https://www.datavis.ca/gallery/re-minard.php&#34;&gt;re-visions and re-interpretations&lt;/a&gt; after being popularized by John Tukey. One of the re-creations was featured prominently in the &lt;a href=&#34;https://www.tandfonline.com/doi/abs/10.1198/jcgs.2009.07098&#34;&gt;original &lt;code&gt;{ggplot2}&lt;/code&gt; article&lt;/a&gt; by you-know-who. One could be excused for considering the matter settled.&lt;/p&gt;
&lt;p&gt;One approach that I have not seen before, however, is re-visioning the Minard’s map using actual geocoded data.&lt;/p&gt;
&lt;p&gt;The usual way to drawing the map is to use a highly schematized approach, taking care to draw the incoming and outgoing armies separately - even though the army spent a significant part of the homeward march backtracking itself. This led to disastrous results, as the Grande Armée, in the accepted fashion of early modern armies, lived off the land coming in; there was little left to live off going out.&lt;/p&gt;
&lt;p&gt;A complication I had to face was the somewhat dated French toponymy. The names that Monsieur Minard used in his map proved difficult to use in modern geocoding use cases.&lt;/p&gt;
&lt;p&gt;This was due to a number of reasons:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Lithuania has freed itself from the shackles of Polish rule, and &lt;a href=&#34;https://en.wikipedia.org/wiki/Kaunas&#34;&gt;Kowno&lt;/a&gt; and &lt;a href=&#34;https://en.wikipedia.org/wiki/Vilnius#Etymology_and_other_names&#34;&gt;Wilna&lt;/a&gt; became Kaunas and Vilnius&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://en.wikipedia.org/wiki/Gagarin,_Smolensk_Oblast&#34;&gt;Gzhatsk&lt;/a&gt; (marked as Chjat in the original map) had its name changed in 1968 after an upstart major, who shot to fame from his birthplace nearby&lt;/li&gt;
&lt;li&gt;some Russian names are simply difficult; there is not much that can be done with &lt;a href=&#34;https://en.wikipedia.org/wiki/Battle_of_Maloyaroslavets&#34;&gt;Maloyaroslavets&lt;/a&gt;, or Malo-Jarosewii in the map. On the other hand the treatment that &lt;a href=&#34;https://en.wikipedia.org/wiki/Vyazma&#34;&gt;Vyazma&lt;/a&gt; received (becoming Wizma in Minard’s rendering and Wixma in Hadley’s) was somewhat surprising.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;At the end I solved this with a little Wikipedia-fu. I am reasonably comfortable in &lt;em&gt;reading&lt;/em&gt; Cyrillic, but I find it rather difficult to &lt;em&gt;write it&lt;/em&gt;, given the cruel and unusual layout or the Russian keyboard.&lt;/p&gt;
&lt;p&gt;I was able to place all the major map locations, with only minor difficulties:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;the path of the force led by &lt;a href=&#34;https://en.wikipedia.org/wiki/%C3%89tienne_Macdonald&#34;&gt;Marshal Macdonald&lt;/a&gt; to lay siege to Riga ended up much more prominent than in the original map; also there was no way to make it appear to start in the same direction as the main army&lt;/li&gt;
&lt;li&gt;in order to make the path of the force led by &lt;a href=&#34;https://en.wikipedia.org/wiki/Nicolas_Oudinot&#34;&gt;Marshal Oudinot&lt;/a&gt; appear correctly crooked around &lt;a href=&#34;https://en.wikipedia.org/wiki/Hlybokaye&#34;&gt;Glubokoe&lt;/a&gt; (Gloubokoe) I had to include the unsuccessful &lt;a href=&#34;https://en.wikipedia.org/wiki/Daugavpils_fortress&#34;&gt;siege of Dinaburg&lt;/a&gt; that was not among Minard’s original labels&lt;/li&gt;
&lt;li&gt;I was unsuccessful in geocoding &lt;a href=&#34;https://en.wikipedia.org/wiki/Battle_of_Tarutino&#34;&gt;Tarutino&lt;/a&gt; – labelled Tarantino, as in Quentin Tarantino, by Minard – as it has a naming conflict with a somewhat bigger city in Ukraine. As only a part of Napoleon’s forces was involved (the Emperor left Moscow only after this Russian victory) I chose to omit it entirely.&lt;/li&gt;
&lt;li&gt;instead of Studianka marked by Minard for the &lt;a href=&#34;https://en.wikipedia.org/wiki/Battle_of_Berezina&#34;&gt;Berezina crossing&lt;/a&gt; I used nearby Borisov. It is close enough not to matter in our use case (it did matter to Napoleon, as he found the bridge in the town burned, and had to build his own nearby).&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;At the end I had a data frame of 29 locations (with a few necessary duplicites).&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;library(tidygeocoder)
library(ggplot2)
library(dplyr)

minard_raw &amp;lt;- data.frame(city = c(&amp;quot;Kaunas&amp;quot;, &amp;quot;Vilnius&amp;quot;, &amp;quot;Глыбо́кае&amp;quot;, &amp;quot;Витебск&amp;quot;, 
                                  &amp;quot;Смоленск&amp;quot;, &amp;quot;Дорогобу́ж&amp;quot;, &amp;quot;Гага́рин&amp;quot;  ,
                                  &amp;quot;Можа́йск&amp;quot;,  &amp;quot;Москва&amp;quot;, &amp;quot;Москва&amp;quot;, 
                                  &amp;quot;Малояросла́вец&amp;quot;, &amp;quot;Можа́йск&amp;quot;, &amp;quot;Вя́зьма&amp;quot;,
                                  &amp;quot;Дорогобу́ж&amp;quot;, &amp;quot;Смоленск&amp;quot;, &amp;quot;О́рша&amp;quot;,
                                  &amp;quot;Бобр&amp;quot;, &amp;quot;Бори́сов&amp;quot;,  &amp;quot;Маладзечна&amp;quot;,
                                  &amp;quot;Сморгонь&amp;quot;, &amp;quot;Vilnius&amp;quot;, &amp;quot;Kaunas&amp;quot;, # La Grande Armée
                                  &amp;quot;Vilnius&amp;quot;, &amp;quot;Daugavpils&amp;quot;,  
                                  &amp;quot;По́лоцк&amp;quot;, &amp;quot;Бобр&amp;quot;, # reserve in Polotskt
                                  &amp;quot;Kaunas&amp;quot;, &amp;quot;Riga&amp;quot;, 
                                  &amp;quot;Riga&amp;quot;, &amp;quot;Kaunas&amp;quot;), # the siege of Riga
                     direction = c(&amp;quot;outward&amp;quot;, &amp;quot;outward&amp;quot;, &amp;quot;outward&amp;quot;, &amp;quot;outward&amp;quot;,
                                   &amp;quot;outward&amp;quot;, &amp;quot;outward&amp;quot;, &amp;quot;outward&amp;quot;, &amp;quot;outward&amp;quot;,
                                   &amp;quot;outward&amp;quot;, &amp;quot;homeward&amp;quot;, &amp;quot;homeward&amp;quot;, &amp;quot;homeward&amp;quot;,
                                   &amp;quot;homeward&amp;quot;, &amp;quot;homeward&amp;quot;, &amp;quot;homeward&amp;quot;, &amp;quot;homeward&amp;quot;,
                                   &amp;quot;homeward&amp;quot;, &amp;quot;homeward&amp;quot;, &amp;quot;homeward&amp;quot;, &amp;quot;homeward&amp;quot;,
                                   &amp;quot;homeward&amp;quot;, &amp;quot;homeward&amp;quot;, # Napoleon
                                   &amp;quot;outward&amp;quot;, &amp;quot;outward&amp;quot;, &amp;quot;homeward&amp;quot;,
                                   &amp;quot;homeward&amp;quot;, # Oudinot
                                   &amp;quot;outward&amp;quot;, &amp;quot;outward&amp;quot;, &amp;quot;homeward&amp;quot;, 
                                   &amp;quot;homeward&amp;quot;), # MacDonald
                     strength = c(422000, 340000, 280000, 210000, 145000,
                                  140000, 127100, 100000, 100000, 100000,
                                  98000, 87000, 55000, 37000, 24000, 20000,
                                  50000, 28000, 12000, 14000, 8000,
                                  4000, # Napoleon
                                  60000, 40000, 33000, 28000, # Oudinot
                                  22000, 22000, 6000, 6000), # MacDonald
                     leader = c(rep(&amp;quot;Napoleon&amp;quot;, 22),  
                                rep(&amp;quot;Oudinot&amp;quot;, 4), 
                                rep(&amp;quot;MacDonald&amp;quot;, 4))) &lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;For geocoding I used the highly recommended &lt;a href=&#34;https://jessecambon.github.io/tag/tidygeocoder&#34;&gt;&lt;code&gt;{tidygeocoder}&lt;/code&gt;&lt;/a&gt; package by Jesse Cambon.&lt;/p&gt;
&lt;p&gt;It supports several backend engines and allows for multiple options to identify objects of interest: addresses, streets, cities, counties, states and so on.&lt;/p&gt;
&lt;p&gt;In my use case the method “osm” (for &lt;a href=&#34;https://wiki.openstreetmap.org/wiki/Nominatim&#34;&gt;OpenStreetMap backend&lt;/a&gt;) and selecting by city performed the best. It also made a rather concise three line call.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;# let tidygeocoder perform its magic!
minard_geocoded &amp;lt;- minard_raw %&amp;gt;% 
  tidygeocoder::geocode(city = city, 
                        method = &amp;quot;osm&amp;quot;) &lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now that we have geocoded the raw data frame we can do a quick overview.&lt;/p&gt;
&lt;p&gt;Note that the output from &lt;code&gt;tidygeocoder::geocode()&lt;/code&gt; is still a regular data frame, and not the special &lt;code&gt;{sf}&lt;/code&gt; kind. This will have implications in plotting the path, as we can use &lt;code&gt;ggplot2::geom_path()&lt;/code&gt;, and not &lt;code&gt;geom_sf()&lt;/code&gt; and friends.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;knitr::kable(minard_geocoded,
             format.args = list(big.mark = &amp;quot;,&amp;quot;,
                                scientific = FALSE))&lt;/code&gt;&lt;/pre&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr class=&#34;header&#34;&gt;
&lt;th align=&#34;left&#34;&gt;city&lt;/th&gt;
&lt;th align=&#34;left&#34;&gt;direction&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;strength&lt;/th&gt;
&lt;th align=&#34;left&#34;&gt;leader&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;lat&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;long&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr class=&#34;odd&#34;&gt;
&lt;td align=&#34;left&#34;&gt;Kaunas&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;outward&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;422,000&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;Napoleon&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;54.89821&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;23.90448&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&#34;even&#34;&gt;
&lt;td align=&#34;left&#34;&gt;Vilnius&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;outward&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;340,000&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;Napoleon&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;54.68705&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;25.28291&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&#34;odd&#34;&gt;
&lt;td align=&#34;left&#34;&gt;Глыбо́кае&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;outward&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;280,000&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;Napoleon&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;55.13923&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;27.68458&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&#34;even&#34;&gt;
&lt;td align=&#34;left&#34;&gt;Витебск&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;outward&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;210,000&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;Napoleon&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;55.19302&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;30.20704&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&#34;odd&#34;&gt;
&lt;td align=&#34;left&#34;&gt;Смоленск&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;outward&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;145,000&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;Napoleon&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;54.77897&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;32.04718&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&#34;even&#34;&gt;
&lt;td align=&#34;left&#34;&gt;Дорогобу́ж&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;outward&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;140,000&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;Napoleon&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;54.91482&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;33.29891&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&#34;odd&#34;&gt;
&lt;td align=&#34;left&#34;&gt;Гага́рин&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;outward&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;127,100&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;Napoleon&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;55.55339&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;34.99051&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&#34;even&#34;&gt;
&lt;td align=&#34;left&#34;&gt;Можа́йск&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;outward&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;100,000&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;Napoleon&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;55.50648&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;36.02131&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&#34;odd&#34;&gt;
&lt;td align=&#34;left&#34;&gt;Москва&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;outward&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;100,000&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;Napoleon&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;55.75054&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;37.61748&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&#34;even&#34;&gt;
&lt;td align=&#34;left&#34;&gt;Москва&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;homeward&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;100,000&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;Napoleon&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;55.75054&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;37.61748&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&#34;odd&#34;&gt;
&lt;td align=&#34;left&#34;&gt;Малояросла́вец&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;homeward&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;98,000&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;Napoleon&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;55.01218&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;36.45902&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&#34;even&#34;&gt;
&lt;td align=&#34;left&#34;&gt;Можа́йск&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;homeward&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;87,000&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;Napoleon&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;55.50648&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;36.02131&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&#34;odd&#34;&gt;
&lt;td align=&#34;left&#34;&gt;Вя́зьма&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;homeward&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;55,000&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;Napoleon&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;55.21036&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;34.29952&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&#34;even&#34;&gt;
&lt;td align=&#34;left&#34;&gt;Дорогобу́ж&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;homeward&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;37,000&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;Napoleon&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;54.91482&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;33.29891&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&#34;odd&#34;&gt;
&lt;td align=&#34;left&#34;&gt;Смоленск&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;homeward&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;24,000&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;Napoleon&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;54.77897&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;32.04718&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&#34;even&#34;&gt;
&lt;td align=&#34;left&#34;&gt;О́рша&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;homeward&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;20,000&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;Napoleon&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;54.51190&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;30.42545&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&#34;odd&#34;&gt;
&lt;td align=&#34;left&#34;&gt;Бобр&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;homeward&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;50,000&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;Napoleon&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;54.34169&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;29.27448&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&#34;even&#34;&gt;
&lt;td align=&#34;left&#34;&gt;Бори́сов&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;homeward&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;28,000&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;Napoleon&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;54.22407&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;28.51178&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&#34;odd&#34;&gt;
&lt;td align=&#34;left&#34;&gt;Маладзечна&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;homeward&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;12,000&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;Napoleon&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;54.30733&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;26.83891&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&#34;even&#34;&gt;
&lt;td align=&#34;left&#34;&gt;Сморгонь&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;homeward&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;14,000&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;Napoleon&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;54.48178&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;26.40128&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&#34;odd&#34;&gt;
&lt;td align=&#34;left&#34;&gt;Vilnius&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;homeward&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;8,000&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;Napoleon&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;54.68705&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;25.28291&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&#34;even&#34;&gt;
&lt;td align=&#34;left&#34;&gt;Kaunas&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;homeward&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;4,000&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;Napoleon&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;54.89821&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;23.90448&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&#34;odd&#34;&gt;
&lt;td align=&#34;left&#34;&gt;Vilnius&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;outward&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;60,000&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;Oudinot&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;54.68705&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;25.28291&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&#34;even&#34;&gt;
&lt;td align=&#34;left&#34;&gt;Daugavpils&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;outward&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;40,000&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;Oudinot&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;55.87123&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;26.51593&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&#34;odd&#34;&gt;
&lt;td align=&#34;left&#34;&gt;По́лоцк&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;homeward&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;33,000&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;Oudinot&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;55.48547&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;28.76823&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&#34;even&#34;&gt;
&lt;td align=&#34;left&#34;&gt;Бобр&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;homeward&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;28,000&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;Oudinot&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;54.34169&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;29.27448&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&#34;odd&#34;&gt;
&lt;td align=&#34;left&#34;&gt;Kaunas&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;outward&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;22,000&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;MacDonald&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;54.89821&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;23.90448&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&#34;even&#34;&gt;
&lt;td align=&#34;left&#34;&gt;Riga&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;outward&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;22,000&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;MacDonald&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;56.94940&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;24.10518&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&#34;odd&#34;&gt;
&lt;td align=&#34;left&#34;&gt;Riga&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;homeward&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;6,000&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;MacDonald&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;56.94940&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;24.10518&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&#34;even&#34;&gt;
&lt;td align=&#34;left&#34;&gt;Kaunas&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;homeward&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;6,000&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;MacDonald&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;54.89821&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;23.90448&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Before plotting we need to create two helper objects:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;data frame of city labels, with duplicities removed&lt;/li&gt;
&lt;li&gt;a helper of X and Y offsets for labels; I wish there was a reliable automatic way to place the labels, but at the end I had to resort to manual adjustments&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;# city labels
city_labels &amp;lt;- minard_geocoded %&amp;gt;%
  select(city, lat, long) %&amp;gt;% 
  distinct()

# offsets - a kludge to make the labels legible
kludge &amp;lt;- data.frame(horizontal = c(0, -.25, -.2, 0, 0,
                                    .25, -.5, 0, 0, 0,
                                    .4, .25, .4, -.2, -.2,
                                    .7, -.25, .4, 0),
                     vertical = c(-.2, -.2, .3, .3, -.3,
                                  -.3, .2, .2, .2, -.2,
                                  -.3, -.2, -.15, .2, -.15,
                                  .1, .2, .2, .15))&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now we can proceed to drawing the map itself. The logic of its construction follows in principle the &lt;a href=&#34;http://vita.had.co.nz/papers/layered-grammar.pdf&#34;&gt;ggplot2 article&lt;/a&gt;, with only minor differences – I have changed the order of the groups, so that advancing Napoleon gets drawn over retreating Oudinot, as in the original map, and of course all the cities are in their proper places.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;# and finally, the plot itself
ggplot() +
  # paths taken by the armies
  geom_path(data = minard_geocoded, 
            aes(x = long, 
                y = lat, 
                size = strength, 
                color = direction, 
                # make sure Napoleon gets drawn over Oudinot, not the other way round
                group = factor(leader, levels = c(&amp;quot;Oudinot&amp;quot;, 
                                                  &amp;quot;MacDonald&amp;quot;,
                                                  &amp;quot;Napoleon&amp;quot;)))) +
  # labels for the cities
  geom_text(data = city_labels,
            aes(x = long,
                y = lat,
                label = city),
            family = &amp;quot;Old Standard TT&amp;quot;, # an old fashioned Cyrillic font
            fontface = &amp;quot;italic&amp;quot;,
            # I wish that this was not necessary... 
            nudge_x = kludge$horizontal,
            nudge_y = kludge$vertical) +
  scale_colour_manual(values = c(&amp;quot;gray10&amp;quot;, 
                                 &amp;quot;#e8cbac&amp;quot;)) + # the color Minard calls &amp;quot;rouge&amp;quot;
  scale_size(range = c(1/10, 17)) + # a &amp;quot;slight&amp;quot; exaggeration
  guides(color = F, size = F) + theme_void() + # just say &amp;quot;no&amp;quot; to distractions
  labs(title = &amp;quot;1812, or There and Back Again&amp;quot;,
       subtitle = &amp;quot;geocoding the Minard&amp;#39;s map&amp;quot;) +
  theme(plot.title = element_text(hjust = 1/2,
                                  face = &amp;quot;bold&amp;quot;),
        plot.subtitle = element_text(hjust = 1/2,
                                     face = &amp;quot;italic&amp;quot;))&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;https://www.jla-data.net/ENG/2021-05-18-minard-map_files/figure-html/map-on-white-1.png&#34; width=&#34;672&#34; /&gt;&lt;/p&gt;
&lt;p&gt;An alternative rendition of the map is over a basemap. Note how closely the path of the armies to Moscow follows current roads – the Smolensk road coming in, and the Kaluga road trying to break out (with the fateful decision to backtrack to Smolensk after Maloyaroslavets).&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;library(ggmap)

# a basemap / consider maptype = &amp;quot;terrain-background&amp;quot; for an alternative look
basemap &amp;lt;- get_stadiamap(bbox = c(left =  23,
                                  bottom = 53.75,
                                  right = 39.25,
                                  top = 57.15),
                         maptype = &amp;quot;stamen_toner&amp;quot;,
                         zoom = 7)

# the plot again, without text labels this time
ggmap(basemap) +
 geom_path(data = minard_geocoded, 
            aes(x = long, 
                y = lat, 
                size = strength, 
                color = direction, 
                group = factor(leader, levels = c(&amp;quot;Oudinot&amp;quot;, 
                                                  &amp;quot;MacDonald&amp;quot;,
                                                  &amp;quot;Napoleon&amp;quot;))),
           alpha = 2/3) + # a slight alpha to retain a hint of the basemap
  scale_colour_manual(values = c(&amp;quot;gray10&amp;quot;, 
                                 &amp;quot;#e8cbac&amp;quot;)) +
  scale_size(range = c(1/4, 17)) +
  guides(color = F, size = F) +
  theme_void() +
  labs(title = &amp;quot;1812, or There and Back Again&amp;quot;,
       subtitle = &amp;quot;geocoding the Minard&amp;#39;s map&amp;quot;) +
  theme(plot.title = element_text(hjust = 1/2,
                                  face = &amp;quot;bold&amp;quot;),
        plot.subtitle = element_text(hjust = 1/2,
                                     face = &amp;quot;italic&amp;quot;))&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;https://www.jla-data.net/ENG/2021-05-18-minard-map_files/figure-html/map-over-basemap-1.png&#34; width=&#34;672&#34; /&gt;&lt;/p&gt;
&lt;p&gt;Yet another alternative approach is presenting the Minard’s map interactively via &lt;code&gt;{leaflet}&lt;/code&gt; and &lt;a href=&#34;https://leafletjs.com/&#34;&gt;leaflet.js&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;This will take some effort, as it is necessary to first translate the army path from a sequence of lat-lon points to a spatial lines object. This needs to be done segment by segment, to preserve the troops information, and care must be taken to maintain the three separate forces.&lt;/p&gt;
&lt;p&gt;Once the lines object is in place the leaflet call itself is not a difficult one to make.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;library(sf) 

# first make the data frame spatial object
sf_path &amp;lt;- minard_geocoded %&amp;gt;%  
  st_as_sf(coords = c(&amp;quot;long&amp;quot;, &amp;quot;lat&amp;quot;), crs = 4326) %&amp;gt;% 
  mutate(direction = as.factor(direction)) # factor for color palette assignment

minard_lines &amp;lt;- NULL # initiate an empty object
  
for (captain in unique(sf_path$leader)) { # i.e. Napoleon, Oudinot, MacDonald
  
  wrk_army &amp;lt;- subset(sf_path, leader == captain)

  # cycle over all segments, except the last one
  for (i in 1:(nrow(wrk_army)-1)) {
    
    # line object from two points
    wrk_line  &amp;lt;- wrk_army[c(i, i+1), ] %&amp;gt;% # current &amp;amp; next point coords
      st_coordinates() %&amp;gt;% 
      st_linestring() %&amp;gt;% 
      st_sfc()
    
    # a single row of results dataframe
    line_data &amp;lt;- data.frame(
      direction = wrk_army$direction[i],
      strength = wrk_army$strength[i],
      leader = wrk_army$leader[i],
      label = paste0(wrk_army$city[i], &amp;quot; to &amp;quot;,
                     wrk_army$city[i+1], &amp;quot;&amp;lt;br&amp;gt;army strength &amp;quot;,
                     format(wrk_army$strength[i], 
                            big.mark = &amp;quot;,&amp;quot;,
                            scientific = F), &amp;quot; men.&amp;quot;),
      geometry = wrk_line
    )
    
    # bind the single row to the output object
    if (is.null(minard_lines)) {
      
      minard_lines &amp;lt;- line_data
      
    } else {
      minard_lines &amp;lt;- dplyr::bind_rows(minard_lines,
                                       line_data)
      
    } # /if - binding results
    
  } # /for segment
  
} # /for leader

# finalize the linear object
minard_lines &amp;lt;- st_as_sf(minard_lines, crs = 4326)

library(leaflet)

# palette for direction
pal &amp;lt;- colorFactor(c(&amp;quot;gray10&amp;quot;, &amp;quot;#e8cbac&amp;quot;),
                   minard_lines$direction)

# the map itself
leaflet(data = minard_lines) %&amp;gt;% 
  addProviderTiles(&amp;quot;CartoDB.Positron&amp;quot;) %&amp;gt;% 
  addPolylines(weight = ~strength/15000,
               color = ~pal(direction),
               opacity = 1,
               popup = ~label)&lt;/code&gt;&lt;/pre&gt;
&lt;div class=&#34;leaflet html-widget html-fill-item&#34; id=&#34;htmlwidget-1&#34; style=&#34;width:100%;height:336px;&#34;&gt;&lt;/div&gt;
&lt;script type=&#34;application/json&#34; data-for=&#34;htmlwidget-1&#34;&gt;{&#34;x&#34;:{&#34;options&#34;:{&#34;crs&#34;:{&#34;crsClass&#34;:&#34;L.CRS.EPSG3857&#34;,&#34;code&#34;:null,&#34;proj4def&#34;:null,&#34;projectedBounds&#34;:null,&#34;options&#34;:{}}},&#34;calls&#34;:[{&#34;method&#34;:&#34;addProviderTiles&#34;,&#34;args&#34;:[&#34;CartoDB.Positron&#34;,null,null,{&#34;errorTileUrl&#34;:&#34;&#34;,&#34;noWrap&#34;:false,&#34;detectRetina&#34;:false}]},{&#34;method&#34;:&#34;addPolylines&#34;,&#34;args&#34;:[[[[{&#34;lng&#34;:[23.9044817,25.2829111],&#34;lat&#34;:[54.8982139,54.6870458]}]],[[{&#34;lng&#34;:[25.2829111,27.6845787],&#34;lat&#34;:[54.6870458,55.139235]}]],[[{&#34;lng&#34;:[27.6845787,30.2070437],&#34;lat&#34;:[55.139235,55.1930197]}]],[[{&#34;lng&#34;:[30.2070437,32.04718121915615],&#34;lat&#34;:[55.1930197,54.77897005]}]],[[{&#34;lng&#34;:[32.04718121915615,33.2989051],&#34;lat&#34;:[54.77897005,54.9148236]}]],[[{&#34;lng&#34;:[33.2989051,34.99051315482606],&#34;lat&#34;:[54.9148236,55.55338655]}]],[[{&#34;lng&#34;:[34.99051315482606,36.0213092],&#34;lat&#34;:[55.55338655,55.506478]}]],[[{&#34;lng&#34;:[36.0213092,37.6174782],&#34;lat&#34;:[55.506478,55.7505412]}]],[[{&#34;lng&#34;:[37.6174782,37.6174782],&#34;lat&#34;:[55.7505412,55.7505412]}]],[[{&#34;lng&#34;:[37.6174782,36.4590246],&#34;lat&#34;:[55.7505412,55.012181]}]],[[{&#34;lng&#34;:[36.4590246,36.0213092],&#34;lat&#34;:[55.012181,55.506478]}]],[[{&#34;lng&#34;:[36.0213092,34.2995187],&#34;lat&#34;:[55.506478,55.2103563]}]],[[{&#34;lng&#34;:[34.2995187,33.2989051],&#34;lat&#34;:[55.2103563,54.9148236]}]],[[{&#34;lng&#34;:[33.2989051,32.04718121915615],&#34;lat&#34;:[54.9148236,54.77897005]}]],[[{&#34;lng&#34;:[32.04718121915615,30.4254486],&#34;lat&#34;:[54.77897005,54.5119008]}]],[[{&#34;lng&#34;:[30.4254486,29.2744782],&#34;lat&#34;:[54.5119008,54.3416872]}]],[[{&#34;lng&#34;:[29.2744782,28.5117849],&#34;lat&#34;:[54.3416872,54.2240665]}]],[[{&#34;lng&#34;:[28.5117849,26.8389111],&#34;lat&#34;:[54.2240665,54.3073327]}]],[[{&#34;lng&#34;:[26.8389111,26.4012822],&#34;lat&#34;:[54.3073327,54.4817816]}]],[[{&#34;lng&#34;:[26.4012822,25.2829111],&#34;lat&#34;:[54.4817816,54.6870458]}]],[[{&#34;lng&#34;:[25.2829111,23.9044817],&#34;lat&#34;:[54.6870458,54.8982139]}]],[[{&#34;lng&#34;:[25.2829111,26.5159337],&#34;lat&#34;:[54.6870458,55.8712267]}]],[[{&#34;lng&#34;:[26.5159337,28.7682339],&#34;lat&#34;:[55.8712267,55.4854656]}]],[[{&#34;lng&#34;:[28.7682339,29.2744782],&#34;lat&#34;:[55.4854656,54.3416872]}]],[[{&#34;lng&#34;:[23.9044817,24.1051846],&#34;lat&#34;:[54.8982139,56.9493977]}]],[[{&#34;lng&#34;:[24.1051846,24.1051846],&#34;lat&#34;:[56.9493977,56.9493977]}]],[[{&#34;lng&#34;:[24.1051846,23.9044817],&#34;lat&#34;:[56.9493977,54.8982139]}]]],null,null,{&#34;interactive&#34;:true,&#34;className&#34;:&#34;&#34;,&#34;stroke&#34;:true,&#34;color&#34;:[&#34;#E8CBAC&#34;,&#34;#E8CBAC&#34;,&#34;#E8CBAC&#34;,&#34;#E8CBAC&#34;,&#34;#E8CBAC&#34;,&#34;#E8CBAC&#34;,&#34;#E8CBAC&#34;,&#34;#E8CBAC&#34;,&#34;#E8CBAC&#34;,&#34;#1A1A1A&#34;,&#34;#1A1A1A&#34;,&#34;#1A1A1A&#34;,&#34;#1A1A1A&#34;,&#34;#1A1A1A&#34;,&#34;#1A1A1A&#34;,&#34;#1A1A1A&#34;,&#34;#1A1A1A&#34;,&#34;#1A1A1A&#34;,&#34;#1A1A1A&#34;,&#34;#1A1A1A&#34;,&#34;#1A1A1A&#34;,&#34;#E8CBAC&#34;,&#34;#E8CBAC&#34;,&#34;#1A1A1A&#34;,&#34;#E8CBAC&#34;,&#34;#E8CBAC&#34;,&#34;#1A1A1A&#34;],&#34;weight&#34;:[28.13333333333333,22.66666666666667,18.66666666666667,14,9.666666666666666,9.333333333333334,8.473333333333333,6.666666666666667,6.666666666666667,6.666666666666667,6.533333333333333,5.8,3.666666666666667,2.466666666666667,1.6,1.333333333333333,3.333333333333333,1.866666666666667,0.8,0.9333333333333333,0.5333333333333333,4,2.666666666666667,2.2,1.466666666666667,1.466666666666667,0.4],&#34;opacity&#34;:1,&#34;fill&#34;:false,&#34;fillColor&#34;:[&#34;#E8CBAC&#34;,&#34;#E8CBAC&#34;,&#34;#E8CBAC&#34;,&#34;#E8CBAC&#34;,&#34;#E8CBAC&#34;,&#34;#E8CBAC&#34;,&#34;#E8CBAC&#34;,&#34;#E8CBAC&#34;,&#34;#E8CBAC&#34;,&#34;#1A1A1A&#34;,&#34;#1A1A1A&#34;,&#34;#1A1A1A&#34;,&#34;#1A1A1A&#34;,&#34;#1A1A1A&#34;,&#34;#1A1A1A&#34;,&#34;#1A1A1A&#34;,&#34;#1A1A1A&#34;,&#34;#1A1A1A&#34;,&#34;#1A1A1A&#34;,&#34;#1A1A1A&#34;,&#34;#1A1A1A&#34;,&#34;#E8CBAC&#34;,&#34;#E8CBAC&#34;,&#34;#1A1A1A&#34;,&#34;#E8CBAC&#34;,&#34;#E8CBAC&#34;,&#34;#1A1A1A&#34;],&#34;fillOpacity&#34;:0.2,&#34;smoothFactor&#34;:1,&#34;noClip&#34;:false},[&#34;Kaunas to Vilnius&lt;br&gt;army strength 422,000 men.&#34;,&#34;Vilnius to Глыбо́кае&lt;br&gt;army strength 340,000 men.&#34;,&#34;Глыбо́кае to Витебск&lt;br&gt;army strength 280,000 men.&#34;,&#34;Витебск to Смоленск&lt;br&gt;army strength 210,000 men.&#34;,&#34;Смоленск to Дорогобу́ж&lt;br&gt;army strength 145,000 men.&#34;,&#34;Дорогобу́ж to Гага́рин&lt;br&gt;army strength 140,000 men.&#34;,&#34;Гага́рин to Можа́йск&lt;br&gt;army strength 127,100 men.&#34;,&#34;Можа́йск to Москва&lt;br&gt;army strength 100,000 men.&#34;,&#34;Москва to Москва&lt;br&gt;army strength 100,000 men.&#34;,&#34;Москва to Малояросла́вец&lt;br&gt;army strength 100,000 men.&#34;,&#34;Малояросла́вец to Можа́йск&lt;br&gt;army strength 98,000 men.&#34;,&#34;Можа́йск to Вя́зьма&lt;br&gt;army strength 87,000 men.&#34;,&#34;Вя́зьма to Дорогобу́ж&lt;br&gt;army strength 55,000 men.&#34;,&#34;Дорогобу́ж to Смоленск&lt;br&gt;army strength 37,000 men.&#34;,&#34;Смоленск to О́рша&lt;br&gt;army strength 24,000 men.&#34;,&#34;О́рша to Бобр&lt;br&gt;army strength 20,000 men.&#34;,&#34;Бобр to Бори́сов&lt;br&gt;army strength 50,000 men.&#34;,&#34;Бори́сов to Маладзечна&lt;br&gt;army strength 28,000 men.&#34;,&#34;Маладзечна to Сморгонь&lt;br&gt;army strength 12,000 men.&#34;,&#34;Сморгонь to Vilnius&lt;br&gt;army strength 14,000 men.&#34;,&#34;Vilnius to Kaunas&lt;br&gt;army strength 8,000 men.&#34;,&#34;Vilnius to Daugavpils&lt;br&gt;army strength 60,000 men.&#34;,&#34;Daugavpils to По́лоцк&lt;br&gt;army strength 40,000 men.&#34;,&#34;По́лоцк to Бобр&lt;br&gt;army strength 33,000 men.&#34;,&#34;Kaunas to Riga&lt;br&gt;army strength 22,000 men.&#34;,&#34;Riga to Riga&lt;br&gt;army strength 22,000 men.&#34;,&#34;Riga to Kaunas&lt;br&gt;army strength 6,000 men.&#34;],null,null,{&#34;interactive&#34;:false,&#34;permanent&#34;:false,&#34;direction&#34;:&#34;auto&#34;,&#34;opacity&#34;:1,&#34;offset&#34;:[0,0],&#34;textsize&#34;:&#34;10px&#34;,&#34;textOnly&#34;:false,&#34;className&#34;:&#34;&#34;,&#34;sticky&#34;:true},null]}],&#34;limits&#34;:{&#34;lat&#34;:[54.2240665,56.9493977],&#34;lng&#34;:[23.9044817,37.6174782]}},&#34;evals&#34;:[],&#34;jsHooks&#34;:[]}&lt;/script&gt;
&lt;hr&gt;
&lt;p&gt;I suppose I could end here, having demonstrated the possibility of geocoding the Minard’s map locations (after some necessary adjustments).&lt;/p&gt;
&lt;p&gt;But there is another interesting aspect of the 1812 campaign that I discovered when doing research for this blog post that I would like to share here:&lt;/p&gt;
&lt;p&gt;The French tradition gives strong accent to hardship caused by winter cold – look at the prominence of the temperature data in the original map. In this way the defeat can be explained away as due to forces of Nature, or Fate, rather than enemy action.&lt;/p&gt;
&lt;p&gt;The Russian tradition takes issue with that – it goes like &lt;em&gt;“Sure, there was some snow, what would you expect in winter? But nothing really harsh, just look at the Berezina river; it was not even frozen over, don’t you see??”&lt;/em&gt; and instead attributes the French losses to starvation caused by marching over countryside they themselves plundered when coming in. This makes them seem kind of self inflicted.&lt;/p&gt;
&lt;p&gt;Also notable is how the Russian tradition stresses the “ordinary people” aspect – 1812 being the original Patriotic War – and downplays the role of senior officers (other than Kutuzov and Bagration).&lt;/p&gt;
&lt;p&gt;This may, and may not, relate to the fact that many of the generals on the Russian side were ethnic Germans. Fun fact here: Tsar Alexander employed in his staff a certain &lt;a href=&#34;https://en.wikipedia.org/wiki/Carl_von_Clausewitz&#34;&gt;von Clausewitz&lt;/a&gt;, who played a key role in negotiating the betrayal of Napoleon by Ludwig Yorck, commander of the Prussian auxiliary corps at Riga.&lt;/p&gt;
</description>
  </item>
  
<item>
  <title>Non-Contiguous Area Cartograms</title>
  <link>https://www.jla-data.net/eng/non-contiguous-area-cartograms/</link>
  <pubDate>Wed, 24 Mar 2021 00:00:00 +0000</pubDate>
  
<guid>https://www.jla-data.net/eng/non-contiguous-area-cartograms/</guid>
  <description>
&lt;script src=&#34;https://www.jla-data.net/rmarkdown-libs/header-attrs/header-attrs.js&#34;&gt;&lt;/script&gt;


&lt;p&gt;A non-contiguous area cartogram – a mouthful of a term – is a concept of displaying two pieces of information in a single &lt;a href=&#34;https://en.wikipedia.org/wiki/Choropleth_map&#34;&gt;chorpoleth map&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;One piece of information is carried by color of polygons (typically administrative units) and the other by rescaling the size of the polygons compared to their original, contiguous, placement.&lt;/p&gt;
&lt;p&gt;This style of visualization has been popularized in US political reporting, where great disparity exists between densely populated urban areas, and less populated, but optically large, rural areas.&lt;/p&gt;
&lt;p&gt;A number of data visualizations has been circulated, variously exploiting, and debunking, this disparity. Famously egregious example being the “Try to impeach this” tweet by Lara Trump.&lt;/p&gt;
&lt;blockquote class=&#34;twitter-tweet tw-align-center&#34;&gt;
&lt;p lang=&#34;und&#34; dir=&#34;ltr&#34;&gt;
&lt;a href=&#34;https://t.co/pYSILiGnrK&#34;&gt;pic.twitter.com/pYSILiGnrK&lt;/a&gt;
&lt;/p&gt;
— Lara Trump (&lt;span class=&#34;citation&#34;&gt;@LaraLeaTrump&lt;/span&gt;) &lt;a href=&#34;https://twitter.com/LaraLeaTrump/status/1178030815671980032?ref_src=twsrc%5Etfw&#34;&gt;September 28, 2019&lt;/a&gt;
&lt;/blockquote&gt;
&lt;script async src=&#34;https://platform.twitter.com/widgets.js&#34; charset=&#34;utf-8&#34;&gt;&lt;/script&gt;
&lt;p&gt;Rescaling administrative areas by population (or total votes cast) is one of the tools that can be used to give some context to the US political map.&lt;/p&gt;
&lt;p&gt;Rescaling is a relatively uncomplicated &lt;a href=&#34;https://geocompr.robinlovelace.net/geometric-operations.html#affine-transformations&#34;&gt;affine transformation&lt;/a&gt;, one that is well implemented in the context of &lt;code&gt;{sf}&lt;/code&gt; package.&lt;/p&gt;
&lt;p&gt;To make it even more easy to use I propose a function, &lt;code&gt;st_rescale()&lt;/code&gt; that takes two arguments:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;data&lt;/code&gt; expected as a {sf} format data frame with a geometry column&lt;/li&gt;
&lt;li&gt;&lt;code&gt;scaling_factor&lt;/code&gt; a numerical vector of scales. It works best with scaling factors between 0 and 1, but it is not strictly required.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The function returns rescaled geometry, implemented in the same coordinate reference system as used by the spatial object provided in the data parameter.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;library(sf)
library(dplyr )
library(ggplot2)


st_rescale &amp;lt;- function(data, scaling_factor) {
  
  # be careful with that recycling!
  if (length(scaling_factor) &amp;gt; 1 &amp;amp; length(scaling_factor) != nrow(data)) {
    stop(&amp;quot;data &amp;amp; scaling factor of incompatible lenghts&amp;quot;)
  }
  
  # take the geometry out...
  geometry &amp;lt;- sf::st_geometry(data)
  
  # magic!:)
  scaled_geometry &amp;lt;- (geometry - sf::st_centroid(geometry)) * 
    scaling_factor + sf::st_centroid(geometry)
  
  # turn the scaled geometry to {sf} object
  scaled_data &amp;lt;- sf::st_as_sf(scaled_geometry, crs = sf::st_crs(data)) 
  
  # and return it back
  scaled_data
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Rescaling works on &lt;code&gt;sfc&lt;/code&gt; level (the geometry column alone). It the proposed function it involves first subtraction of centroid coordinates, then multiplication of the geometry by the scaling factor, and lastly adding back the centroid coordinates. This ensures that the centroid of the rescaled polygon will be the same as the centroid of the original one.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;To demonstrate the technique I will “borrow” the file of 2016 Pennsylvania election results used by &lt;a href=&#34;https://www.infoworld.com/author/Sharon-Machlis/&#34;&gt;Sharon Machlis&lt;/a&gt; in her article &lt;a href=&#34;https://www.infoworld.com/article/3586147/how-to-create-an-election-map-in-r.html&#34;&gt;How to create an election map in R&lt;/a&gt; published on InfoWorld website.&lt;/p&gt;
&lt;p&gt;As there is a slight mismatch in naming conventions between the csv file and county names in the &lt;code&gt;{tigris}&lt;/code&gt; package, which is &lt;em&gt;the&lt;/em&gt; authoritative source of US administrative area polygons, I am converting county names in both datasets to uppercase.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;pa_data &amp;lt;- readr::read_csv(&amp;quot;pa_2016_presidential.csv&amp;quot;) %&amp;gt;% 
  mutate(votes_cast = Clinton + Trump,
         PctMargin = PctMargin * ifelse(Winner == &amp;quot;Trump&amp;quot;, 1, -1),
         County = toupper(County)) # uppercase to smoothen the join

pa_shape &amp;lt;- tigris::counties(state = &amp;#39;PA&amp;#39;, resolution = &amp;#39;20m&amp;#39;) %&amp;gt;% 
  mutate(County = toupper(NAME)) # uppercase to smoothen the join

chrt_src &amp;lt;- pa_shape %&amp;gt;% 
  inner_join(pa_data, by = c(&amp;quot;County&amp;quot; = &amp;quot;County&amp;quot;))&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The first visualization is a classic choropleth map - each county painted in a shade of red &amp;amp; blue proportional to the margin of victory of Trump vs. Clinton.&lt;/p&gt;
&lt;p&gt;In this viz Pennsylvania transforms into a sea of red color, interrupted by two blue spots. What the map does not make immediately obvious is that the two blue spots are Philadelphia and Pittsburgh, and that the sea of red is mostly void.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;ggplot() +
  geom_sf(data = chrt_src, aes(fill = PctMargin),
          color = &amp;quot;gray75&amp;quot;, size = .15) +
  scale_fill_gradient2(low = &amp;#39;blue&amp;#39;,
                       high = &amp;#39;red&amp;#39;) +
  labs(title = &amp;#39;Pennsylvania 2016; plain vanilla choropleth&amp;#39;,
       fill = &amp;#39;Margin&amp;#39;) +
  theme_void() &lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;https://www.jla-data.net/ENG/2021-03-24-non-continuous-choropleth_files/figure-html/pa-vanilla-1.png&#34; width=&#34;672&#34; /&gt;&lt;/p&gt;
&lt;p&gt;As an alternative I propose another map, one where the county polygons are rescaled in proportion of total votes cast. The original county lines are kept in grey to give some idea by how much was the polygon shrunk.&lt;/p&gt;
&lt;p&gt;This alternative map gives more prominence to the two metropolitan areas, and visually shrinks the rural counties. The deeply red &lt;a href=&#34;https://en.wikipedia.org/wiki/Potter_County,_Pennsylvania&#34;&gt;Potter County&lt;/a&gt; close to the NY border, where 7,553 votes were cast – compared to 692,773 in much smaller Philadelphia – disappears almost entirely.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;# rescale PA counties by total of votes cast
chrt_src_rescaled &amp;lt;- chrt_src %&amp;gt;% 
  st_rescale(chrt_src$votes_cast / max(chrt_src$votes_cast))

ggplot() +
  # rescaled polygons with fill
  geom_sf(data = chrt_src_rescaled, aes(fill = chrt_src$PctMargin),
          color = &amp;quot;gray75&amp;quot;, size = .15) +
  # original county boundaries for context as outline
  geom_sf(data = chrt_src, fill = NA, color = &amp;quot;gray75&amp;quot;, size = .15) +
  scale_fill_gradient2(low = &amp;#39;blue&amp;#39;,
                       high = &amp;#39;red&amp;#39;) +
  labs(title = &amp;#39;Pennsylvania 2016; counties rescaled by total votes cast&amp;#39;,
       fill = &amp;#39;Margin&amp;#39;) +
  theme_void() &lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;https://www.jla-data.net/ENG/2021-03-24-non-continuous-choropleth_files/figure-html/pa-rescaled-1.png&#34; width=&#34;672&#34; /&gt;&lt;/p&gt;
&lt;p&gt;I believe my demonstration has shown a possible approach to encoding two pieces of information, namely margin of victory of a politician per administrative unit, and the size of voting population of the said administrative unit.&lt;/p&gt;
</description>
  </item>
  
<item>
  <title>Finding Points of Interest</title>
  <link>https://www.jla-data.net/eng/finding-pois-along-a-route/</link>
  <pubDate>Fri, 12 Feb 2021 00:00:00 +0000</pubDate>
  
<guid>https://www.jla-data.net/eng/finding-pois-along-a-route/</guid>
  <description>
&lt;script src=&#34;https://www.jla-data.net/rmarkdown-libs/header-attrs/header-attrs.js&#34;&gt;&lt;/script&gt;
&lt;script src=&#34;https://www.jla-data.net/rmarkdown-libs/htmlwidgets/htmlwidgets.js&#34;&gt;&lt;/script&gt;
&lt;script src=&#34;https://www.jla-data.net/rmarkdown-libs/jquery/jquery.min.js&#34;&gt;&lt;/script&gt;
&lt;link href=&#34;https://www.jla-data.net/rmarkdown-libs/leaflet/leaflet.css&#34; rel=&#34;stylesheet&#34; /&gt;
&lt;script src=&#34;https://www.jla-data.net/rmarkdown-libs/leaflet/leaflet.js&#34;&gt;&lt;/script&gt;
&lt;link href=&#34;https://www.jla-data.net/rmarkdown-libs/leafletfix/leafletfix.css&#34; rel=&#34;stylesheet&#34; /&gt;
&lt;script src=&#34;https://www.jla-data.net/rmarkdown-libs/proj4/proj4.min.js&#34;&gt;&lt;/script&gt;
&lt;script src=&#34;https://www.jla-data.net/rmarkdown-libs/Proj4Leaflet/proj4leaflet.js&#34;&gt;&lt;/script&gt;
&lt;link href=&#34;https://www.jla-data.net/rmarkdown-libs/rstudio_leaflet/rstudio_leaflet.css&#34; rel=&#34;stylesheet&#34; /&gt;
&lt;script src=&#34;https://www.jla-data.net/rmarkdown-libs/leaflet-binding/leaflet.js&#34;&gt;&lt;/script&gt;
&lt;script src=&#34;https://www.jla-data.net/rmarkdown-libs/leaflet-providers/leaflet-providers_1.9.0.js&#34;&gt;&lt;/script&gt;
&lt;script src=&#34;https://www.jla-data.net/rmarkdown-libs/leaflet-providers-plugin/leaflet-providers-plugin.js&#34;&gt;&lt;/script&gt;
&lt;link href=&#34;https://www.jla-data.net/rmarkdown-libs/leaflet-awesomemarkers/leaflet.awesome-markers.css&#34; rel=&#34;stylesheet&#34; /&gt;
&lt;script src=&#34;https://www.jla-data.net/rmarkdown-libs/leaflet-awesomemarkers/leaflet.awesome-markers.min.js&#34;&gt;&lt;/script&gt;
&lt;link href=&#34;https://www.jla-data.net/rmarkdown-libs/fontawesome/font-awesome.min.css&#34; rel=&#34;stylesheet&#34; /&gt;


&lt;p&gt;In a recent &lt;a href=&#34;https://twitter.com/hashtag/rspatial&#34;&gt;#rspatial&lt;/a&gt; Twitter conversation I discussed analytical problem of finding establishments of a certain type along a walking route from point A to point B.&lt;/p&gt;
&lt;p&gt;It is an interesting problem, one that deserves a bit more space than 280 characters allow.&lt;/p&gt;
&lt;p&gt;The issue can be split into two analytical problems:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;finding the walking route from point A to point B (as a line)&lt;/li&gt;
&lt;li&gt;finding points of interest of a given type within distance from this line&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Both analytical use cases are lend themselves easily to techniques from spatial R toolset.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;In this demonstration I will be using two packages / APIs:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href=&#34;https://munterfinger.github.io/hereR/&#34;&gt;&lt;code&gt;{hereR}&lt;/code&gt;&lt;/a&gt; package to access API of &lt;a href=&#34;https://developer.here.com/&#34;&gt;HERE.com&lt;/a&gt;; the API requires registration and provides a generous freemium tier&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href=&#34;https://docs.ropensci.org/osmdata/&#34;&gt;&lt;code&gt;{osmdata}&lt;/code&gt;&lt;/a&gt; package to access &lt;a href=&#34;https://www.openstreetmap.org/&#34;&gt;Open Street Map&lt;/a&gt; data; the OSM data are free to use under the &lt;a href=&#34;https://www.openstreetmap.org/copyright&#34;&gt;ODbL licence&lt;/a&gt; license&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This blog post will focus more on technique used rather then the actual result; however a toy problem is necessary to demonstrate the tools. I will take inspiration from the &lt;a href=&#34;https://en.wikipedia.org/wiki/It%27s_a_Long_Way_to_Tipperary&#34;&gt;“Tipperary”&lt;/a&gt; song and look for a place to have a drink along the route between two London landmarks - Piccadily Circus and Leicester square (it’s &lt;em&gt;not&lt;/em&gt; a long walk by the way).&lt;/p&gt;
&lt;p&gt;The first step is loading the packages and setting up the API key via &lt;code&gt;hereR::set_key()&lt;/code&gt;.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;library(dplyr)   # ... because dplyr :)
library(osmdata) # data part
library(hereR)   # routing part / needs API
library(sf)      # spatial data processing

# I keep my key as an environment variable to prevent accidental sharing
secret_key &amp;lt;- Sys.getenv(&amp;quot;HERE_API_KEY&amp;quot;) # insert your API key here...

set_key(secret_key) &lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The second step is geocoding the locations and calculating the walking route (transport mode = pedestrian) between the two.&lt;/p&gt;
&lt;p&gt;It will be returned in format of &lt;code&gt;{sf}&lt;/code&gt; package, with vertical dimension (height) reflected. As the Z dimension can lead to issues in plotting and buffering it is best to remove it immediately.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;# It&amp;#39;s a long way, to Tipperary...
destinations &amp;lt;- c(&amp;quot;Piccadilly Circus, London&amp;quot;,
                  &amp;quot;Leicester Square, London&amp;quot;) %&amp;gt;% 
  hereR::geocode() # geocode

# routing call - shortest walking path between the first and second destination
walking_route &amp;lt;- hereR::route(origin = destinations[1, ],
                      destination = destinations[2, ],
                      transport_mode = &amp;quot;pedestrian&amp;quot;) %&amp;gt;% 
  st_zm() # vertical dimesion is neither required, nor helpful

walking_route&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;## Simple feature collection with 1 feature and 11 fields
## geometry type:  LINESTRING
## dimension:      XY
## bbox:           xmin: -0.13451 ymin: 51.51008 xmax: -0.13022 ymax: 51.51057
## geographic CRS: WGS 84
##   id rank section           departure             arrival       type       mode
## 1  1    1       1 2021-02-22 16:37:09 2021-02-22 16:42:29 pedestrian pedestrian
##   distance duration duration_base consumption                       geometry
## 1      318      320           320          NA LINESTRING (-0.13451 51.510...&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Third step is creating a buffer along the line object; a the distance will be in meters I am briefly reprojecting my line from WGS84 (in degrees) to Ordnance Survey CRS (any metric CRS would do).&lt;/p&gt;
&lt;p&gt;As the OSM results come in EPSG:4326 and degrees are required for leaflet visualization I am reverting back to the safety of WGS84 immediately.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;# a buffer of 20 meters from route; a transformation to metric 
# e.g. Ordnance Survey EPSG is required to use meters 
# (units of WGS84 are degrees, making a buffer somewhat complicated)
buffer &amp;lt;- walking_route %&amp;gt;% 
  # this could be another planar CRS relevant to the area of interest
  st_transform(&amp;quot;EPSG:27700&amp;quot;) %&amp;gt;% 
  st_buffer(20) %&amp;gt;% # size of the buffer / in units of the planar CRS
  st_transform(4326) # back to the safety of WGS84!&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The fourth step involves creating an overpass query to OSM backend. This takes two arguments&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;area of interest, defined by the bounding box of my buffer object&lt;/li&gt;
&lt;li&gt;type of OSM features, by key &amp;amp; value &lt;a href=&#34;https://wiki.openstreetmap.org/wiki/Map_features#Amenity&#34;&gt;as listed on the OSM wiki&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Once the search result is obtained it is spatially joined to the buffer object via inner join technique (not left means inner join).&lt;/p&gt;
&lt;p&gt;This will leave only those amenities that are within the buffer polygon.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;# search result  
search_res &amp;lt;- opq(bbox = st_bbox(buffer), nodes_only = T) %&amp;gt;% 
  # 1) area of interest = the buffer
  add_osm_feature(key = &amp;quot;amenity&amp;quot;,  
                  value = c(&amp;quot;bar&amp;quot;, &amp;quot;restaurant&amp;quot;, &amp;quot;pub&amp;quot;)) %&amp;gt;%
  # 2) search values - a watering hole, in OSM parlance
  osmdata_sf(quiet = F) # 3) result format

# osmdata returns multiple types; only points are relevant in our search
watering_holes &amp;lt;- search_res$osm_points 

# and finally - the intersection of buffer &amp;amp; search result
result &amp;lt;- watering_holes %&amp;gt;% 
  st_join(buffer, left = F) %&amp;gt;%  # not left = filtering join!
  select(osm_id, name)

result&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;## Simple feature collection with 4 features and 2 fields
## geometry type:  POINT
## dimension:      XY
## bbox:           xmin: -0.1329428 ymin: 51.51005 xmax: -0.1324365 ymax: 51.51041
## geographic CRS: WGS 84
##                osm_id                 name                    geometry
## 348904266   348904266     Angus Steakhouse POINT (-0.1329228 51.51005)
## 348905523   348905523                HAPPY POINT (-0.1324716 51.51013)
## 4376186998 4376186998 Bubba Gump Shrimp Co POINT (-0.1324365 51.51041)
## 6255364830 6255364830     HaiDiLao Hot Pot POINT (-0.1329428 51.51033)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;My work could in principle stop here, but in order to make certain we can perform a visual check.&lt;/p&gt;
&lt;p&gt;I am also showing off a little by using the &lt;a href=&#34;https://fontawesome.com/&#34;&gt;font awesome&lt;/a&gt; tankard icon, just because.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;# these watering holes did not make the cut...
holes_oos &amp;lt;- watering_holes %&amp;gt;% # oos = out of scope
  anti_join(st_drop_geometry(result), by = &amp;quot;osm_id&amp;quot;) # in scope are in scope

# a visual check / 

library(leaflet)

# a beer tankard icon
awesome &amp;lt;- makeAwesomeIcon(
  icon = &amp;quot;beer&amp;quot;,
  iconColor = &amp;quot;orange&amp;quot;,
  markerColor = &amp;quot;green&amp;quot;,
  library = &amp;quot;fa&amp;quot;
)

leaflet(result) %&amp;gt;% 
  addProviderTiles(&amp;quot;CartoDB.Positron&amp;quot;) %&amp;gt;% 
  addAwesomeMarkers(icon = awesome,
                    label = ~ name) %&amp;gt;% 
  addPolygons(data = buffer,
              stroke = F,
              fillColor = &amp;quot;blue&amp;quot;,
              fillOpacity = 1/5,
              label = &amp;quot;20 meter neigbourhood&amp;quot;) %&amp;gt;% 
  addPolylines(data = walking_route,
               color = &amp;quot;red&amp;quot;,
               label = &amp;quot;walking route&amp;quot;) %&amp;gt;% 
  addCircleMarkers(data = holes_oos,
                   stroke = F,
                   fillColor = &amp;quot;gray&amp;quot;,
                   fillOpacity = 1/2,
                   label = ~ name)&lt;/code&gt;&lt;/pre&gt;
&lt;div id=&#34;htmlwidget-1&#34; style=&#34;width:100%;height:336px;&#34; class=&#34;leaflet html-widget&#34;&gt;&lt;/div&gt;
&lt;script type=&#34;application/json&#34; data-for=&#34;htmlwidget-1&#34;&gt;{&#34;x&#34;:{&#34;options&#34;:{&#34;crs&#34;:{&#34;crsClass&#34;:&#34;L.CRS.EPSG3857&#34;,&#34;code&#34;:null,&#34;proj4def&#34;:null,&#34;projectedBounds&#34;:null,&#34;options&#34;:{}}},&#34;calls&#34;:[{&#34;method&#34;:&#34;addProviderTiles&#34;,&#34;args&#34;:[&#34;CartoDB.Positron&#34;,null,null,{&#34;errorTileUrl&#34;:&#34;&#34;,&#34;noWrap&#34;:false,&#34;detectRetina&#34;:false}]},{&#34;method&#34;:&#34;addAwesomeMarkers&#34;,&#34;args&#34;:[[51.5100549,51.5101296,51.5104136,51.5103311],[-0.1329228,-0.1324716,-0.1324365,-0.1329428],{&#34;icon&#34;:&#34;beer&#34;,&#34;markerColor&#34;:&#34;green&#34;,&#34;iconColor&#34;:&#34;orange&#34;,&#34;spin&#34;:false,&#34;squareMarker&#34;:false,&#34;iconRotate&#34;:0,&#34;font&#34;:&#34;monospace&#34;,&#34;prefix&#34;:&#34;fa&#34;},null,null,{&#34;interactive&#34;:true,&#34;draggable&#34;:false,&#34;keyboard&#34;:true,&#34;title&#34;:&#34;&#34;,&#34;alt&#34;:&#34;&#34;,&#34;zIndexOffset&#34;:0,&#34;opacity&#34;:1,&#34;riseOnHover&#34;:false,&#34;riseOffset&#34;:250},null,null,null,null,[&#34;Angus Steakhouse&#34;,&#34;HAPPY&#34;,&#34;Bubba Gump Shrimp Co&#34;,&#34;HaiDiLao Hot Pot&#34;],{&#34;interactive&#34;:false,&#34;permanent&#34;:false,&#34;direction&#34;:&#34;auto&#34;,&#34;opacity&#34;:1,&#34;offset&#34;:[0,0],&#34;textsize&#34;:&#34;10px&#34;,&#34;textOnly&#34;:false,&#34;className&#34;:&#34;&#34;,&#34;sticky&#34;:true},null]},{&#34;method&#34;:&#34;addPolygons&#34;,&#34;args&#34;:[[[[{&#34;lng&#34;:[-0.134344743416851,-0.134215985086582,-0.134108903051854,-0.134003688311223,-0.133936589977803,-0.133925589342104,-0.133725588583312,-0.133712764140479,-0.133572763599984,-0.133556406451653,-0.133539996040632,-0.133420658150733,-0.132788386439166,-0.132386036095321,-0.132378969700715,-0.132250145532724,-0.131576571531743,-0.13095130869119,-0.130937131975402,-0.130922719055021,-0.130908109001771,-0.130893341421793,-0.130878456348284,-0.130863494132961,-0.130848495336665,-0.130833500619414,-0.130818550630163,-0.130803685896611,-0.130788946715328,-0.130774373042515,-0.130760004385681,-0.130745879696544,-0.130732037265428,-0.130232035862441,-0.130217984270785,-0.130204319491823,-0.130191081563895,-0.130178309274613,-0.130166040047204,-0.130154309830854,-0.130143152995385,-0.13013260223054,-0.130122688450209,-0.130113440701843,-0.130104886081356,-0.130097049653725,-0.130089954379559,-0.129959955139437,-0.129953817381168,-0.129948409214184,-0.12994374546153,-0.12993983890583,-0.129936700254258,-0.129934338109193,-0.129932758944642,-0.129931967088512,-0.129931964710741,-0.12993275181736,-0.129934326250481,-0.12993668369422,-0.129939817686525,-0.129943719636905,-0.129948378849964,-0.129953782554736,-0.129959915939684,-0.129966762193311,-0.129974302550229,-0.129982516342608,-0.129991381056823,-0.130000872395168,-0.130010964342448,-0.130021629237298,-0.130032837847984,-0.130044559452547,-0.13005676192299,-0.130069411813347,-0.130082474451356,-0.130095914033481,-0.130109693723052,-0.13012377575123,-0.130138121520521,-0.130152691710568,-0.130167446385916,-0.130182345105473,-0.130197347033348,-0.130212411050775,-0.130227495868819,-0.130242560141522,-0.130257562579245,-0.130272462061823,-0.130287217751267,-0.130301789203703,-0.130316136480208,-0.13033022025628,-0.130344001929628,-0.13035744372596,-0.130370508802527,-0.130383161349098,-0.130395366686112,-0.130407091359735,-0.13041830323354,-0.130428971576607,-0.13043906714774,-0.130448562275623,-0.130457430934661,-0.130465648816318,-0.130473193395748,-0.130480043993532,-0.130564483789795,-0.130859738227312,-0.131388689991607,-0.13140355805679,-0.131418683645499,-0.132108681172436,-0.132111031277367,-0.132237485995665,-0.132643963015278,-0.132659368696106,-0.133329366227855,-0.13334437613195,-0.133359514208983,-0.133374737930979,-0.133390004529358,-0.133523566984489,-0.13364080414703,-0.133828891488034,-0.133903410143204,-0.133916357494644,-0.133929395719288,-0.134079395138868,-0.134095220271675,-0.13411109026679,-0.134126956952605,-0.134142772167555,-0.134282771631134,-0.13428525634747,-0.134415255851081,-0.134545255870004,-0.134560173856771,-0.134574954322146,-0.134589556754347,-0.134603941129542,-0.134618068021552,-0.13463189870991,-0.134645395285983,-0.134658520756883,-0.134671239146849,-0.134683515595855,-0.134695316455158,-0.134706609379525,-0.134717363415885,-0.134727549088174,-0.134737138478119,-0.134746105301769,-0.134754424981534,-0.134762074713552,-0.134769033530196,-0.134775282357548,-0.134780804067681,-0.134785583525612,-0.134789607630783,-0.134792865352985,-0.134795347762578,-0.134797048054993,-0.134797961569369,-0.134798085801342,-0.134797420409917,-0.134795967218401,-0.134793730209418,-0.134790715513987,-0.13478693139474,-0.134782388223259,-0.134777098451672,-0.134771076578511,-0.134764339108988,-0.134756904509753,-0.134748793158282,-0.134740027287028,-0.134730630922484,-0.134720629819332,-0.13471005138985,-0.134698924628775,-0.134687280033841,-0.134675149522167,-0.134662566342801,-0.134649564985553,-0.134636181086489,-0.134622451330226,-0.134608413349403,-0.134594105621502,-0.134579567363413,-0.134564838423905,-0.134549959174425,-0.134534970398423,-0.134519913179565,-0.13450482878913,-0.134489758572864,-0.134474743837668,-0.134344743416851],&#34;lat&#34;:[51.5102784452583,51.510268540768,51.5102608920621,51.5102679063669,51.5102762936538,51.5102775307473,51.5102975308191,51.5102986294899,51.5103086295249,51.5103095041295,51.5103097959869,51.5103097959992,51.5103947279498,51.5104634219021,51.5104645684983,51.5104843876022,51.5105917690153,51.5107383149964,51.5107413772928,51.5107439750088,51.5107461011024,51.5107477498098,51.5107489166618,51.510749598495,51.5107497934611,51.5107495010317,51.5107487219993,51.510747458476,51.5107457138869,51.5107434929615,51.5107408017204,51.5107376474593,51.510734038729,51.5105940382195,51.5105898150201,51.5105851235582,51.5105799775801,51.5105743921637,51.5105683836746,51.5105619697179,51.5105551690869,51.5105480017076,51.5105404885807,51.5105326517201,51.510524514088,51.5105160995281,51.5105074326953,51.5103374324144,51.5103288338578,51.5103200466329,51.510311094825,51.5103020029705,51.5102927959896,51.5102834991181,51.510274137838,51.510264737808,51.510255324793,51.5102459245933,51.5102365629743,51.5102272655954,51.5102180579402,51.5102089652459,51.5102000124351,51.5101912240466,51.5101826241688,51.5101742363731,51.5101660836499,51.5101581883449,51.5101505720987,51.5101432557865,51.5101362594619,51.5101296023009,51.5101233025505,51.5101173774775,51.510111843322,51.5101067152526,51.5101020073249,51.5100977324429,51.5100939023235,51.5100905274648,51.5100876171169,51.5100851792567,51.5100832205663,51.5100817464142,51.5100807608408,51.5100802665477,51.5100802648895,51.5100807558708,51.5100817381458,51.5100832090224,51.5100851644689,51.5100875991258,51.5100905063197,51.5100938780825,51.5100977051723,51.5101019770997,51.5101066821556,51.5101118074439,51.5101173389168,51.5101232614129,51.5101295586993,51.5101362135158,51.510143207622,51.5101505218477,51.5101581361454,51.5101660296449,51.5101741807107,51.5101825670016,51.5102929876036,51.5103756587978,51.5102516854513,51.5102484867864,51.510245799089,51.5101357994881,51.5101354313873,51.5101159768179,51.5100465783016,51.5100442303668,51.5099542306933,51.5099524727312,51.509951213507,51.5099504565585,51.509950204012,51.5099502040177,51.5099418299265,51.5099230211879,51.5099137063532,51.5099122788361,51.5099112213759,51.5099012214106,51.509900440821,51.5099002052676,51.5099005154654,51.5099013704729,51.5099113704302,51.5099115547325,51.5099215546901,51.5099315546874,51.5099329504847,51.5099348315605,51.509937192759,51.5099400276085,51.5099433283389,51.5099470859032,51.5099512900024,51.5099559291134,51.5099609905208,51.5099664603518,51.5099723236142,51.5099785642373,51.5099851651161,51.5099921081583,51.5099993743335,51.5100069437259,51.5100147955884,51.5100229083998,51.5100312599235,51.5100398272687,51.510048586953,51.5100575149669,51.5100665868393,51.510075777705,51.5100850623724,51.5100944153931,51.510103811131,51.5101132238332,51.5101226277,51.5101319969561,51.5101413059209,51.5101505290793,51.5101596411511,51.5101686171606,51.5101774325052,51.5101860630226,51.5101944850568,51.5102026755237,51.5102106119736,51.5102182726531,51.5102256365646,51.5102326835241,51.5102393942162,51.5102457502471,51.5102517341953,51.5102573296591,51.5102625213015,51.5102672948924,51.5102716373477,51.5102755367649,51.5102789824558,51.5102819649759,51.5102844761502,51.5102865090958,51.5102880582404,51.5102891193378,51.5102896894796,51.5102897671032,51.5102893519957,51.5102884452949,51.5102784452583]}]]],null,null,{&#34;interactive&#34;:true,&#34;className&#34;:&#34;&#34;,&#34;stroke&#34;:false,&#34;color&#34;:&#34;#03F&#34;,&#34;weight&#34;:5,&#34;opacity&#34;:0.5,&#34;fill&#34;:true,&#34;fillColor&#34;:&#34;blue&#34;,&#34;fillOpacity&#34;:0.2,&#34;smoothFactor&#34;:1,&#34;noClip&#34;:false},null,null,&#34;20 meter neigbourhood&#34;,{&#34;interactive&#34;:false,&#34;permanent&#34;:false,&#34;direction&#34;:&#34;auto&#34;,&#34;opacity&#34;:1,&#34;offset&#34;:[0,0],&#34;textsize&#34;:&#34;10px&#34;,&#34;textOnly&#34;:false,&#34;className&#34;:&#34;&#34;,&#34;sticky&#34;:true},null]},{&#34;method&#34;:&#34;addPolylines&#34;,&#34;args&#34;:[[[[{&#34;lng&#34;:[-0.13451,-0.13438,-0.13425,-0.13411,-0.13396,-0.13388,-0.13368,-0.13354,-0.13339,-0.13272,-0.13231,-0.13218,-0.13149,-0.13085,-0.13035,-0.13022],&#34;lat&#34;:[51.51011,51.5101,51.51009,51.51008,51.51009,51.5101,51.51012,51.51013,51.51013,51.51022,51.51029,51.51031,51.51042,51.51057,51.51043,51.51026]}]]],null,null,{&#34;interactive&#34;:true,&#34;className&#34;:&#34;&#34;,&#34;stroke&#34;:true,&#34;color&#34;:&#34;red&#34;,&#34;weight&#34;:5,&#34;opacity&#34;:0.5,&#34;fill&#34;:false,&#34;fillColor&#34;:&#34;red&#34;,&#34;fillOpacity&#34;:0.2,&#34;smoothFactor&#34;:1,&#34;noClip&#34;:false},null,null,&#34;walking route&#34;,{&#34;interactive&#34;:false,&#34;permanent&#34;:false,&#34;direction&#34;:&#34;auto&#34;,&#34;opacity&#34;:1,&#34;offset&#34;:[0,0],&#34;textsize&#34;:&#34;10px&#34;,&#34;textOnly&#34;:false,&#34;className&#34;:&#34;&#34;,&#34;sticky&#34;:true},null]},{&#34;method&#34;:&#34;addCircleMarkers&#34;,&#34;args&#34;:[[51.5105033,51.5100034,51.5107132,51.5106002],[-0.1324927,-0.1306168,-0.1317583,-0.1325496],10,null,null,{&#34;interactive&#34;:true,&#34;className&#34;:&#34;&#34;,&#34;stroke&#34;:false,&#34;color&#34;:&#34;#03F&#34;,&#34;weight&#34;:5,&#34;opacity&#34;:0.5,&#34;fill&#34;:true,&#34;fillColor&#34;:&#34;gray&#34;,&#34;fillOpacity&#34;:0.5},null,null,null,null,[&#34;Siirgista Bros&#34;,&#34;All Bar One&#34;,&#34;Vantra Loungevity&#34;,&#34;Skewer &amp;amp; Beer&#34;],{&#34;interactive&#34;:false,&#34;permanent&#34;:false,&#34;direction&#34;:&#34;auto&#34;,&#34;opacity&#34;:1,&#34;offset&#34;:[0,0],&#34;textsize&#34;:&#34;10px&#34;,&#34;textOnly&#34;:false,&#34;className&#34;:&#34;&#34;,&#34;sticky&#34;:true},null]}],&#34;limits&#34;:{&#34;lat&#34;:[51.5099002052676,51.5107497934611],&#34;lng&#34;:[-0.134798085801342,-0.129931964710741]}},&#34;evals&#34;:[],&#34;jsHooks&#34;:[]}&lt;/script&gt;
&lt;p&gt;&lt;br&gt;
I believe my walkthrough demonstrated that both routing and finding points of interest are tasks that can be handled without leaving the comfort of your R session.&lt;/p&gt;
&lt;p&gt;More advanced topics in the same vein include finding points of interest within walking distance from a coordinate (using &lt;code&gt;hereR::isoline()&lt;/code&gt; approach) and querying historical OSM data (by utilizing the &lt;code&gt;datetime&lt;/code&gt; and &lt;code&gt;datetime2&lt;/code&gt; arguments of your &lt;code&gt;osmdata::opq()&lt;/code&gt; call).&lt;/p&gt;
</description>
  </item>
  
<item>
  <title>Road Routing in R</title>
  <link>https://www.jla-data.net/eng/routing-in-r-context/</link>
  <pubDate>Fri, 25 Sep 2020 00:00:00 +0000</pubDate>
  
<guid>https://www.jla-data.net/eng/routing-in-r-context/</guid>
  <description>
&lt;script src=&#34;https://www.jla-data.net/rmarkdown-libs/header-attrs/header-attrs.js&#34;&gt;&lt;/script&gt;
&lt;script src=&#34;https://www.jla-data.net/rmarkdown-libs/htmlwidgets/htmlwidgets.js&#34;&gt;&lt;/script&gt;
&lt;script src=&#34;https://www.jla-data.net/rmarkdown-libs/jquery/jquery.min.js&#34;&gt;&lt;/script&gt;
&lt;link href=&#34;https://www.jla-data.net/rmarkdown-libs/leaflet/leaflet.css&#34; rel=&#34;stylesheet&#34; /&gt;
&lt;script src=&#34;https://www.jla-data.net/rmarkdown-libs/leaflet/leaflet.js&#34;&gt;&lt;/script&gt;
&lt;link href=&#34;https://www.jla-data.net/rmarkdown-libs/leafletfix/leafletfix.css&#34; rel=&#34;stylesheet&#34; /&gt;
&lt;script src=&#34;https://www.jla-data.net/rmarkdown-libs/proj4/proj4.min.js&#34;&gt;&lt;/script&gt;
&lt;script src=&#34;https://www.jla-data.net/rmarkdown-libs/Proj4Leaflet/proj4leaflet.js&#34;&gt;&lt;/script&gt;
&lt;link href=&#34;https://www.jla-data.net/rmarkdown-libs/rstudio_leaflet/rstudio_leaflet.css&#34; rel=&#34;stylesheet&#34; /&gt;
&lt;script src=&#34;https://www.jla-data.net/rmarkdown-libs/leaflet-binding/leaflet.js&#34;&gt;&lt;/script&gt;
&lt;script src=&#34;https://www.jla-data.net/rmarkdown-libs/leaflet-providers/leaflet-providers_1.9.0.js&#34;&gt;&lt;/script&gt;
&lt;script src=&#34;https://www.jla-data.net/rmarkdown-libs/leaflet-providers-plugin/leaflet-providers-plugin.js&#34;&gt;&lt;/script&gt;


&lt;p&gt;A frequent use case in spatial analysis is routing (or navigation) – finding the optimal route between two (or more) locations.&lt;/p&gt;
&lt;p&gt;As the use case is a common one there are a number of REST APIs providing standardized solutions.&lt;/p&gt;
&lt;p&gt;In this blog post I share my personal experience with three different routing engines, implemented via three R packages:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href=&#34;http://project-osrm.org/&#34;&gt;Project OSRM&lt;/a&gt;, implemented via the &lt;code&gt;{osrm}&lt;/code&gt; package, available on CRAN&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href=&#34;https://www.mapbox.com/navigation/&#34;&gt;Mapbox&lt;/a&gt;, implemented via the &lt;code&gt;{mapboxapi}&lt;/code&gt; package, available on GitHub via &lt;code&gt;remotes::install_github(&#34;walkerke/mapboxapi&#34;)&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href=&#34;https://developer.here.com/&#34;&gt;HERE&lt;/a&gt;, implemented via the &lt;code&gt;{hereR}&lt;/code&gt; package, available on CRAN&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For my demonstration I will be using two semi-random locations in central Prague. While all the three APIs are pretty global in coverage I have found that I can more easily pick my favorite when looking at results from a familiar setting (and as a consequence your mileage may vary).&lt;/p&gt;
&lt;p&gt;The first step is attaching all the packages and creating a spatial data frame of my locations; to achieve this I am using the &lt;code&gt;{tidygeocoder}&lt;/code&gt; package (other approaches are possible, but I have found the OSM geocoder very reliable).&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;library(sf)
library(dplyr)
library(tidygeocoder)
library(mapboxapi)
library(hereR)
library(osrm)

# two semi-random Prague addresses
adresy &amp;lt;- c(&amp;quot;Gogolova 212/1, Praha 1&amp;quot;,
            &amp;quot;Soudní 988/1, Praha 4&amp;quot;)

# geocode the two addresses &amp;amp; transform to {sf} data structure
data &amp;lt;- tidygeocoder::geo(adresy, method = &amp;quot;osm&amp;quot;) %&amp;gt;% 
  st_as_sf(coords = c(&amp;quot;long&amp;quot;, &amp;quot;lat&amp;quot;), crs = 4326)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The first approach is via the completely open source OSRM engine; this approach is unique in that it does not require any API authorization.&lt;/p&gt;
&lt;p&gt;It will run by default against the OSRM demo server, with some limitations (in order to manage the resource costs), but you are free to run it against your own implementation of the routing engine; docker images are available.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;osroute &amp;lt;- osrm::osrmRoute(loc = data,
                           returnclass = &amp;quot;sf&amp;quot;)

summary(osroute)&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;##      src                dst               duration        distance    
##  Length:1           Length:1           Min.   :13.85   Min.   :8.558  
##  Class :character   Class :character   1st Qu.:13.85   1st Qu.:8.558  
##  Mode  :character   Mode  :character   Median :13.85   Median :8.558  
##                                        Mean   :13.85   Mean   :8.558  
##                                        3rd Qu.:13.85   3rd Qu.:8.558  
##                                        Max.   :13.85   Max.   :8.558  
##           geometry
##  LINESTRING   :1  
##  epsg:4326    :0  
##  +proj=long...:0  
##                   
##                   
## &lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The &lt;code&gt;osrm::osrmRoute()&lt;/code&gt; accepts as argument either &lt;code&gt;{sf}&lt;/code&gt; data frame of points (as used in this example) or source and destination as points. It returns a &lt;code&gt;{sf}&lt;/code&gt; dataframe with LINESTRING geometry type and data fields &lt;code&gt;duration&lt;/code&gt; (in minutes) and &lt;code&gt;distance&lt;/code&gt; (in kilometers).&lt;/p&gt;
&lt;p&gt;The first commercial alternative is the Mapbox engine. While it requires a registration a very generous free tier is available. An API key is necessary; &lt;code&gt;{mapboxapi}&lt;/code&gt; provides a convenient way of setting it once for ever in your R profile.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;mroute &amp;lt;- mapboxapi::mb_directions(input_data = data,
                                   profile = &amp;quot;driving&amp;quot;)

summary(mroute)&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;##           geometry    distance        duration    
##  LINESTRING   :1   Min.   :10.25   Min.   :20.92  
##  epsg:4326    :0   1st Qu.:10.25   1st Qu.:20.92  
##  +proj=long...:0   Median :10.25   Median :20.92  
##                    Mean   :10.25   Mean   :20.92  
##                    3rd Qu.:10.25   3rd Qu.:20.92  
##                    Max.   :10.25   Max.   :20.92&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The &lt;code&gt;mapboxapi::mb_directions()&lt;/code&gt; again accepts as argument &lt;code&gt;{sf}&lt;/code&gt; data frame of points; setting origin and destination separately is possible, but not quite straightforward as with the other two APIs / packages.&lt;/p&gt;
&lt;p&gt;It will again return a &lt;code&gt;{sf}&lt;/code&gt; dataframe with LINESTRING geometry type and data fields &lt;code&gt;duration&lt;/code&gt; (in minutes) and &lt;code&gt;distance&lt;/code&gt; (in kilometers), in a structure very similar to &lt;code&gt;{osrm}&lt;/code&gt; results.&lt;/p&gt;
&lt;p&gt;The second commercial alternative is the HERE engine (provided by a company known as Nokia Maps in the times before truly smart phones). It again requires registration, and provides a very generous free tier.&lt;/p&gt;
&lt;p&gt;The key has to be set once per R session via a &lt;code&gt;hereR::set_key()&lt;/code&gt; function call; for practical reasons this call was omitted from the code chunk quoted below.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;hroute &amp;lt;- hereR::route(origin = data[1, ],
                       destination =  data[2, ],
                       transport_mode = &amp;quot;car&amp;quot;) %&amp;gt;% 
  st_zm() # the Z (height) dimension is troublesome...

summary(hroute)&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;##        id         rank      section    departure                  
##  Min.   :1   Min.   :1   Min.   :1   Min.   :2021-02-19 18:00:03  
##  1st Qu.:1   1st Qu.:1   1st Qu.:1   1st Qu.:2021-02-19 18:00:03  
##  Median :1   Median :1   Median :1   Median :2021-02-19 18:00:03  
##  Mean   :1   Mean   :1   Mean   :1   Mean   :2021-02-19 18:00:03  
##  3rd Qu.:1   3rd Qu.:1   3rd Qu.:1   3rd Qu.:2021-02-19 18:00:03  
##  Max.   :1   Max.   :1   Max.   :1   Max.   :2021-02-19 18:00:03  
##     arrival                        type               mode          
##  Min.   :2021-02-19 18:17:57   Length:1           Length:1          
##  1st Qu.:2021-02-19 18:17:57   Class :character   Class :character  
##  Median :2021-02-19 18:17:57   Mode  :character   Mode  :character  
##  Mean   :2021-02-19 18:17:57                                        
##  3rd Qu.:2021-02-19 18:17:57                                        
##  Max.   :2021-02-19 18:17:57                                        
##     distance       duration    duration_base  consumption            geometry
##  Min.   :8779   Min.   :1074   Min.   :824   Min.   :4.48   LINESTRING   :1  
##  1st Qu.:8779   1st Qu.:1074   1st Qu.:824   1st Qu.:4.48   epsg:4326    :0  
##  Median :8779   Median :1074   Median :824   Median :4.48   +proj=long...:0  
##  Mean   :8779   Mean   :1074   Mean   :824   Mean   :4.48                    
##  3rd Qu.:8779   3rd Qu.:1074   3rd Qu.:824   3rd Qu.:4.48                    
##  Max.   :8779   Max.   :1074   Max.   :824   Max.   :4.48&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The API requires setting of origin and destination separately; in my case provided in &lt;code&gt;{sf}&lt;/code&gt; format as the first and second row of the &lt;code&gt;data&lt;/code&gt; data frame.&lt;/p&gt;
&lt;p&gt;The results of the &lt;code&gt;hereR::route()&lt;/code&gt; call are the most detailed from the three. Apart form the &lt;code&gt;distance&lt;/code&gt; (in meters) and &lt;code&gt;travelTime&lt;/code&gt; (in seconds), so not quite like the OSRM and Mapbox results, it returns departure and arrival times and allows consideration for traffic. It again returns a &lt;code&gt;{sf}&lt;/code&gt; LINESTRING geometry.&lt;/p&gt;
&lt;p&gt;In order to make an evaluation of the three routes I draw a simple leaflet overview:&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;library(leaflet)

leaflet(data = data) %&amp;gt;% 
  addProviderTiles(&amp;quot;CartoDB.Positron&amp;quot;) %&amp;gt;% 
  addMarkers(label = ~address) %&amp;gt;% 
  addPolylines(data = osroute,
               label = &amp;quot;OSRM engine&amp;quot;,
               color = &amp;quot;red&amp;quot;) %&amp;gt;% 
  addPolylines(data = mroute,
               label = &amp;quot;Mapbox engine&amp;quot;,
               color = &amp;quot;blue&amp;quot;) %&amp;gt;% 
  addPolylines(data = hroute,
               label = &amp;quot;HERE engine&amp;quot;,
               color = &amp;quot;green&amp;quot;)&lt;/code&gt;&lt;/pre&gt;
&lt;div id=&#34;htmlwidget-1&#34; style=&#34;width:100%;height:940.8px;&#34; class=&#34;leaflet html-widget&#34;&gt;&lt;/div&gt;
&lt;script type=&#34;application/json&#34; data-for=&#34;htmlwidget-1&#34;&gt;{&#34;x&#34;:{&#34;options&#34;:{&#34;crs&#34;:{&#34;crsClass&#34;:&#34;L.CRS.EPSG3857&#34;,&#34;code&#34;:null,&#34;proj4def&#34;:null,&#34;projectedBounds&#34;:null,&#34;options&#34;:{}}},&#34;calls&#34;:[{&#34;method&#34;:&#34;addProviderTiles&#34;,&#34;args&#34;:[&#34;CartoDB.Positron&#34;,null,null,{&#34;errorTileUrl&#34;:&#34;&#34;,&#34;noWrap&#34;:false,&#34;detectRetina&#34;:false}]},{&#34;method&#34;:&#34;addMarkers&#34;,&#34;args&#34;:[[50.0933659,50.0580812],[14.4104742053172,14.4374974],null,null,null,{&#34;interactive&#34;:true,&#34;draggable&#34;:false,&#34;keyboard&#34;:true,&#34;title&#34;:&#34;&#34;,&#34;alt&#34;:&#34;&#34;,&#34;zIndexOffset&#34;:0,&#34;opacity&#34;:1,&#34;riseOnHover&#34;:false,&#34;riseOffset&#34;:250},null,null,null,null,[&#34;Gogolova 212/1, Praha 1&#34;,&#34;Soudní 988/1, Praha 4&#34;],{&#34;interactive&#34;:false,&#34;permanent&#34;:false,&#34;direction&#34;:&#34;auto&#34;,&#34;opacity&#34;:1,&#34;offset&#34;:[0,0],&#34;textsize&#34;:&#34;10px&#34;,&#34;textOnly&#34;:false,&#34;className&#34;:&#34;&#34;,&#34;sticky&#34;:true},null]},{&#34;method&#34;:&#34;addPolylines&#34;,&#34;args&#34;:[[[[{&#34;lng&#34;:[14.41041,14.40998,14.41088,14.41097,14.40917,14.40793,14.40934,14.40612,14.40892,14.41003,14.41558,14.41348,14.41301,14.41436,14.41382,14.41499,14.41923,14.42099,14.42181,14.42483,14.43261,14.43363,14.43766,14.43975,14.44042,14.44783,14.44713,14.44453,14.44187,14.44146,14.43825,14.43734],&#34;lat&#34;:[50.09352,50.09479,50.09469,50.09529,50.09517,50.09685,50.09377,50.09283,50.09277,50.09002,50.0887,50.08444,50.08163,50.0774,50.07412,50.06755,50.06801,50.0678,50.06677,50.06499,50.06507,50.06543,50.06462,50.06532,50.06445,50.06097,50.06035,50.06031,50.05954,50.057,50.05715,50.05799]}]]],null,null,{&#34;interactive&#34;:true,&#34;className&#34;:&#34;&#34;,&#34;stroke&#34;:true,&#34;color&#34;:&#34;red&#34;,&#34;weight&#34;:5,&#34;opacity&#34;:0.5,&#34;fill&#34;:false,&#34;fillColor&#34;:&#34;red&#34;,&#34;fillOpacity&#34;:0.2,&#34;smoothFactor&#34;:1,&#34;noClip&#34;:false},null,null,&#34;OSRM engine&#34;,{&#34;interactive&#34;:false,&#34;permanent&#34;:false,&#34;direction&#34;:&#34;auto&#34;,&#34;opacity&#34;:1,&#34;offset&#34;:[0,0],&#34;textsize&#34;:&#34;10px&#34;,&#34;textOnly&#34;:false,&#34;className&#34;:&#34;&#34;,&#34;sticky&#34;:true},null]},{&#34;method&#34;:&#34;addPolylines&#34;,&#34;args&#34;:[[[[{&#34;lng&#34;:[14.410417,14.410308,14.409989,14.410878,14.410936,14.409171,14.408078,14.409321,14.406094,14.408966,14.409719,14.413829,14.414029,14.423659,14.426079,14.434996,14.436998,14.437581,14.433638,14.429684,14.429526,14.43078,14.439804,14.440214,14.440586,14.443241,14.442444,14.441319,14.44133,14.438248,14.438281,14.437333],&#34;lat&#34;:[50.093523,50.093507,50.094822,50.094689,50.095328,50.095172,50.096881,50.093732,50.092889,50.092741,50.09114,50.093225,50.093222,50.094874,50.095207,50.097136,50.097424,50.087398,50.081752,50.078681,50.069555,50.061632,50.053835,50.053401,50.052582,50.055195,50.056129,50.056173,50.056972,50.05715,50.057273,50.057992]}]]],null,null,{&#34;interactive&#34;:true,&#34;className&#34;:&#34;&#34;,&#34;stroke&#34;:true,&#34;color&#34;:&#34;blue&#34;,&#34;weight&#34;:5,&#34;opacity&#34;:0.5,&#34;fill&#34;:false,&#34;fillColor&#34;:&#34;blue&#34;,&#34;fillOpacity&#34;:0.2,&#34;smoothFactor&#34;:1,&#34;noClip&#34;:false},null,null,&#34;Mapbox engine&#34;,{&#34;interactive&#34;:false,&#34;permanent&#34;:false,&#34;direction&#34;:&#34;auto&#34;,&#34;opacity&#34;:1,&#34;offset&#34;:[0,0],&#34;textsize&#34;:&#34;10px&#34;,&#34;textOnly&#34;:false,&#34;className&#34;:&#34;&#34;,&#34;sticky&#34;:true},null]},{&#34;method&#34;:&#34;addPolylines&#34;,&#34;args&#34;:[[[[{&#34;lng&#34;:[14.40996,14.40969,14.40941,14.40919,14.40911,14.40903,14.40874,14.40863,14.40833,14.40814,14.40799,14.40782,14.40773,14.40763,14.40756,14.40835,14.40896,14.4092,14.40983,14.41013,14.41028,14.41045,14.41073,14.41086,14.41106,14.41148,14.41169,14.41183,14.41204,14.41257,14.41276,14.41315,14.41339,14.41427,14.41487,14.416,14.41634,14.41663,14.41677,14.41707,14.41732,14.41752,14.41842,14.41881,14.41934,14.4196,14.42045,14.42064,14.42079,14.42101,14.42132,14.42141,14.42159,14.42169,14.42177,14.42184,14.42191,14.42195,14.42204,14.42207,14.4222,14.42234,14.42248,14.42254,14.4226,14.4227,14.42278,14.4229,14.42302,14.42317,14.42333,14.42353,14.42368,14.42383,14.42407,14.42431,14.42456,14.42489,14.42516,14.42533,14.42548,14.42565,14.42579,14.42592,14.42606,14.42617,14.42631,14.42641,14.42647,14.42654,14.42659,14.42664,14.42667,14.42671,14.42666,14.42667,14.4267,14.42687,14.4269,14.42711,14.42713,14.42716,14.42722,14.42726,14.42728,14.4273,14.42736,14.4277,14.42798,14.42839,14.42836,14.42834,14.42832,14.4286,14.42904,14.42932,14.42986,14.43087,14.43171,14.43193,14.43206,14.43219,14.4323,14.43239,14.43244,14.43251,14.4326,14.43266,14.43273,14.43285,14.433,14.43312,14.43323,14.43333,14.43356,14.43379,14.4349,14.43576,14.43662,14.43677,14.43691,14.43701,14.43711,14.43721,14.43729,14.43735,14.4374,14.43745,14.43751,14.43753,14.43759,14.4376,14.43762,14.43763,14.43764,14.43764,14.43766,14.43767,14.43767,14.43767,14.43766,14.43764,14.43763,14.43762,14.43757,14.43751,14.43746,14.4374,14.43729,14.43713,14.43692,14.43634,14.43572,14.43543,14.43507,14.43442,14.43431,14.434,14.43379,14.43362,14.43345,14.43326,14.43306,14.4328,14.43271,14.43252,14.43233,14.4319,14.43121,14.43093,14.4308,14.43063,14.43056,14.43046,14.4303,14.43017,14.43004,14.42991,14.42975,14.42957,14.42944,14.42933,14.42928,14.42922,14.42915,14.42912,14.42912,14.42911,14.42911,14.42911,14.4291,14.4291,14.4291,14.42916,14.42921,14.42922,14.42928,14.42933,14.42935,14.42937,14.42939,14.42943,14.42945,14.4295,14.42954,14.42957,14.42962,14.42966,14.4298,14.43002,14.43012,14.4302,14.43023,14.43025,14.43026,14.43027,14.4303,14.43031,14.43031,14.43032,14.43032,14.43034,14.43036,14.43038,14.43039,14.4304,14.43041,14.43042,14.43043,14.43044,14.43044,14.43045,14.43046,14.43047,14.43048,14.43052,14.43057,14.43061,14.43071,14.43075,14.43086,14.431,14.43129,14.43258,14.43281,14.43333,14.43348,14.43368,14.43519,14.43531,14.43549,14.43566,14.43569,14.4358,14.43585,14.43595,14.43614,14.43625,14.43642,14.43658,14.4367,14.43686,14.43699,14.43712,14.43738,14.43886,14.43954,14.43985,14.43996,14.44006,14.44017,14.44026,14.44031,14.44036,14.44043,14.44049,14.44053,14.44068,14.44079,14.44092,14.44102,14.44112,14.44118,14.44129,14.44146,14.44172,14.44181,14.44208,14.44225,14.4423,14.44238,14.44244,14.44248,14.44217,14.44147,14.4411,14.44065,14.44024,14.4402,14.44028,14.43987,14.43845],&#34;lat&#34;:[50.09484,50.09494,50.09505,50.09515,50.0952,50.09524,50.09571,50.09589,50.09635,50.09665,50.09689,50.09716,50.0973,50.09748,50.09763,50.09771,50.09778,50.09781,50.09789,50.09793,50.09795,50.09797,50.09801,50.09803,50.09806,50.09812,50.09816,50.09819,50.09823,50.09831,50.09834,50.0984,50.09844,50.09857,50.09866,50.09883,50.09888,50.09892,50.09894,50.09898,50.09901,50.09904,50.09917,50.09923,50.09933,50.09938,50.09951,50.09954,50.09957,50.09961,50.09966,50.09968,50.09978,50.09972,50.09966,50.09958,50.09946,50.09939,50.09921,50.09915,50.09889,50.09859,50.0983,50.09816,50.09804,50.09788,50.09777,50.09765,50.09754,50.09743,50.09733,50.09723,50.09717,50.09712,50.09704,50.09697,50.0969,50.0968,50.09672,50.09667,50.09663,50.09658,50.09654,50.09649,50.09642,50.09636,50.09627,50.09618,50.09611,50.096,50.09588,50.09574,50.09564,50.0955,50.09538,50.09528,50.09516,50.09444,50.0943,50.09346,50.09339,50.09326,50.09304,50.09286,50.09277,50.0927,50.09264,50.09266,50.09268,50.0927,50.09298,50.09312,50.09327,50.09328,50.09329,50.0933,50.09333,50.09339,50.09345,50.09347,50.09343,50.09338,50.09333,50.09329,50.09316,50.09304,50.09293,50.09288,50.09281,50.09273,50.09266,50.09262,50.09259,50.09256,50.09252,50.0925,50.09252,50.09256,50.09259,50.09256,50.09252,50.09248,50.09245,50.09239,50.09231,50.09225,50.09217,50.09184,50.09142,50.0913,50.09076,50.09065,50.09033,50.09005,50.08992,50.08986,50.08955,50.08923,50.08893,50.08873,50.08835,50.08793,50.08782,50.08775,50.08738,50.08716,50.08698,50.08682,50.08659,50.08632,50.08602,50.08532,50.08459,50.08424,50.08374,50.08284,50.08268,50.08226,50.08195,50.08174,50.08155,50.08135,50.0812,50.08102,50.08096,50.08084,50.08073,50.08048,50.08008,50.07991,50.07983,50.07972,50.07967,50.0796,50.07948,50.07937,50.07925,50.07907,50.07879,50.07841,50.07807,50.0777,50.07743,50.07715,50.07665,50.07634,50.0763,50.07595,50.07581,50.07574,50.07554,50.07544,50.07529,50.07458,50.07384,50.07356,50.07278,50.0722,50.07202,50.07181,50.07158,50.07118,50.07074,50.07017,50.06963,50.06948,50.06937,50.06927,50.06902,50.06866,50.06848,50.0683,50.06815,50.06794,50.06775,50.06757,50.06686,50.06675,50.06669,50.0665,50.06645,50.06574,50.06506,50.0648,50.06463,50.06436,50.06401,50.06383,50.0637,50.06335,50.06323,50.06293,50.06271,50.06256,50.06251,50.0623,50.06212,50.06199,50.06178,50.06172,50.06156,50.06139,50.06109,50.06009,50.05991,50.05951,50.05939,50.05924,50.05809,50.058,50.05784,50.05768,50.05765,50.05753,50.05747,50.05733,50.05706,50.05691,50.05665,50.05646,50.05633,50.05618,50.05606,50.05594,50.05573,50.05461,50.05406,50.05382,50.05367,50.05356,50.05346,50.05331,50.05321,50.05308,50.0529,50.05273,50.05256,50.05263,50.05268,50.05275,50.05282,50.0529,50.05295,50.05305,50.05321,50.05344,50.05352,50.05376,50.05393,50.05398,50.05409,50.05418,50.05426,50.05447,50.05498,50.05528,50.0556,50.05594,50.05603,50.05716,50.05717,50.05715]}]]],null,null,{&#34;interactive&#34;:true,&#34;className&#34;:&#34;&#34;,&#34;stroke&#34;:true,&#34;color&#34;:&#34;green&#34;,&#34;weight&#34;:5,&#34;opacity&#34;:0.5,&#34;fill&#34;:false,&#34;fillColor&#34;:&#34;green&#34;,&#34;fillOpacity&#34;:0.2,&#34;smoothFactor&#34;:1,&#34;noClip&#34;:false},null,null,&#34;HERE engine&#34;,{&#34;interactive&#34;:false,&#34;permanent&#34;:false,&#34;direction&#34;:&#34;auto&#34;,&#34;opacity&#34;:1,&#34;offset&#34;:[0,0],&#34;textsize&#34;:&#34;10px&#34;,&#34;textOnly&#34;:false,&#34;className&#34;:&#34;&#34;,&#34;sticky&#34;:true},null]}],&#34;limits&#34;:{&#34;lat&#34;:[50.05256,50.09978],&#34;lng&#34;:[14.406094,14.44783]}},&#34;evals&#34;:[],&#34;jsHooks&#34;:[]}&lt;/script&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;As someone familiar with both Prague road network and traffic situation I find all three routes accurate and relevant.&lt;/p&gt;
&lt;p&gt;Having said that I consider, based on a sample of one, the green route generated by the HERE API preferable.&lt;/p&gt;
&lt;p&gt;It correctly finds that the shortest route (the one identified by OSRM in red) passes through the very historical center of Prague, and is likely to be plagued by heavy traffic.&lt;/p&gt;
&lt;p&gt;The routes chosen by the two commercial implementations are quite close, but the one from HERE makes better use of the Letná tunnel and is likely to avoid some of the traffic commonly encountered on the Vltava river embankments.&lt;/p&gt;
</description>
  </item>
  
<item>
  <title>Lines from Points</title>
  <link>https://www.jla-data.net/eng/lines-from-points/</link>
  <pubDate>Mon, 31 Aug 2020 00:00:00 +0000</pubDate>
  
<guid>https://www.jla-data.net/eng/lines-from-points/</guid>
  <description>


&lt;p&gt;A question was raised recently on the &lt;a href=&#34;https://community.rstudio.com/&#34;&gt;RStudio discussion forum&lt;/a&gt; about an algorithm for linking spatial points by a network of lines.&lt;/p&gt;
&lt;p&gt;The &lt;em&gt;lines from points&lt;/em&gt; use case is frequently utilized in both visualizing of regional development – the lines representing flow from one region to another via color and / or thickness – and in network analysis – measuring &amp;amp; visualizing distance (i.e. length of the line) – between two or more areas of interest.&lt;/p&gt;
&lt;p&gt;As I was unable to refer the poster of the question to a suitable published walkthrough I propose one of my own.&lt;/p&gt;
&lt;p&gt;It is based on a function (I might be able to extend it into a package when time allows) &lt;code&gt;points_to_lines()&lt;/code&gt;. The function takes four arguments, three of which are mandatory:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;data frame of spatial points, expected in &lt;code&gt;{sf}&lt;/code&gt; package format; it is placed as the first argument, so the function is pipe friendly&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;name of column containing technical IDs of points (typically &lt;a href=&#34;https://en.wikipedia.org/wiki/FIPS_county_code&#34;&gt;FIPS&lt;/a&gt; codes in the US, &lt;a href=&#34;https://en.wikipedia.org/wiki/Nomenclature_of_Territorial_Units_for_Statistics&#34;&gt;NUTS&lt;/a&gt; in the EU, or some other ID)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;name of column containing names of the points for labels&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;indication whether order of the points matters (meaning whether line from A to B is equivalent to line from B to A); default is &lt;code&gt;TRUE&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The function returns a spatial data frame of four columns: ID of starting point, ID of ending point, label (names of the two points, separated by a dash) and a geometry column of type &lt;code&gt;LINESTRING&lt;/code&gt;; the geometry will be in the same CRS as original points.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;library(sf)
library(dplyr)

points_to_lines &amp;lt;- function(data, ids, names, order_matters = TRUE) {
  
  # dataframe of combinations - based on row index
  idx &amp;lt;- expand.grid(start = seq(1, nrow(data), 1),
                     end = seq(1, nrow(data), 1)) %&amp;gt;%
    # no line with start &amp;amp; end being the same point
    dplyr::filter(start != end) %&amp;gt;%  
    # when order doesn&amp;#39;t matter just one direction is enough
    dplyr::filter(order_matters | start &amp;gt; end) 
  
  
  # cycle over the combinations
  for (i in seq_along(idx$start)) {
    
    # line object from two points
    wrk_line  &amp;lt;- data[c(idx$start[i], idx$end[i]), ] %&amp;gt;% 
      st_coordinates() %&amp;gt;% 
      st_linestring() %&amp;gt;% 
      st_sfc()
    
    # a single row of results dataframe
    line_data &amp;lt;- data.frame(
      start = pull(data, ids)[idx$start[i]],
      end = pull(data, ids)[idx$end[i]],
      label = paste(pull(data, names)[idx$start[i]], 
                    &amp;quot;-&amp;quot;, 
                    pull(data, names)[idx$end[i]]),
      geometry = wrk_line
    )
    
    # bind results rows to a single object
    if (i == 1) {
      res &amp;lt;- line_data
      
    } else {
      res &amp;lt;- dplyr::bind_rows(res, line_data)
      
    } # /if - saving results
    
  } # /for
  
  # finalize function result
  res &amp;lt;- sf::st_as_sf(res, crs = sf::st_crs(data))
  
  res
  
} # /function&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The function can be easily sourced &amp;amp; then used as a one liner in any script; it requires only &lt;code&gt;{sf}&lt;/code&gt; and &lt;code&gt;{dplyr}&lt;/code&gt; packages, so no cruel or unusual dependencies are involved.&lt;/p&gt;
&lt;p&gt;The intended use case is to generate a spatial data frame of lines from a spatial data frame of points (either centroids or points-on-a-surfaces or what not) and the result then joined with actual data via one of the &lt;code&gt;dplyr::*_join()&lt;/code&gt; functions.&lt;/p&gt;
&lt;p&gt;To demonstrate the use of the function I am showing links between five semi random counties in North Carolina (using the popular &lt;code&gt;nc.shp&lt;/code&gt; shapefile that ships with the &lt;code&gt;{sf}&lt;/code&gt; package, and is therefore widely available).&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;# Well known &amp;amp; much loved shapefile of NC included with sf package
nc_polygons &amp;lt;- sf::st_read(system.file(&amp;quot;shape/nc.shp&amp;quot;, package=&amp;quot;sf&amp;quot;), quiet = T)

set.seed(16)

# five semi random county centroids
nc_points &amp;lt;- nc_polygons %&amp;gt;% 
  sf::st_centroid() %&amp;gt;% 
  slice(sample(1:nrow(nc_polygons), 5))
  
# function of lines from points
nc_lines &amp;lt;- points_to_lines(nc_points, ids = &amp;quot;FIPS&amp;quot;, names = &amp;quot;NAME&amp;quot;)

# a graphic overview
library(ggplot2)
ggplot() +
  geom_sf(data = nc_polygons, color = &amp;quot;gray45&amp;quot;, fill = NA) +
  geom_sf(data = nc_lines, color = &amp;quot;red&amp;quot;) &lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;https://www.jla-data.net/ENG/2020-08-31-lines-from-points_files/figure-html/aplikace-1.png&#34; width=&#34;100%&#34; /&gt;&lt;/p&gt;
&lt;p&gt;The algorithm to create lines comes in two flavors, depending on whether order matters for your use case.&lt;/p&gt;
&lt;p&gt;In case order &lt;em&gt;does&lt;/em&gt; matter – i.e. a line from Greene to Pender counties is different from the one from Pender to Greene – there will be &lt;code&gt;nrow(data) × (nrow(data) - 1)&lt;/code&gt; lines (each point is connected to every other point except itself).&lt;/p&gt;
&lt;p&gt;In case order &lt;em&gt;does not&lt;/em&gt; matter – i.e. once a line is drawn from Greene to Pender there will be no need to plot another in opposite direction – there will be only half as much lines required.&lt;/p&gt;
&lt;p&gt;To pick which behavior is desirable change the value of &lt;code&gt;order_matters&lt;/code&gt; argument; the default is &lt;code&gt;TRUE&lt;/code&gt;, meaning yes, order does matter.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;# when order matters &amp;gt;&amp;gt; both directions are required &amp;gt;&amp;gt; 20 rows
points_to_lines(nc_points, ids = &amp;quot;FIPS&amp;quot;, names = &amp;quot;NAME&amp;quot;, order_matters = T) %&amp;gt;% 
  knitr::kable()&lt;/code&gt;&lt;/pre&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr class=&#34;header&#34;&gt;
&lt;th align=&#34;left&#34;&gt;start&lt;/th&gt;
&lt;th align=&#34;left&#34;&gt;end&lt;/th&gt;
&lt;th align=&#34;left&#34;&gt;label&lt;/th&gt;
&lt;th align=&#34;left&#34;&gt;geometry&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr class=&#34;odd&#34;&gt;
&lt;td align=&#34;left&#34;&gt;37079&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;37141&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;Greene - Pender&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;LINESTRING (-77.67889 35.48…&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&#34;even&#34;&gt;
&lt;td align=&#34;left&#34;&gt;37161&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;37141&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;Rutherford - Pender&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;LINESTRING (-81.91787 35.39…&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&#34;odd&#34;&gt;
&lt;td align=&#34;left&#34;&gt;37181&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;37141&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;Vance - Pender&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;LINESTRING (-78.41127 36.36…&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&#34;even&#34;&gt;
&lt;td align=&#34;left&#34;&gt;37023&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;37141&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;Burke - Pender&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;LINESTRING (-81.70216 35.74…&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&#34;odd&#34;&gt;
&lt;td align=&#34;left&#34;&gt;37141&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;37079&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;Pender - Greene&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;LINESTRING (-77.91628 34.52…&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&#34;even&#34;&gt;
&lt;td align=&#34;left&#34;&gt;37161&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;37079&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;Rutherford - Greene&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;LINESTRING (-81.91787 35.39…&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&#34;odd&#34;&gt;
&lt;td align=&#34;left&#34;&gt;37181&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;37079&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;Vance - Greene&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;LINESTRING (-78.41127 36.36…&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&#34;even&#34;&gt;
&lt;td align=&#34;left&#34;&gt;37023&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;37079&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;Burke - Greene&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;LINESTRING (-81.70216 35.74…&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&#34;odd&#34;&gt;
&lt;td align=&#34;left&#34;&gt;37141&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;37161&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;Pender - Rutherford&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;LINESTRING (-77.91628 34.52…&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&#34;even&#34;&gt;
&lt;td align=&#34;left&#34;&gt;37079&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;37161&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;Greene - Rutherford&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;LINESTRING (-77.67889 35.48…&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&#34;odd&#34;&gt;
&lt;td align=&#34;left&#34;&gt;37181&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;37161&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;Vance - Rutherford&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;LINESTRING (-78.41127 36.36…&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&#34;even&#34;&gt;
&lt;td align=&#34;left&#34;&gt;37023&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;37161&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;Burke - Rutherford&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;LINESTRING (-81.70216 35.74…&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&#34;odd&#34;&gt;
&lt;td align=&#34;left&#34;&gt;37141&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;37181&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;Pender - Vance&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;LINESTRING (-77.91628 34.52…&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&#34;even&#34;&gt;
&lt;td align=&#34;left&#34;&gt;37079&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;37181&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;Greene - Vance&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;LINESTRING (-77.67889 35.48…&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&#34;odd&#34;&gt;
&lt;td align=&#34;left&#34;&gt;37161&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;37181&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;Rutherford - Vance&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;LINESTRING (-81.91787 35.39…&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&#34;even&#34;&gt;
&lt;td align=&#34;left&#34;&gt;37023&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;37181&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;Burke - Vance&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;LINESTRING (-81.70216 35.74…&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&#34;odd&#34;&gt;
&lt;td align=&#34;left&#34;&gt;37141&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;37023&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;Pender - Burke&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;LINESTRING (-77.91628 34.52…&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&#34;even&#34;&gt;
&lt;td align=&#34;left&#34;&gt;37079&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;37023&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;Greene - Burke&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;LINESTRING (-77.67889 35.48…&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&#34;odd&#34;&gt;
&lt;td align=&#34;left&#34;&gt;37161&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;37023&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;Rutherford - Burke&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;LINESTRING (-81.91787 35.39…&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&#34;even&#34;&gt;
&lt;td align=&#34;left&#34;&gt;37181&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;37023&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;Vance - Burke&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;LINESTRING (-78.41127 36.36…&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;# if directions don&amp;#39;t matter &amp;gt;&amp;gt; a single direction is enough &amp;gt;&amp;gt; 10 rows only
points_to_lines(nc_points, ids = &amp;quot;FIPS&amp;quot;, names = &amp;quot;NAME&amp;quot;, order_matters = F) %&amp;gt;% 
  knitr::kable()&lt;/code&gt;&lt;/pre&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr class=&#34;header&#34;&gt;
&lt;th align=&#34;left&#34;&gt;start&lt;/th&gt;
&lt;th align=&#34;left&#34;&gt;end&lt;/th&gt;
&lt;th align=&#34;left&#34;&gt;label&lt;/th&gt;
&lt;th align=&#34;left&#34;&gt;geometry&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr class=&#34;odd&#34;&gt;
&lt;td align=&#34;left&#34;&gt;37079&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;37141&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;Greene - Pender&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;LINESTRING (-77.67889 35.48…&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&#34;even&#34;&gt;
&lt;td align=&#34;left&#34;&gt;37161&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;37141&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;Rutherford - Pender&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;LINESTRING (-81.91787 35.39…&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&#34;odd&#34;&gt;
&lt;td align=&#34;left&#34;&gt;37181&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;37141&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;Vance - Pender&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;LINESTRING (-78.41127 36.36…&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&#34;even&#34;&gt;
&lt;td align=&#34;left&#34;&gt;37023&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;37141&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;Burke - Pender&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;LINESTRING (-81.70216 35.74…&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&#34;odd&#34;&gt;
&lt;td align=&#34;left&#34;&gt;37161&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;37079&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;Rutherford - Greene&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;LINESTRING (-81.91787 35.39…&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&#34;even&#34;&gt;
&lt;td align=&#34;left&#34;&gt;37181&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;37079&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;Vance - Greene&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;LINESTRING (-78.41127 36.36…&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&#34;odd&#34;&gt;
&lt;td align=&#34;left&#34;&gt;37023&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;37079&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;Burke - Greene&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;LINESTRING (-81.70216 35.74…&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&#34;even&#34;&gt;
&lt;td align=&#34;left&#34;&gt;37181&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;37161&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;Vance - Rutherford&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;LINESTRING (-78.41127 36.36…&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&#34;odd&#34;&gt;
&lt;td align=&#34;left&#34;&gt;37023&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;37161&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;Burke - Rutherford&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;LINESTRING (-81.70216 35.74…&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&#34;even&#34;&gt;
&lt;td align=&#34;left&#34;&gt;37023&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;37181&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;Burke - Vance&lt;/td&gt;
&lt;td align=&#34;left&#34;&gt;LINESTRING (-81.70216 35.74…&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
</description>
  </item>
  
<item>
  <title>Merging Data Frames in R</title>
  <link>https://www.jla-data.net/eng/merging-data-frames-in-r/</link>
  <pubDate>Thu, 06 Aug 2020 00:00:00 +0000</pubDate>
  
<guid>https://www.jla-data.net/eng/merging-data-frames-in-r/</guid>
  <description>


&lt;p&gt;Recently I was facing an optimization problem: I needed to produce a largish data frame of cash flow projections. This turned out to be a rather slow operation.&lt;/p&gt;
&lt;p&gt;The main issue being that in my use case it was not feasible to pre-allocate the final structure ahead, so I had to make do with building the output piece by piece via repeated &lt;code&gt;rbind&lt;/code&gt; calls.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;base::rbind()&lt;/code&gt; function is okay when called once or twice per script, but when used thousands of times in a row it gets rather slow; the root cause being memory management.&lt;/p&gt;
&lt;p&gt;This drew me to investigating three alternatives to the base scenario, a study in optimization that I would like to share with you:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;dplyr::bind_rows()&lt;/code&gt; from the authors of mighty &lt;code&gt;{tidyverse}&lt;/code&gt;
&lt;li&gt;
&lt;code&gt;data.table::rbindlist()&lt;/code&gt; from the alternative realm of &lt;code&gt;{data.table}&lt;/code&gt;
&lt;li&gt;
spinning up an in memory SQLite database, and running inserts of intermediary results in the SQL way
&lt;/ul&gt;
&lt;p&gt;As my original use case was needlessly complicated I am illustrating the three approaches on a simplified use case of pasting together 5000 copies of the popular &lt;a href=&#34;https://stat.ethz.ch/R-manual/R-devel/library/datasets/html/mtcars.html&#34;&gt;mtcars&lt;/a&gt; dataset.&lt;/p&gt;
&lt;p&gt;For measuring the time elapsed I am using the simple, yet elegant, &lt;a href=&#34;https://github.com/collectivemedia/tictoc&#34;&gt;&lt;code&gt;{tictoc}&lt;/code&gt;&lt;/a&gt; package.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;tictoc::tic()
for (i in 1:5000) {

  if (i == 1) {
    res_base &amp;lt;- mtcars
  } else {
    res_base &amp;lt;- rbind(res_base, mtcars)
  }
    
}
tictoc::toc()&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;## 311.291 sec elapsed&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The base approach was just that: basic. It took five minutes to run, and established a baseline for evaluating performance of the more sophisticated approaches.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;tictoc::tic()
for (i in 1:5000) {
  
  if (i == 1) {
    res_dplyr &amp;lt;- mtcars
  } else {
    res_dplyr &amp;lt;- dplyr::bind_rows(res_dplyr, mtcars)
  }
  
}
tictoc::toc()&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;## 269.352 sec elapsed&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The &lt;code&gt;dplyr&lt;/code&gt; approach is very similar to base – both in syntax and speed (which was somewhat unfortunate, as I was expecting a better performance).&lt;/p&gt;
&lt;p&gt;Unless you are running a closed &lt;code&gt;tidyverse&lt;/code&gt; shop I am not recommending this solution.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;tictoc::tic()
for (i in 1:5000) {
  
  if (i == 1) {
    res_dtable &amp;lt;- mtcars
  } else {
    res_dtable &amp;lt;- data.table::rbindlist(list(res_dtable, mtcars))
  }
  
}
tictoc::toc()&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;## 23.228 sec elapsed&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The &lt;code&gt;data.table&lt;/code&gt; asks for a slightly modified syntax, as the &lt;code&gt;rbidlist()&lt;/code&gt; function requires a list of data frames as argument. It also was, in line with the package reputation, blazingly fast.&lt;/p&gt;
&lt;p&gt;This approach is probably the best from a general perspective.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;tictoc::tic()

con &amp;lt;- DBI::dbConnect(RSQLite::SQLite(), &amp;quot;:memory:&amp;quot;)

for (i in 1:5000) {
  
  if (i == 1) DBI::dbCreateTable(con, &amp;quot;mtcars&amp;quot;, mtcars)
  
  DBI::dbAppendTable(con, &amp;quot;mtcars&amp;quot;, mtcars)
  
}

res_sqlite &amp;lt;- DBI::dbReadTable(con, &amp;quot;mtcars&amp;quot;)

DBI::dbDisconnect(con)
tictoc::toc()&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;## 22.036 sec elapsed&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The final alternative considered was a relational database. These are normally not associated with fast speed, but the concept of repeated insert was familiar from my SQL background and seemed appropriate for the use case at hand. As the volume of data was not an issue from available memory constraint perspective the database was created in memory.&lt;/p&gt;
&lt;p&gt;I was pleasantly surprised that the humble database was able to keep up with the best that R world has to offer (i.e. &lt;code&gt;data.table&lt;/code&gt;) and handily beat the &lt;code&gt;dplyr&lt;/code&gt; solution.&lt;/p&gt;
&lt;p&gt;On the other hand the benefits of an in memory database approach, when compared to the &lt;code&gt;data.table&lt;/code&gt; solution, are only slight and probably worth it only to the hardest core of SQL fans.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://www.jla-data.net/ENG/2020-08-06-merging-data-frames_files/figure-html/overview-1.png&#34; width=&#34;672&#34; /&gt;&lt;/p&gt;
&lt;p&gt;And finally, because an image is worth a thousand of words, a graphical overview of the times elapsed.&lt;/p&gt;
</description>
  </item>
  
<item>
  <title>Leaflet Map Markers in R</title>
  <link>https://www.jla-data.net/eng/leaflet-markers-in-r/</link>
  <pubDate>Wed, 22 Jul 2020 00:00:00 +0000</pubDate>
  
<guid>https://www.jla-data.net/eng/leaflet-markers-in-r/</guid>
  <description>
&lt;script src=&#34;https://www.jla-data.net/rmarkdown-libs/htmlwidgets/htmlwidgets.js&#34;&gt;&lt;/script&gt;
&lt;script src=&#34;https://www.jla-data.net/rmarkdown-libs/jquery/jquery.min.js&#34;&gt;&lt;/script&gt;
&lt;link href=&#34;https://www.jla-data.net/rmarkdown-libs/leaflet/leaflet.css&#34; rel=&#34;stylesheet&#34; /&gt;
&lt;script src=&#34;https://www.jla-data.net/rmarkdown-libs/leaflet/leaflet.js&#34;&gt;&lt;/script&gt;
&lt;link href=&#34;https://www.jla-data.net/rmarkdown-libs/leafletfix/leafletfix.css&#34; rel=&#34;stylesheet&#34; /&gt;
&lt;script src=&#34;https://www.jla-data.net/rmarkdown-libs/Proj4Leaflet/proj4-compressed.js&#34;&gt;&lt;/script&gt;
&lt;script src=&#34;https://www.jla-data.net/rmarkdown-libs/Proj4Leaflet/proj4leaflet.js&#34;&gt;&lt;/script&gt;
&lt;link href=&#34;https://www.jla-data.net/rmarkdown-libs/rstudio_leaflet/rstudio_leaflet.css&#34; rel=&#34;stylesheet&#34; /&gt;
&lt;script src=&#34;https://www.jla-data.net/rmarkdown-libs/leaflet-binding/leaflet.js&#34;&gt;&lt;/script&gt;
&lt;script src=&#34;https://www.jla-data.net/rmarkdown-libs/leaflet-providers/leaflet-providers_1.9.0.js&#34;&gt;&lt;/script&gt;
&lt;script src=&#34;https://www.jla-data.net/rmarkdown-libs/leaflet-providers-plugin/leaflet-providers-plugin.js&#34;&gt;&lt;/script&gt;
&lt;link href=&#34;https://www.jla-data.net/rmarkdown-libs/leaflet-awesomemarkers/leaflet.awesome-markers.css&#34; rel=&#34;stylesheet&#34; /&gt;
&lt;script src=&#34;https://www.jla-data.net/rmarkdown-libs/leaflet-awesomemarkers/leaflet.awesome-markers.min.js&#34;&gt;&lt;/script&gt;
&lt;link href=&#34;https://www.jla-data.net/rmarkdown-libs/fontawesome/font-awesome.min.css&#34; rel=&#34;stylesheet&#34; /&gt;


&lt;p&gt;The &lt;a href=&#34;https://leafletjs.com/&#34;&gt;leaflet.js&lt;/a&gt; JavaScript library, as extended by
&lt;a href=&#34;https://rstudio.github.io/leaflet/&#34;&gt;&lt;code&gt;{leaflet}&lt;/code&gt;&lt;/a&gt; package, is a powerful tool
for visualizing spatial data in R. On the other hand the combination of R and
JavaScript worlds creates complexities, some of them with not immediately
obvious solutions.&lt;/p&gt;
&lt;p&gt;In this post I present several approaches to plotting spatial point data in a visually
pleasing and convincing way.&lt;/p&gt;
&lt;p&gt;I am demonstrating the approach on a dataset of headquarters of four
technological companies, colloquially abbreviated as FANGs (&lt;a href=&#34;https://www.facebook.com/&#34;&gt;Facebook&lt;/a&gt;,
&lt;a href=&#34;https://www.apple.com/&#34;&gt;Apple&lt;/a&gt;, &lt;a href=&#34;https://www.netflix.com/&#34;&gt;Netflix&lt;/a&gt; and
&lt;a href=&#34;https://www.google.com/&#34;&gt;Google&lt;/a&gt;) – but the techniques are universal and
can be easily adapted to any point data.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;library(leaflet)
library(dplyr)
library(sf)

# dramatis personae: Company HQs as a {sf} data frame
fangs &amp;lt;- data.frame(
  ticker = c(&amp;quot;FB&amp;quot;, &amp;quot;AAPL&amp;quot;, &amp;quot;NFLX&amp;quot;, &amp;quot;GOOG&amp;quot;),
  address = c(
    &amp;quot;1 Hacker Way Menlo Park, CA 94025&amp;quot;,
    &amp;quot;One Apple Park Way Cupertino, CA 95014&amp;quot;,
    &amp;quot;100 Winchester Cir. Los Gatos, CA 95032&amp;quot;,
    &amp;quot;1600 Amphitheatre Pkwy. Mountain View, CA 94043&amp;quot;
  )
) %&amp;gt;%
  tidygeocoder::geocode(address = address,
                        method = &amp;quot;osm&amp;quot;) %&amp;gt;%
  sf::st_as_sf(coords = c(&amp;quot;long&amp;quot;, &amp;quot;lat&amp;quot;), crs = 4326) &lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The initial step is geocoding the addresses; for this purpose I am using the
highly recommended &lt;a href=&#34;https://jessecambon.github.io/tidygeocoder/&#34;&gt;&lt;code&gt;{tidygeocoder}&lt;/code&gt;&lt;/a&gt;
package by Jesse Cambon. I have found the OSM &lt;a href=&#34;https://nominatim.org/&#34;&gt;Nominatim&lt;/a&gt;
backend very reliable.&lt;/p&gt;
&lt;p&gt;The geocoded data frame is then converted to &lt;a href=&#34;https://r-spatial.github.io/sf/index.html&#34;&gt;&lt;code&gt;{sf}&lt;/code&gt;&lt;/a&gt;
package format, allowing for more concise leaflet calls (there will be no need to specify lon/lat columns).&lt;/p&gt;
&lt;p&gt;The first map is drawn with plain vanilla markers – at only three lines of code
this is a not great, not terrible approach. To personalize it somewhat I am
including the HQ address as a point label (note the tilde notation, required by &lt;code&gt;{leaflet}&lt;/code&gt;).&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;leaflet(fangs) %&amp;gt;%
  addMarkers(label = ~ address) %&amp;gt;%
  addProviderTiles(&amp;quot;CartoDB.Positron&amp;quot;)&lt;/code&gt;&lt;/pre&gt;
&lt;div id=&#34;htmlwidget-1&#34; style=&#34;width:100%;height:604.8px;&#34; class=&#34;leaflet html-widget&#34;&gt;&lt;/div&gt;
&lt;script type=&#34;application/json&#34; data-for=&#34;htmlwidget-1&#34;&gt;{&#34;x&#34;:{&#34;options&#34;:{&#34;crs&#34;:{&#34;crsClass&#34;:&#34;L.CRS.EPSG3857&#34;,&#34;code&#34;:null,&#34;proj4def&#34;:null,&#34;projectedBounds&#34;:null,&#34;options&#34;:{}}},&#34;calls&#34;:[{&#34;method&#34;:&#34;addMarkers&#34;,&#34;args&#34;:[[37.4831486,37.3337269,37.25962235,37.42248575],[-122.1500282,-122.0118369,-121.962679007307,-122.085584566136],null,null,null,{&#34;interactive&#34;:true,&#34;draggable&#34;:false,&#34;keyboard&#34;:true,&#34;title&#34;:&#34;&#34;,&#34;alt&#34;:&#34;&#34;,&#34;zIndexOffset&#34;:0,&#34;opacity&#34;:1,&#34;riseOnHover&#34;:false,&#34;riseOffset&#34;:250},null,null,null,null,[&#34;1 Hacker Way Menlo Park, CA 94025&#34;,&#34;One Apple Park Way Cupertino, CA 95014&#34;,&#34;100 Winchester Cir. Los Gatos, CA 95032&#34;,&#34;1600 Amphitheatre Pkwy. Mountain View, CA 94043&#34;],{&#34;interactive&#34;:false,&#34;permanent&#34;:false,&#34;direction&#34;:&#34;auto&#34;,&#34;opacity&#34;:1,&#34;offset&#34;:[0,0],&#34;textsize&#34;:&#34;10px&#34;,&#34;textOnly&#34;:false,&#34;className&#34;:&#34;&#34;,&#34;sticky&#34;:true},null]},{&#34;method&#34;:&#34;addProviderTiles&#34;,&#34;args&#34;:[&#34;CartoDB.Positron&#34;,null,null,{&#34;errorTileUrl&#34;:&#34;&#34;,&#34;noWrap&#34;:false,&#34;detectRetina&#34;:false}]}],&#34;limits&#34;:{&#34;lat&#34;:[37.25962235,37.4831486],&#34;lng&#34;:[-122.1500282,-121.962679007307]}},&#34;evals&#34;:[],&#34;jsHooks&#34;:[]}&lt;/script&gt;
&lt;br&gt;
&lt;p&gt;
There are cases when the inverted teardrop of Leaflet marker is not desirable;
in such situation a call of Circle Markers may be a better approach.
&lt;/p&gt;
&lt;p&gt;This is a common use case when dealing with very numerous points – circles can be
scaled down much more easily than the teardrops.&lt;/p&gt;
&lt;p&gt;With regards to Circle Markers I have found it preferable to override the default
behavior of stroke (border color) and opacity (fill intensity).&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;leaflet(fangs) %&amp;gt;%
  addCircleMarkers(
    label = ~ address,
    fillColor = &amp;quot;goldenrod&amp;quot;,
    fillOpacity = 1,
    stroke = F
  ) %&amp;gt;%
  addProviderTiles(&amp;quot;CartoDB.Positron&amp;quot;)&lt;/code&gt;&lt;/pre&gt;
&lt;div id=&#34;htmlwidget-2&#34; style=&#34;width:100%;height:604.8px;&#34; class=&#34;leaflet html-widget&#34;&gt;&lt;/div&gt;
&lt;script type=&#34;application/json&#34; data-for=&#34;htmlwidget-2&#34;&gt;{&#34;x&#34;:{&#34;options&#34;:{&#34;crs&#34;:{&#34;crsClass&#34;:&#34;L.CRS.EPSG3857&#34;,&#34;code&#34;:null,&#34;proj4def&#34;:null,&#34;projectedBounds&#34;:null,&#34;options&#34;:{}}},&#34;calls&#34;:[{&#34;method&#34;:&#34;addCircleMarkers&#34;,&#34;args&#34;:[[37.4831486,37.3337269,37.25962235,37.42248575],[-122.1500282,-122.0118369,-121.962679007307,-122.085584566136],10,null,null,{&#34;interactive&#34;:true,&#34;className&#34;:&#34;&#34;,&#34;stroke&#34;:false,&#34;color&#34;:&#34;#03F&#34;,&#34;weight&#34;:5,&#34;opacity&#34;:0.5,&#34;fill&#34;:true,&#34;fillColor&#34;:&#34;goldenrod&#34;,&#34;fillOpacity&#34;:1},null,null,null,null,[&#34;1 Hacker Way Menlo Park, CA 94025&#34;,&#34;One Apple Park Way Cupertino, CA 95014&#34;,&#34;100 Winchester Cir. Los Gatos, CA 95032&#34;,&#34;1600 Amphitheatre Pkwy. Mountain View, CA 94043&#34;],{&#34;interactive&#34;:false,&#34;permanent&#34;:false,&#34;direction&#34;:&#34;auto&#34;,&#34;opacity&#34;:1,&#34;offset&#34;:[0,0],&#34;textsize&#34;:&#34;10px&#34;,&#34;textOnly&#34;:false,&#34;className&#34;:&#34;&#34;,&#34;sticky&#34;:true},null]},{&#34;method&#34;:&#34;addProviderTiles&#34;,&#34;args&#34;:[&#34;CartoDB.Positron&#34;,null,null,{&#34;errorTileUrl&#34;:&#34;&#34;,&#34;noWrap&#34;:false,&#34;detectRetina&#34;:false}]}],&#34;limits&#34;:{&#34;lat&#34;:[37.25962235,37.4831486],&#34;lng&#34;:[-122.1500282,-121.962679007307]}},&#34;evals&#34;:[],&#34;jsHooks&#34;:[]}&lt;/script&gt;
&lt;br&gt;
&lt;p&gt;
The classical leaflet markers with a little white dot may seem a bit overused on today’s
web.
&lt;/p&gt;
&lt;p&gt;They can be made to look a bit more interesting by using a &lt;a href=&#34;https://fontawesome.com/&#34;&gt;Font Awesome&lt;/a&gt;
icon in place of the white dot. A number of icons is supported, in this case
I am choosing the &lt;a href=&#34;https://fontawesome.com/v4.7.0/icon/fire&#34;&gt;fire&lt;/a&gt; icon.&lt;/p&gt;
&lt;p&gt;Note that I am on purpose using a single marker, with the same icon, for all HQ locations.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;# a single icon is declared
awesome &amp;lt;- makeAwesomeIcon(
  icon = &amp;quot;fire&amp;quot;,
  iconColor = &amp;quot;black&amp;quot;,
  markerColor = &amp;quot;blue&amp;quot;,
  library = &amp;quot;fa&amp;quot;
)

leaflet(fangs) %&amp;gt;%
  addAwesomeMarkers(icon = awesome,
                    label = ~ address) %&amp;gt;%
  addProviderTiles(&amp;quot;CartoDB.Positron&amp;quot;)&lt;/code&gt;&lt;/pre&gt;
&lt;div id=&#34;htmlwidget-3&#34; style=&#34;width:100%;height:604.8px;&#34; class=&#34;leaflet html-widget&#34;&gt;&lt;/div&gt;
&lt;script type=&#34;application/json&#34; data-for=&#34;htmlwidget-3&#34;&gt;{&#34;x&#34;:{&#34;options&#34;:{&#34;crs&#34;:{&#34;crsClass&#34;:&#34;L.CRS.EPSG3857&#34;,&#34;code&#34;:null,&#34;proj4def&#34;:null,&#34;projectedBounds&#34;:null,&#34;options&#34;:{}}},&#34;calls&#34;:[{&#34;method&#34;:&#34;addAwesomeMarkers&#34;,&#34;args&#34;:[[37.4831486,37.3337269,37.25962235,37.42248575],[-122.1500282,-122.0118369,-121.962679007307,-122.085584566136],{&#34;icon&#34;:&#34;fire&#34;,&#34;markerColor&#34;:&#34;blue&#34;,&#34;iconColor&#34;:&#34;black&#34;,&#34;spin&#34;:false,&#34;squareMarker&#34;:false,&#34;iconRotate&#34;:0,&#34;font&#34;:&#34;monospace&#34;,&#34;prefix&#34;:&#34;fa&#34;},null,null,{&#34;interactive&#34;:true,&#34;draggable&#34;:false,&#34;keyboard&#34;:true,&#34;title&#34;:&#34;&#34;,&#34;alt&#34;:&#34;&#34;,&#34;zIndexOffset&#34;:0,&#34;opacity&#34;:1,&#34;riseOnHover&#34;:false,&#34;riseOffset&#34;:250},null,null,null,null,[&#34;1 Hacker Way Menlo Park, CA 94025&#34;,&#34;One Apple Park Way Cupertino, CA 95014&#34;,&#34;100 Winchester Cir. Los Gatos, CA 95032&#34;,&#34;1600 Amphitheatre Pkwy. Mountain View, CA 94043&#34;],{&#34;interactive&#34;:false,&#34;permanent&#34;:false,&#34;direction&#34;:&#34;auto&#34;,&#34;opacity&#34;:1,&#34;offset&#34;:[0,0],&#34;textsize&#34;:&#34;10px&#34;,&#34;textOnly&#34;:false,&#34;className&#34;:&#34;&#34;,&#34;sticky&#34;:true},null]},{&#34;method&#34;:&#34;addProviderTiles&#34;,&#34;args&#34;:[&#34;CartoDB.Positron&#34;,null,null,{&#34;errorTileUrl&#34;:&#34;&#34;,&#34;noWrap&#34;:false,&#34;detectRetina&#34;:false}]}],&#34;limits&#34;:{&#34;lat&#34;:[37.25962235,37.4831486],&#34;lng&#34;:[-122.1500282,-121.962679007307]}},&#34;evals&#34;:[],&#34;jsHooks&#34;:[]}&lt;/script&gt;
&lt;br&gt;
&lt;p&gt;
A logical next step is to personalize the markers and icons of each location;
such personalization is possible with regards to both icon and marker color.
&lt;/p&gt;
&lt;p&gt;To achieve this a named list (called &lt;code&gt;logos&lt;/code&gt; in my case) of Awesome Icons is
created first. In the main leaflet call the actual icon shown is looked up based on a
key value (ticker code) stored in &lt;code&gt;fangs$ticker&lt;/code&gt; column. Again, note the tilde notation.&lt;/p&gt;
&lt;p&gt;Font Awesome supports logos of Facebook, Apple and Google. For Netflix, the
smallest of the lot, I had to make do with a TV.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;# named list of awesome icons
logos &amp;lt;- awesomeIconList(
  &amp;quot;FB&amp;quot; = makeAwesomeIcon(
    icon = &amp;quot;facebook&amp;quot;,
    markerColor = &amp;quot;blue&amp;quot;,
    library = &amp;quot;fa&amp;quot;
  ),
  &amp;quot;AAPL&amp;quot; = makeAwesomeIcon(
    icon = &amp;quot;apple&amp;quot;,
    markerColor = &amp;quot;green&amp;quot;,
    library = &amp;quot;fa&amp;quot;
  ),
  &amp;quot;NFLX&amp;quot; = makeAwesomeIcon(
    icon = &amp;quot;tv&amp;quot;,
    markerColor = &amp;quot;red&amp;quot;,
    library = &amp;quot;fa&amp;quot;
  ),
  &amp;quot;GOOG&amp;quot; = makeAwesomeIcon(
    icon = &amp;quot;google&amp;quot;,
    markerColor = &amp;quot;orange&amp;quot;,
    library = &amp;quot;fa&amp;quot;
  )
)

leaflet(fangs) %&amp;gt;%
  addAwesomeMarkers(icon = ~ logos[ticker], # lookup from list based on ticker
                    label = ~ address) %&amp;gt;%
  addProviderTiles(&amp;quot;CartoDB.Positron&amp;quot;)&lt;/code&gt;&lt;/pre&gt;
&lt;div id=&#34;htmlwidget-4&#34; style=&#34;width:100%;height:604.8px;&#34; class=&#34;leaflet html-widget&#34;&gt;&lt;/div&gt;
&lt;script type=&#34;application/json&#34; data-for=&#34;htmlwidget-4&#34;&gt;{&#34;x&#34;:{&#34;options&#34;:{&#34;crs&#34;:{&#34;crsClass&#34;:&#34;L.CRS.EPSG3857&#34;,&#34;code&#34;:null,&#34;proj4def&#34;:null,&#34;projectedBounds&#34;:null,&#34;options&#34;:{}}},&#34;calls&#34;:[{&#34;method&#34;:&#34;addAwesomeMarkers&#34;,&#34;args&#34;:[[37.4831486,37.3337269,37.25962235,37.42248575],[-122.1500282,-122.0118369,-121.962679007307,-122.085584566136],{&#34;icon&#34;:[&#34;facebook&#34;,&#34;apple&#34;,&#34;tv&#34;,&#34;google&#34;],&#34;markerColor&#34;:[&#34;blue&#34;,&#34;green&#34;,&#34;red&#34;,&#34;orange&#34;],&#34;iconColor&#34;:&#34;white&#34;,&#34;spin&#34;:false,&#34;squareMarker&#34;:false,&#34;iconRotate&#34;:0,&#34;prefix&#34;:&#34;fa&#34;},null,null,{&#34;interactive&#34;:true,&#34;draggable&#34;:false,&#34;keyboard&#34;:true,&#34;title&#34;:&#34;&#34;,&#34;alt&#34;:&#34;&#34;,&#34;zIndexOffset&#34;:0,&#34;opacity&#34;:1,&#34;riseOnHover&#34;:false,&#34;riseOffset&#34;:250},null,null,null,null,[&#34;1 Hacker Way Menlo Park, CA 94025&#34;,&#34;One Apple Park Way Cupertino, CA 95014&#34;,&#34;100 Winchester Cir. Los Gatos, CA 95032&#34;,&#34;1600 Amphitheatre Pkwy. Mountain View, CA 94043&#34;],{&#34;interactive&#34;:false,&#34;permanent&#34;:false,&#34;direction&#34;:&#34;auto&#34;,&#34;opacity&#34;:1,&#34;offset&#34;:[0,0],&#34;textsize&#34;:&#34;10px&#34;,&#34;textOnly&#34;:false,&#34;className&#34;:&#34;&#34;,&#34;sticky&#34;:true},null]},{&#34;method&#34;:&#34;addProviderTiles&#34;,&#34;args&#34;:[&#34;CartoDB.Positron&#34;,null,null,{&#34;errorTileUrl&#34;:&#34;&#34;,&#34;noWrap&#34;:false,&#34;detectRetina&#34;:false}]}],&#34;limits&#34;:{&#34;lat&#34;:[37.25962235,37.4831486],&#34;lng&#34;:[-122.1500282,-121.962679007307]}},&#34;evals&#34;:[],&#34;jsHooks&#34;:[]}&lt;/script&gt;
&lt;br&gt;
&lt;p&gt;
The last step is representing each spatial point / company headquarters by a
free format image. I am choosing a website favicon of the respective company,
rescaled to 25×25 pixels.
&lt;/p&gt;
&lt;p&gt;This again requires setting up a named list of favicons first, with URLs to
individual homepage icons. This lookup list is then used in the main leaflet
call to refer to image to be displayed.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;# a named list of rescaled icons with links to images
favicons &amp;lt;- iconList(
  &amp;quot;FB&amp;quot; = makeIcon(
    iconUrl = &amp;quot;https://www.facebook.com/favicon.ico&amp;quot;,
    iconWidth = 25,
    iconHeight = 25
  ),
  &amp;quot;AAPL&amp;quot; = makeIcon(
    iconUrl = &amp;quot;https://www.apple.com/favicon.ico&amp;quot;,
    iconWidth = 25,
    iconHeight = 25
  ),
  &amp;quot;NFLX&amp;quot; = makeIcon(
    iconUrl = &amp;quot;https://www.netflix.com/favicon.ico&amp;quot;,
    iconWidth = 25,
    iconHeight = 25
  ),
  &amp;quot;GOOG&amp;quot; = makeIcon(
    iconUrl = &amp;quot;https://www.google.com/favicon.ico&amp;quot;,
    iconWidth = 25,
    iconHeight = 25
  )
)

leaflet(fangs) %&amp;gt;%
  addMarkers(icon = ~ favicons[ticker], # lookup based on ticker
             label = ~ address) %&amp;gt;%
  addProviderTiles(&amp;quot;CartoDB.Positron&amp;quot;)&lt;/code&gt;&lt;/pre&gt;
&lt;div id=&#34;htmlwidget-5&#34; style=&#34;width:100%;height:604.8px;&#34; class=&#34;leaflet html-widget&#34;&gt;&lt;/div&gt;
&lt;script type=&#34;application/json&#34; data-for=&#34;htmlwidget-5&#34;&gt;{&#34;x&#34;:{&#34;options&#34;:{&#34;crs&#34;:{&#34;crsClass&#34;:&#34;L.CRS.EPSG3857&#34;,&#34;code&#34;:null,&#34;proj4def&#34;:null,&#34;projectedBounds&#34;:null,&#34;options&#34;:{}}},&#34;calls&#34;:[{&#34;method&#34;:&#34;addMarkers&#34;,&#34;args&#34;:[[37.4831486,37.3337269,37.25962235,37.42248575],[-122.1500282,-122.0118369,-121.962679007307,-122.085584566136],{&#34;iconUrl&#34;:{&#34;data&#34;:[&#34;https://www.facebook.com/favicon.ico&#34;,&#34;https://www.apple.com/favicon.ico&#34;,&#34;https://www.netflix.com/favicon.ico&#34;,&#34;https://www.google.com/favicon.ico&#34;],&#34;index&#34;:[0,1,2,3]},&#34;iconWidth&#34;:25,&#34;iconHeight&#34;:25},null,null,{&#34;interactive&#34;:true,&#34;draggable&#34;:false,&#34;keyboard&#34;:true,&#34;title&#34;:&#34;&#34;,&#34;alt&#34;:&#34;&#34;,&#34;zIndexOffset&#34;:0,&#34;opacity&#34;:1,&#34;riseOnHover&#34;:false,&#34;riseOffset&#34;:250},null,null,null,null,[&#34;1 Hacker Way Menlo Park, CA 94025&#34;,&#34;One Apple Park Way Cupertino, CA 95014&#34;,&#34;100 Winchester Cir. Los Gatos, CA 95032&#34;,&#34;1600 Amphitheatre Pkwy. Mountain View, CA 94043&#34;],{&#34;interactive&#34;:false,&#34;permanent&#34;:false,&#34;direction&#34;:&#34;auto&#34;,&#34;opacity&#34;:1,&#34;offset&#34;:[0,0],&#34;textsize&#34;:&#34;10px&#34;,&#34;textOnly&#34;:false,&#34;className&#34;:&#34;&#34;,&#34;sticky&#34;:true},null]},{&#34;method&#34;:&#34;addProviderTiles&#34;,&#34;args&#34;:[&#34;CartoDB.Positron&#34;,null,null,{&#34;errorTileUrl&#34;:&#34;&#34;,&#34;noWrap&#34;:false,&#34;detectRetina&#34;:false}]}],&#34;limits&#34;:{&#34;lat&#34;:[37.25962235,37.4831486],&#34;lng&#34;:[-122.1500282,-121.962679007307]}},&#34;evals&#34;:[],&#34;jsHooks&#34;:[]}&lt;/script&gt;
&lt;br&gt;
&lt;p&gt;
I believe I have in my short example shown both the ease,
and the potential, of visualizing point data in Leaflet.
&lt;/p&gt;
&lt;p&gt;For more information consider my more detailed &lt;a href=&#34;https://www.jla-data.net/eng/leaflet-in-r-tips-and-tricks/&#34;&gt;Leaflet in R walkthtough&lt;/a&gt;.&lt;/p&gt;
</description>
  </item>
  
<item>
  <title>Promoting Best Development Practices</title>
  <link>https://www.jla-data.net/eng/changing-rstudio-settings-programmaticaly/</link>
  <pubDate>Mon, 01 Jun 2020 00:00:00 +0000</pubDate>
  
<guid>https://www.jla-data.net/eng/changing-rstudio-settings-programmaticaly/</guid>
  <description>


&lt;p&gt;As a trainer of R I often work with beginners, eager to learn but somewhat overwhelmed by the sheer volume of information. This applies equally to data science concepts in general, R as a language and RStudio as an integrated development environment.&lt;/p&gt;
&lt;p&gt;Data science (which is in my opinion less of a “science” and more like Data Housekeeping, but I digress…) is hard to reduce to a few unmutable truths. R is a powerful, and thus complex, ecosystem of Open Source packages, vibrant but unlikely to ever be easy to navigate for novice users.&lt;/p&gt;
&lt;p&gt;On the other hand there &lt;em&gt;are&lt;/em&gt; a few unmutable truths that can be applied to RStudio IDE that are not a part of the standard defaults. These include, but are not limited to, never saving nor restoring environment in .RData file, and strictly applying UTF-8 formatting (especially for users from non-ASCII language background).&lt;/p&gt;
&lt;p&gt;The recent &lt;a href=&#34;https://blog.rstudio.com/2020/05/27/rstudio-1-3-release/&#34;&gt;1.3 release&lt;/a&gt; of RStudio has introduced a powerful new feature: the settings are now stored as a plain text file (&lt;code&gt;rstudio-prefs.json&lt;/code&gt;) that can be manipulated programatically – e.g. by a R script.&lt;/p&gt;
&lt;p&gt;This allows me to fulfill a long time desire; an init script for new users overriding the default settings by &lt;em&gt;Jindra’s best practices&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;In my trainings I can ask my students to run this script now, and thank me later.&lt;/p&gt;
&lt;script src=&#34;https://gist.github.com/jlacko/8c6e19e59c6c78d8143e67d0f2c8eddb.js&#34;&gt;&lt;/script&gt;
&lt;p&gt;This script, which I have made available as a gist on GitHub, overrides four settings that have been the biggest pain points:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;saving workspace in .RData (never)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;loading workspace from .RData (never)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;saving history (never)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;setting UTF-8 as default character encoding&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Overriding these settings programatically is much easier than instructing my users to click the relevant checkboxes manually at the start of my trainings.&lt;/p&gt;
&lt;p&gt;The technique can be also extended easily by more seasoned users to save their settings in a version control system, such as git in general or GitHub specifically.&lt;/p&gt;
</description>
  </item>
  
<item>
  <title>Spatial Aggregation</title>
  <link>https://www.jla-data.net/eng/spatial-aggregation/</link>
  <pubDate>Wed, 12 Feb 2020 00:00:00 +0000</pubDate>
  
<guid>https://www.jla-data.net/eng/spatial-aggregation/</guid>
  <description>


&lt;p&gt;When dealing with spatial data in sales and / or social science context it is common that data are reported per administrative units (defined as polygons).&lt;/p&gt;
&lt;p&gt;This has its benefits – administrative units, such as counties, states or districts, are generally well understood by our users, and make a good base for convincing choropleth maps – but also disadvantages. Administrative areas differ greatly in size and population and are not always good inputs for modelling.&lt;/p&gt;
&lt;p&gt;To remedy this I propose three different approaches for spatial aggregation of data reported per administrative area polygons:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;based on &lt;a href=&#34;https://en.wikipedia.org/wiki/Buffer_(GIS)&#34;&gt;spatial buffers&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;based on &lt;a href=&#34;https://en.wikipedia.org/wiki/Voronoi_diagram&#34;&gt;Voronoi polygons&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;based on &lt;a href=&#34;https://en.wikipedia.org/wiki/Grid_(spatial_index)&#34;&gt;equal distance grid&lt;/a&gt; cells&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;As my post is about general techniques, and not a specific implementation, any spatial data object would do. I am choosing to demonstrate the techniques on the North Carolina shapefile that ships with &lt;code&gt;{sf}&lt;/code&gt; package, based on nothing else than its general availability (&lt;code&gt;nc.shp&lt;/code&gt; is the Iris of spatial data).&lt;/p&gt;
&lt;p&gt;All the techniques are distance related a projected CRS is thus required. Being an European, metric born &amp;amp; raised, am choosing one based on US Survey Feet; I confess I am mildly amused by the rationale behind 660 feet to a furlong.&lt;/p&gt;
&lt;p&gt;My first step is creating of 3 spatial objects:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;county data of births in the years 1979 to 1984 from the &lt;code&gt;nc.shp&lt;/code&gt; dataset; note that I calculate a column of county area (in squared survey feet); this will come handy later on&lt;/li&gt;
&lt;li&gt;NC state boundaries, obtained by dissolving the &lt;code&gt;nc.shp&lt;/code&gt; polygons&lt;/li&gt;
&lt;li&gt;point data of three semi-random cities in NC; these will be basis for the aggregation&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;library(sf)
library(dplyr)
library(ggplot2)

# NC counties - a shapefile shipped with the sf package
counties &amp;lt;- st_read(system.file(&amp;quot;shape/nc.shp&amp;quot;, package = &amp;quot;sf&amp;quot;), quiet = T) %&amp;gt;% 
  select(BIR79)  %&amp;gt;% # a single variable: births for period 1979-84
  st_transform(crs = 6543) %&amp;gt;%  # a quaint local projection
  mutate(cty_area = units::drop_units(st_area(.))) # county area (in feet)
  
# NC state borders
state &amp;lt;- counties %&amp;gt;% 
  summarize()

# three semi-random cities in NC
points &amp;lt;- data.frame(name = c(&amp;quot;Raleigh&amp;quot;, &amp;quot;Greensboro&amp;quot;, &amp;quot;Wilmington&amp;quot;),
                     x = c(-78.633333, -79.819444, -77.912222),
                     y = c(35.766667, 36.08, 34.223333)) %&amp;gt;% 
  st_as_sf(coords = c(&amp;quot;x&amp;quot;, &amp;quot;y&amp;quot;), crs = 4326) %&amp;gt;% 
  st_transform(crs = st_crs(counties))  # same as counties&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;As I will be drawing a chart of NC births a lot I am creating a convenience function to simplify this task (and to not repeat myself).&lt;/p&gt;
&lt;p&gt;The first step is to apply this function to the raw county data, and in doing so gain an overall understanding of the births metric.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;# define the function
chart &amp;lt;- function(dataframe) {
  ggplot() +
  geom_sf(data = dataframe, aes(fill = BIR79), alpha = .5, lwd = .25) +
  geom_sf(data = state, lwd = .75, fill = NA) + 
  geom_sf(data = points, color = &amp;quot;red&amp;quot;, size = 2) +
  scale_fill_gradient(trans = &amp;quot;log10&amp;quot;, 
                      low = &amp;quot;white&amp;quot;,
                      high = &amp;quot;firebrick&amp;quot;,
                      labels = scales::comma_format()) +
  labs(fill = &amp;quot;Births\n1979 - 84&amp;quot;) +
  guides(fill = guide_legend(override.aes = list(alpha = 0.5))) +
  theme(legend.text.align = 1,
        legend.title.align = 1/2)
}

# apply it to raw county data
chart(counties)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;https://www.jla-data.net/ENG/2020-02-12-spatial-aggregation_files/figure-html/overview-1.png&#34; width=&#34;100%&#34; /&gt;&lt;/p&gt;
&lt;p&gt;The second step is to prepare spatial objects that will be basis of our future aggregation.&lt;/p&gt;
&lt;p&gt;Buffers are the easiest, produced by a call to &lt;code&gt;sf::st_buffer()&lt;/code&gt; on our points data, with second argument of distance — in our case 50 miles – and then cut to shape via &lt;code&gt;sf::st_intersection()&lt;/code&gt; with the shape of NC state.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;# create the buffers object
buffers &amp;lt;- st_buffer(points, 50 * 5280) %&amp;gt;% # 50 miles circle
  st_intersection(state) # cut to shape of NC state

# display the buffers
ggplot() +
  geom_sf(data = buffers, aes(fill = name), alpha = .5) +
  geom_sf(data = state, lwd = .75, fill = NA) + 
  geom_sf(data = points, color = &amp;quot;red&amp;quot;, pch = 4, size = 2) +
  labs(fill = &amp;quot;Zone&amp;quot;)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;https://www.jla-data.net/ENG/2020-02-12-spatial-aggregation_files/figure-html/buffers-1.png&#34; width=&#34;100%&#34; /&gt;&lt;/p&gt;
&lt;p&gt;The Voronoi polygons are somewhat more challenging, as the geometry creation necessitates more steps; the &lt;code&gt;sf::st_voronoi()&lt;/code&gt; function requires as argument a &lt;code&gt;sfc&lt;/code&gt; object of &lt;code&gt;MULTIPOINT&lt;/code&gt; type. This means first extracting geometry, i.e. without any data, from the &lt;code&gt;sf&lt;/code&gt; object of points, and then merging of the list of multiple points to a single multipoint object via &lt;code&gt;sf::st_union()&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The resulting polygon is then cut to shape of NC state, converted back to &lt;code&gt;sf&lt;/code&gt; class and joined with the original point data to re-gain the dimension of city names it lost in previous steps.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;# create the voronoi object
voronoi &amp;lt;- points %&amp;gt;% 
  st_geometry() %&amp;gt;% # to get sfc from sf
  st_union() %&amp;gt;% # to get a sfc of MULTIPOINT type
  st_voronoi(envelope = st_geometry(state)) %&amp;gt;% # NC sized Voronoi polygon
  st_collection_extract(type = &amp;quot;POLYGON&amp;quot;) %&amp;gt;% # a list of polygons
  st_sf() %&amp;gt;% # from list to sf object
  st_intersection(state) %&amp;gt;% # cut to shape of NC state
  st_join(points) # put names back

# display the Voronoi polygons
ggplot() +
  geom_sf(data = voronoi, aes(fill = name), alpha = .5) +
  geom_sf(data = state, lwd = .75, fill = NA) + 
  geom_sf(data = points, color = &amp;quot;red&amp;quot;, pch = 4, size = 2) +
  labs(fill = &amp;quot;Zone&amp;quot;)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;https://www.jla-data.net/ENG/2020-02-12-spatial-aggregation_files/figure-html/voronoi-1.png&#34; width=&#34;100%&#34; /&gt;&lt;/p&gt;
&lt;p&gt;Making of a grid requires applying &lt;code&gt;sf::st_make_grid()&lt;/code&gt; to the NC state with second argument of grid cell size – in our case 50 by 50 miles; the resulting object will again be a geometry without any data (object of class &lt;code&gt;sfc&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;It is then converted back to &lt;code&gt;sf&lt;/code&gt; class, with city names re-attached. I am also creating a technical key based on row number, as I will need an unique identification of each polygon (i.e. grid cell) in later stages of our process.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;# create the grid object
grid &amp;lt;- state %&amp;gt;% 
  st_make_grid(cellsize = c(50 * 5280, 50 * 5280)) %&amp;gt;% # 50 × 50 miles
  st_sf() %&amp;gt;% # from sfc to sf
  st_intersection(state) %&amp;gt;% # cut to shape of NC state
  st_join(points) %&amp;gt;% # get names back
  mutate(id = row_number()) # generate key for later use

# display the grid
ggplot() +
  geom_sf(data = grid, aes(fill = name), alpha = .5) +
  geom_sf(data = state, lwd = .75, fill = NA) + 
  geom_sf(data = points, color = &amp;quot;red&amp;quot;, pch = 4, size = 2) +
  labs(fill = &amp;quot;Zone&amp;quot;)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;https://www.jla-data.net/ENG/2020-02-12-spatial-aggregation_files/figure-html/grid-1.png&#34; width=&#34;100%&#34; /&gt;&lt;/p&gt;
&lt;p&gt;The third step is combining the county births data with geometries of interest via &lt;code&gt;sf::st_intersection()&lt;/code&gt;.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;# naive intersection
buffers_raw &amp;lt;- buffers %&amp;gt;% 
  st_intersection(counties) # raw intersection

# this will not do for a result...
chart(buffers_raw)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;https://www.jla-data.net/ENG/2020-02-12-spatial-aggregation_files/figure-html/prusecik-buffers-raw-1.png&#34; width=&#34;100%&#34; /&gt;&lt;/p&gt;
&lt;p&gt;This obviously is not a satisfactory result, as the data retain the original county dimension.&lt;/p&gt;
&lt;p&gt;It is necessary to dissolve the counties, and assign a proportion of the births measure to each buffer polygon; it is reasonable to assume an equal density of the births metric per county area, and based on that assign births to buffer in proportion of the county area contained in the buffer.&lt;/p&gt;
&lt;p&gt;From technical perspective it is necessary to have two items in place before this step:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;total area of source polygons (the intersection will split some county polygons, so the original area has to be calculated beforehand)&lt;/li&gt;
&lt;li&gt;unique id of target polygon, which will serve as a grouping variable; for the buffers and Voronoi polygons city name is OK, for the grid a technical id is necessary&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;# new data object based on buffers
buffers_data &amp;lt;- buffers %&amp;gt;% 
  st_intersection(counties) %&amp;gt;% # raw intersection
  mutate(in_area = units::drop_units(st_area(.))) %&amp;gt;% # area of polygon
  # calculate a proportion of births equal to proportion of area
  mutate(BIR79 = BIR79 * in_area / cty_area) %&amp;gt;% 
  group_by(name) %&amp;gt;% # group by name of buffer
  summarise(BIR79 = sum(BIR79)) # total of births in named buffer

# plot the results
chart(buffers_data)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;https://www.jla-data.net/ENG/2020-02-12-spatial-aggregation_files/figure-html/prusecik-buffers-fin-1.png&#34; width=&#34;100%&#34; /&gt;&lt;/p&gt;
&lt;p&gt;The technique to assign birth data to Voronoi polygons is exactly the same as for the spatial buffers.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;# new data object based on Voronoi polygons
voronoi_data &amp;lt;- voronoi %&amp;gt;% 
  st_intersection(counties) %&amp;gt;% # raw intresection
  mutate(in_area = units::drop_units(st_area(.))) %&amp;gt;% # area of polygon
  # calculate a proportion of births equal to proportion of area
  mutate(BIR79 = BIR79 * in_area / cty_area) %&amp;gt;% 
  group_by(name) %&amp;gt;% # group by name of Voronoi polygon
  summarise(BIR79 = sum(BIR79)) # total of births in named polygon

# plot the results
chart(voronoi_data)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;https://www.jla-data.net/ENG/2020-02-12-spatial-aggregation_files/figure-html/prusecik-voronoi-1.png&#34; width=&#34;100%&#34; /&gt;&lt;/p&gt;
&lt;p&gt;Two important differences between buffers and Voronoi polygons are that:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;the Voronoi polygons are not overlapping&lt;/li&gt;
&lt;li&gt;the Voronoi polygons cover the entire NC state&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This has the consequence that we can confirm our result of our calculation by comparing the totals per county with totals per Voronoi polygons; we can reasonable expect these two to be equal (there is no double counting, and the entire state is covered).&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;# checksum - do the totals add up?
all.equal(sum(counties$BIR79), sum(voronoi_data$BIR79)) &lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;## [1] TRUE&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Lastly we consider the grid cells.&lt;/p&gt;
&lt;p&gt;The technique is again the same – assign to each grid cell a proportion of county births equal to the proportion of county area.&lt;/p&gt;
&lt;p&gt;In this case the technical key of grid cells comes handy as grouping variable, as there are more grid cells than city points.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;# new data object based on grid
grid_data &amp;lt;- grid %&amp;gt;% 
  st_intersection(counties) %&amp;gt;% # raw intersection
  mutate(in_area = units::drop_units(st_area(.))) %&amp;gt;% # area of cell
  # calculate a proportion of births equal to proportion of area
  mutate(BIR79 = BIR79 * in_area / cty_area) %&amp;gt;% 
  group_by(id) %&amp;gt;% # group by id of grid cell
  summarise(BIR79 = sum(BIR79)) # total of births in cell by id

# plot the results
chart(grid_data)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;https://www.jla-data.net/ENG/2020-02-12-spatial-aggregation_files/figure-html/prusecik-grid-1.png&#34; width=&#34;100%&#34; /&gt;&lt;/p&gt;
&lt;p&gt;Again, as the cells (like the Voronoi polygons, and unlike the buffers) cover the entire area of NC state with zero overlap it makes sense to compare the totals.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;# checksum - do the totals add up?
all.equal(sum(counties$BIR79), sum(grid_data$BIR79)) &lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;## [1] TRUE&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The final step is considering which spatial aggregation technique is the most appropriate in your use case.&lt;/p&gt;
&lt;p&gt;This is (obviously) impossible to determine without some understanding of your use case.&lt;/p&gt;
&lt;p&gt;A few rules of thumb to consider are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;buffers&lt;/strong&gt; are often a good idea when considering “bad” things – such as number of burglaries in the neighborhood; such metrics can spoil the figures for multiple areas of interest without diminishing.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Voronoi polygons&lt;/strong&gt; are a good idea when considering “nice” things – such as potential customers, who will either visit store A or store B, but not both, for their shopping.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;grid cells&lt;/strong&gt; are good idea when you need to consider not only a &lt;em&gt;presence&lt;/em&gt; of something, but also an &lt;em&gt;absence&lt;/em&gt; of the thing – cells being empty carry information. Grid cells also create the illusion of impartiality – the entire region is covered, and even cells &lt;em&gt;seem&lt;/em&gt; fair.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
</description>
  </item>
  
<item>
  <title>Interactive Map Generator</title>
  <link>https://www.jla-data.net/eng/jla-leaflet-generator/</link>
  <pubDate>Thu, 12 Dec 2019 00:00:00 +0000</pubDate>
  
<guid>https://www.jla-data.net/eng/jla-leaflet-generator/</guid>
  <description>
&lt;script src=&#34;https://www.jla-data.net/rmarkdown-libs/header-attrs/header-attrs.js&#34;&gt;&lt;/script&gt;


&lt;p&gt;While R, &lt;code&gt;{leaflet}&lt;/code&gt; package from RStudio and the Javascript &lt;a href=&#34;https://leafletjs.com/&#34;&gt;leaflet.js&lt;/a&gt; library are open source tools, available in principle to everybody, not everybody has the technical skill, resources or inclination to master them.&lt;/p&gt;
&lt;p&gt;To make mapping of point data accessible to a wider audience I propose this app, built in Shiny and hosted on &lt;a href=&#34;https://shinyapps.io&#34; class=&#34;uri&#34;&gt;https://shinyapps.io&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;It takes a single input (a MS Excel file; scroll down for a link to a sample) and produces two outputs:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;a downloadable file in html format containing both the map and the leaflet.js library, so it can be used in a general html context, for example in an iframe&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;a downloadable excel file with identifed errors in input coordinates (if any)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div align=&#34;center&#34;&gt;
&lt;iframe src=&#34;https://jlacko.shinyapps.io/listek-eng/&#34; width=&#34;800&#34; height=&#34;600&#34; style=&#34;border: none; display:block;&#34;&gt;
&lt;/iframe&gt;
&lt;/div&gt;
&lt;p&gt;The app expects as input an &lt;em&gt;xlsx&lt;/em&gt; file with 6 columns:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;em&gt;id&lt;/em&gt; – primary key, bold first line of a popup&lt;/li&gt;
&lt;li&gt;&lt;em&gt;lng&lt;/em&gt; – longitude of a point coordinate&lt;/li&gt;
&lt;li&gt;&lt;em&gt;lat&lt;/em&gt; – latitude of a point coordinate&lt;/li&gt;
&lt;li&gt;&lt;em&gt;category&lt;/em&gt; – category of points; determines color of markers&lt;/li&gt;
&lt;li&gt;&lt;em&gt;label&lt;/em&gt; – body of popup; may contain HTML code if required&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;A sample of data in expected structure can be downloaded by following &lt;a href=&#34;https://github.com/jlacko/leaflet-generator/raw/master/data-raw/sample.xlsx?raw=true&#34;&gt;this link&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;A note to users: it is perfectly OK to use HTML links (anchor tags) in the label field.
However, if you are to use the map in an iframe it is advisable to specify &lt;code&gt;target=&#34;_blank&#34;&lt;/code&gt;, so the link opens in a new browser tab (and not the original iframe). It will look much better that way.&lt;/p&gt;
</description>
  </item>
  
<item>
  <title>Merging Geometry of {sf} Objects in R</title>
  <link>https://www.jla-data.net/eng/merging-geometry-of-sf-objects-in-r/</link>
  <pubDate>Tue, 15 Oct 2019 00:00:00 +0000</pubDate>
  
<guid>https://www.jla-data.net/eng/merging-geometry-of-sf-objects-in-r/</guid>
  <description>


&lt;p&gt;A frequent use case in spatial data processing is merging multiple geometries. In my line of work this usually involves merging polygons of administrative regions to larger, seemingly arbitrary, units – sales areas and what not.&lt;/p&gt;
&lt;p&gt;In the olden days of &lt;code&gt;{sp}&lt;/code&gt;, when shapefiles were S3 objects &lt;em&gt;sui generis&lt;/em&gt;, this was not exactly easy. Now, with the &lt;code&gt;{sf}&lt;/code&gt; package, when spatial objects are modified &lt;code&gt;data.frames&lt;/code&gt; (and &lt;code&gt;data.frame&lt;/code&gt; manipulation is supported by the mighty &lt;code&gt;{dplyr}&lt;/code&gt;) this process is much less challenging.&lt;/p&gt;
&lt;p&gt;In fact it is so easy it might seem like magic.&lt;/p&gt;
&lt;p&gt;To demonstrate the workflow I am using the North Carolina shapefile from the &lt;code&gt;{sf}&lt;/code&gt; package, and a data frame of three semi random cities.&lt;/p&gt;
&lt;p&gt;To make the process more fun (for an European, metric born &amp;amp; raised) I am projecting the data to a quaint local CRS denominated in US survey feet.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;library(sf)
library(dplyr)
library(ggplot2)

# NC counties as polygons - a shapefile shipped with the sf package
counties &amp;lt;- st_read(system.file(&amp;quot;shape/nc.shp&amp;quot;, package = &amp;quot;sf&amp;quot;), quiet = T) %&amp;gt;% 
  st_transform(2264) # a feety CRS, to make it interesting :)

# three NC cities as points
points &amp;lt;- data.frame(name = c(&amp;quot;Raleigh&amp;quot;, &amp;quot;Greensboro&amp;quot;, &amp;quot;Wilmington&amp;quot;),
                     x = c(-78.633333, -79.819444, -77.912222),
                     y = c(35.766667, 36.08, 34.223333)) %&amp;gt;% 
  st_as_sf(coords = c(&amp;quot;x&amp;quot;, &amp;quot;y&amp;quot;), crs = 4326) %&amp;gt;% 
  st_transform(2264) # transform to a feety CRS


# buffer of 50 miles around Raleigh city centre
buffer &amp;lt;- st_buffer(subset(points, name == &amp;quot;Raleigh&amp;quot;), 5280 * 50)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;First a simple overview of my spatial objects:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;100 counties of North Carolina&lt;/li&gt;
&lt;li&gt;3 cities in NC as points&lt;/li&gt;
&lt;li&gt;a red buffer of 50 miles around Raleigh (the state capital)&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;ggplot() +
  geom_sf(data = counties) +
  geom_sf(data = points, aes(color = name), show.legend = &amp;quot;point&amp;quot;) +
  geom_sf(data = buffer, fill = NA, color = &amp;quot;red&amp;quot;) +
  scale_color_viridis_d() +
  theme(legend.position = &amp;quot;bottom&amp;quot;) +
  labs(color = &amp;quot;City name:&amp;quot;)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;https://www.jla-data.net/ENG/2019-10-15-merging-geometry-of-sf-objects-in-r_files/figure-html/overview-1.png&#34; width=&#34;100%&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;p&gt;The first step is determining which counties are at least partly covered by the red buffer.&lt;/p&gt;
&lt;p&gt;The best way to handle this is via &lt;code&gt;sf::st_intersects()&lt;/code&gt; and setting the &lt;code&gt;sparse&lt;/code&gt; argument to false (so a logical vector will be returned).&lt;/p&gt;
&lt;p&gt;In this case the logical vector is recoded to “yes” / “no” string values via &lt;code&gt;ifelse()&lt;/code&gt;.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;counties$close2raleigh &amp;lt;- ifelse(sf::st_intersects(counties, buffer, sparse = F), 
                                 &amp;quot;Yes&amp;quot;, 
                                 &amp;quot;No&amp;quot;)

glimpse(counties)&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;## Observations: 100
## Variables: 16
## $ AREA          &amp;lt;dbl&amp;gt; 0.114, 0.061, 0.143, 0.070, 0.153, 0.097, 0.062, 0…
## $ PERIMETER     &amp;lt;dbl&amp;gt; 1.442, 1.231, 1.630, 2.968, 2.206, 1.670, 1.547, 1…
## $ CNTY_         &amp;lt;dbl&amp;gt; 1825, 1827, 1828, 1831, 1832, 1833, 1834, 1835, 18…
## $ CNTY_ID       &amp;lt;dbl&amp;gt; 1825, 1827, 1828, 1831, 1832, 1833, 1834, 1835, 18…
## $ NAME          &amp;lt;fct&amp;gt; Ashe, Alleghany, Surry, Currituck, Northampton, He…
## $ FIPS          &amp;lt;fct&amp;gt; 37009, 37005, 37171, 37053, 37131, 37091, 37029, 3…
## $ FIPSNO        &amp;lt;dbl&amp;gt; 37009, 37005, 37171, 37053, 37131, 37091, 37029, 3…
## $ CRESS_ID      &amp;lt;int&amp;gt; 5, 3, 86, 27, 66, 46, 15, 37, 93, 85, 17, 79, 39, …
## $ BIR74         &amp;lt;dbl&amp;gt; 1091, 487, 3188, 508, 1421, 1452, 286, 420, 968, 1…
## $ SID74         &amp;lt;dbl&amp;gt; 1, 0, 5, 1, 9, 7, 0, 0, 4, 1, 2, 16, 4, 4, 4, 18, …
## $ NWBIR74       &amp;lt;dbl&amp;gt; 10, 10, 208, 123, 1066, 954, 115, 254, 748, 160, 5…
## $ BIR79         &amp;lt;dbl&amp;gt; 1364, 542, 3616, 830, 1606, 1838, 350, 594, 1190, …
## $ SID79         &amp;lt;dbl&amp;gt; 0, 3, 6, 2, 3, 5, 2, 2, 2, 5, 2, 5, 4, 4, 6, 17, 4…
## $ NWBIR79       &amp;lt;dbl&amp;gt; 19, 12, 260, 145, 1197, 1237, 139, 371, 844, 176, …
## $ geometry      &amp;lt;MULTIPOLYGON [US_survey_foot]&amp;gt; MULTIPOLYGON (((1270814 …
## $ close2raleigh &amp;lt;chr[,1]&amp;gt; &amp;quot;No&amp;quot;, &amp;quot;No&amp;quot;, &amp;quot;No&amp;quot;, &amp;quot;No&amp;quot;, &amp;quot;No&amp;quot;, &amp;quot;No&amp;quot;, &amp;quot;No&amp;quot;, &amp;quot;No&amp;quot;…&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The dataset now has 100 observations (counties) with 16 variables (including the special geometry column).&lt;/p&gt;
&lt;p&gt;Of the 100 counties in NC there are 25 that are at least partly covered by the 50 mile buffer around Raleigh.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;ggplot() +
  geom_sf(data = counties, aes(fill = close2raleigh)) +
  geom_sf(data = subset(points, name == &amp;quot;Raleigh&amp;quot;), pch = 4, color = &amp;quot;red&amp;quot;) +
  geom_sf(data = buffer, fill = NA, color = &amp;quot;red&amp;quot;) +
  scale_fill_viridis_d() +
  theme(legend.position = &amp;quot;bottom&amp;quot;) +
  labs(fill = &amp;quot;Close to Raleigh?&amp;quot;)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;https://www.jla-data.net/ENG/2019-10-15-merging-geometry-of-sf-objects-in-r_files/figure-html/chart-first-1.png&#34; width=&#34;100%&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;p&gt;The “magic” part of merging the counties according to the value of &lt;code&gt;close2raleigh&lt;/code&gt; column is straightforward – performing a &lt;code&gt;dplyr::group_by()&lt;/code&gt; followed by &lt;code&gt;dplyr::summarize()&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;In many cases it would be advantageous to perform some additional calculations, such as summarizing population or customer potential of the areas; in this example I have omitted this for the sake of clarity and focused on the merging operation only.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;counties &amp;lt;- counties %&amp;gt;% 
  group_by(close2raleigh) %&amp;gt;% 
  summarise()

glimpse(counties)&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;## Observations: 2
## Variables: 2
## $ close2raleigh &amp;lt;chr&amp;gt; &amp;quot;No&amp;quot;, &amp;quot;Yes&amp;quot;
## $ geometry      &amp;lt;GEOMETRY [US_survey_foot]&amp;gt; MULTIPOLYGON (((2739147 314.…&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The merged dataset now has only two variables – the &lt;code&gt;close2raleigh&lt;/code&gt; grouping variable, plus the special geometry column. It has two observations, one for each “yes” and “no” value of &lt;code&gt;close2raleigh&lt;/code&gt;.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;ggplot() +
  geom_sf(data = counties, aes(fill = close2raleigh)) +
  geom_sf(data = subset(points, name == &amp;quot;Raleigh&amp;quot;), pch = 4, color = &amp;quot;red&amp;quot;) +
  geom_sf(data = buffer, fill = NA, color = &amp;quot;red&amp;quot;) +
  scale_fill_viridis_d() +
  theme(legend.position = &amp;quot;bottom&amp;quot;) +
  labs(fill = &amp;quot;Close to Raleigh?&amp;quot;)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;https://www.jla-data.net/ENG/2019-10-15-merging-geometry-of-sf-objects-in-r_files/figure-html/chart-second-1.png&#34; width=&#34;100%&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;p&gt;A basic understanding of &lt;code&gt;dplyr&lt;/code&gt; data manipulation is by now common. On the other hand the application of the &lt;code&gt;dplyr&lt;/code&gt; verbs to spatial data science workflow is not that well discussed, and in my opinion an interesting simplification in a number of use cases.&lt;/p&gt;
</description>
  </item>
  
<item>
  <title>Leaflet in R</title>
  <link>https://www.jla-data.net/eng/leaflet-in-r-tips-and-tricks/</link>
  <pubDate>Wed, 17 Jul 2019 00:00:00 +0000</pubDate>
  
<guid>https://www.jla-data.net/eng/leaflet-in-r-tips-and-tricks/</guid>
  <description>
&lt;script src=&#34;https://www.jla-data.net/rmarkdown-libs/htmlwidgets/htmlwidgets.js&#34;&gt;&lt;/script&gt;
&lt;script src=&#34;https://www.jla-data.net/rmarkdown-libs/jquery/jquery-3.6.0.min.js&#34;&gt;&lt;/script&gt;
&lt;link href=&#34;https://www.jla-data.net/rmarkdown-libs/leaflet/leaflet.css&#34; rel=&#34;stylesheet&#34; /&gt;
&lt;script src=&#34;https://www.jla-data.net/rmarkdown-libs/leaflet/leaflet.js&#34;&gt;&lt;/script&gt;
&lt;link href=&#34;https://www.jla-data.net/rmarkdown-libs/leafletfix/leafletfix.css&#34; rel=&#34;stylesheet&#34; /&gt;
&lt;script src=&#34;https://www.jla-data.net/rmarkdown-libs/proj4/proj4.min.js&#34;&gt;&lt;/script&gt;
&lt;script src=&#34;https://www.jla-data.net/rmarkdown-libs/Proj4Leaflet/proj4leaflet.js&#34;&gt;&lt;/script&gt;
&lt;link href=&#34;https://www.jla-data.net/rmarkdown-libs/rstudio_leaflet/rstudio_leaflet.css&#34; rel=&#34;stylesheet&#34; /&gt;
&lt;script src=&#34;https://www.jla-data.net/rmarkdown-libs/leaflet-binding/leaflet.js&#34;&gt;&lt;/script&gt;
&lt;script src=&#34;https://www.jla-data.net/rmarkdown-libs/leaflet-providers/leaflet-providers_2.0.0.js&#34;&gt;&lt;/script&gt;
&lt;script src=&#34;https://www.jla-data.net/rmarkdown-libs/leaflet-providers-plugin/leaflet-providers-plugin.js&#34;&gt;&lt;/script&gt;
&lt;link href=&#34;https://www.jla-data.net/rmarkdown-libs/leaflet-markercluster/MarkerCluster.css&#34; rel=&#34;stylesheet&#34; /&gt;
&lt;link href=&#34;https://www.jla-data.net/rmarkdown-libs/leaflet-markercluster/MarkerCluster.Default.css&#34; rel=&#34;stylesheet&#34; /&gt;
&lt;script src=&#34;https://www.jla-data.net/rmarkdown-libs/leaflet-markercluster/leaflet.markercluster.js&#34;&gt;&lt;/script&gt;
&lt;script src=&#34;https://www.jla-data.net/rmarkdown-libs/leaflet-markercluster/leaflet.markercluster.freezable.js&#34;&gt;&lt;/script&gt;
&lt;script src=&#34;https://www.jla-data.net/rmarkdown-libs/leaflet-markercluster/leaflet.markercluster.layersupport.js&#34;&gt;&lt;/script&gt;
&lt;link href=&#34;https://www.jla-data.net/rmarkdown-libs/leaflet-easybutton/easy-button.css&#34; rel=&#34;stylesheet&#34; /&gt;
&lt;script src=&#34;https://www.jla-data.net/rmarkdown-libs/leaflet-easybutton/easy-button.js&#34;&gt;&lt;/script&gt;
&lt;script src=&#34;https://www.jla-data.net/rmarkdown-libs/leaflet-easybutton/EasyButton-binding.js&#34;&gt;&lt;/script&gt;
&lt;link href=&#34;https://www.jla-data.net/rmarkdown-libs/ionicons/ionicons.min.css&#34; rel=&#34;stylesheet&#34; /&gt;


&lt;p&gt;Interactive maps are a powerful visualization tool, and the JavaScript library &lt;a href=&#34;https://en.wikipedia.org/wiki/Leaflet_(software)&#34;&gt;leaflet.js&lt;/a&gt; is a great means to achieving this objective. The &lt;a href=&#34;https://rstudio.github.io/leaflet/&#34;&gt;{leaflet}&lt;/a&gt; package from &lt;a href=&#34;https://www.rstudio.com&#34;&gt;RStudio&lt;/a&gt; makes this library accessible from R.&lt;/p&gt;
&lt;p&gt;The package documentation is good, but as the interactive visualization is usually the last step of a complex process I felt the need to share some of my lessons learned.&lt;/p&gt;
&lt;p&gt;For this demonstrations I am using a data frame of seven government buildings in the Czech Republic, but the actual choice of points is not that crucial – what I found nice for demonstration purposes is that:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;the seven buildings are in two separate cities&lt;/li&gt;
&lt;li&gt;can be grouped to three branches of power&lt;/li&gt;
&lt;li&gt;have both names and links to Wikipedia entries&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The first step is creating the the data frame and making it feel spatial via the excellent &lt;code&gt;{sf}&lt;/code&gt; package. By using a spatial data frame as &lt;code&gt;data&lt;/code&gt; object of our &lt;code&gt;leaflet&lt;/code&gt; call we are absolved from the need to specify longitude and latitude. This would be hassle (but doable) for points, but next to impossible for polygons.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;library(sf)             # for working with spatial data
library(dplyr)          # data frame manipulation
library(leaflet)        # because leaflet :)
library(htmltools)      # tools to support html workflow
library(rnaturalearth)  # interface to https://www.naturalearthdata.com/
library(leaflet.extras) # extending the leaflet.js


# set up a data frame of points
body &amp;lt;- data.frame(name = c(&amp;quot;Kramářova vila&amp;quot;, &amp;quot;Pražský hrad&amp;quot;, &amp;quot;Strakova akademie&amp;quot;, &amp;quot;Nejvyšší soud&amp;quot;, &amp;quot;Ústavní soud&amp;quot;, &amp;quot;Sněmovna&amp;quot;, &amp;quot;Senát&amp;quot;),
                   branch = c(&amp;quot;executive&amp;quot;, &amp;quot;executive&amp;quot;, &amp;quot;executive&amp;quot;, &amp;quot;judiciary&amp;quot;, &amp;quot;judiciary&amp;quot;, &amp;quot;legislature&amp;quot;, &amp;quot;legislature&amp;quot;),
                   link = c(&amp;quot;https://en.wikipedia.org/wiki/Kram%C3%A1%C5%99%27s_Villa&amp;quot;,
                            &amp;quot;https://en.wikipedia.org/wiki/Prague_Castle&amp;quot;,
                            &amp;quot;https://en.wikipedia.org/wiki/Straka_Academy&amp;quot;,
                            &amp;quot;https://en.wikipedia.org/wiki/Supreme_Court_of_the_Czech_Republic&amp;quot;,
                            &amp;quot;https://en.wikipedia.org/wiki/Constitutional_Court_of_the_Czech_Republic&amp;quot;,
                            &amp;quot;https://en.wikipedia.org/wiki/Chamber_of_Deputies_of_the_Czech_Republic&amp;quot;,
                            &amp;quot;https://en.wikipedia.org/wiki/Senate_of_the_Czech_Republic&amp;quot;),
                   lat = c(14.4104392, 14.3990089, 14.4117831, 16.6021958, 16.6044039, 14.4039458, 14.4053489),
                   lon = c(50.0933681, 50.0895897, 50.0920997, 49.2051925, 49.1977642, 50.0891494, 50.0900269))


# transform the data frame from plain vanilla one to spatial
body &amp;lt;- body %&amp;gt;% 
  sf::st_as_sf(coords = c(&amp;quot;lat&amp;quot;, &amp;quot;lon&amp;quot;), # columns with geometry
               crs = 4326) # WGS84 is a sensible default...&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The first and easiest (“hello word”) call to leaflet takes just four lines of code.&lt;/p&gt;
&lt;p&gt;What it does is:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;declare a leaflet object (with our spatial data frame as &lt;code&gt;data&lt;/code&gt; object)&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;add a basemap layer&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;add a data layer – markers showing our seven buildings&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;display the prepared leaflet object&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;With regards to basemap and formatting it relies on (usually sensible) defaults.&lt;/p&gt;
&lt;p&gt;It may not be overwhelming, but it is a start.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;# first prepare a leaflet plot ...
lplot &amp;lt;- leaflet::leaflet(data = body) %&amp;gt;% # create leaflet object
  leaflet::addTiles() %&amp;gt;% # add basemap
  leaflet::addMarkers() # add data layer - markers

lplot #  ... then display it&lt;/code&gt;&lt;/pre&gt;
&lt;div class=&#34;leaflet html-widget html-fill-item&#34; id=&#34;htmlwidget-1&#34; style=&#34;width:100%;height:480px;&#34;&gt;&lt;/div&gt;
&lt;script type=&#34;application/json&#34; data-for=&#34;htmlwidget-1&#34;&gt;{&#34;x&#34;:{&#34;options&#34;:{&#34;crs&#34;:{&#34;crsClass&#34;:&#34;L.CRS.EPSG3857&#34;,&#34;code&#34;:null,&#34;proj4def&#34;:null,&#34;projectedBounds&#34;:null,&#34;options&#34;:{}}},&#34;calls&#34;:[{&#34;method&#34;:&#34;addTiles&#34;,&#34;args&#34;:[&#34;https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png&#34;,null,null,{&#34;minZoom&#34;:0,&#34;maxZoom&#34;:18,&#34;tileSize&#34;:256,&#34;subdomains&#34;:&#34;abc&#34;,&#34;errorTileUrl&#34;:&#34;&#34;,&#34;tms&#34;:false,&#34;noWrap&#34;:false,&#34;zoomOffset&#34;:0,&#34;zoomReverse&#34;:false,&#34;opacity&#34;:1,&#34;zIndex&#34;:1,&#34;detectRetina&#34;:false,&#34;attribution&#34;:&#34;&amp;copy; &lt;a href=\&#34;https://openstreetmap.org/copyright/\&#34;&gt;OpenStreetMap&lt;\/a&gt;,  &lt;a href=\&#34;https://opendatacommons.org/licenses/odbl/\&#34;&gt;ODbL&lt;\/a&gt;&#34;}]},{&#34;method&#34;:&#34;addMarkers&#34;,&#34;args&#34;:[[50.0933681,50.0895897,50.0920997,49.2051925,49.1977642,50.0891494,50.0900269],[14.4104392,14.3990089,14.4117831,16.6021958,16.6044039,14.4039458,14.4053489],null,null,null,{&#34;interactive&#34;:true,&#34;draggable&#34;:false,&#34;keyboard&#34;:true,&#34;title&#34;:&#34;&#34;,&#34;alt&#34;:&#34;&#34;,&#34;zIndexOffset&#34;:0,&#34;opacity&#34;:1,&#34;riseOnHover&#34;:false,&#34;riseOffset&#34;:250},null,null,null,null,null,{&#34;interactive&#34;:false,&#34;permanent&#34;:false,&#34;direction&#34;:&#34;auto&#34;,&#34;opacity&#34;:1,&#34;offset&#34;:[0,0],&#34;textsize&#34;:&#34;10px&#34;,&#34;textOnly&#34;:false,&#34;className&#34;:&#34;&#34;,&#34;sticky&#34;:true},null]}],&#34;limits&#34;:{&#34;lat&#34;:[49.1977642,50.0933681],&#34;lng&#34;:[14.3990089,16.6044039]}},&#34;evals&#34;:[],&#34;jsHooks&#34;:[]}&lt;/script&gt;
&lt;p&gt;&lt;br&gt;&lt;/p&gt;
&lt;p&gt;An important aspect of working with leaflet is saving your work – this allows you to create a visualization while in R, and utilize it somewhere else in a general HTML context. Such as embedding in a website, or attaching to an email.&lt;/p&gt;
&lt;p&gt;This is easily done via &lt;code&gt;save_html&lt;/code&gt; function from the &lt;a href=&#34;https://github.com/rstudio/htmltools&#34;&gt;&lt;code&gt;{htmltools}&lt;/code&gt;&lt;/a&gt; package.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;# saving the prepared leaflet plot as a html file
htmltools::save_html(lplot, &amp;quot;leaflet.html&amp;quot;)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The default settings of leaflet maps are okayish, but some extra work is usually required before you can consider your output presentation worthy.&lt;/p&gt;
&lt;p&gt;The two most common tweaks are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;change the basemap – I find the default basemap too colorful, and as consequence distracting. &lt;a href=&#34;https://carto.com/blog/getting-to-know-positron-and-dark-matter/&#34;&gt;Positron&lt;/a&gt; from Carto gives a subtle hint of color, and reminds me of Toner basemap from Stamen that is no more&lt;/li&gt;
&lt;li&gt;label the markers – it is the labels that gives a real meaning to the points of interest&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For labeling the markers it is necessary to map a column containing the popup text via tilde (~) operator to &lt;code&gt;popup&lt;/code&gt; argument of the &lt;code&gt;addMarkers&lt;/code&gt; call.&lt;/p&gt;
&lt;p&gt;Not strictly necessary, but still a good practice, especially when dealing with data frames from uncertain sources, is sanitizing the text of the label for unexpected characters by wrapping it in &lt;code&gt;htmlEscape&lt;/code&gt; function from &lt;a href=&#34;https://github.com/rstudio/htmltools&#34;&gt;&lt;code&gt;{htmltools}&lt;/code&gt;&lt;/a&gt; package.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;# first prepare a leaflet plot ...
lplot &amp;lt;- leaflet(body) %&amp;gt;% 
  leaflet::addProviderTiles(&amp;quot;CartoDB.Positron&amp;quot;) %&amp;gt;% 
  addMarkers(popup = ~htmltools::htmlEscape(name)) # note the tilde! ~

lplot #  ... then display it&lt;/code&gt;&lt;/pre&gt;
&lt;div class=&#34;leaflet html-widget html-fill-item&#34; id=&#34;htmlwidget-2&#34; style=&#34;width:100%;height:480px;&#34;&gt;&lt;/div&gt;
&lt;script type=&#34;application/json&#34; data-for=&#34;htmlwidget-2&#34;&gt;{&#34;x&#34;:{&#34;options&#34;:{&#34;crs&#34;:{&#34;crsClass&#34;:&#34;L.CRS.EPSG3857&#34;,&#34;code&#34;:null,&#34;proj4def&#34;:null,&#34;projectedBounds&#34;:null,&#34;options&#34;:{}}},&#34;calls&#34;:[{&#34;method&#34;:&#34;addProviderTiles&#34;,&#34;args&#34;:[&#34;CartoDB.Positron&#34;,null,null,{&#34;errorTileUrl&#34;:&#34;&#34;,&#34;noWrap&#34;:false,&#34;detectRetina&#34;:false}]},{&#34;method&#34;:&#34;addMarkers&#34;,&#34;args&#34;:[[50.0933681,50.0895897,50.0920997,49.2051925,49.1977642,50.0891494,50.0900269],[14.4104392,14.3990089,14.4117831,16.6021958,16.6044039,14.4039458,14.4053489],null,null,null,{&#34;interactive&#34;:true,&#34;draggable&#34;:false,&#34;keyboard&#34;:true,&#34;title&#34;:&#34;&#34;,&#34;alt&#34;:&#34;&#34;,&#34;zIndexOffset&#34;:0,&#34;opacity&#34;:1,&#34;riseOnHover&#34;:false,&#34;riseOffset&#34;:250},[&#34;Kramářova vila&#34;,&#34;Pražský hrad&#34;,&#34;Strakova akademie&#34;,&#34;Nejvyšší soud&#34;,&#34;Ústavní soud&#34;,&#34;Sněmovna&#34;,&#34;Senát&#34;],null,null,null,null,{&#34;interactive&#34;:false,&#34;permanent&#34;:false,&#34;direction&#34;:&#34;auto&#34;,&#34;opacity&#34;:1,&#34;offset&#34;:[0,0],&#34;textsize&#34;:&#34;10px&#34;,&#34;textOnly&#34;:false,&#34;className&#34;:&#34;&#34;,&#34;sticky&#34;:true},null]}],&#34;limits&#34;:{&#34;lat&#34;:[49.1977642,50.0933681],&#34;lng&#34;:[14.3990089,16.6044039]}},&#34;evals&#34;:[],&#34;jsHooks&#34;:[]}&lt;/script&gt;
&lt;p&gt;&lt;br&gt;&lt;/p&gt;
&lt;p&gt;The points form two distinct clusters – the government and Parliament are in Prague, while the two top courts sit in Brno. This makes navigating the map sort of tricky.&lt;/p&gt;
&lt;p&gt;One way to remedy this is to group the markers in clusters. An useful feature of clusters is that they zoom in once clicked.&lt;/p&gt;
&lt;p&gt;Clusters are formed via the &lt;code&gt;clusterOptions&lt;/code&gt; argument of a markers call; the default &lt;code&gt;clusterOptions = markerClusterOptions()&lt;/code&gt; is good in vast majority of cases.&lt;/p&gt;
&lt;p&gt;When we created a way to zoom the map to a very fine detail (via double clicking a cluster) it is good idea to add a feature to restore the zoom level to its original setting, showing the full map. This is done the easiest via &lt;code&gt;addResetMapButton()&lt;/code&gt; from the &lt;a href=&#34;https://bhaskarvk.github.io/leaflet.extras/&#34;&gt;&lt;code&gt;{leaflet.extras}&lt;/code&gt;&lt;/a&gt; package.&lt;/p&gt;
&lt;p&gt;Finally we are replacing the default teardrop shaped markers with dots via &lt;code&gt;addCircleMarkers()&lt;/code&gt; instead of plain &lt;code&gt;addMarkers()&lt;/code&gt; function. The circles / dots have more mapable features than plain markers, and therefore can carry more information.&lt;/p&gt;
&lt;p&gt;In this case I am using color to show information about the branches of the government. The variable is an obviously categorical one, and I am first creating a palette mapping the branch to color via a named vector using &lt;code&gt;colorFactor()&lt;/code&gt; function from &lt;code&gt;{leaflet}&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The palette is then used twice:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;first in the &lt;code&gt;color&lt;/code&gt; argument of the &lt;code&gt;addCircleMarkers&lt;/code&gt; function to give color to the markers&lt;/li&gt;
&lt;li&gt;secondly in the &lt;code&gt;pal&lt;/code&gt; argument of the &lt;code&gt;addLegend&lt;/code&gt; function to give explanation of the colors used in map legend&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In a different context we might also consider:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;mapping the &lt;code&gt;radius&lt;/code&gt; of the dots to a numeric variable and have the size of markers vary&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;creating the palette via a &lt;code&gt;colorNumeric()&lt;/code&gt; call and map the intensity of color of the dots to a numeric variable&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;# prepare a palette - manual colors according to branch column
palPwr &amp;lt;- leaflet::colorFactor(palette = c(&amp;quot;executive&amp;quot; = &amp;quot;red&amp;quot;, 
                                           &amp;quot;judiciary&amp;quot; = &amp;quot;goldenrod&amp;quot;, 
                                           &amp;quot;legislature&amp;quot; = &amp;quot;steelblue&amp;quot;), 
                               domain = body$branch)

# first prepare a leaflet plot ...
lplot &amp;lt;- leaflet(body) %&amp;gt;% 
  addProviderTiles(&amp;quot;CartoDB.Positron&amp;quot;) %&amp;gt;% 
  addCircleMarkers(radius = 10, # size of the dots
                   fillOpacity = .7, # alpha of the dots
                   stroke = FALSE, # no outline
                   popup = ~htmlEscape(name),
                   color = palPwr(body$branch),
                   clusterOptions = markerClusterOptions()) %&amp;gt;% 
  leaflet::addLegend(position = &amp;quot;bottomright&amp;quot;,
            values = ~branch, # data frame column for legend
            opacity = .7, # alpha of the legend
            pal = palPwr, # palette declared earlier
            title = &amp;quot;Branch&amp;quot;) %&amp;gt;%  # legend title
  leaflet.extras::addResetMapButton()

lplot #  ... then display it&lt;/code&gt;&lt;/pre&gt;
&lt;div class=&#34;leaflet html-widget html-fill-item&#34; id=&#34;htmlwidget-3&#34; style=&#34;width:100%;height:480px;&#34;&gt;&lt;/div&gt;
&lt;script type=&#34;application/json&#34; data-for=&#34;htmlwidget-3&#34;&gt;{&#34;x&#34;:{&#34;options&#34;:{&#34;crs&#34;:{&#34;crsClass&#34;:&#34;L.CRS.EPSG3857&#34;,&#34;code&#34;:null,&#34;proj4def&#34;:null,&#34;projectedBounds&#34;:null,&#34;options&#34;:{}}},&#34;calls&#34;:[{&#34;method&#34;:&#34;addProviderTiles&#34;,&#34;args&#34;:[&#34;CartoDB.Positron&#34;,null,null,{&#34;errorTileUrl&#34;:&#34;&#34;,&#34;noWrap&#34;:false,&#34;detectRetina&#34;:false}]},{&#34;method&#34;:&#34;addCircleMarkers&#34;,&#34;args&#34;:[[50.0933681,50.0895897,50.0920997,49.2051925,49.1977642,50.0891494,50.0900269],[14.4104392,14.3990089,14.4117831,16.6021958,16.6044039,14.4039458,14.4053489],10,null,null,{&#34;interactive&#34;:true,&#34;className&#34;:&#34;&#34;,&#34;stroke&#34;:false,&#34;color&#34;:[&#34;#FF0000&#34;,&#34;#FF0000&#34;,&#34;#FF0000&#34;,&#34;#DAA520&#34;,&#34;#DAA520&#34;,&#34;#4682B4&#34;,&#34;#4682B4&#34;],&#34;weight&#34;:5,&#34;opacity&#34;:0.5,&#34;fill&#34;:true,&#34;fillColor&#34;:[&#34;#FF0000&#34;,&#34;#FF0000&#34;,&#34;#FF0000&#34;,&#34;#DAA520&#34;,&#34;#DAA520&#34;,&#34;#4682B4&#34;,&#34;#4682B4&#34;],&#34;fillOpacity&#34;:0.7},{&#34;showCoverageOnHover&#34;:true,&#34;zoomToBoundsOnClick&#34;:true,&#34;spiderfyOnMaxZoom&#34;:true,&#34;removeOutsideVisibleBounds&#34;:true,&#34;spiderLegPolylineOptions&#34;:{&#34;weight&#34;:1.5,&#34;color&#34;:&#34;#222&#34;,&#34;opacity&#34;:0.5},&#34;freezeAtZoom&#34;:false},null,[&#34;Kramářova vila&#34;,&#34;Pražský hrad&#34;,&#34;Strakova akademie&#34;,&#34;Nejvyšší soud&#34;,&#34;Ústavní soud&#34;,&#34;Sněmovna&#34;,&#34;Senát&#34;],null,null,{&#34;interactive&#34;:false,&#34;permanent&#34;:false,&#34;direction&#34;:&#34;auto&#34;,&#34;opacity&#34;:1,&#34;offset&#34;:[0,0],&#34;textsize&#34;:&#34;10px&#34;,&#34;textOnly&#34;:false,&#34;className&#34;:&#34;&#34;,&#34;sticky&#34;:true},null]},{&#34;method&#34;:&#34;addLegend&#34;,&#34;args&#34;:[{&#34;colors&#34;:[&#34;#FF0000&#34;,&#34;#DAA520&#34;,&#34;#4682B4&#34;],&#34;labels&#34;:[&#34;executive&#34;,&#34;judiciary&#34;,&#34;legislature&#34;],&#34;na_color&#34;:null,&#34;na_label&#34;:&#34;NA&#34;,&#34;opacity&#34;:0.7,&#34;position&#34;:&#34;bottomright&#34;,&#34;type&#34;:&#34;factor&#34;,&#34;title&#34;:&#34;Branch&#34;,&#34;extra&#34;:null,&#34;layerId&#34;:null,&#34;className&#34;:&#34;info legend&#34;,&#34;group&#34;:null}]},{&#34;method&#34;:&#34;addEasyButton&#34;,&#34;args&#34;:[{&#34;icon&#34;:&#34;ion-arrow-shrink&#34;,&#34;title&#34;:&#34;Reset View&#34;,&#34;onClick&#34;:&#34;function(btn, map){ map.setView(map._initialCenter, map._initialZoom); }&#34;,&#34;position&#34;:&#34;topleft&#34;}]}],&#34;limits&#34;:{&#34;lat&#34;:[49.1977642,50.0933681],&#34;lng&#34;:[14.3990089,16.6044039]}},&#34;evals&#34;:[&#34;calls.3.args.0.onClick&#34;],&#34;jsHooks&#34;:{&#34;render&#34;:[{&#34;code&#34;:&#34;function(el, x, data) {\n  return (function(el, x){ var map = this; map._initialCenter = map.getCenter(); map._initialZoom = map.getZoom();}).call(this.getMap(), el, x, data);\n}&#34;,&#34;data&#34;:null}]}}&lt;/script&gt;
&lt;p&gt;&lt;br&gt;&lt;/p&gt;
&lt;p&gt;Two other commonly encountered use cases, especially in a commercial context, are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;including a custom HTML code in the popup, such as a HTML link to a web site&lt;/li&gt;
&lt;li&gt;using a custom image as an icon for the marker, such as a corporate logo&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The custom HTML is easy, all it takes is constructing a column in the body data frame with the HTML code of the label.&lt;/p&gt;
&lt;p&gt;For the purpose of my example I am using three basic HTML tags:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;making the name of the building bold via the &lt;a href=&#34;https://developer.mozilla.org/cs/docs/Web/HTML/Element/b&#34;&gt;&lt;code&gt;&amp;lt;b&amp;gt;&lt;/code&gt; = bring attention&lt;/a&gt; tag&lt;/li&gt;
&lt;li&gt;forcing a new line after the name via the &lt;a href=&#34;https://developer.mozilla.org/cs/docs/Web/HTML/Element/br&#34;&gt;&lt;code&gt;&amp;lt;br&amp;gt;&lt;/code&gt; = break line&lt;/a&gt; tag&lt;/li&gt;
&lt;li&gt;creating an external link to &lt;a href=&#34;https://en.wikipedia.org/&#34;&gt;wikipedia&lt;/a&gt; via the &lt;a href=&#34;https://developer.mozilla.org/cs/docs/Web/HTML/Element/a&#34;&gt;&lt;code&gt;&amp;lt;a&amp;gt;&lt;/code&gt; = anchor&lt;/a&gt; tag&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The custom icon takes two steps:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;declaring the icon via the &lt;code&gt;makeIcon()&lt;/code&gt; function from the &lt;code&gt;{leaflet}&lt;/code&gt; package&lt;/li&gt;
&lt;li&gt;specifying the icon declared earlier in the &lt;code&gt;icon&lt;/code&gt; argument of an &lt;code&gt;addMarkers&lt;/code&gt; call&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;# create a column with HTML code for popup text
body &amp;lt;- body %&amp;gt;% 
  dplyr::mutate(label = paste0(&amp;quot;&amp;lt;b&amp;gt;&amp;quot;, htmlEscape(body$name), &amp;quot;&amp;lt;/b&amp;gt; &amp;lt;br&amp;gt;&amp;quot;,
                      &amp;quot;Be sure to check &amp;quot;,
                      &amp;#39;&amp;lt;a href=&amp;quot;&amp;#39;, # note the use of single quotes - to make a single &amp;quot; a legit piece of code
                       body$link,
                       &amp;#39;&amp;quot;target=&amp;quot;_blank&amp;quot;&amp;gt;the wikipedia page&amp;lt;/a&amp;gt;.&amp;#39;)) # again note the combination of single &amp;amp; double quotes

# declare an icon - link to an image somwehere on the net
ikonka &amp;lt;- leaflet::makeIcon(iconUrl = &amp;quot;https://www.jla-data.net/img/netopejr.png&amp;quot;, # url to icon
                   iconWidth = 50, iconHeight = 50) # sizing as required

# first prepare a leaflet plot ...
lplot &amp;lt;- leaflet(body) %&amp;gt;% 
  addProviderTiles(&amp;quot;CartoDB.Positron&amp;quot;) %&amp;gt;%
  addMarkers(popup = ~label, 
             clusterOptions = markerClusterOptions(), 
             icon = ikonka) %&amp;gt;% 
  addResetMapButton()

lplot #  ... then display it&lt;/code&gt;&lt;/pre&gt;
&lt;div class=&#34;leaflet html-widget html-fill-item&#34; id=&#34;htmlwidget-4&#34; style=&#34;width:100%;height:480px;&#34;&gt;&lt;/div&gt;
&lt;script type=&#34;application/json&#34; data-for=&#34;htmlwidget-4&#34;&gt;{&#34;x&#34;:{&#34;options&#34;:{&#34;crs&#34;:{&#34;crsClass&#34;:&#34;L.CRS.EPSG3857&#34;,&#34;code&#34;:null,&#34;proj4def&#34;:null,&#34;projectedBounds&#34;:null,&#34;options&#34;:{}}},&#34;calls&#34;:[{&#34;method&#34;:&#34;addProviderTiles&#34;,&#34;args&#34;:[&#34;CartoDB.Positron&#34;,null,null,{&#34;errorTileUrl&#34;:&#34;&#34;,&#34;noWrap&#34;:false,&#34;detectRetina&#34;:false}]},{&#34;method&#34;:&#34;addMarkers&#34;,&#34;args&#34;:[[50.0933681,50.0895897,50.0920997,49.2051925,49.1977642,50.0891494,50.0900269],[14.4104392,14.3990089,14.4117831,16.6021958,16.6044039,14.4039458,14.4053489],{&#34;iconUrl&#34;:{&#34;data&#34;:&#34;https://www.jla-data.net/img/netopejr.png&#34;,&#34;index&#34;:0},&#34;iconWidth&#34;:50,&#34;iconHeight&#34;:50},null,null,{&#34;interactive&#34;:true,&#34;draggable&#34;:false,&#34;keyboard&#34;:true,&#34;title&#34;:&#34;&#34;,&#34;alt&#34;:&#34;&#34;,&#34;zIndexOffset&#34;:0,&#34;opacity&#34;:1,&#34;riseOnHover&#34;:false,&#34;riseOffset&#34;:250},[&#34;&lt;b&gt;Kramářova vila&lt;\/b&gt; &lt;br&gt;Be sure to check &lt;a href=\&#34;https://en.wikipedia.org/wiki/Kram%C3%A1%C5%99%27s_Villa\&#34;target=\&#34;_blank\&#34;&gt;the wikipedia page&lt;\/a&gt;.&#34;,&#34;&lt;b&gt;Pražský hrad&lt;\/b&gt; &lt;br&gt;Be sure to check &lt;a href=\&#34;https://en.wikipedia.org/wiki/Prague_Castle\&#34;target=\&#34;_blank\&#34;&gt;the wikipedia page&lt;\/a&gt;.&#34;,&#34;&lt;b&gt;Strakova akademie&lt;\/b&gt; &lt;br&gt;Be sure to check &lt;a href=\&#34;https://en.wikipedia.org/wiki/Straka_Academy\&#34;target=\&#34;_blank\&#34;&gt;the wikipedia page&lt;\/a&gt;.&#34;,&#34;&lt;b&gt;Nejvyšší soud&lt;\/b&gt; &lt;br&gt;Be sure to check &lt;a href=\&#34;https://en.wikipedia.org/wiki/Supreme_Court_of_the_Czech_Republic\&#34;target=\&#34;_blank\&#34;&gt;the wikipedia page&lt;\/a&gt;.&#34;,&#34;&lt;b&gt;Ústavní soud&lt;\/b&gt; &lt;br&gt;Be sure to check &lt;a href=\&#34;https://en.wikipedia.org/wiki/Constitutional_Court_of_the_Czech_Republic\&#34;target=\&#34;_blank\&#34;&gt;the wikipedia page&lt;\/a&gt;.&#34;,&#34;&lt;b&gt;Sněmovna&lt;\/b&gt; &lt;br&gt;Be sure to check &lt;a href=\&#34;https://en.wikipedia.org/wiki/Chamber_of_Deputies_of_the_Czech_Republic\&#34;target=\&#34;_blank\&#34;&gt;the wikipedia page&lt;\/a&gt;.&#34;,&#34;&lt;b&gt;Senát&lt;\/b&gt; &lt;br&gt;Be sure to check &lt;a href=\&#34;https://en.wikipedia.org/wiki/Senate_of_the_Czech_Republic\&#34;target=\&#34;_blank\&#34;&gt;the wikipedia page&lt;\/a&gt;.&#34;],null,{&#34;showCoverageOnHover&#34;:true,&#34;zoomToBoundsOnClick&#34;:true,&#34;spiderfyOnMaxZoom&#34;:true,&#34;removeOutsideVisibleBounds&#34;:true,&#34;spiderLegPolylineOptions&#34;:{&#34;weight&#34;:1.5,&#34;color&#34;:&#34;#222&#34;,&#34;opacity&#34;:0.5},&#34;freezeAtZoom&#34;:false},null,null,{&#34;interactive&#34;:false,&#34;permanent&#34;:false,&#34;direction&#34;:&#34;auto&#34;,&#34;opacity&#34;:1,&#34;offset&#34;:[0,0],&#34;textsize&#34;:&#34;10px&#34;,&#34;textOnly&#34;:false,&#34;className&#34;:&#34;&#34;,&#34;sticky&#34;:true},null]},{&#34;method&#34;:&#34;addEasyButton&#34;,&#34;args&#34;:[{&#34;icon&#34;:&#34;ion-arrow-shrink&#34;,&#34;title&#34;:&#34;Reset View&#34;,&#34;onClick&#34;:&#34;function(btn, map){ map.setView(map._initialCenter, map._initialZoom); }&#34;,&#34;position&#34;:&#34;topleft&#34;}]}],&#34;limits&#34;:{&#34;lat&#34;:[49.1977642,50.0933681],&#34;lng&#34;:[14.3990089,16.6044039]}},&#34;evals&#34;:[&#34;calls.2.args.0.onClick&#34;],&#34;jsHooks&#34;:{&#34;render&#34;:[{&#34;code&#34;:&#34;function(el, x, data) {\n  return (function(el, x){ var map = this; map._initialCenter = map.getCenter(); map._initialZoom = map.getZoom();}).call(this.getMap(), el, x, data);\n}&#34;,&#34;data&#34;:null}]}}&lt;/script&gt;
&lt;p&gt;&lt;br&gt;&lt;/p&gt;
&lt;p&gt;With a lot of data displayed at once your leaflet map may become somewhat cluttered. In such cases it is a good idea to partition your data into groups, and allow user to switch them on and off – especially useful when one of the groups is much smaller than the rest, and at a risk of being overwhelmed.&lt;/p&gt;
&lt;p&gt;The first step is creating filtered dataset of the individual groups – I am creating one for Prague points, and one for Brno ones.&lt;/p&gt;
&lt;p&gt;The second step is drawing the leaflet map. Note how:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;the &lt;code&gt;data&lt;/code&gt; object of the root leaflet object contains the original data frame, but is never actually used (except for determining the initial zoom level)&lt;/li&gt;
&lt;li&gt;the &lt;code&gt;addCircleMarkers&lt;/code&gt; call is executed twice, with different values for &lt;code&gt;data&lt;/code&gt; object and with specified value of the &lt;code&gt;group&lt;/code&gt; object&lt;/li&gt;
&lt;li&gt;the &lt;code&gt;addLayersControl&lt;/code&gt; from &lt;code&gt;{leaflet}&lt;/code&gt; creates a checkbox to select any (or all) of the groups specified in &lt;code&gt;overlayGroups&lt;/code&gt; object; it is necessary that the items in vector provided match the names of groups created in previous &lt;code&gt;addCircleMarkers&lt;/code&gt; calls&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;While most of the default options in &lt;code&gt;{leaflet}&lt;/code&gt; are sensible I found the &lt;code&gt;addLayersControl&lt;/code&gt; to be an exception, as it is by default collapsed. This is easily remedied by a &lt;code&gt;options = layersControlOptions(collapsed = FALSE)&lt;/code&gt; call.&lt;/p&gt;
&lt;p&gt;Setting the &lt;code&gt;overlayGroups&lt;/code&gt; object of &lt;code&gt;addLayersControl&lt;/code&gt; call creates a control with &lt;a href=&#34;https://en.wikipedia.org/wiki/Checkbox&#34;&gt;check box&lt;/a&gt; functionality (all groups can be turned on or off separately).&lt;/p&gt;
&lt;p&gt;In some use cases it might be desirable to create a &lt;a href=&#34;https://en.wikipedia.org/wiki/Radio_button&#34;&gt;radio button&lt;/a&gt; functionality (one, and only one, group can be selected at any time); this can be done by assigning the vector of groups to a &lt;code&gt;baseGroups&lt;/code&gt; object of the &lt;code&gt;addLayersControl&lt;/code&gt; instead of &lt;code&gt;overlayGroups&lt;/code&gt;.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;# data frame or Prague points
praha &amp;lt;- body %&amp;gt;% 
  dplyr::filter(branch != &amp;quot;judiciary&amp;quot;) # a shortcut - all except judiciary are in Prague

# data frame of Brno points
brno &amp;lt;- body %&amp;gt;% 
  filter(branch == &amp;quot;judiciary&amp;quot;) # only judiciary happens to be in Brno (and only in Brno)

# first prepare a leaflet plot ...
lplot &amp;lt;- leaflet(data = body) %&amp;gt;% # data = original body - to get the zoom right
  addProviderTiles(&amp;quot;CartoDB.Positron&amp;quot;) %&amp;gt;% 
  addCircleMarkers(data = praha, # first group
                   radius = 10,
                   fillOpacity = .7,
                   stroke = FALSE,
                   popup = ~htmlEscape(name),
                   color = palPwr(praha$branch), # using already created palette
                   clusterOptions = markerClusterOptions(),
                   group = &amp;quot;Prague&amp;quot;) %&amp;gt;% 
  addCircleMarkers(data = brno, # second group
                   radius = 10,
                   fillOpacity = .7,
                   stroke = FALSE,
                   popup = ~htmlEscape(name),
                   color = palPwr(brno$branch), # using already created palette
                   clusterOptions = markerClusterOptions(),
                   group = &amp;quot;Brno&amp;quot;) %&amp;gt;% 
  addLegend(position = &amp;quot;bottomright&amp;quot;,
            values = ~branch,
            opacity = .7,
            pal = palPwr, # palette declared previously
            title = &amp;quot;Branch&amp;quot;) %&amp;gt;% 
  leaflet::addLayersControl(overlayGroups = c(&amp;quot;Prague&amp;quot;, &amp;quot;Brno&amp;quot;),
                   options = layersControlOptions(collapsed = FALSE)) %&amp;gt;% 
  addResetMapButton()

lplot #  ... then display it&lt;/code&gt;&lt;/pre&gt;
&lt;div class=&#34;leaflet html-widget html-fill-item&#34; id=&#34;htmlwidget-5&#34; style=&#34;width:100%;height:480px;&#34;&gt;&lt;/div&gt;
&lt;script type=&#34;application/json&#34; data-for=&#34;htmlwidget-5&#34;&gt;{&#34;x&#34;:{&#34;options&#34;:{&#34;crs&#34;:{&#34;crsClass&#34;:&#34;L.CRS.EPSG3857&#34;,&#34;code&#34;:null,&#34;proj4def&#34;:null,&#34;projectedBounds&#34;:null,&#34;options&#34;:{}}},&#34;calls&#34;:[{&#34;method&#34;:&#34;addProviderTiles&#34;,&#34;args&#34;:[&#34;CartoDB.Positron&#34;,null,null,{&#34;errorTileUrl&#34;:&#34;&#34;,&#34;noWrap&#34;:false,&#34;detectRetina&#34;:false}]},{&#34;method&#34;:&#34;addCircleMarkers&#34;,&#34;args&#34;:[[50.0933681,50.0895897,50.0920997,50.0891494,50.0900269],[14.4104392,14.3990089,14.4117831,14.4039458,14.4053489],10,null,&#34;Prague&#34;,{&#34;interactive&#34;:true,&#34;className&#34;:&#34;&#34;,&#34;stroke&#34;:false,&#34;color&#34;:[&#34;#FF0000&#34;,&#34;#FF0000&#34;,&#34;#FF0000&#34;,&#34;#4682B4&#34;,&#34;#4682B4&#34;],&#34;weight&#34;:5,&#34;opacity&#34;:0.5,&#34;fill&#34;:true,&#34;fillColor&#34;:[&#34;#FF0000&#34;,&#34;#FF0000&#34;,&#34;#FF0000&#34;,&#34;#4682B4&#34;,&#34;#4682B4&#34;],&#34;fillOpacity&#34;:0.7},{&#34;showCoverageOnHover&#34;:true,&#34;zoomToBoundsOnClick&#34;:true,&#34;spiderfyOnMaxZoom&#34;:true,&#34;removeOutsideVisibleBounds&#34;:true,&#34;spiderLegPolylineOptions&#34;:{&#34;weight&#34;:1.5,&#34;color&#34;:&#34;#222&#34;,&#34;opacity&#34;:0.5},&#34;freezeAtZoom&#34;:false},null,[&#34;Kramářova vila&#34;,&#34;Pražský hrad&#34;,&#34;Strakova akademie&#34;,&#34;Sněmovna&#34;,&#34;Senát&#34;],null,null,{&#34;interactive&#34;:false,&#34;permanent&#34;:false,&#34;direction&#34;:&#34;auto&#34;,&#34;opacity&#34;:1,&#34;offset&#34;:[0,0],&#34;textsize&#34;:&#34;10px&#34;,&#34;textOnly&#34;:false,&#34;className&#34;:&#34;&#34;,&#34;sticky&#34;:true},null]},{&#34;method&#34;:&#34;addCircleMarkers&#34;,&#34;args&#34;:[[49.2051925,49.1977642],[16.6021958,16.6044039],10,null,&#34;Brno&#34;,{&#34;interactive&#34;:true,&#34;className&#34;:&#34;&#34;,&#34;stroke&#34;:false,&#34;color&#34;:[&#34;#DAA520&#34;,&#34;#DAA520&#34;],&#34;weight&#34;:5,&#34;opacity&#34;:0.5,&#34;fill&#34;:true,&#34;fillColor&#34;:[&#34;#DAA520&#34;,&#34;#DAA520&#34;],&#34;fillOpacity&#34;:0.7},{&#34;showCoverageOnHover&#34;:true,&#34;zoomToBoundsOnClick&#34;:true,&#34;spiderfyOnMaxZoom&#34;:true,&#34;removeOutsideVisibleBounds&#34;:true,&#34;spiderLegPolylineOptions&#34;:{&#34;weight&#34;:1.5,&#34;color&#34;:&#34;#222&#34;,&#34;opacity&#34;:0.5},&#34;freezeAtZoom&#34;:false},null,[&#34;Nejvyšší soud&#34;,&#34;Ústavní soud&#34;],null,null,{&#34;interactive&#34;:false,&#34;permanent&#34;:false,&#34;direction&#34;:&#34;auto&#34;,&#34;opacity&#34;:1,&#34;offset&#34;:[0,0],&#34;textsize&#34;:&#34;10px&#34;,&#34;textOnly&#34;:false,&#34;className&#34;:&#34;&#34;,&#34;sticky&#34;:true},null]},{&#34;method&#34;:&#34;addLegend&#34;,&#34;args&#34;:[{&#34;colors&#34;:[&#34;#FF0000&#34;,&#34;#DAA520&#34;,&#34;#4682B4&#34;],&#34;labels&#34;:[&#34;executive&#34;,&#34;judiciary&#34;,&#34;legislature&#34;],&#34;na_color&#34;:null,&#34;na_label&#34;:&#34;NA&#34;,&#34;opacity&#34;:0.7,&#34;position&#34;:&#34;bottomright&#34;,&#34;type&#34;:&#34;factor&#34;,&#34;title&#34;:&#34;Branch&#34;,&#34;extra&#34;:null,&#34;layerId&#34;:null,&#34;className&#34;:&#34;info legend&#34;,&#34;group&#34;:null}]},{&#34;method&#34;:&#34;addLayersControl&#34;,&#34;args&#34;:[[],[&#34;Prague&#34;,&#34;Brno&#34;],{&#34;collapsed&#34;:false,&#34;autoZIndex&#34;:true,&#34;position&#34;:&#34;topright&#34;}]},{&#34;method&#34;:&#34;addEasyButton&#34;,&#34;args&#34;:[{&#34;icon&#34;:&#34;ion-arrow-shrink&#34;,&#34;title&#34;:&#34;Reset View&#34;,&#34;onClick&#34;:&#34;function(btn, map){ map.setView(map._initialCenter, map._initialZoom); }&#34;,&#34;position&#34;:&#34;topleft&#34;}]}],&#34;limits&#34;:{&#34;lat&#34;:[49.1977642,50.0933681],&#34;lng&#34;:[14.3990089,16.6044039]}},&#34;evals&#34;:[&#34;calls.5.args.0.onClick&#34;],&#34;jsHooks&#34;:{&#34;render&#34;:[{&#34;code&#34;:&#34;function(el, x, data) {\n  return (function(el, x){ var map = this; map._initialCenter = map.getCenter(); map._initialZoom = map.getZoom();}).call(this.getMap(), el, x, data);\n}&#34;,&#34;data&#34;:null}]}}&lt;/script&gt;
&lt;p&gt;&lt;br&gt;&lt;/p&gt;
&lt;p&gt;While points are the most commonly used spatial items in leaflet maps they are not the only ones possible. Other options include polygons and lines.&lt;/p&gt;
&lt;p&gt;Unlike points, with just two coordinates, it is rarely practical to specify polygon boundaries directly in R code, and polygons are usually imported. Either in one of the popular formats such as &lt;a href=&#34;https://en.wikipedia.org/wiki/Shapefile&#34;&gt;ESRI shapefile&lt;/a&gt; or &lt;a href=&#34;https://en.wikipedia.org/wiki/GeoJSON&#34;&gt;GeoJSON&lt;/a&gt;, or via one of the spatial R packages.&lt;/p&gt;
&lt;p&gt;In this case I am using state borders of the Czech Republic provided via &lt;a href=&#34;https://docs.ropensci.org/rnaturalearth/&#34;&gt;&lt;code&gt;{rnaturalearth}&lt;/code&gt;&lt;/a&gt; package, serving as an interface to &lt;a href=&#34;http://www.naturalearthdata.com/&#34;&gt;Natural Earth&lt;/a&gt; data.&lt;/p&gt;
&lt;p&gt;I am using the polygon just to illuminate the borders, and I am not mapping any data to it. Should I desire so the most common use case would be to map a the color of &lt;code&gt;fill&lt;/code&gt; object to a data item via a palette to create a &lt;a href=&#34;https://en.wikipedia.org/wiki/Choropleth_map&#34;&gt;choropleth map&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;As I wanted something a bit different for my last example I am using an unusual background map – the &lt;a href=&#34;https://earthobservatory.nasa.gov/features/IntotheBlack&#34;&gt;NASA 2012 view of Earth at night&lt;/a&gt; – for no better reason than to show off.&lt;/p&gt;
&lt;p&gt;As I want the continent of Europe to be displayed nice and clear I specify via the &lt;code&gt;setView&lt;/code&gt; call from &lt;code&gt;{leaflet}&lt;/code&gt; package the center of my map to Munich, Bavaria, and zoom the map out a bit by setting the &lt;code&gt;zoom&lt;/code&gt; attribute of &lt;code&gt;setView&lt;/code&gt; call to 4.&lt;/p&gt;
&lt;p&gt;And finally I removed the lengthy attribution at the bottom of the map by setting &lt;code&gt;options&lt;/code&gt; object of my root &lt;code&gt;leaflet&lt;/code&gt; call to &lt;code&gt;leafletOptions(attributionControl = FALSE)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;This is a naughty thing to do, and should only be used with care and for for a good reason. But there are other ways to provide attribution and the control uses valuable screen real estate.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;# Czechia as a country from the Natural Earth
czechia &amp;lt;- rnaturalearth::ne_countries(country = &amp;quot;Czechia&amp;quot;, scale = &amp;#39;large&amp;#39;)

# first prepare a leaflet plot ...
lplot &amp;lt;- leaflet(body,
                 options = leafletOptions(attributionControl = FALSE)) %&amp;gt;% # naughty me!
  addProviderTiles(&amp;quot;NASAGIBS.ViirsEarthAtNight2012&amp;quot;) %&amp;gt;%  # something different...
  addCircleMarkers(radius = 2,
                   popup = ~htmlEscape(name),
                   color = &amp;quot;cornflowerblue&amp;quot;) %&amp;gt;% 
  leaflet::addPolygons(data = czechia,
              fill = NA,
              weight = 3,
              color = &amp;quot;orangered&amp;quot;,
              opacity = .8) %&amp;gt;% 
  leaflet::setView(lng = 11.57549, # map centered on Munich, Bavaria
          lat = 48.13743,
          zoom = 4)  # &amp;amp; zoomed out a bit...

lplot #  ... then display it&lt;/code&gt;&lt;/pre&gt;
&lt;div class=&#34;leaflet html-widget html-fill-item&#34; id=&#34;htmlwidget-6&#34; style=&#34;width:100%;height:672px;&#34;&gt;&lt;/div&gt;
&lt;script type=&#34;application/json&#34; data-for=&#34;htmlwidget-6&#34;&gt;{&#34;x&#34;:{&#34;options&#34;:{&#34;crs&#34;:{&#34;crsClass&#34;:&#34;L.CRS.EPSG3857&#34;,&#34;code&#34;:null,&#34;proj4def&#34;:null,&#34;projectedBounds&#34;:null,&#34;options&#34;:{}},&#34;attributionControl&#34;:false},&#34;calls&#34;:[{&#34;method&#34;:&#34;addProviderTiles&#34;,&#34;args&#34;:[&#34;NASAGIBS.ViirsEarthAtNight2012&#34;,null,null,{&#34;errorTileUrl&#34;:&#34;&#34;,&#34;noWrap&#34;:false,&#34;detectRetina&#34;:false}]},{&#34;method&#34;:&#34;addCircleMarkers&#34;,&#34;args&#34;:[[50.0933681,50.0895897,50.0920997,49.2051925,49.1977642,50.0891494,50.0900269],[14.4104392,14.3990089,14.4117831,16.6021958,16.6044039,14.4039458,14.4053489],2,null,null,{&#34;interactive&#34;:true,&#34;className&#34;:&#34;&#34;,&#34;stroke&#34;:true,&#34;color&#34;:&#34;cornflowerblue&#34;,&#34;weight&#34;:5,&#34;opacity&#34;:0.5,&#34;fill&#34;:true,&#34;fillColor&#34;:&#34;cornflowerblue&#34;,&#34;fillOpacity&#34;:0.2},null,null,[&#34;Kramářova vila&#34;,&#34;Pražský hrad&#34;,&#34;Strakova akademie&#34;,&#34;Nejvyšší soud&#34;,&#34;Ústavní soud&#34;,&#34;Sněmovna&#34;,&#34;Senát&#34;],null,null,{&#34;interactive&#34;:false,&#34;permanent&#34;:false,&#34;direction&#34;:&#34;auto&#34;,&#34;opacity&#34;:1,&#34;offset&#34;:[0,0],&#34;textsize&#34;:&#34;10px&#34;,&#34;textOnly&#34;:false,&#34;className&#34;:&#34;&#34;,&#34;sticky&#34;:true},null]},{&#34;method&#34;:&#34;addPolygons&#34;,&#34;args&#34;:[[[[{&#34;lng&#34;:[14.81039270000014,14.83168339000014,14.86785689300007,14.98206180800008,14.98412886500006,14.98288863100001,14.9817517490001,14.98113163200014,14.98206180800008,14.98485233500014,14.9946708570001,14.99777144400005,14.99663456200005,14.98144169100001,14.96521529100011,14.96097782400005,14.96108117600008,14.96562870300002,14.97069299300009,14.97637740100004,14.98206180800008,14.99653120900012,15.00118208800009,15.00397261600006,15.02298954300011,15.07363244600006,15.08210738100007,15.09388960700008,15.10794559700008,15.11921105900007,15.12251835100005,15.12251835100005,15.13151005100011,15.14442915800009,15.15610803200008,15.16075891100013,15.17016402200011,15.22711145000008,15.2537764890001,15.26979618300007,15.26876265500007,15.26008101400004,15.25305301900011,15.25605025200014,15.26535201000007,15.27713423600005,15.28777958100005,15.30772668500006,15.32581343600009,15.34100630600011,15.35299523900008,15.35330529800007,15.3505147700001,15.34968794800008,15.35609582500012,15.3685787850001,15.37025516800006,15.38131392400007,15.39082238800006,15.40012414500009,15.44177535000009,15.64186649600015,15.65323531000004,15.66646447700015,15.67380253000005,15.68434452300011,15.76744022600008,15.79224491400004,15.79441532300009,15.79761926300009,15.84815881300011,15.85456669100006,15.88226525800007,15.94148645000007,15.95802290800015,15.97145878100011,15.98448124200004,15.99316288200012,15.9986405840001,15.99636682100009,15.98200077300007,15.98003706800006,15.97921024600004,15.9799337150001,15.98200077300007,16.02447880000011,16.08649051900008,16.12865848800004,16.1602844650001,16.17547733500004,16.19232385200013,16.20451949100004,16.2117541910001,16.2190922450001,16.23201135200011,16.26828820800006,16.30094771400013,16.33164351400009,16.41680627500011,16.42590132600009,16.39448205600004,16.3983061110001,16.3983061110001,16.39551558400012,16.39117476400014,16.38962447100005,16.38828088400007,16.38838423700008,16.39117476400014,16.38259647600012,16.36202925600014,16.35262414500008,16.33546757000011,16.30342818200012,16.28771854700005,16.27996708200004,16.26498091700006,16.2474109290001,16.23201135200011,16.22653365100012,16.21733524600012,16.21123742700007,16.21609501100008,16.2179553630001,16.19800826000008,16.19015344300004,16.19955855300009,16.23201135200011,16.24493046000012,16.2496846920001,16.26250044800008,16.26983850100009,16.27696984900012,16.28864872200009,16.33422733500009,16.34373579900006,16.35076379400007,16.35148726400007,16.35066044100006,16.35324426300014,16.37102095600008,16.41556604000007,16.43778690600001,16.45215295400004,16.47757775900004,16.49204716000006,16.50475956300011,16.53504195200014,16.54589400300009,16.55726281700009,16.56666792800013,16.5842379150001,16.61865441900005,16.66061568200007,16.70123335700009,16.73203251100006,16.75425337700011,16.76644901600011,16.77730106600006,16.79528446400005,16.81771203600005,16.83755578600005,16.85760624200009,16.86976208200008,16.88096399000003,16.8903691000001,16.9070089110001,16.91899784300006,16.92778283700005,16.94628300000008,16.95527469900011,16.9577551670001,16.95754846200015,16.96033898900009,16.97501509600008,16.98100956300001,16.98566044100008,16.99630578600008,17.00839807100007,17.01480594900011,17.01284224400007,16.99981978300013,16.99837284300014,16.98783085100007,16.96964074700011,16.9452494710001,16.92654260200001,16.91672408000005,16.90928267400002,16.89791385900014,16.86587447100004,16.86577111800011,16.8929529210001,16.91579390400008,16.94400462900012,16.95878869600008,16.98193973800008,17.08467248500008,17.09562788900007,17.11888228400008,17.13169803800005,17.14544397000009,17.17593306500007,17.18761193900013,17.18544152800007,17.1888521730001,17.19505334500008,17.20104781100011,17.21086633300007,17.24610965900004,17.26988081900009,17.31680301900005,17.33747359200007,17.31907678200008,17.32186730900011,17.32538130700007,17.3295154220001,17.33406294700004,17.3328227130001,17.33478641800014,17.34171106000011,17.35504357900004,17.3658956300001,17.38801314300011,17.40982059700013,17.41912235500007,17.42418664500013,17.4295609940001,17.43483199100012,17.43999963400012,17.4693518470001,17.51699751800004,17.60639774600014,17.62954878700012,17.64670536300008,17.67636763500013,17.68194869000007,17.68453251100007,17.69104374100004,17.70799361100003,17.71357466600006,17.73197147600007,17.73445194500005,17.73496870900007,17.73424523900007,17.73197147600007,17.7211194250001,17.71915572100008,17.72142948400008,17.73197147600007,17.74757775900011,17.73817264800005,17.71791548700014,17.67533410600007,17.64866906700013,17.60040327900012,17.58944787600012,17.58210982300005,17.58417688000009,17.63275272600009,17.64835900900005,17.65848758900009,17.6669625240001,17.6776078690001,17.69073368300005,17.71791548700014,17.73197147600007,17.73238488800007,17.73259159400004,17.73238488800007,17.73197147600007,17.72266971900012,17.71946578000006,17.72256636500009,17.73197147600007,17.74303023200005,17.74985152200011,17.75543257700014,17.76328739400006,17.77455285700012,17.83935510200013,17.87573531100011,17.91211551900011,17.94157108500011,17.95976119000005,17.99986210100013,18.03241825300009,18.03748254400006,18.03572554500008,18.02869755000009,18.02011926200007,18.0121610920001,18.00689009600006,18.00244592300004,18.01907389900015,18.0332450760001,18.09163944500008,18.08512821400012,18.09815067500006,18.1620227460001,18.17721561700003,18.20873824100011,18.22052046700009,18.24398156700008,18.25586714700009,18.26010461400006,18.26702925600003,18.27261031100005,18.29245406100006,18.30692346200007,18.33493208800007,18.33379520600008,18.33245161900001,18.33069462100013,18.32852421100006,18.36883182700009,18.4074858000001,18.48179650900008,18.5050509030001,18.54442834500011,18.55920780400004,18.5654089760001,18.56292850700004,18.56726932800012,18.59383101400005,18.56633915200007,18.56675256400007,18.5841158450001,18.6076802980001,18.61770552600012,18.62401005000004,18.63734257000004,18.66814172400012,18.68240441800009,18.69542688000013,18.71506392400008,18.72767297400009,18.74224572700007,18.75785201000011,18.77345829300012,18.7884444580001,18.79257857300013,18.79929650800005,18.80394738700011,18.81572961400011,18.82017378800012,18.83453983600012,18.83743371600011,18.83319624900008,18.79226851400006,18.77356164500006,18.73253055800012,18.70452193200009,18.67558313000004,18.64282027200005,18.63589563000005,18.62897098800008,18.60044559800014,18.55621057100009,18.53564335100012,18.53047570800001,18.52799523900003,18.52293094900006,18.51466271900011,18.48179650900008,18.43921512900002,18.41678755700013,18.38764204900011,18.38516158000004,18.36158636600004,18.32459680200009,18.19003137200011,18.16057580600011,18.13649458800006,18.11778771900009,18.10507531800005,18.10145796700004,18.10162968600014,18.10290490700004,18.09629032300006,18.0755163980001,18.04606083200011,18.0128845620001,17.95924442600011,17.93505985500013,17.91407922300004,17.90085005700013,17.89464888500007,17.88689742000014,17.87873254400003,17.86033573400005,17.84121545400004,17.8201314690001,17.79553348800005,17.77941044100004,17.74489058400007,17.72721724400006,17.53508426900007,17.49849735500004,17.4679049070001,17.45333215300013,17.4295609940001,17.41122471900013,17.39173384600011,17.37437056500011,17.26026900200009,17.21220992000013,17.16745813000009,17.11371464100009,17.10461958800011,17.09872847500009,17.0843624260001,17.04994592300005,17.02534794100006,16.97480839000013,16.96333622200012,16.9475232340001,16.94504276600014,16.91052290800008,16.89667362500009,16.87300581900007,16.85657271300011,16.81812544700006,16.79890181400012,16.78050500500012,16.74433150200011,16.72903527900004,16.69100142400012,16.67508508300008,16.66195926900014,16.65472456900005,16.65100386600005,16.64314904700012,16.62402876700011,16.6055286050001,16.54579065000007,16.52873742600013,16.51953902200012,16.51034061700003,16.49225386500012,16.48191857900011,16.45308313000007,16.43571984800005,16.38497359200008,16.37401818800009,16.35830855300011,16.35272749800001,16.3394983310001,16.31872440600006,16.31758752400015,16.17775109800007,16.08535363800007,16.03233361800005,15.93177128100012,15.93032434100013,15.93032434100013,15.92505334500009,15.9081034750001,15.90706994600012,15.89962854000009,15.88836307700012,15.8757540280001,15.8859859610001,15.87761437900011,15.87017297300008,15.85921757000011,15.84009729000013,15.83327600100006,15.82831506400004,15.82428430100012,15.81849654100006,15.78790409300004,15.77922245300007,15.74366906700004,15.72682255000004,15.70377486100008,15.68134729000008,15.6037292880001,15.54418668100007,15.5212537030001,15.47185103300006,15.45035363800011,15.40591190600014,15.35785282300009,15.33552860500004,15.28870975700011,15.28374882000014,15.27961470600013,15.27455041500005,15.26690230300008,15.26287154200008,15.26039107300011,15.25708378100012,15.24323449700006,15.23806685400004,15.16179244000011,15.14194868900012,15.14856327300004,15.14897668400005,15.14473921700008,15.1374011640001,15.05957645700005,15.00397261600006,14.98206180800008,14.97885786900011,14.97730757700009,14.97730757700009,14.97823775300014,14.96459517400004,14.96418176300003,14.96831587700007,14.96821252400011,14.94702518700007,14.9397904870001,14.93813684000014,14.94010054500009,14.94444136600015,14.94888553800007,14.95105594900008,14.93958378100004,14.91932662000005,14.86765018700009,14.8154569910001,14.80036747200012,14.79447635900002,14.79044559700012,14.78042037000009,14.77535607900012,14.72274947100004,14.70383589700009,14.70021854600012,14.70073531000014,14.69567102000008,14.69114043900004,14.67562056500012,14.65918745900007,14.65133264100012,14.64544152900004,14.63469283100011,14.62818160000003,14.61288537600009,14.60513391100008,14.6019299730001,14.60182661900006,14.60058638500004,14.59417850700009,14.57877893000011,14.54880659900007,14.53382043400009,14.52203820800008,14.48214400200007,14.45816613700015,14.44359338400008,14.42116581200008,14.4053528230001,14.35336633300008,14.33321252500008,14.32535770600015,14.31574589000013,14.2165271400001,14.07483036300007,14.04082727000014,14.03245568800008,14.0151957600001,14.0108549390001,14.00620406000013,14.00806441200004,14.0137488200001,14.0204667560001,14.02346398900005,14.02832157400005,14.03286910000008,14.03472945100009,14.03214563000009,14.02615116400005,14.01922652100009,14.01416223100011,14.00775435400007,13.99111454300004,13.98232954900007,13.91504683400007,13.89313602700011,13.87494592300007,13.8559289960001,13.81572473100007,13.79619104000008,13.74792525200007,13.72467085800014,13.71061486800002,13.67335616000011,13.65444258600007,13.63738936300012,13.6217830810001,13.6111377360001,13.60865726700013,13.59046716300008,13.57341394000014,13.55646407100005,13.53889408300006,13.52239544700009,13.51594974700004,13.50210046400008,13.49259200000009,13.48225671300008,13.45889896600005,13.42727299000003,13.39854089300013,13.38417484500013,13.38355472800015,13.37239261800005,13.32991459100009,13.29952884900013,13.28733321100012,13.26728275500008,13.20682133000014,13.17850264500007,13.16258630300013,13.14946048900015,13.05582279500001,13.04342045100015,13.04321374500009,13.01127771000012,13.00673018400008,13.00538659700001,12.9998055420001,12.98244226100007,12.95433028200006,12.9398608810001,12.92291101100011,12.88467045100012,12.87092451900008,12.8753686930001,12.85666182500009,12.79775069200011,12.77790694100011,12.76209395300012,12.72933109500011,12.70917728600003,12.66308190900011,12.64354821800009,12.63217940200011,12.62721846500006,12.62432458500007,12.62298099800012,12.61553959200009,12.60499759900011,12.59373213700007,12.58288008700012,12.57502526800008,12.56872074400007,12.56231286700012,12.55828210400003,12.55363122500006,12.54660323000007,12.53606123900011,12.51218672700011,12.50195479300004,12.50267826300012,12.5074324950001,12.49947432400006,12.49689050300015,12.50536543700014,12.50464196800007,12.49637373900012,12.48252445400004,12.44924483200009,12.43394860800007,12.41958256000004,12.39891198700013,12.38857670000002,12.38361576300008,12.39539799000008,12.4367391350001,12.45265547700012,12.45585941500011,12.45637618000003,12.46247399900011,12.48252445400004,12.48986250800004,12.51291019700011,12.52097172000009,12.52407230600005,12.51787113500006,12.50360843900009,12.46268070500014,12.46381758600006,12.47074222800006,12.46815840600004,12.45131188900007,12.41451827000006,12.39922204600012,12.39818851700005,12.24687992300011,12.24367598400005,12.2434692790001,12.24140222100004,12.23251387500011,12.2180444740001,12.20202478000004,12.18786543800007,12.17918379700012,12.17856368000005,12.18559167500007,12.18269779500008,12.17504968200009,12.16378422000014,12.1392895920001,12.08988692200006,12.07955163500014,12.09205733300007,12.10239261900006,12.10911055500009,12.11097090600009,12.10725020300009,12.09918868000008,12.07614099100005,12.10134354700003,12.14931481900001,12.16853845200012,12.17442956500014,12.17411950700006,12.17804691600011,12.18920902500014,12.20378177900011,12.23251387500011,12.23964522300014,12.24295251500007,12.24243575000011,12.23799157700012,12.23644128400008,12.23509769700013,12.23375411000006,12.23251387500011,12.22982670100009,12.22889652500004,12.22993005400011,12.23251387500011,12.24998051000006,12.25432133000004,12.25845544500007,12.26021244300006,12.26124597200004,12.27323490400008,12.28336348400012,12.30041670700007,12.31436934400006,12.31436934400006,12.30858158300009,12.30558435100008,12.30868493600011,12.31405928600009,12.33379968300005,12.33648685700007,12.34465173300009,12.35581384200012,12.3671826580001,12.39818851700005,12.40893721500007,12.43828942900012,12.45017500800014,12.45379235900015,12.4627840580001,12.46681481900009,12.46898522900008,12.46836511300009,12.46702152500012,12.46681481900009,12.4695019940001,12.47156905100007,12.47508304800004,12.48252445400004,12.51022302200008,12.55053064000012,12.62535811400005,12.67879154400006,12.6918140060001,12.70297611500004,12.72509362800014,12.73790938300004,12.75423913600008,12.77025883000005,12.78813887500007,12.79434004700008,12.80839603700008,12.81738773600003,12.82575931800011,12.91836348500007,12.95257328300008,12.96063110300011,12.98244226100007,12.99660160300004,13.0031128330001,13.00962406400015,13.0178922930001,13.0262638750001,13.03453210400005,13.04228357000005,13.05106856300011,13.06037032100005,13.0697754310001,13.07887048300009,13.0789738360001,13.07918054200007,13.10739587400013,13.16010583500014,13.18470381700013,13.19906986500013,13.23234948700008,13.25177982500014,13.26800622600007,13.2846460370001,13.30562666800009,13.31627201300009,13.32185306800011,13.3593701580001,13.36536462400011,13.36598474100009,13.36877526800015,13.38097090600007,13.38634525600011,13.40040124500013,13.40701582800006,13.42934004800011,13.44794356300005,13.46489343200005,13.48225671300008,13.49217858900008,13.49817305500011,13.49910323000006,13.49331547100007,13.50995528100012,13.52328780100004,13.52721521000009,13.51563968900007,13.55656742300008,13.6019393310001,13.6917529700001,13.71102828000005,13.74906213400007,13.77066288200004,13.81655155400011,13.83453495300009,13.86347375500014,13.8695715740001,13.87535933400008,13.88218062400006,13.88269738800008,13.88032027200003,13.87908003700011,13.88331750500006,13.89251591000004,13.90099084400015,13.91070601400008,13.92331506400012,13.93354699700009,13.94884322100006,13.95959191900008,13.9791256100001,14.01571252400004,14.03493615700006,14.1907922770001,14.20298791500011,14.22128137200008,14.23213342300002,14.26810022000009,14.34654504400001,14.37589725700008,14.38189172400013,14.35522668500008,14.31832971200006,14.29280155400011,14.29373173000008,14.30220666500006,14.30375695800009,14.28380985500007,14.25001346900009,14.23833459500011,14.24949670400014,14.26355269400005,14.28753055800007,14.31936324000011,14.35657027200006,14.3641150310001,14.3693860270001,14.37589725700008,14.38674930800005,14.39780806400006,14.42581669100014,14.46209354700011,14.47346236200011,14.48214400200007,14.48793176300012,14.49010217300011,14.49351281800006,14.5029179280001,14.51532027200008,14.5422953690001,14.55459436000004,14.56668664500012,14.57433475800011,14.57743534300005,14.57557499200004,14.56782352700014,14.55583459400009,14.5503568930001,14.56182906100011,14.61712284300012,14.62921512800011,14.63458947800007,14.6288017170001,14.61185184700011,14.60833785000005,14.61319543500008,14.64792199700011,14.66218469200007,14.70042525200006,14.73752893100004,14.75923303200005,14.77535607900012,14.78507124800007,14.79457971200014,14.81039270000014],&#34;lat&#34;:[50.85844716400005,50.85798207600003,50.86438995400009,50.85906728200003,50.86769724600008,50.90242380800002,50.90526601200007,50.90909006800003,50.91467112300005,50.91808176700006,50.92510976200008,50.93017405200005,50.95921620700004,50.97322052000005,50.98133372000005,50.99265085900002,50.99265085900002,50.99606150300006,50.99869700200007,51.00040232400004,51.00117747000006,51.00784373000006,51.01244293200001,51.02068532300005,51.00965240500004,51.00262441000005,50.99275421200007,50.98541615800006,50.98102366200006,50.98247060200005,50.99265085900002,50.99275421200007,51.00582834900011,51.01156443300006,51.00784373000006,50.99265085900002,50.97797475200004,50.977406311,50.96903472900003,50.95265330000005,50.94298980700005,50.93249949100009,50.91410268200009,50.89989166300002,50.88227000000005,50.86573354100004,50.8548814900001,50.84475291000005,50.83968861900006,50.83173044900009,50.81297190400001,50.80325673500006,50.79323150600005,50.78372304300005,50.77545481400001,50.77294911000008,50.77261261000005,50.78000234000005,50.79064768500005,50.79798573800004,50.80020782500004,50.75576609400007,50.75096018500007,50.73809275300006,50.73354522700002,50.73142649400005,50.74419057200002,50.74269195600003,50.73587066700007,50.729772848,50.67515085900006,50.67370391900006,50.674220683,50.68838002600005,50.68688140900004,50.67861318000008,50.66290354400003,50.64936431900004,50.63556671200011,50.62368113200007,50.61623972600005,50.61298411100007,50.6097801720001,50.60662791000006,50.60363067700003,50.60859161400008,50.64678049800004,50.64404164700001,50.62864207000003,50.62409454400007,50.62657501300005,50.63634185800002,50.64910593700007,50.65913116500009,50.66088816400007,50.66042307600007,50.65510040300002,50.64404164700001,50.58662913000011,50.56756052700003,50.5593439740001,50.55179921500006,50.54849192300004,50.5457013960001,50.53991363500002,50.53484934500004,50.52714955700004,50.52125844300004,50.52182688400011,50.51417877200002,50.50120798800002,50.49278472900001,50.49035593700005,50.49604034400009,50.49278472900001,50.479865621,50.47164906800008,50.46498280900006,50.45676625600002,50.45537099200006,50.45165028900003,50.45128855400013,50.44017812200012,50.43712921100008,50.44002309200006,50.42415842700005,50.40627838100001,50.40260935500002,50.3768228150001,50.37103505500004,50.36442047200005,50.36545400100003,50.3694330850001,50.37186187800005,50.37186187800005,50.36994985000003,50.36064809200009,50.35134633400007,50.34225128200011,50.33351796500004,50.31837677000003,50.30793813100009,50.29796458000008,50.28499379500006,50.25533152300009,50.24272247300006,50.22799469100006,50.20773752900006,50.18882395500002,50.15471751000005,50.14221181200007,50.12743235300003,50.10702016300009,50.0930158500001,50.09492787700002,50.12195465200004,50.13228993800006,50.14340037100008,50.15693959600007,50.17440623,50.18675689700005,50.18861724900007,50.18773875000004,50.18972886500002,50.19156280600008,50.19693715400003,50.21176829000005,50.21709096300002,50.21729766900005,50.21306020200011,50.21347361300012,50.21714264000012,50.22923492500009,50.23197377500004,50.23181874700002,50.2291832480001,50.22313710600004,50.21290517200008,50.20995961500007,50.21848622700007,50.23166371700007,50.24272247300006,50.26701039600006,50.28494211900004,50.29775787400003,50.3069046020001,50.31925527000006,50.33863393200004,50.35992462200001,50.37821807900009,50.4084487920001,50.42240142900009,50.43294342100005,50.43108306900005,50.42026669700003,50.41459828700006,50.41635528600004,50.39795847600006,50.39366933200007,50.38116363600007,50.3768228150001,50.37671946300007,50.38075022400007,50.37847646100006,50.375685934,50.36483388300006,50.35191477500003,50.34323313400007,50.33641184500003,50.32214915000004,50.31775665300005,50.3186351530001,50.31300242200005,50.30824819000007,50.30447581000006,50.30111684200004,50.29822296200005,50.29569081700005,50.28266835600003,50.27000763000008,50.25972402000009,50.25326446600003,50.271557923,50.2726431280001,50.26132598900001,50.24272247300006,50.24055206300007,50.23977691700007,50.24050038700007,50.24272247300006,50.26556345600007,50.26835398400003,50.25822540300008,50.26210113600003,50.27109283500006,50.29739613900001,50.30556101500004,50.312382304,50.31506947800004,50.31103871700013,50.30767974900003,50.29176340700009,50.28948964500007,50.28680247000004,50.28380523700012,50.28065297500008,50.261946106,50.25279937800009,50.24272247300006,50.23600453800005,50.21750437400003,50.20236318000009,50.19109771800005,50.17471628900007,50.16799835200005,50.16680979500005,50.16324412000007,50.15316721600003,50.14588083900004,50.10634836900003,50.10180084300008,50.10298940000008,50.10614166300006,50.10774363200009,50.10546986900006,50.09678822800002,50.09487620099999,50.09389434900002,50.09296417300008,50.09218902600007,50.09146555600007,50.08634959000007,50.08087188800009,50.07513580400003,50.06908966100009,50.06056305000008,50.04950429400007,50.03715362600012,50.02521637000008,50.01519114200003,49.97364329100004,49.96868235300009,49.97581370000005,49.99276357000006,49.99581248000008,49.9965876270001,50.0028404750001,50.00723297100008,50.0172065230001,50.02413116500007,50.02428619500002,50.02268422499999,50.02413116500007,50.04676544200002,50.04408711000012,50.04180450500009,50.0172065230001,49.99875803600007,49.98904286700004,49.98123972600003,49.97581370000005,49.95829539000009,49.95488474600005,49.9517324830001,49.94604807600005,49.94057037400007,49.92506744400005,49.91829783100012,49.90780751600006,49.90966786800008,49.92542917900006,49.92713450100003,49.92827138300002,49.92883982400009,49.92883982400009,49.93204376300007,49.92315541600003,49.89664540700004,49.89669708300006,49.91297515900008,49.90718739800009,49.88904897100007,49.8737010710001,49.86145375600007,49.85220367500007,49.83158477800005,49.80476471000007,49.77437896700012,49.74295969700007,49.71386586600006,49.70637278300005,49.70032664000009,49.69856964100002,49.69577911400005,49.68885447200007,49.67381662999999,49.66890736900005,49.66968251600007,49.67407501300006,49.67583201100005,49.66859731100008,49.66079416900006,49.62637766600001,49.61676584900009,49.59929921500004,49.59025583900008,49.54762278200009,49.52695221000009,49.51026072200004,49.50953725200004,49.50488637299999,49.480288391,49.47925486300004,49.4850426230001,49.49579132100003,49.49672149700008,49.49579132100003,49.48597279900007,49.49015859000009,49.481683655,49.47346710200004,49.45486358700002,49.4460785940001,49.44060089100013,49.42907704700009,49.39507395500006,49.38546213800005,49.38975128200009,49.34226064100001,49.33019141800007,49.31125478100007,49.27694163100007,49.2586998500001,49.23306833900004,49.20257924500005,49.16976471000005,49.14294464100006,49.1369283320001,49.09225006200008,49.07028757800002,49.04718821200002,49.02915313800013,49.01912791000011,49.02186676000007,49.01938629200008,49.01049794600006,48.99303131100002,48.97820017600007,48.94724599200008,48.93355173800005,48.92171783500005,48.92099436500006,48.92337148100007,48.92058095300003,48.91174428300003,48.87257354800009,48.86291005400007,48.812990621,48.81676300100013,48.83810536700013,48.84275624700008,48.83815704300004,48.8302163340001,48.82177561400009,48.81960520500009,48.85779408800006,48.86606231800003,48.85975779200002,48.83391957600007,48.82461781800005,48.80575592100003,48.79371531200006,48.77402659200003,48.74632802399999,48.64987396300008,48.63594716400009,48.62315724700004,48.60416615800007,48.63077952100009,48.69697703000007,48.71899119100006,48.71981801400007,48.71077463800002,48.70922434500001,48.71377187100005,48.72963653600006,48.73309885700009,48.73206532800002,48.73392567900002,48.74002349900006,48.751857402,48.76622345,48.77826405900005,48.78338002600005,48.78482696500005,48.79629913400005,48.80353383400002,48.805600891,48.80477406900006,48.79970977900008,48.79939971900011,48.80219024700007,48.79454213500007,48.73707794300007,48.73030832900004,48.72725942000001,48.72844797800003,48.73557932600006,48.7335122680001,48.73284047500003,48.74653472900003,48.74286570200006,48.75805857400006,48.80642771400001,48.81138865200008,48.81831329400005,48.822602438,48.81970855800002,48.8302505490001,48.8347464000001,48.8350564580001,48.83309275300006,48.8420327760001,48.841671041,48.843893128,48.84916412400013,48.85009430000007,48.85200632800009,48.85712229500008,48.86942128500003,48.87231516500002,48.87226348900002,48.87086822500002,48.85846588200006,48.8549518840001,48.8549518840001,48.85846588200006,48.8873530070001,48.90261173300006,48.90848866800006,48.93670400000012,48.94481720000003,48.95468739900009,48.97081044600007,48.9749962370001,48.97535797200003,48.97763173500003,48.98259267200008,48.98672678700011,48.98667511100008,48.98259267200008,48.96915680000002,48.963885803,48.95293040000003,48.95075998900005,48.93722076400006,48.93747914700002,48.951741842,48.96533274299999,48.97892364500008,48.99303131100002,48.99721710200005,49.00977447500007,49.00791412400007,49.00626047800002,49.00290151000009,48.99825063100003,48.99282460500005,48.97174062200013,48.94326690700008,48.91267445900009,48.88502756800007,48.82239573200006,48.80978668200002,48.80281036400002,48.79650583900012,48.78859934500007,48.78213979100012,48.78033111600003,48.76281280600007,48.76157257100003,48.77557688400013,48.78033111600003,48.77650706000007,48.76699859700001,48.75485463500009,48.74312408500002,48.72400380500004,48.69341135700002,48.6731025190001,48.64610158300006,48.61553497400006,48.58954172800007,48.58653496300009,48.57623504600006,48.57695851700008,48.58349558500005,48.59290069600009,48.60233164500006,48.60328765900003,48.59974782300007,48.60031626400011,48.60452789300005,48.61119415300006,48.617576193,48.62132273400003,48.62049591099999,48.61093577100009,48.60871368400008,48.61062571200002,48.62447499700006,48.64318186500007,48.63651560500004,48.59706064900003,48.5862861130001,48.57142913900007,48.56070627900006,48.55863922100009,48.557915752,48.58117014600002,48.59171213900008,48.60116892500004,48.60612986299999,48.62039255800006,48.62587026000007,48.63951283800007,48.64240671800006,48.64380198200003,48.65315541600008,48.65460235600007,48.65398223900009,48.65491241400004,48.66116526300006,48.66726308200002,48.67005361000007,48.67191396100007,48.67506622300003,48.68328277600007,48.70018097000006,48.70648549400006,48.73098012400003,48.74302073200009,48.75242584300004,48.75929880800003,48.76643015600006,48.77981435200009,48.84337636300005,48.86730255200006,48.87247019500005,48.87634592800002,48.88223704000002,48.89345082600006,48.9090571090001,48.92724721300006,48.94616078700007,48.94481720000003,48.95101837200009,48.95995839500004,48.96703806600006,48.96934193000008,48.97024200500003,48.96605621400009,48.955049133,48.93763417600006,48.94502390600006,48.95995839500004,48.97768341100006,48.99303131100002,49.02109161400004,49.03850657200006,49.06692861000001,49.09364532500005,49.10056996700003,49.10563425700012,49.10749460900011,49.11834666000006,49.13514150000013,49.15483022100007,49.23818430600004,49.24278350900006,49.242886861,49.26779490200006,49.27709665900001,49.28676015300003,49.29492502900005,49.29962758400002,49.31910959900002,49.3267577110001,49.33270050100002,49.33957346700008,49.336731263,49.32386383100003,49.32221018500006,49.3278429170001,49.33254547200006,49.34324249300006,49.39114654600009,49.40473744700007,49.41889679000003,49.42949045800002,49.44395985900003,49.46018625900005,49.49300079400005,49.50984731000004,49.51377472000011,49.51279286700004,49.51501495400005,49.52240468300006,49.52989776599999,49.53883778900011,49.55082672200008,49.56255727200006,49.58472646100007,49.59557851200013,49.60312327100009,49.61164988200001,49.61971140600009,49.62214019800005,49.62999501600008,49.63252716100008,49.63387074800004,49.64611806300006,49.65939890500006,49.66999257500005,49.67469513000005,49.68503041600003,49.69180002900008,49.70022328700007,49.719498597,49.73231435100008,49.74285634400006,49.75789418600003,49.76926300100003,49.77970164000006,49.79613474600002,49.81711537700004,49.83122304300007,49.82724395800007,49.84269521100008,49.87023874900005,49.88553497300002,49.9049653120001,49.91220001200007,49.91576568700005,49.93126861600005,49.94212066600009,49.95560821600004,49.97023264600004,49.98056793200003,49.98304840100012,49.99276357000006,49.99276357000006,50.04495676700013,50.05131296900005,50.06040802000003,50.07063995400001,50.080510152,50.08857167600009,50.0945144650001,50.10283437200006,50.11797556600008,50.13296173100004,50.15569936100012,50.170737203,50.18262278300004,50.19378489200007,50.21104482000005,50.23083689400003,50.24272247300006,50.25481475800005,50.25915557900002,50.26380645799999,50.27662221300007,50.29088490800005,50.29977325500006,50.31517283100005,50.31398033800006,50.31171051100002,50.30297719300005,50.29372711200004,50.27657053700007,50.26876739500004,50.26246287100012,50.25956899000003,50.25910390200004,50.25657175800002,50.25295440700005,50.24835520400011,50.24272247300006,50.24256744500012,50.24225738500003,50.24168894399999,50.2409654750001,50.23905344700007,50.23703806600012,50.23481597900012,50.23249054000009,50.22117340100003,50.21740102100007,50.21088979100001,50.20505035500013,50.19988271100003,50.17233917300005,50.16221059200008,50.16081532800011,50.16732655900007,50.17621490500009,50.186911927,50.19931427000007,50.21709096300002,50.22649607400005,50.24272247300006,50.25858713800007,50.2663902800001,50.27140289400005,50.27905100500003,50.31517283100005,50.321994121,50.33253611300007,50.33935740200012,50.34070099000009,50.34049428300004,50.34188954700001,50.34555857400001,50.34948598300006,50.35284495100008,50.35491200800006,50.35940785800007,50.36447214800005,50.3694330850001,50.37356720000012,50.38876007100005,50.39635650700011,50.39992218100006,50.3937210080001,50.39465118400004,50.40152415000001,50.42343495800007,50.43154815700008,50.43532053600011,50.43594065400008,50.43433868400002,50.43588897700006,50.44183176700007,50.44302032500009,50.44141835600006,50.40539988200005,50.40415964800003,50.40923412300005,50.42296987000005,50.43366689100004,50.4519086720001,50.49268137600008,50.49635040400007,50.49764231400003,50.49650543200003,50.49278472900001,50.49113108400006,50.4906143190001,50.49107940700004,50.49268137600008,50.49268137600008,50.49278472900001,50.4989859010001,50.49702219700005,50.50875274700006,50.52534088200007,50.58202992800007,50.58089304700006,50.57365834600007,50.56895579000009,50.57577708000007,50.59603424100005,50.60239044300009,50.61934031200009,50.62347442700012,50.62709177700002,50.62833201100004,50.62548980700008,50.6216140750001,50.60657623400003,50.60130523700009,50.59432891900009,50.59727447600001,50.60709299800006,50.62089060500001,50.62445627900009,50.62915883400005,50.63520497700001,50.64321482300009,50.65122467100007,50.66218007500005,50.675667623,50.69101552400006,50.70672515900004,50.71215118500002,50.71184112600012,50.71426991800008,50.72320994100004,50.7246052040001,50.72134958900001,50.72367502900003,50.73514719700007,50.7352505490001,50.73654246100004,50.74274363200003,50.74801462800006,50.75504262300008,50.76351755800006,50.77323272700001,50.78041575200005,50.78062245700004,50.77876210500001,50.77995066400003,50.78480824800006,50.79721059200004,50.80206817700004,50.80475535100008,50.80175811800005,50.80258494100009,50.8479051720001,50.85513987300006,50.87260650700001,50.87937611900004,50.88413035100005,50.88020294200008,50.89596425400005,50.92087229400003,50.93063914000008,50.93751210600006,50.95348012400008,50.96397043900005,50.96769114200005,50.96970652300008,50.97482249000008,50.97761301700005,50.98247060200005,50.99265085900002,51.02143463200004,51.03683420800003,51.04001230900009,51.03233835900001,51.02799753800004,51.02244232200012,51.01699045900004,51.01326975600004,51.0131147260001,51.0209437060001,51.01965179400007,51.02337249800009,51.03719594300013,51.02872100900002,51.022700704,51.01670623800005,51.00851552400003,51.00303782200005,50.99874867800007,50.99265085900002,50.98340077800002,50.97549428300006,50.96572743700001,50.95068959600003,50.93864898700006,50.92428293900007,50.91208730100003,50.90635121700008,50.92087229400003,50.92071726600007,50.9094001270001,50.89611928300009,50.87095286100005,50.85307281500009,50.84557973200008,50.83937856100009,50.83436594600003,50.81596913700012,50.81069814100009,50.81018137600005,50.81297190400001,50.82005157500002,50.83162709600008,50.85844716400005]}]]],null,null,{&#34;interactive&#34;:true,&#34;className&#34;:&#34;&#34;,&#34;stroke&#34;:true,&#34;color&#34;:&#34;orangered&#34;,&#34;weight&#34;:3,&#34;opacity&#34;:0.8,&#34;fill&#34;:null,&#34;fillColor&#34;:&#34;orangered&#34;,&#34;fillOpacity&#34;:0.2,&#34;smoothFactor&#34;:1,&#34;noClip&#34;:false},null,null,null,{&#34;interactive&#34;:false,&#34;permanent&#34;:false,&#34;direction&#34;:&#34;auto&#34;,&#34;opacity&#34;:1,&#34;offset&#34;:[0,0],&#34;textsize&#34;:&#34;10px&#34;,&#34;textOnly&#34;:false,&#34;className&#34;:&#34;&#34;,&#34;sticky&#34;:true},null]}],&#34;limits&#34;:{&#34;lat&#34;:[48.557915752,51.04001230900009],&#34;lng&#34;:[12.07614099100005,18.83743371600011]},&#34;setView&#34;:[[48.13743,11.57549],4,[]]},&#34;evals&#34;:[],&#34;jsHooks&#34;:[]}&lt;/script&gt;
&lt;p&gt;&lt;br&gt;&lt;/p&gt;
&lt;p&gt;I hope I have demonstrated that using &lt;code&gt;leaflet.js&lt;/code&gt; library via the &lt;code&gt;{leaflet}&lt;/code&gt; package is both a powerful visualization technique, and a fun thing to do.&lt;/p&gt;
&lt;p&gt;Now I wish you the best in &lt;em&gt;your&lt;/em&gt; efforts.&lt;/p&gt;
</description>
  </item>
  
<item>
  <title>Text Classification in R</title>
  <link>https://www.jla-data.net/eng/vocabulary-based-text-classification/</link>
  <pubDate>Fri, 25 Jan 2019 00:00:00 +0000</pubDate>
  
<guid>https://www.jla-data.net/eng/vocabulary-based-text-classification/</guid>
  <description>


&lt;p&gt;Text classification in R is fun. While there are many possible approaches this blog post proposes a Keras (with Tensorflow backend) workflow based on vocabulary of lemmatized tokens.&lt;/p&gt;
&lt;p&gt;The workflow proposed is particularly advantageous for text in languages other than English, with complicated inflected forms - remember &lt;em&gt;ROMANES EUNT DOMUS&lt;/em&gt; scene from the &lt;a href=&#34;https://en.wikipedia.org/wiki/Monty_Python%27s_Life_of_Brian&#34;&gt;Life of Brian&lt;/a&gt;?&lt;/p&gt;
&lt;p&gt;The tokenisation and &lt;a href=&#34;https://en.wikipedia.org/wiki/Lemmatisation&#34;&gt;lemmatisation&lt;/a&gt; is performed using R package &lt;a href=&#34;https://github.com/bnosac/udpipe&#34;&gt;&lt;code&gt;udpipe&lt;/code&gt;&lt;/a&gt;. The main classification work is done via &lt;code&gt;keras&lt;/code&gt;, with light help of &lt;code&gt;caret&lt;/code&gt; and with &lt;code&gt;dplyr&lt;/code&gt; pipes used to hold everything together.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;library(tidyverse) # mainly dplyr
library(udpipe)    # tokenization &amp;amp; lemmatization
library(caret)     # used to split the dataset to train / test
library(keras)     # because Keras :)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;As a “problem” to solve I will train my model to determine autorship of Tweet data, using timelines of two popular accounts.&lt;/p&gt;
&lt;p&gt;I will be using a dataset of 1000 tweets; half each by &lt;a href=&#34;https://twitter.com/hadleywickham&#34;&gt;Hadley Wickham&lt;/a&gt; and &lt;a href=&#34;https://twitter.com/mariekondo&#34;&gt;Marie Kondo&lt;/a&gt;. It contains lots and lots of tidines, and some sparkling with joy.&lt;/p&gt;
&lt;p&gt;The dataset was collected with help of &lt;code&gt;rtweet&lt;/code&gt; library and can be downloaded by running below quoted code.&lt;/p&gt;
&lt;p&gt;It is also necessary to download the udpipe model. I am storing it in &lt;code&gt;tempdir()&lt;/code&gt;, but in a real world situation it will make more sense to store it in a permanent place. The models tend to be large.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;# directory for source data files
network_path &amp;lt;- &amp;#39;http://www.jla-data.net/ENG/2019-01-25-vocabulary-based-text-classification_files/&amp;#39;

tf_tweets &amp;lt;- tempfile(fileext = &amp;quot;.csv&amp;quot;) # create a temporary csv file
download.file(paste0(network_path, &amp;#39;tidy_tweets.csv&amp;#39;), tf_tweets, quiet = T)
tweets &amp;lt;- read.csv(tf_tweets, stringsAsFactors = F) # read the tweet data in

# download current udpipe model for English
udtarget &amp;lt;- udpipe_download_model(language = &amp;quot;english&amp;quot;,
                                  model_dir = tempdir())
# load the model
udmodel &amp;lt;- udpipe_load_model(file = udtarget$file_model) 

table(tweets$name) # verify structure of downloaded tweets&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;## 
## hadleywickham    MarieKondo 
##           500           500&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The first step is applying the &lt;code&gt;udpipe_annotate()&lt;/code&gt; function to the text of tweets. I am storing the id of the tweet as document id, enabling me to join the tweet data to individual words and lemmas later.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;words &amp;lt;- udpipe_annotate(udmodel, x = tweets$text, doc_id = tweets$id) %&amp;gt;% 
  as.data.frame() %&amp;gt;%
  select(id = doc_id, token, lemma, upos, sentence_id) %&amp;gt;%
  mutate(id = as.numeric(id))

# a sneak peak at the words object
glimpse(words)&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;## Rows: 24,179
## Columns: 5
## $ id          &amp;lt;dbl&amp;gt; 1.431262e+18, 1.431262e+18, 1.431262e+18, 1.431262e+18, 1.…
## $ token       &amp;lt;chr&amp;gt; &amp;quot;@_TimTaylor_&amp;quot;, &amp;quot;And&amp;quot;, &amp;quot;board_url&amp;quot;, &amp;quot;(&amp;quot;, &amp;quot;)&amp;quot;, &amp;quot;will&amp;quot;, &amp;quot;war…
## $ lemma       &amp;lt;chr&amp;gt; &amp;quot;@_TimTaylor_&amp;quot;, &amp;quot;and&amp;quot;, &amp;quot;board_url&amp;quot;, &amp;quot;(&amp;quot;, &amp;quot;)&amp;quot;, &amp;quot;will&amp;quot;, &amp;quot;war…
## $ upos        &amp;lt;chr&amp;gt; &amp;quot;SYM&amp;quot;, &amp;quot;CCONJ&amp;quot;, &amp;quot;NOUN&amp;quot;, &amp;quot;PUNCT&amp;quot;, &amp;quot;PUNCT&amp;quot;, &amp;quot;AUX&amp;quot;, &amp;quot;VERB&amp;quot;, &amp;quot;…
## $ sentence_id &amp;lt;int&amp;gt; 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2…&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The second step is construction of vocabulary. It is a simple data frame containg two fields: lemma, and id. It will be used to translate the lemmas to integers, to be fed to the keras model.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;vocabulary &amp;lt;- words %&amp;gt;%
  count(lemma) %&amp;gt;%
  ungroup() %&amp;gt;%
  arrange(desc(n)) %&amp;gt;%
  filter(n &amp;gt;=3) %&amp;gt;%  # little predictive value in rare words
  mutate(id_slovo = row_number()) %&amp;gt;% # unique id per lemma
  select(lemma, id_slovo)

# a sneak peak at the vocabulary object
glimpse(vocabulary)&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;## Rows: 988
## Columns: 2
## $ lemma    &amp;lt;chr&amp;gt; &amp;quot;.&amp;quot;, &amp;quot;the&amp;quot;, &amp;quot;be&amp;quot;, &amp;quot;to&amp;quot;, &amp;quot;you&amp;quot;, &amp;quot;,&amp;quot;, &amp;quot;a&amp;quot;, &amp;quot;:&amp;quot;, &amp;quot;!&amp;quot;, &amp;quot;I&amp;quot;, &amp;quot;and&amp;quot;…
## $ id_slovo &amp;lt;int&amp;gt; 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18…&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The third part is preparing keras input matrix. It starts as a dataframe (later converted to matrix) with 150 numerical columns, padded with zeroes. I yet have to see a 150 word tweet, so the size has some reserve.&lt;/p&gt;
&lt;p&gt;This is a rather complicated pipe, and while it does the work required it looks as a candidate for refactoring (I have a vague feeling that I am not properly using the &lt;code&gt;fill&lt;/code&gt; argument of the &lt;code&gt;spread()&lt;/code&gt; function).&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;# 150 zeroes for each tweet id for padding
vata &amp;lt;- expand.grid(id = unique(words$id),
                    word_num = 1:150,
                    id_slovo = 0)

word_matrix &amp;lt;- words %&amp;gt;% # words
  # filtering join! words not in vocabulary are discarded
  inner_join(vocabulary, by = c(&amp;#39;lemma&amp;#39; = &amp;#39;lemma&amp;#39;)) %&amp;gt;% 
  select(id, lemma, id_slovo) %&amp;gt;%
  group_by(id) %&amp;gt;%
  mutate(word_num = row_number()) %&amp;gt;% # 
  ungroup() %&amp;gt;%
  select(id, word_num, id_slovo) %&amp;gt;% # relevant columns
  rbind(vata) %&amp;gt;% # bind the 150 zeroes per tweet
  group_by(id, word_num) %&amp;gt;%
  mutate(id_slovo = max(id_slovo)) %&amp;gt;% # will include duplicites
  ungroup() %&amp;gt;%
  unique() %&amp;gt;% # remove duplicites
  spread(word_num, id_slovo) # spread to matrix format

keras_input &amp;lt;- tweets %&amp;gt;%
  select(id, name, text) %&amp;gt;%
  inner_join(word_matrix, by = c(&amp;#39;id&amp;#39; = &amp;#39;id&amp;#39;))

# this will be input for keras
glimpse(keras_input)&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;## Rows: 998
## Columns: 153
## $ id    &amp;lt;dbl&amp;gt; 1.431262e+18, 1.267958e+18, 1.273371e+18, 1.415105e+18, 1.383026…
## $ name  &amp;lt;chr&amp;gt; &amp;quot;hadleywickham&amp;quot;, &amp;quot;hadleywickham&amp;quot;, &amp;quot;hadleywickham&amp;quot;, &amp;quot;hadleywickha…
## $ text  &amp;lt;chr&amp;gt; &amp;quot;@_TimTaylor_ And board_url() will warn if you use it with a non…
## $ `1`   &amp;lt;dbl&amp;gt; 11, 91, 17, 13, 13, 25, 10, 371, 13, 4, 23, 20, 125, 766, 54, 13…
## $ `2`   &amp;lt;dbl&amp;gt; 20, 9, 3, 8, 8, 508, 218, 23, 8, 47, 5, 10, 155, 36, 872, 8, 295…
## $ `3`   &amp;lt;dbl&amp;gt; 21, 0, 2, 83, 50, 30, 5, 673, 2, 142, 281, 30, 63, 10, 16, 2, 10…
## $ `4`   &amp;lt;dbl&amp;gt; 57, 0, 20, 3, 23, 7, 390, 0, 177, 2, 112, 469, 71, 112, 350, 177…
## $ `5`   &amp;lt;dbl&amp;gt; 39, 0, 14, 58, 30, 166, 2, 0, 12, 343, 61, 4, 7, 412, 578, 12, 2…
## $ `6`   &amp;lt;dbl&amp;gt; 5, 0, 734, 27, 7, 18, 476, 0, 33, 6, 179, 25, 365, 31, 8, 33, 4,…
## $ `7`   &amp;lt;dbl&amp;gt; 42, 0, 14, 304, 89, 96, 4, 0, 89, 5, 0, 28, 19, 0, 266, 189, 484…
## $ `8`   &amp;lt;dbl&amp;gt; 17, 0, 21, 9, 151, 5, 223, 0, 14, 229, 0, 814, 31, 0, 35, 12, 5,…
## $ `9`   &amp;lt;dbl&amp;gt; 28, 0, 981, 255, 64, 63, 170, 0, 739, 92, 0, 32, 0, 0, 2, 44, 22…
## $ `10`  &amp;lt;dbl&amp;gt; 7, 0, 22, 413, 56, 42, 436, 0, 74, 4, 0, 554, 0, 0, 14, 14, 321,…
## $ `11`  &amp;lt;dbl&amp;gt; 899, 0, 10, 28, 40, 31, 0, 0, 8, 145, 0, 180, 0, 0, 645, 724, 20…
## $ `12`  &amp;lt;dbl&amp;gt; 0, 0, 87, 7, 82, 20, 0, 0, 6, 4, 0, 18, 0, 0, 14, 14, 114, 186, …
## $ `13`  &amp;lt;dbl&amp;gt; 0, 0, 119, 655, 20, 16, 0, 0, 6, 7, 0, 17, 0, 0, 224, 3, 679, 1,…
## $ `14`  &amp;lt;dbl&amp;gt; 0, 0, 53, 27, 220, 951, 0, 0, 11, 6, 0, 4, 0, 0, 8, 55, 42, 27, …
## $ `15`  &amp;lt;dbl&amp;gt; 0, 0, 2, 622, 922, 101, 0, 0, 403, 48, 0, 393, 0, 0, 266, 9, 6, …
## $ `16`  &amp;lt;dbl&amp;gt; 0, 0, 702, 457, 21, 203, 0, 0, 16, 39, 0, 1, 0, 0, 8, 128, 5, 6,…
## $ `17`  &amp;lt;dbl&amp;gt; 0, 0, 74, 4, 65, 21, 0, 0, 83, 17, 0, 17, 0, 0, 266, 0, 207, 137…
## $ `18`  &amp;lt;dbl&amp;gt; 0, 0, 179, 11, 11, 16, 0, 0, 14, 3, 0, 3, 0, 0, 359, 0, 63, 3, 0…
## $ `19`  &amp;lt;dbl&amp;gt; 0, 0, 0, 449, 10, 83, 0, 0, 3, 323, 0, 328, 0, 0, 964, 0, 75, 7,…
## $ `20`  &amp;lt;dbl&amp;gt; 0, 0, 0, 1, 3, 6, 0, 0, 58, 5, 0, 4, 0, 0, 16, 0, 511, 1, 0, 20,…
## $ `21`  &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 69, 20, 0, 0, 237, 25, 0, 43, 0, 0, 8, 0, 1, 0, 0, 2…
## $ `22`  &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 17, 21, 0, 0, 4, 16, 0, 18, 0, 0, 0, 0, 0, 0, 0, 1, …
## $ `23`  &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 16, 3, 0, 0, 1, 2, 0, 7, 0, 0, 0, 0, 0, 0, 0, 171, 0…
## $ `24`  &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 11, 926, 0, 0, 0, 130, 0, 385, 0, 0, 0, 0, 0, 0, 0, …
## $ `25`  &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 17, 20, 0, 0, 0, 12, 0, 28, 0, 0, 0, 0, 0, 0, 0, 7, …
## $ `26`  &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 3, 118, 0, 0, 0, 5, 0, 50, 0, 0, 0, 0, 0, 0, 0, 217,…
## $ `27`  &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 1, 6, 0, 0, 0, 315, 0, 168, 0, 0, 0, 0, 0, 0, 0, 144…
## $ `28`  &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 150, 0, 0, 0, 6, 0, 11, 0, 0, 0, 0, 0, 0, 0, 4, 0…
## $ `29`  &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 14, 0, 0, 0, 265, 0, 527, 0, 0, 0, 0, 0, 0, 0, 43…
## $ `30`  &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 891, 0, 0, 0, 6, 0, 21, 0, 0, 0, 0, 0, 0, 0, 11, …
## $ `31`  &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 14, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 292, 0…
## $ `32`  &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 21, 0, 0, 0, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 315, …
## $ `33`  &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 186, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 0…
## $ `34`  &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, …
## $ `35`  &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 118, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0,…
## $ `36`  &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 21, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, …
## $ `37`  &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 53, 0,…
## $ `38`  &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, …
## $ `39`  &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 21, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 380, 0…
## $ `40`  &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 668, 0,…
## $ `41`  &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 27, 0,…
## $ `42`  &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 926, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 40, 0…
## $ `43`  &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 74, 0,…
## $ `44`  &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 118, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 43, 0…
## $ `45`  &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0…
## $ `46`  &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 150, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 83, 0…
## $ `47`  &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ `48`  &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ `49`  &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 21, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ `50`  &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ `51`  &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 213, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ `52`  &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 21, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ `53`  &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 186, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ `54`  &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ `55`  &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ `56`  &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 118, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ `57`  &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 21, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ `58`  &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ `59`  &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 213, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ `60`  &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 21, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ `61`  &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `62`  &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `63`  &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `64`  &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `65`  &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `66`  &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `67`  &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `68`  &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `69`  &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `70`  &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `71`  &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `72`  &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `73`  &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `74`  &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `75`  &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `76`  &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `77`  &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `78`  &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `79`  &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `80`  &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `81`  &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `82`  &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `83`  &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `84`  &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `85`  &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `86`  &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `87`  &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `88`  &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `89`  &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `90`  &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `91`  &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `92`  &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `93`  &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `94`  &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `95`  &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `96`  &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `97`  &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `98`  &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `99`  &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `100` &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `101` &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `102` &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `103` &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `104` &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `105` &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `106` &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `107` &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `108` &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `109` &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `110` &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `111` &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `112` &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `113` &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `114` &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `115` &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `116` &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `117` &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `118` &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `119` &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `120` &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `121` &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `122` &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `123` &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `124` &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `125` &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `126` &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `127` &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `128` &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `129` &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `130` &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `131` &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `132` &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `133` &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `134` &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `135` &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `136` &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `137` &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `138` &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `139` &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `140` &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `141` &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `142` &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `143` &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `144` &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `145` &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `146` &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `147` &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `148` &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `149` &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ `150` &amp;lt;dbl&amp;gt; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Once the full keras input is prepared I split it into training and testing parts.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;set.seed(42) # Zaphod Beeblebrox advises to trust no other!

idx &amp;lt;- createDataPartition(keras_input$name, p = .8, list = F, times = 1) # 80 / 20 split

train_data &amp;lt;- keras_input[idx, ] # train dataset
test_data &amp;lt;- keras_input[-idx, ] # verification&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;With the training dataset ready a couple technical steps are necessary: converting the categorical field of author to a number, and conveting the whole input to a numerical matrix. The vocabulary size variable will be used to size keras input.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;train_data &amp;lt;- train_data %&amp;gt;%
  mutate(hadley = ifelse(name == &amp;#39;hadleywickham&amp;#39;, 1,0)) %&amp;gt;% # binary output
  select(-id, -name, -text)

x_train &amp;lt;- data.matrix(train_data %&amp;gt;% select(-hadley)) # everything except target
y_train &amp;lt;- data.matrix(train_data %&amp;gt;% select(hadley)) # target, and target only

vocab_size &amp;lt;- vocabulary %&amp;gt;% # count unique word ids
  pull(id_slovo) %&amp;gt;% 
  unique() %&amp;gt;%
  length() + 1 # one extra for the zero padding&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Once all the inputs are ready I define &amp;amp; train my model.&lt;/p&gt;
&lt;p&gt;The model uses an embedding layer of the size of the vocabulary, and one bidirectional &lt;a href=&#34;https://keras.rstudio.com/reference/layer_lstm.html&#34;&gt;LSTM&lt;/a&gt; layer. As the LSTM’s are notoriously prone to overfitting a dropout layer is necessary.&lt;/p&gt;
&lt;p&gt;The final layer is a single output node, representing the probability of a particular tweet being Hadley’s.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;model &amp;lt;- keras_model_sequential() 

model %&amp;gt;% 
  layer_embedding(input_dim = vocab_size, output_dim = 256) %&amp;gt;%
  bidirectional(layer_lstm(units = 128)) %&amp;gt;%
  layer_dropout(rate = 0.5) %&amp;gt;% 
  layer_dense(units = 1, activation = &amp;#39;sigmoid&amp;#39;) # 1 = Hadley, 0 = Marie

model %&amp;gt;% 
  compile(optimizer = &amp;quot;rmsprop&amp;quot;,
          loss = &amp;quot;binary_crossentropy&amp;quot;,
          metrics = c(&amp;quot;accuracy&amp;quot;))

history &amp;lt;- model %&amp;gt;%  # fit the model (this will take a while...)
  fit(x_train, 
      y_train, 
      epochs = 25, 
      batch_size = nrow(train_data)/5, 
      validation_split = 1/5)

summary(model)&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;## Model: &amp;quot;sequential&amp;quot;
## ________________________________________________________________________________
##  Layer (type)                       Output Shape                    Param #     
## ================================================================================
##  embedding (Embedding)              (None, None, 256)               253184      
##  bidirectional (Bidirectional)      (None, 256)                     394240      
##  dropout (Dropout)                  (None, 256)                     0           
##  dense (Dense)                      (None, 1)                       257         
## ================================================================================
## Total params: 647,681
## Trainable params: 647,681
## Non-trainable params: 0
## ________________________________________________________________________________&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;With the model trained I verify its effectiveness on the testing dataset, using the same pre–processing as for the training data.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;pred_data &amp;lt;- test_data %&amp;gt;% # expected results
  select(id, name, text)

test_data &amp;lt;- test_data %&amp;gt;%
  mutate(hadley = ifelse(name == &amp;#39;hadleywickham&amp;#39;, 1,0)) %&amp;gt;% # binary output
  select(-id, -name, -text) # no cheating!

x_pred &amp;lt;- data.matrix(test_data %&amp;gt;% select(-hadley)) # keras needs matrix

pred &amp;lt;- model %&amp;gt;% # let keras sweat...
  predict(x_pred)

verifikace &amp;lt;- pred_data %&amp;gt;% # correct results ...
  cbind(pred) # ... joined with predictions

verifikace &amp;lt;- verifikace %&amp;gt;%
  mutate(name_pred = ifelse(pred &amp;gt; 0.5, &amp;#39;hadleywickham&amp;#39;, &amp;#39;MarieKondo&amp;#39;))

conf_mtx &amp;lt;- table(verifikace$name, verifikace$name_pred)

print(paste0(&amp;#39;Correctly predicted &amp;#39;,
             sum(diag(conf_mtx)), &amp;#39; of &amp;#39;,
             sum(conf_mtx), &amp;#39; tweets, which means &amp;#39;, 
             round(100 * sum(diag(conf_mtx))/sum(conf_mtx), 2), 
             &amp;#39;% of the total.&amp;#39;))&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;## [1] &amp;quot;Correctly predicted 180 of 199 tweets, which means 90.45% of the total.&amp;quot;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Having accurary over 90% in a toy example such as this is not bad :)&lt;/p&gt;
&lt;p&gt;It can be further improved in a number of ways - the two most obvious are including more training data (500 tweets is not that many), or adding more layers to create a more complicated model.&lt;/p&gt;
</description>
  </item>
  
<item>
  <title>Optimizing Prague Bar Network</title>
  <link>https://www.jla-data.net/eng/branch-network-optimization-in-r/</link>
  <pubDate>Mon, 14 Jan 2019 00:00:00 +0000</pubDate>
  
<guid>https://www.jla-data.net/eng/branch-network-optimization-in-r/</guid>
  <description>
&lt;script src=&#34;https://www.jla-data.net/rmarkdown-libs/htmlwidgets/htmlwidgets.js&#34;&gt;&lt;/script&gt;
&lt;script src=&#34;https://www.jla-data.net/rmarkdown-libs/jquery/jquery.min.js&#34;&gt;&lt;/script&gt;
&lt;link href=&#34;https://www.jla-data.net/rmarkdown-libs/leaflet/leaflet.css&#34; rel=&#34;stylesheet&#34; /&gt;
&lt;script src=&#34;https://www.jla-data.net/rmarkdown-libs/leaflet/leaflet.js&#34;&gt;&lt;/script&gt;
&lt;link href=&#34;https://www.jla-data.net/rmarkdown-libs/leafletfix/leafletfix.css&#34; rel=&#34;stylesheet&#34; /&gt;
&lt;script src=&#34;https://www.jla-data.net/rmarkdown-libs/Proj4Leaflet/proj4-compressed.js&#34;&gt;&lt;/script&gt;
&lt;script src=&#34;https://www.jla-data.net/rmarkdown-libs/Proj4Leaflet/proj4leaflet.js&#34;&gt;&lt;/script&gt;
&lt;link href=&#34;https://www.jla-data.net/rmarkdown-libs/rstudio_leaflet/rstudio_leaflet.css&#34; rel=&#34;stylesheet&#34; /&gt;
&lt;script src=&#34;https://www.jla-data.net/rmarkdown-libs/leaflet-binding/leaflet.js&#34;&gt;&lt;/script&gt;
&lt;script src=&#34;https://www.jla-data.net/rmarkdown-libs/leaflet-providers/leaflet-providers.js&#34;&gt;&lt;/script&gt;
&lt;script src=&#34;https://www.jla-data.net/rmarkdown-libs/leaflet-providers-plugin/leaflet-providers-plugin.js&#34;&gt;&lt;/script&gt;


&lt;p&gt;Optimizing branch presence is a common activity in marketing. In this blog post I propose a R centered workflow for this task.&lt;/p&gt;
&lt;p&gt;While the “problem” of optimizing locations of Prague bars is meant only half seriously, the case study uses real world data and shows the ease with which R can be used as a tool enabling more serious work.&lt;/p&gt;
&lt;p&gt;The main steps taken are the following:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;exploring the point data (location of bars in Prague)&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;creating an equal distance grid covering the City of Prague&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;assigning target and feature variables (population, visitors, metro stations) to the grid cells&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;fitting a model predicting the number of bars accoding to the feature variables&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;visualizing residuals - difference between observed and modeled count of bars per cell&lt;/li&gt;
&lt;/ul&gt;
&lt;div id=&#34;getting-the-bars-data-in&#34; class=&#34;section level3&#34;&gt;
&lt;h3&gt;Getting the Bars Data in&lt;/h3&gt;
&lt;p&gt;I am using an existing CSV file, listing names and coordinates of all Prague bars. The file can be downloaded by running code from the block below.&lt;/p&gt;
&lt;p&gt;Comparable results could be obtained from R via either Google Places API via &lt;code&gt;googleway::google_places()&lt;/code&gt; and / or OpenStreetMap API via &lt;code&gt;osmdata::osmdata_sf()&lt;/code&gt;.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;library(tidyverse) # mainly ggplot &amp;amp; dplyr
library(RCzechia)  # spatial objects of the Czech Republic
library(scales)    # aligned with tidyverse, but not a part of the core
library(units)     # for handling area units (square kilometers)
library(sf)        # spatial vector data operations package

# directory for source data files
network_path &amp;lt;- &amp;#39;http://www.jla-data.net/ENG/2019-01-14-optimizing-prague-bar-network_files/&amp;#39;

tf_bars &amp;lt;- tempfile(fileext = &amp;quot;.csv&amp;quot;) # create a temporary csv file
download.file(paste0(network_path, &amp;#39;prague_bars.csv&amp;#39;), tf_bars, quiet = T)
bars &amp;lt;- read.csv(tf_bars) # read the bar data in&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div id=&#34;additional-spatial-objects&#34; class=&#34;section level3&#34;&gt;
&lt;h3&gt;Additional Spatial Objects&lt;/h3&gt;
&lt;p&gt;To present the Prague bars in a broader context I am also displaying a polygon representing the borders of the &lt;a href=&#34;https://en.wikipedia.org/wiki/Prague&#34;&gt;City of Prague&lt;/a&gt; and a polyline of the part of &lt;a href=&#34;https://en.wikipedia.org/wiki/Vltava&#34;&gt;Vltava&lt;/a&gt; river passing through the city. Both spatial objects come from package &lt;a href=&#34;https://github.com/jlacko/RCzechia&#34;&gt;RCzechia&lt;/a&gt;, which can be installed from CRAN.&lt;/p&gt;
&lt;p&gt;During this exercise, and later when creating the grid and filling it with data, I will frequently switch between two &lt;a href=&#34;https://en.wikipedia.org/wiki/Spatial_reference_system&#34;&gt;coordinate reference systems&lt;/a&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;spherical &lt;a href=&#34;https://epsg.io/4326&#34;&gt;EPSG:4326&lt;/a&gt;, which is the familiar degree based WGS84 used by GPS, Google and many others&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;planar &lt;a href=&#34;https://epsg.io/5514&#34;&gt;EPSG:5514&lt;/a&gt; by ing. Křovák, which is the official Czech CRS and has eastings and northings in meters&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The spherical coordinates are ubiquitous and are handy for visualization using standard packages, but for operations involving distance or area only a metric CRS will do.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;obrys &amp;lt;- RCzechia::kraje(&amp;quot;high&amp;quot;) %&amp;gt;% # all the Czech NUTS3 entities ...
  filter(KOD_CZNUTS3 == &amp;#39;CZ010&amp;#39;) %&amp;gt;% #  ... just Prague
  select(geometry) %&amp;gt;% # only the boundaries (no data)
  st_transform(5514) # to a metric CRS (for the buffer to work)

bbox &amp;lt;- obrys %&amp;gt;%
  st_buffer(1000) # 1 kilometer buffer

obrys &amp;lt;- st_transform(obrys, 4326) # back to WGS84

vltava &amp;lt;- RCzechia::reky() %&amp;gt;% # all the Czech rivers ...
  filter(NAZEV == &amp;#39;Vltava&amp;#39;) %&amp;gt;% # ... the one relevant
  st_transform(5514) %&amp;gt;% # to a metric CRS
  st_intersection(bbox) %&amp;gt;% # clip to the box around Prague
  st_transform(4326) # back to WGS84&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div id=&#34;initial-overview&#34; class=&#34;section level3&#34;&gt;
&lt;h3&gt;Initial Overview&lt;/h3&gt;
&lt;p&gt;Having downloaded the bar location data, and prepared the other spatial objects to give them necessary context, I draw a simple scatterplot. This is the exploratory phase, and a basic &lt;code&gt;ggplot2&lt;/code&gt; chart will do.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;ggplot() +
  geom_point(data = bars, aes(x = lon, y = lat), pch = 4, alpha = 0.7, col = &amp;quot;red&amp;quot;) +
  geom_sf(data = vltava, color = &amp;#39;slategray3&amp;#39;, lwd = 1.25) +
  geom_sf(data = obrys, fill = NA, color = &amp;#39;gray75&amp;#39;, lwd = 1, alpha = 0.6) +
  theme_bw() +
  theme(axis.title.y = element_blank(), 
        axis.title.x = element_blank())&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;https://www.jla-data.net/ENG/2019-01-14-optimizing-prague-bar-network_files/figure-html/plot-points-1.png&#34; width=&#34;672&#34; /&gt;&lt;/p&gt;
&lt;p&gt;The bars in Prague seem to follow a roughly octopus shape - a big cluster in the center, with tentacles spreading to the outskirts.&lt;/p&gt;
&lt;p&gt;With a little local knowledge (there is a reason I am picking &lt;em&gt;this&lt;/em&gt; city :) I can tell that the tentacles seem to follow the metro lines.&lt;/p&gt;
&lt;p&gt;The points in the city center overlap greatly; a density plot gives better understanding of the situation.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;ggplot() +
  stat_density_2d(data = bars, aes(x = lon, y = lat, fill = ..level..), 
                  geom = &amp;quot;polygon&amp;quot;, alpha = .15, color = NA) +
  scale_fill_gradient2(&amp;quot;Bars&amp;quot;, low = &amp;quot;white&amp;quot;, mid = &amp;quot;yellow&amp;quot;, high = &amp;quot;red&amp;quot;) +
  geom_sf(data = vltava, color = &amp;#39;slategray3&amp;#39;, lwd = 1.25) +
  geom_sf(data = obrys, fill = NA, color = &amp;#39;gray75&amp;#39;, lwd = 1, alpha = 0.6) +
  theme_bw() +
  theme(axis.title.y = element_blank(), 
        axis.title.x = element_blank(),
        legend.text.align = 1)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;https://www.jla-data.net/ENG/2019-01-14-optimizing-prague-bar-network_files/figure-html/plot-density-1.png&#34; width=&#34;672&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;div id=&#34;creating-equal-distance-grid&#34; class=&#34;section level3&#34;&gt;
&lt;h3&gt;Creating Equal Distance Grid&lt;/h3&gt;
&lt;p&gt;The appropriate size of grid cells can be adjusted as required. For the purpose of my exercise I am setting the cell area to two square kilometers. This will make a grid of 322 cells.&lt;/p&gt;
&lt;p&gt;When creating the grid via &lt;code&gt;sf::st_make_grid()&lt;/code&gt; it is necessary that my underlying spatial object is in a planar CRS (meaning WGS84 will not do).&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;# size of squares, in units of the CRS (i.e. meters for 5514)
grid_spacing &amp;lt;- 1000*sqrt(2)  

obrys &amp;lt;- st_transform(obrys, 5514) # temporarily transform to a metric CRS

krabicka &amp;lt;- st_bbox(obrys)

xrange &amp;lt;- krabicka$xmax - krabicka$xmin 
yrange &amp;lt;- krabicka$ymax - krabicka$ymin

# count the polygons necessary &amp;amp; round up to the nearest integer
rozmery &amp;lt;- c(xrange/grid_spacing , yrange/grid_spacing) %&amp;gt;% 
  ceiling() 

grid &amp;lt;- st_make_grid(obrys, square = T, n = rozmery) %&amp;gt;% # make the grid
  st_intersection(obrys) %&amp;gt;% # clop the inside part, as a sfc object
  st_transform(4326) %&amp;gt;% # convert to WGS84
  st_sf() %&amp;gt;% # make the sfc a sf object, capable of holding data
  mutate(id = row_number()) # create id of the grid cell

obrys &amp;lt;- st_transform(obrys, 4326) # back to WGS84

ggplot() + 
  geom_sf(data = grid, fill = NA, color = &amp;#39;gray50&amp;#39;, alpha = 0.6) +
  geom_sf(data = vltava, color = &amp;#39;slategray3&amp;#39;, lwd = 1.25) +
  geom_sf(data = obrys, fill = NA, color = &amp;#39;gray75&amp;#39;, lwd = 1, alpha = 0.6) +
  theme_bw() +
  theme(axis.title.y = element_blank(), 
        axis.title.x = element_blank())&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;https://www.jla-data.net/ENG/2019-01-14-optimizing-prague-bar-network_files/figure-html/grid-1.png&#34; width=&#34;672&#34; /&gt;&lt;/p&gt;
&lt;p&gt;The grid looks somewhat twisted. This is an expected output, as the Křovák projection is by design not aligned with north on top. The reasons for that are historical, and not really relevant for this exercise. The important thing is that the grid is spaced evenly, and each grid cell (except for the edge ones) has area of 2 km².&lt;/p&gt;
&lt;p&gt;Having prepared the grid I join it to the data frame of bars, and count the totals per grid cell.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;bars &amp;lt;- bars %&amp;gt;% # convert to a sf object
    st_as_sf(coords = c(&amp;quot;lon&amp;quot;, &amp;quot;lat&amp;quot;), 
           crs = 4326, agr = &amp;quot;constant&amp;quot;)

pruseciky &amp;lt;- st_join(bars, grid) %&amp;gt;%
  st_set_geometry(NULL) %&amp;gt;%
  group_by(id) %&amp;gt;%
  tally() %&amp;gt;%
  select(id, barcount = n)

grid &amp;lt;- left_join(grid, pruseciky, by = &amp;#39;id&amp;#39;) %&amp;gt;%
  mutate(barcount = ifelse(is.na(barcount), 0, barcount)) # replace NAs with zero

ggplot() +
  geom_sf(data = grid, aes(fill = barcount), color = &amp;#39;gray50&amp;#39;, alpha = 0.6) +
  scale_fill_gradient2(midpoint = 30,
                       low = &amp;#39;green2&amp;#39;,
                       mid = &amp;#39;yellow&amp;#39;,
                       high = &amp;#39;red3&amp;#39;,
                       na.value = &amp;#39;white&amp;#39;,
                       name = &amp;#39;bar count&amp;#39;) +
  geom_sf(data = vltava, color = &amp;#39;slategray3&amp;#39;, lwd = 1.25) +
  geom_sf(data = obrys, fill = NA, color = &amp;#39;gray75&amp;#39;, lwd = 1, alpha = 0.6) +
  theme_bw() +
  theme(axis.title.y = element_blank(), 
        axis.title.x = element_blank(),
        legend.text.align = 1)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;https://www.jla-data.net/ENG/2019-01-14-optimizing-prague-bar-network_files/figure-html/bars-per-grid-1.png&#34; width=&#34;672&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;div id=&#34;feature-data&#34; class=&#34;section level3&#34;&gt;
&lt;h3&gt;Feature data&lt;/h3&gt;
&lt;p&gt;After an extensive fielwork investigating the Prague bars and their patrons I decided on three features for my model:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;em&gt;local population&lt;/em&gt;, using data from the latest census in 2011, by the &lt;a href=&#34;https://www.czso.cz/csu/czso/home&#34;&gt;Czech Statistical Office&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;foreign visitors&lt;/em&gt;, using as proxy number of hotel beds as of 2017, also by the Statistical Office&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;&lt;em&gt;metro stations&lt;/em&gt;, using a GeoJSON from Prague City &lt;a href=&#34;http://opendata.praha.eu/en/&#34;&gt;open data portal&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The data sets were lightly edited for size, and can be downloaded by running code below.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;tf_czso &amp;lt;- tempfile(fileext = &amp;quot;.csv&amp;quot;) # creae a temporary csv file
download.file(paste0(network_path,&amp;#39;CZSO_data.csv&amp;#39;), tf_czso, quiet = T) 
czso &amp;lt;- read.csv(tf_czso) # read the Czech Statistic Office data

tf_metro &amp;lt;- tempfile(fileext = &amp;quot;.geojson&amp;quot;) # a temoprary geojson
download.file(paste0(network_path,&amp;#39;metro_stations.geojson&amp;#39;), tf_metro, quiet = T)
metro &amp;lt;- st_read(tf_metro, quiet = T) # read the metro stations&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Metro stations are points, and easy to assign to grid cells directly. The population and hotel beds are more tricky, as they are reported for administrative districts (Prague has 57 of these).&lt;/p&gt;
&lt;p&gt;Assigning values per district to the grid cells required making an assumption of equal density of the metric across a district; then it was easy to assign the metric according to the proportion of area of district intersecting each grid cell.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;prazske_casti &amp;lt;- RCzechia::casti() %&amp;gt;% # shapefile all borroughs of Czech cities
  filter(NAZ_OBEC == &amp;#39;Praha&amp;#39;) %&amp;gt;% # Prague ones
  mutate(cast = as.numeric(KOD)) %&amp;gt;% # keys in RCzechia are character
  inner_join(czso, by = &amp;#39;cast&amp;#39;)

# transform to a metric CRS (for area measurement)
prazske_casti &amp;lt;- st_transform(prazske_casti, 5514)
grid &amp;lt;- st_transform(grid, 5514)

prazske_casti$pr_area &amp;lt;- st_area(prazske_casti) # total area of the borrough

# create a temp structure for calculating the population &amp;amp; beds per grid cell
asdf &amp;lt;- prazske_casti %&amp;gt;%
  # intersection of borrough and grid cell - there will be partial intersections
  # (there will be more rows of intersections than of grid cells)
  st_intersection(grid) %&amp;gt;% 
  select(id, pr_area, pop, beds)

asdf$in_area &amp;lt;- drop_units(st_area(asdf)) # area of intersection of borrough &amp;amp; grid cell

asdf &amp;lt;- asdf %&amp;gt;%
  st_set_geometry(NULL) %&amp;gt;%
  mutate(pop = pop * in_area / pr_area,  # share of metric as proportion of area
         beds = replace_na(beds * in_area / pr_area, 0)) %&amp;gt;%
  group_by(id) %&amp;gt;% # group by cell id
  summarise(pop = drop_units(sum(pop)), # totals per grid cell
            beds = drop_units(sum(beds))) 

grid &amp;lt;- left_join(grid, asdf, by = &amp;#39;id&amp;#39;) # attach the temp structure

grid &amp;lt;- st_transform(grid, 4326) # back to WGS84

# count metro stations per grid cell &amp;amp; attach
pruseciky &amp;lt;- st_join(metro, grid) %&amp;gt;%
  st_set_geometry(NULL) %&amp;gt;%
  group_by(id) %&amp;gt;%
  tally() %&amp;gt;%
  select(id, stations = n)

grid &amp;lt;- left_join(grid, pruseciky, by = &amp;#39;id&amp;#39;) # now the grid information is complete!

ggplot() + # plot population
  geom_sf(data = grid, aes(fill = pop), color = &amp;#39;gray50&amp;#39;, alpha = 0.6) +
  scale_fill_gradient2(low = &amp;#39;green2&amp;#39;,
                       mid = &amp;#39;yellow&amp;#39;,
                       high = &amp;#39;red3&amp;#39;,
                       na.value = &amp;#39;white&amp;#39;,
                       name = &amp;#39;population&amp;#39;,
                       labels = comma) +
  geom_sf(data = vltava, color = &amp;#39;slategray3&amp;#39;, lwd = 1.25) +
  geom_sf(data = obrys, fill = NA, color = &amp;#39;gray75&amp;#39;, lwd = 1, alpha = 0.6) +
  theme_bw() +
  theme(axis.title.y = element_blank(), 
        axis.title.x = element_blank(),
        legend.text.align = 1)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;https://www.jla-data.net/ENG/2019-01-14-optimizing-prague-bar-network_files/figure-html/allocate-data-to-grid-1.png&#34; width=&#34;672&#34; /&gt;&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;ggplot() + # plot hotel beds
  geom_sf(data = grid, aes(fill = beds), color = &amp;#39;gray50&amp;#39;, alpha = 0.6) +
  scale_fill_gradient2(low = &amp;#39;green2&amp;#39;,
                       mid = &amp;#39;yellow&amp;#39;,
                       high = &amp;#39;red3&amp;#39;,
                       na.value = &amp;#39;white&amp;#39;,
                       name = &amp;#39;hotel beds&amp;#39;,
                       labels = comma) +
  geom_sf(data = vltava, color = &amp;#39;slategray3&amp;#39;, lwd = 1.25) +
  geom_sf(data = obrys, fill = NA, color = &amp;#39;gray75&amp;#39;, lwd = 1, alpha = 0.6) +
  theme_bw() +
  theme(axis.title.y = element_blank(), 
        axis.title.x = element_blank(),
        legend.text.align = 1)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;https://www.jla-data.net/ENG/2019-01-14-optimizing-prague-bar-network_files/figure-html/allocate-data-to-grid-2.png&#34; width=&#34;672&#34; /&gt;&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;ggplot() + # plot metro stations
  geom_sf(data = grid, aes(fill = stations), color = &amp;#39;gray50&amp;#39;, alpha = 0.6) +
  scale_fill_gradient2(low = &amp;#39;green2&amp;#39;,
                       mid = &amp;#39;yellow&amp;#39;,
                       high = &amp;#39;red3&amp;#39;,
                       na.value = &amp;#39;white&amp;#39;,
                       name = &amp;#39;metro stations&amp;#39;,
                       breaks = c(1, 2, 3)) +
  geom_sf(data = vltava, color = &amp;#39;slategray3&amp;#39;, lwd = 1.25) +
  geom_sf(data = obrys, fill = NA, color = &amp;#39;gray75&amp;#39;, lwd = 1, alpha = 0.6) +
  theme_bw() +
  theme(axis.title.y = element_blank(), 
        axis.title.x = element_blank(),
        legend.text.align = 1)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;https://www.jla-data.net/ENG/2019-01-14-optimizing-prague-bar-network_files/figure-html/allocate-data-to-grid-3.png&#34; width=&#34;672&#34; /&gt;&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;# as final step: replace missing metro stations with zeroes
grid &amp;lt;- grid %&amp;gt;%
  mutate(stations = ifelse(is.na(stations), 0, stations))&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div id=&#34;model&#34; class=&#34;section level3&#34;&gt;
&lt;h3&gt;Model&lt;/h3&gt;
&lt;p&gt;Now that both target variable and model features are assigned to the grid cells it is easy to fit a model. A linear regression is a good first step.&lt;/p&gt;
&lt;p&gt;Note that modeling is the key factor setting R apart from other GIS tools. While I am opting for a plain vanilla linear regression in this case, I could easily throw the full R modeling arsenal at the problem, if I so desired. This is a race in which the regular GIS packages, both closed and open source, are in no position to compete.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;# simple does it - linear regression
model &amp;lt;- lm(data = grid, barcount ~ pop + beds + stations)

print(summary(model))&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;## 
## Call:
## lm(formula = barcount ~ pop + beds + stations, data = grid)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -18.028  -1.430   0.150   0.733  40.323 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(&amp;gt;|t|)    
## (Intercept) -0.7495977  0.4141490  -1.810 0.071244 .  
## pop          0.0006343  0.0000874   7.258 3.04e-12 ***
## beds         0.0030737  0.0002195  14.005  &amp;lt; 2e-16 ***
## stations     3.0116793  0.7878523   3.823 0.000159 ***
## ---
## Signif. codes:  0 &amp;#39;***&amp;#39; 0.001 &amp;#39;**&amp;#39; 0.01 &amp;#39;*&amp;#39; 0.05 &amp;#39;.&amp;#39; 0.1 &amp;#39; &amp;#39; 1
## 
## Residual standard error: 5.243 on 318 degrees of freedom
## Multiple R-squared:  0.6893, Adjusted R-squared:  0.6864 
## F-statistic: 235.2 on 3 and 318 DF,  p-value: &amp;lt; 2.2e-16&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;All the coefficient appear statistically significant, and R² of 0.69 is a respectable figure for a simple model.&lt;/p&gt;
&lt;p&gt;It is interesting that the coefficient for foreign visitors is by an order of magnitude higher than for locals. It takes 1577 Prague residents to support a bar, but only 325 foreign visitors.&lt;/p&gt;
&lt;p&gt;As interesting as the model and its coefficients may be from the point of view of network optimalization they are secondary. We are more interested in the residuals. From differences between observed and modeled values of bar count per grid cell I can tell areas that have too high, and too low, number of bars (branch locations). This will be the key output.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;resids &amp;lt;- model$residuals # extract residuals from model

grid &amp;lt;- grid %&amp;gt;% # ... attach them to grid
  cbind(resids)&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div id=&#34;report-the-results&#34; class=&#34;section level3&#34;&gt;
&lt;h3&gt;Report the results&lt;/h3&gt;
&lt;p&gt;As this will be the main output of my investigation I will present the plot of residuals interactively, using toolset from the &lt;code&gt;leaflet&lt;/code&gt; package.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;library(leaflet)
library(htmltools)

# diverging palette - green is good, red is bad
pal &amp;lt;- colorBin(palette = &amp;quot;RdYlGn&amp;quot;,  domain = grid$resids,  bins = 5,  reverse = T)

grid &amp;lt;- grid %&amp;gt;% # create a HTML formatted popup label of grid cell
  mutate(label = paste0(round(abs(resids)),&amp;#39; &amp;lt;u&amp;gt;&amp;#39;, 
                        ifelse(resids &amp;gt; 0, &amp;#39;more&amp;#39;, &amp;#39;less&amp;#39;),&amp;#39;&amp;lt;/u&amp;gt; bars than expected&amp;#39;))

leaflet() %&amp;gt;%
  addProviderTiles(providers$CartoDB.Positron) %&amp;gt;%
  setView(lng = 14.46, lat = 50.07, zoom = 11) %&amp;gt;%
  addPolygons(data = grid, 
              fillColor = ~pal(resids),
              fillOpacity = 0.55,
              stroke = F, 
              popup = ~label) &lt;/code&gt;&lt;/pre&gt;
&lt;div id=&#34;htmlwidget-1&#34; style=&#34;width:100%;height:604.8px;&#34; class=&#34;leaflet html-widget&#34;&gt;&lt;/div&gt;
&lt;script type=&#34;application/json&#34; data-for=&#34;htmlwidget-1&#34;&gt;{&#34;x&#34;:{&#34;options&#34;:{&#34;crs&#34;:{&#34;crsClass&#34;:&#34;L.CRS.EPSG3857&#34;,&#34;code&#34;:null,&#34;proj4def&#34;:null,&#34;projectedBounds&#34;:null,&#34;options&#34;:{}}},&#34;calls&#34;:[{&#34;method&#34;:&#34;addProviderTiles&#34;,&#34;args&#34;:[&#34;CartoDB.Positron&#34;,null,null,{&#34;errorTileUrl&#34;:&#34;&#34;,&#34;noWrap&#34;:false,&#34;detectRetina&#34;:false}]},{&#34;method&#34;:&#34;addPolygons&#34;,&#34;args&#34;:[[[[{&#34;lng&#34;:[14.3374886752334,14.3531671442364,14.3537612564878,14.3537332344886,14.3530302742094,14.3517271447921,14.3507228102893,14.3503515276346,14.3495239876307,14.3484879511567,14.3466569648955,14.3459861558723,14.3455738652148,14.3448844344797,14.3441454107291,14.3435254641377,14.3432678128683,14.342941537128,14.3414984088099,14.3412873054062,14.3412083572141,14.3412655551897,14.3408654619569,14.3404130396962,14.3384449750249,14.3384510794517,14.3376986952229,14.3374968887054,14.3374886752334],&#34;lat&#34;:[49.949231710439,49.950633956808,49.9478659937728,49.9478610148786,49.9480381012006,49.9482875312223,49.9482944273348,49.9482553362961,49.9482066803465,49.9482020075993,49.9483237597114,49.9481145367148,49.9480502490711,49.9479100659028,49.9476753039616,49.9476720414281,49.9476324714122,49.947662194432,49.9481517033238,49.9484002349485,49.9485849764504,49.9486330304117,49.9487417433492,49.9487470102502,49.9485565420092,49.9485870439389,49.9484616067849,49.9492105891074,49.949231710439]}]],[[{&#34;lng&#34;:[14.3537612564878,14.3531671442364,14.3719130548881,14.372838052029,14.3727146624246,14.3726928393599,14.3722782204536,14.3722061111613,14.3721914786703,14.3722188650661,14.3721748576532,14.3720873745757,14.3719805501624,14.3717508442946,14.3715777878246,14.3714500910908,14.3712845969216,14.3695088365874,14.3688423435617,14.368439935512,14.3671563478459,14.3671010014189,14.3670432166478,14.3670545960402,14.3668290377546,14.3664671171276,14.3661559419464,14.3659395363087,14.3656714243061,14.3654220683295,14.3645540206999,14.3615946700202,14.3604570132404,14.3588007426113,14.3537612564878],&#34;lat&#34;:[49.9478659937728,49.950633956808,49.9523076600116,49.9479901631301,49.9482834245789,49.9484253463967,49.9490770244203,49.9492507681341,49.9493420470509,49.9497683802559,49.9498917125588,49.9500400312132,49.9501702861517,49.9504006805577,49.9505485361926,49.9506337229225,49.9507134500288,49.9512413295655,49.9513731130522,49.951401016052,49.9513743366319,49.9510792985084,49.9509846417609,49.9503409205485,49.9502020633745,49.9499413852824,49.9496087160584,49.9495046214494,49.9494553653335,49.949520065164,49.9490756863795,49.9480257544369,49.9475322085346,49.9487612730294,49.9478659937728]}]],[[{&#34;lng&#34;:[14.372838052029,14.3719130548881,14.3906602627271,14.3929537617824,14.3913964159971,14.390909021107,14.3908724938573,14.3909288925309,14.3909070871057,14.3906939043417,14.3905167105077,14.3905085784526,14.3895442168347,14.3894395242309,14.3891135468876,14.3890465902081,14.3889672523425,14.3890967794764,14.3890502094304,14.3889678774698,14.3889190013347,14.3887800163875,14.3887295332751,14.3889709964955,14.3890398925579,14.3890017988907,14.3890005328319,14.3888756510975,14.3880349755676,14.3879116010906,14.3878461123764,14.387229299174,14.386882114624,14.386725132136,14.3860434571421,14.3855660203729,14.385460148545,14.382382443319,14.3798862649096,14.3798224565525,14.3796273900971,14.3788432418918,14.3785300309125,14.3780799892762,14.3770935150798,14.3768759626069,14.3751461327029,14.3751307355173,14.3741939265101,14.3732720520878,14.3731678525404,14.3730032458221,14.372838052029],&#34;lat&#34;:[49.9479901631301,49.9523076600116,49.9539783339193,49.9432523837162,49.9440117549455,49.9441224735841,49.9442005470096,49.9443156680506,49.9445616983406,49.9446338436143,49.9446725240055,49.9447026602153,49.9451738097977,49.9451523233733,49.9452513625026,49.945826846437,49.9459682737217,49.946697042627,49.9468220551648,49.946926183378,49.9471395781768,49.9473671855357,49.9476650311984,49.9480355311436,49.9480895913081,49.9481078918612,49.9481716783755,49.9484175152715,49.9498606162813,49.9498323825759,49.9499017950324,49.949873451806,49.9497479490986,49.9497130898151,49.9496565431311,49.9494804033889,49.9493197546193,49.9492766237478,49.9492721763491,49.9492916322597,49.9491580621907,49.9487214606561,49.9484787814389,49.947880528466,49.9467427542148,49.9466978501931,49.9475719073583,49.947512443405,49.9468425290177,49.9471996245303,49.9474299585413,49.9475975393976,49.9479901631301]}]],[[{&#34;lng&#34;:[14.3929537617824,14.3906602627271,14.3945201234504,14.3945080402939,14.3942940885303,14.394487232339,14.394440449603,14.3944041682438,14.3944271971715,14.3945928034401,14.3946797977892,14.3947759093318,14.3950089195319,14.3952384557037,14.3955179871351,14.3957560612476,14.3958385812645,14.3959589025939,14.3960072383849,14.3965673229687,14.3967134682664,14.3968414499331,14.3969288274186,14.3968528514374,14.3969160604096,14.3967693246129,14.3966430228444,14.3965025307079,14.3964473375528,14.3959083353603,14.3956258065132,14.3935524835079,14.3933173577494,14.3929537617824],&#34;lat&#34;:[49.9432523837162,49.9539783339193,49.9543219184185,49.9542692179458,49.9539743416401,49.9539085730004,49.9534266215213,49.9533002243585,49.9530747260562,49.9521862625496,49.9509930026642,49.9502657249524,49.9492671726487,49.9485954282519,49.9479299488061,49.9474814290436,49.9471782666161,49.9469285706805,49.9467287423367,49.9456007332485,49.9452564893794,49.9449366794155,49.9444922647003,49.9438013185072,49.9437905154509,49.9432510207389,49.942989087629,49.9427422289527,49.9427497514432,49.9421925865171,49.9419772862148,49.9429877353847,49.9430750856614,49.9432523837162]}]],[[{&#34;lng&#34;:[14.3264068647683,14.3317963775335,14.3333977855666,14.3331049530338,14.3317834600377,14.3314265560987,14.3308899938449,14.3298583481369,14.3292807401997,14.3280143502288,14.3277598832937,14.326832842615,14.3265379571137,14.3260837802319,14.3255038769079,14.3251033855858,14.3250414940084,14.3251536829385,14.3254698896897,14.3261595563971,14.3262513265064,14.3264068647683],&#34;lat&#34;:[49.9606838606783,49.9611665437817,49.9537221464069,49.953887192623,49.9545495308003,49.9547762805404,49.9551775691677,49.9555976051481,49.9557625534493,49.9560016022167,49.9560693110053,49.9562515107275,49.9564082787295,49.9567703628451,49.9572870296606,49.9580133966611,49.9584538374154,49.9588647578658,49.9592581012897,49.9599272743773,49.9603396321003,49.9606838606783]}]],[[{&#34;lng&#34;:[14.3333977855666,14.3317963775335,14.3505456367622,14.3531671442364,14.3374886752334,14.3372420667003,14.3370887029415,14.3366926517934,14.3361572125985,14.3350337383145,14.3343769293297,14.3338318115594,14.3333977855666],&#34;lat&#34;:[49.9537221464069,49.9611665437817,49.9628436960906,49.950633956808,49.949231710439,49.9498658670343,49.9501408030228,49.9507462216252,49.9514698781213,49.9526446930054,49.9531278188585,49.9534775173168,49.9537221464069]}]],[[{&#34;lng&#34;:[14.3531671442364,14.3505456367622,14.3692961964289,14.3719130548881,14.3531671442364],&#34;lat&#34;:[49.950633956808,49.9628436960906,49.9645178183149,49.9523076600116,49.950633956808]}]],[[{&#34;lng&#34;:[14.3719130548881,14.3692961964289,14.3880480540079,14.3906602627271,14.3719130548881],&#34;lat&#34;:[49.9523076600116,49.9645178183149,49.9661889103029,49.9539783339193,49.9523076600116]}]],[[{&#34;lng&#34;:[14.3945201234504,14.3906602627271,14.3880480540079,14.3990284952011,14.3990203894352,14.3989532337249,14.3987766202993,14.3986787835737,14.3986368193109,14.3985487144886,14.3984538568814,14.3982937973907,14.3982031170511,14.397797232341,14.3974260076931,14.3971328790989,14.3969575227352,14.3966331815971,14.3961328421611,14.3957660583427,14.3955875820735,14.3952224467658,14.3950170183601,14.3948130587844,14.3947837312014,14.3945201234504],&#34;lat&#34;:[49.9543219184185,49.9539783339193,49.9661889103029,49.9671659838773,49.9671298146136,49.9666882656064,49.9660030825249,49.965734704989,49.9652688027961,49.9647567710175,49.9643421645261,49.963834352411,49.9631579898033,49.9619729917544,49.9612597808666,49.9608750030248,49.9604579515533,49.9599658340482,49.9591051630521,49.9583891606861,49.958115780362,49.9573914803195,49.9567078936204,49.9557904447508,49.9554716098709,49.9543219184185]}]],[[{&#34;lng&#34;:[14.4084073716913,14.4255556528015,14.4266450707828,14.4255227325781,14.4247448192444,14.424330806611,14.4231711237783,14.4221676413661,14.4216622655596,14.4203721100142,14.4199907459057,14.4194835107383,14.4190495627313,14.4173269332831,14.4169163372855,14.4165670563937,14.4155462999334,14.4152677212267,14.4148565944377,14.4146598094674,14.4143416712762,14.4141834384279,14.4116501301222,14.4113264478661,14.4110549442685,14.4108377801152,14.4097057843849,14.4094194674041,14.4089892168943,14.4086861579092,14.4084073716913],&#34;lat&#34;:[49.9679996913336,49.9695220029679,49.9644118132702,49.9641352650452,49.9640144321199,49.9639646331787,49.963909391634,49.9639246334928,49.9639166355448,49.9637039351133,49.9636587421608,49.9636396781399,49.9636596095487,49.9639176533267,49.9639817633727,49.9640868943523,49.9645977370514,49.9648251347243,49.9653175859554,49.9654662948315,49.9655652005536,49.9655985264654,49.9658701794345,49.9659521573006,49.96604149229,49.9661597057823,49.966889798339,49.9671637860825,49.9677196908558,49.9679132268346,49.9679996913336]}]],[[{&#34;lng&#34;:[14.4266450707828,14.4255556528015,14.4429311416299,14.4428541484045,14.4413298019558,14.438685029524,14.4385316927644,14.4383585204523,14.4382597538832,14.4376390147997,14.4371378636816,14.436679986361,14.4359730533181,14.4356490891685,14.4355364497703,14.4349483705927,14.43443480521,14.4334773733386,14.4331041504837,14.4326441284156,14.4326330170921,14.4322535964536,14.431731042828,14.4312390911179,14.4302995327445,14.4298078966576,14.429315337461,14.4293326666691,14.4288011712316,14.4283969529735,14.4278087583582,14.4266898745951,14.4266450707828],&#34;lat&#34;:[49.9644118132702,49.9695220029679,49.9710618028139,49.9709336844345,49.9694133010202,49.9681952465609,49.9681389138219,49.9681433573509,49.9681459525566,49.9682619481088,49.9682062037785,49.9682472271991,49.968070234798,49.968079737568,49.9680688488595,49.9678148000011,49.9678133963709,49.9676260766938,49.9675312814036,49.9675414222189,49.96750177426,49.9673627718247,49.9673322424003,49.9671396058072,49.9669147260008,49.966610385352,49.9661757229127,49.9659379272132,49.9656100803637,49.9649643349348,49.964575817492,49.9644228528016,49.9644118132702]}]],[[{&#34;lng&#34;:[14.4536781338189,14.4630684129388,14.463137243795,14.4625849881175,14.4624868464651,14.4627909890563,14.4623058188027,14.4613669762666,14.4607334389931,14.4591455298151,14.458053120546,14.4573803214605,14.4561212322378,14.4545566968149,14.4540517424919,14.4537029193158,14.4536781338189],&#34;lat&#34;:[49.9720128404593,49.9728429728931,49.9725189566002,49.9726052672379,49.97232406259,49.9722800601892,49.9708460288204,49.9709825904593,49.9711563849722,49.9716999476376,49.9718975094923,49.9719586395055,49.9719750947877,49.9719410184898,49.9719691456102,49.9719340289197,49.9720128404593]}]],[[{&#34;lng&#34;:[14.463137243795,14.4630684129388,14.4642090615207,14.4641740062147,14.4632912250845,14.4631833296047,14.463137243795],&#34;lat&#34;:[49.9725189566002,49.9728429728931,49.9729437564067,49.9727659092139,49.9728139665384,49.9725117538333,49.9725189566002]}]],[[{&#34;lng&#34;:[14.3308516778016,14.3317963775335,14.3264068647683,14.3269167886105,14.3270849180437,14.3273639047156,14.3281865004222,14.3292970302414,14.3300834143548,14.330805879071,14.3308516778016],&#34;lat&#34;:[49.9655570385447,49.9611665437817,49.9606838606783,49.961812359558,49.9627832931272,49.9633765411952,49.9642817262003,49.9649287407479,49.9652556909687,49.9655317963959,49.9655570385447]}],[{&#34;lng&#34;:[14.3279080158409,14.3291688940148,14.3296805744189,14.3275299492536,14.3272210128633,14.3269254990772,14.3268794665859,14.3271873229382,14.3276732686127,14.3279080158409],&#34;lat&#34;:[49.9732628763389,49.9733757771683,49.9709986218515,49.9708105380577,49.971070087047,49.9714882414818,49.9719367282663,49.9724059242473,49.973012252675,49.9732628763389]}]],[[{&#34;lng&#34;:[14.3453472551324,14.3479228041042,14.3505456367622,14.3317963775335,14.3308516778016,14.3323973659281,14.333769031987,14.3342858244093,14.3345878465816,14.3347639600907,14.3352011679719,14.335533618732,14.3367025704894,14.3373120379187,14.3378249935217,14.3385859561406,14.3393214011257,14.3402298201434,14.3409263106445,14.341059545124,14.3413130523083,14.3415524215536,14.3425470729451,14.3429446862604,14.343457083997,14.3439425653529,14.3445375611026,14.3449812495111,14.345381222163,14.3454644841168,14.3455844051477,14.3456451566246,14.345769072904,14.3459057860631,14.346072113045,14.3467862599451,14.347141258673,14.3469589176536,14.3468877486312,14.3466947728123,14.3466304856085,14.3464837562079,14.3463212866399,14.3454526801232,14.3452103590078,14.3450642526428,14.3451920115731,14.3458054460701,14.3462445234995,14.3458773247209,14.3453876957273,14.3453472551324],&#34;lat&#34;:[49.974823148189,49.9750533494093,49.9628436960906,49.9611665437817,49.9655570385447,49.9664089244333,49.9671417160467,49.9673594451707,49.9674647242859,49.9676083878638,49.9676007670151,49.9675652517575,49.9673223713576,49.967139984312,49.9669620309254,49.9666025666924,49.9663335867354,49.9661201071873,49.9658535342238,49.9658183399329,49.9657866412635,49.9658069617065,49.9660904477219,49.9662250401642,49.9664318937151,49.9667194860902,49.9672093070286,49.9677058382689,49.9686389799758,49.9700315284229,49.9705278843413,49.9710507209113,49.9714630145305,49.9717502774705,49.9719521376334,49.9724144650776,49.9725531263852,49.9728161361572,49.9734093284424,49.9734165887009,49.9734603127907,49.973651891085,49.9737726194023,49.9735442940438,49.9736043277425,49.9736947468118,49.9738468658773,49.9743397713428,49.9747886815331,49.9748442667988,49.9748231020479,49.974823148189]}],[{&#34;lng&#34;:[14.3296805744189,14.3291688940148,14.3393091680906,14.3369294086683,14.3365043143777,14.3352353434075,14.334580793939,14.3339890741736,14.3335949279926,14.3327171322741,14.3323644554475,14.331308740661,14.3296805744189],&#34;lat&#34;:[49.9709986218515,49.9733757771683,49.9742832344236,49.9735761457396,49.9734427997863,49.9729873081677,49.9726722964048,49.9723361245706,49.972087801784,49.971430907317,49.9711083141722,49.9711409863028,49.9709986218515]}]],[[{&#34;lng&#34;:[14.3505456367622,14.3479228041042,14.3666780153592,14.3692961964289,14.3505456367622],&#34;lat&#34;:[49.9628436960906,49.9750533494093,49.9767278906242,49.9645178183149,49.9628436960906]}]],[[{&#34;lng&#34;:[14.3692961964289,14.3666780153592,14.3854345252518,14.3880480540079,14.3692961964289],&#34;lat&#34;:[49.9645178183149,49.9767278906242,49.9783994006614,49.9661889103029,49.9645178183149]}]],[[{&#34;lng&#34;:[14.3990284952011,14.3880480540079,14.3854345252518,14.4041923312541,14.406690074869,14.4051507969993,14.4046061734731,14.4043782449793,14.4034498658847,14.4025406310869,14.402324709014,14.4022374885413,14.4020211387628,14.4017318686487,14.4015806861954,14.4014879907292,14.4014200649956,14.4014250372405,14.4014862689354,14.4013523036197,14.4012273833479,14.4011700065013,14.4007127434281,14.4005772927003,14.4004827973757,14.4004681983842,14.4004244120491,14.4003559031009,14.4001647969277,14.3999898884692,14.3999495572294,14.3998421051476,14.3991915124711,14.3990284952011],&#34;lat&#34;:[49.9671659838773,49.9661889103029,49.9783994006614,49.9800678793707,49.9683772560296,49.9689119481326,49.9690801029282,49.9691971686174,49.9698770585349,49.9706404229282,49.9705939081815,49.9705990427686,49.9704886826865,49.9704074184967,49.9704556968341,49.9705417589807,49.9707219667485,49.9708001024072,49.9709185468653,49.9709988523135,49.9708715686499,49.9708424150369,49.9707458491853,49.9704571581093,49.9704752590906,49.9704013500508,49.9704040825178,49.9698957044682,49.9692195860309,49.9679963295842,49.9679085134108,49.9678292515912,49.9678933821262,49.9671659838773]}]],[[{&#34;lng&#34;:[14.406690074869,14.4041923312541,14.4229514308381,14.4255556528015,14.4084073716913,14.408291484286,14.4074146573248,14.406840233222,14.406690074869],&#34;lat&#34;:[49.9683772560296,49.9800678793707,49.981733326603,49.9695220029679,49.9679996913336,49.9680356330889,49.9681833584492,49.9683250944616,49.9683772560296]}]],[[{&#34;lng&#34;:[14.4429311416299,14.4255556528015,14.4229514308381,14.4417118214759,14.4439696316773,14.4429311416299],&#34;lat&#34;:[49.9710618028139,49.9695220029679,49.981733326603,49.9833957422101,49.9727898007993,49.9710618028139]}]],[[{&#34;lng&#34;:[14.4439696316773,14.4417118214759,14.4604735006392,14.4630684129388,14.4536781338189,14.4536638203387,14.4532001956211,14.452837540289,14.4521000432674,14.4511591493316,14.4507243333369,14.4503503973251,14.4499823748495,14.4494764221814,14.4485691670873,14.447617371952,14.4458831185659,14.4451705642797,14.4446600219684,14.4439696316773],&#34;lat&#34;:[49.9727898007993,49.9833957422101,49.9850551260449,49.9728429728931,49.9720128404593,49.9720583535444,49.9721621011346,49.972284670349,49.9725870833727,49.9730359474318,49.973228452501,49.9733728875431,49.9735014180515,49.9736240965734,49.9738054681054,49.9739163676123,49.9737576175732,49.9737996424205,49.9739385034488,49.9727898007993]}]],[[{&#34;lng&#34;:[14.4642090615207,14.4630684129388,14.4604735006392,14.4792364658002,14.4796030095802,14.4784357938303,14.4762861353292,14.4760139754508,14.4746883053769,14.4745698256091,14.4740618133876,14.4738998411115,14.4737704819574,14.4739044827975,14.4739791818187,14.4739996400069,14.4740586037678,14.4695174235384,14.4695416506254,14.4687305381743,14.4680484897135,14.4668028215013,14.4663701568868,14.4662465393768,14.4651279004303,14.464439150318,14.4642582607493,14.4642090615207],&#34;lat&#34;:[49.9729437564067,49.9728429728931,49.9850551260449,49.9867114779616,49.9849836733852,49.9847142905418,49.9840287059835,49.9841843811135,49.9833395000119,49.9832856653498,49.9838483250835,49.9838455580998,49.9838270630903,49.9834702567632,49.9810301964297,49.9807587498584,49.9804782676169,49.9799537174032,49.980184280161,49.9803701270861,49.9806771750701,49.9810297377762,49.9811114099867,49.980449705882,49.9758473868884,49.9737998692709,49.9731933581681,49.9729437564067]}]],[[{&#34;lng&#34;:[14.4796030095802,14.4792364658002,14.4870247892391,14.4868402321335,14.4867956551615,14.4868588019058,14.4870515758616,14.4828342354421,14.4808205232127,14.4796030095802],&#34;lat&#34;:[49.9849836733852,49.9867114779616,49.9873980897274,49.9867916554807,49.986463479882,49.9860202011436,49.985761494397,49.9853287681426,49.9852646488064,49.9849836733852]}]],[[{&#34;lng&#34;:[14.6156860924545,14.6293861796363,14.6302579574282,14.6302434480495,14.6296151086465,14.6292269772112,14.6285820253061,14.6282505470682,14.6265625407911,14.6257002329845,14.6231530847921,14.6226900757617,14.622414044228,14.622132155228,14.6214760704052,14.6213903959327,14.6195577591561,14.6194401314176,14.6194761867595,14.61926092819,14.6189719871872,14.6185099081168,14.6182506011287,14.6180696236886,14.6178446682196,14.6170499432596,14.6168952820979,14.6162470058805,14.6158934867758,14.6156860924545],&#34;lat&#34;:[49.9986623859204,49.999853127086,49.9956824366285,49.9956803457085,49.9956538043225,49.9956085686536,49.9960647800571,49.9962534537252,49.9969559962234,49.9972654777942,49.9984111885195,49.9986101015824,49.9986869070429,49.9987217408251,49.998771769717,49.9984641083111,49.9986864767385,49.9981360621423,49.9980592665665,49.9975960798461,49.997741977349,49.9979289796292,49.9980886118736,49.9981550736655,49.9983106155714,49.9985906247003,49.9983228651436,49.9984787873834,49.9985807750355,49.9986623859204]}]],[[{&#34;lng&#34;:[14.6302579574282,14.6293861796363,14.6436634671389,14.6450286147466,14.6451575710217,14.6469894482018,14.6453876049591,14.6402181283587,14.6388990728084,14.6387725122469,14.6385870972511,14.637936527809,14.6373381983034,14.6369708886882,14.6366885289216,14.636123773124,14.6358291622821,14.6348414576427,14.6343977689576,14.6340622050017,14.6336678160294,14.6302579574282],&#34;lat&#34;:[49.9956824366285,49.999853127086,50.0010922546014,50.0001786406847,50.0001238678726,49.9988252504069,49.997868492495,49.9945119487758,49.9952416726931,49.9952951036984,49.995327096853,49.9953794155349,49.99540868464,49.9954436680278,49.9954890176884,49.9956243491447,49.9957108193109,49.9960598285826,49.9961666503595,49.9962012068377,49.9961737698342,49.9956824366285]}]],[[{&#34;lng&#34;:[14.3290681036969,14.3291688940148,14.3279080158409,14.3279241339392,14.3289857742789,14.3290681036969],&#34;lat&#34;:[49.9738439989891,49.9733757771683,49.9732628763389,49.9732800844238,49.9738177681452,49.9738439989891]}]],[[{&#34;lng&#34;:[14.3393091680906,14.3291688940148,14.3290681036969,14.3294521914753,14.3302745990567,14.33023219241,14.3300085734895,14.3294021993522,14.3294449498827,14.3295187504543,14.329674249568,14.3297833135547,14.3301203134519,14.3301093195617,14.3299997206695,14.3307040452542,14.3317381996005,14.3326728401985,14.33271719111,14.3327066180793,14.3325287516108,14.3324073305362,14.3347371799523,14.3347830789853,14.3355546386805,14.3352601057426,14.3358043594869,14.3365507369247,14.3371174240591,14.3376683923926,14.3391609559785,14.3396563865662,14.3393656143671,14.3389156994217,14.3388799647324,14.3388084934859,14.3387449580199,14.3386402482183,14.3386400414769,14.3385163526803,14.3384511297928,14.338314053821,14.3382712266069,14.3382337609252,14.3381160821778,14.3379618775665,14.3376513784157,14.3376750581662,14.3376601068023,14.3377164717902,14.3378269517299,14.3380329236662,14.3381382893055,14.3382778003896,14.3385307885307,14.3388035478158,14.3389661422685,14.3391449041829,14.3392241221469,14.3392518871191,14.3391168727088,14.339171273644,14.3391257208369,14.3391459255814,14.3391002695472,14.338966635151,14.3389803156096,14.3390547867163,14.3390339397379,14.3389170963452,14.3388209814598,14.3389913588577,14.3390151051241,14.3387559641826,14.3385071790459,14.3382969030508,14.338280408768,14.3380921408586,14.3380507188013,14.3378792032152,14.3377058723997,14.3375095869691,14.3374359069837,14.3374359862104,14.3371305087934,14.3370509966163,14.3369552866091,14.336480772488,14.3362801779115,14.3361952371777,14.3359951017008,14.3359801957447,14.3452986455206,14.3479228041042,14.3453472551324,14.3443348992801,14.3427145873083,14.3423659827688,14.3423279820176,14.3414376798924,14.3406850689956,14.3393091680906],&#34;lat&#34;:[49.9742832344236,49.9733757771683,49.9738439989891,49.9739663714299,49.9742567721147,49.9744498676228,49.9746053170505,49.9745693657583,49.9747081765507,49.9748433230574,49.9750318052197,49.9751136452297,49.9752992229302,49.975367954262,49.9754945789383,49.9756719162914,49.9758641580706,49.9759596132447,49.9761865260514,49.9763671297697,49.9768613663696,49.977383711707,49.977604372357,49.977695259888,49.9781949293268,49.9785890445175,49.9788354456709,49.9792704001202,49.9796265496584,49.9798837074715,49.9805368860167,49.9808298228797,49.9812078529982,49.9812988745082,49.981348508953,49.9813535543679,49.9816437041016,49.9818654495746,49.9820136648706,49.9820252052248,49.9820515965808,49.9820762816938,49.9821019527932,49.9821897389404,49.9822662659848,49.9823077551057,49.9824691562093,49.9825436211487,49.9826432255004,49.9827660000199,49.982804747778,49.9829414486592,49.9829633993233,49.9830399633835,49.9831112445849,49.9833556743956,49.9835893435139,49.9836758613952,49.9837382269715,49.9838126935362,49.9839298813073,49.9844486175582,49.9845641828225,49.9846188209232,49.9847492638623,49.9848855468412,49.9849593892966,49.9850255058968,49.9851093320627,49.9851629693329,49.9852917147082,49.9854139735042,49.9855764943309,49.9857817976833,49.985815919529,49.9858182654744,49.985667194054,49.985662792608,49.9856897696354,49.9859713517034,49.9859871666344,49.9859061611065,49.9859122786711,49.9859655701188,49.9860734105441,49.9860052078092,49.986010989498,49.9862474952868,49.9863847763633,49.9864131250702,49.9864193687985,49.9864297553892,49.987262916373,49.9750533494093,49.974823148189,49.9748242986534,49.9749296034239,49.9749189466616,49.9749025681458,49.9748340305032,49.974692018767,49.9742832344236]}]],[[{&#34;lng&#34;:[14.3479228041042,14.3452986455206,14.36405851094,14.3666780153592,14.3479228041042],&#34;lat&#34;:[49.9750533494093,49.987262916373,49.9889378765479,49.9767278906242,49.9750533494093]}]],[[{&#34;lng&#34;:[14.3666780153592,14.36405851094,14.3828196757223,14.3854345252518,14.3666780153592],&#34;lat&#34;:[49.9767278906242,49.9889378765479,49.9906098046031,49.9783994006614,49.9767278906242]}]],[[{&#34;lng&#34;:[14.3854345252518,14.3828196757223,14.401582137337,14.4041923312541,14.3854345252518],&#34;lat&#34;:[49.9783994006614,49.9906098046031,49.9922787003891,49.9800678793707,49.9783994006614]}]],[[{&#34;lng&#34;:[14.4041923312541,14.401582137337,14.4203458932536,14.4229514308381,14.4041923312541],&#34;lat&#34;:[49.9800678793707,49.9922787003891,49.9939445637568,49.981733326603,49.9800678793707]}]],[[{&#34;lng&#34;:[14.4229514308381,14.4203458932536,14.4391109409417,14.4417118214759,14.4229514308381],&#34;lat&#34;:[49.981733326603,49.9939445637568,49.9956073945586,49.9833957422101,49.981733326603]}]],[[{&#34;lng&#34;:[14.4417118214759,14.4391109409417,14.4578772778708,14.4604735006392,14.4417118214759],&#34;lat&#34;:[49.9833957422101,49.9956073945586,49.9972671926479,49.9850551260449,49.9833957422101]}]],[[{&#34;lng&#34;:[14.4604735006392,14.4578772778708,14.4766449015102,14.4792364658002,14.4604735006392],&#34;lat&#34;:[49.9850551260449,49.9972671926479,49.9989239578792,49.9867114779616,49.9850551260449]}]],[[{&#34;lng&#34;:[14.4870247892391,14.4792364658002,14.4766449015102,14.4954138093295,14.4965437326539,14.4930131380057,14.4909527541689,14.4887559977556,14.4870748973253,14.4840004170843,14.4840498999995,14.4842017282773,14.4845842816347,14.4847682944684,14.4849545917573,14.484851118432,14.4849124185162,14.4844552048448,14.4843025179653,14.484295644693,14.4846503604298,14.4852176355724,14.4859152408241,14.4871042991417,14.4870247892391],&#34;lat&#34;:[49.9873980897274,49.9867114779616,49.9989239578792,50.000577690108,49.995244041469,49.9944630066932,49.9940242817818,49.9935191445573,49.9931707479227,49.9924935184248,49.9921042091283,49.9917400741149,49.9918146293008,49.9914062326849,49.9907806012562,49.9904069407315,49.9901390975304,49.9897900695121,49.9894659760872,49.9891080899112,49.9874897151149,49.9875153944288,49.9876194405099,49.9876593456628,49.9873980897274]}]],[[{&#34;lng&#34;:[14.4965437326539,14.4954138093295,14.5141839987981,14.5157426814916,14.5134884546382,14.5135094353462,14.5134897546168,14.5138135209152,14.5098415860237,14.5098765528675,14.5082515838957,14.5081148029027,14.5075813264454,14.509423129828,14.5092497119934,14.5081998385487,14.5077867059179,14.507320841702,14.505813871993,14.5040321864754,14.4979285227772,14.4969353301388,14.4965437326539],&#34;lat&#34;:[49.995244041469,50.000577690108,50.002228389191,49.9948570000346,49.9946076270583,49.9942281626897,49.9939351434781,49.9926569660156,49.992318097235,49.9924615548896,49.9922128746162,49.9924502166655,49.9935472439048,49.9939276070575,49.9943401324777,49.9960861446372,49.9966947483068,49.9975511676035,49.9972436946874,49.9968361747811,49.9955065595984,49.9953306621146,49.995244041469]}]],[[{&#34;lng&#34;:[14.5157426814916,14.5141839987981,14.5265696815491,14.5268295708011,14.5276612209062,14.5283650971166,14.5288122247683,14.5296088329583,14.5300865881485,14.5292632464828,14.5278944447404,14.5271523899453,14.5261535374371,14.5243894501431,14.5198306852272,14.5196954662248,14.5192010824794,14.5193986302605,14.5182598662732,14.5189873731086,14.5188437157061,14.518018207658,14.5175831337112,14.5161571278645,14.5162200260737,14.5157426814916],&#34;lat&#34;:[49.9948570000346,50.002228389191,50.0033158956034,50.003132887019,50.0025228436054,50.0019904220913,50.001614416518,50.0010740639665,50.000788940853,50.0004525634763,49.9996553538499,49.999185531313,49.9985932591105,49.9975079535914,49.9972522554387,49.9972586209512,49.9971740048163,49.9962972601171,49.996194430423,49.9949255781526,49.9948473530226,49.9944913601207,49.9952350824484,49.995016887535,49.994909800151,49.9948570000346]}]],[[{&#34;lng&#34;:[14.5891047927773,14.5892775225554,14.589286993226,14.5892298040891,14.5891047927773],&#34;lat&#34;:[50.0087857910215,50.0088008512361,50.0087557372285,50.0087292669966,50.0087857910215]}]],[[{&#34;lng&#34;:[14.5949627464929,14.6080540823129,14.6105159007499,14.6104073722619,14.6101514301864,14.6101534231888,14.6100761333711,14.6098148902918,14.6097400715216,14.6096468192099,14.6095463413295,14.6092059892471,14.6088456401808,14.6086566549734,14.6083254034183,14.6083198974519,14.6086783996103,14.6088661635953,14.6092341460028,14.6093960808281,14.6093094102308,14.6091878495822,14.6087565757358,14.6084334208043,14.6080171134688,14.6079974881449,14.6080248996427,14.6078974596589,14.6056987319913,14.6039676244001,14.6036733653767,14.6035965345757,14.6035183135212,14.6030115667864,14.6024121405289,14.6023409122457,14.6023047677157,14.6023310357255,14.6021525326686,14.6020607401536,14.600480820709,14.5992244787044,14.5967076999694,14.596475542857,14.5963028501094,14.5960315575807,14.5957662992351,14.5950394280126,14.5947427284647,14.5947184709305,14.5946928370156,14.5947616490764,14.5949627464929],&#34;lat&#34;:[50.0092963942643,50.0104363824778,49.9986847467416,49.9987080129337,49.9988480531027,49.9990280501923,49.9991255710375,49.9992646957744,49.9993363017388,49.9995295126904,49.9996248338837,49.9997988996562,50.0000200343946,50.0001776944063,50.0007685402161,50.0010582112001,50.0012175220071,50.0014352808204,50.0015984086056,50.0016451634478,50.0019043625421,50.0019296213061,50.0020692809192,50.0022693385819,50.002461832355,50.0025682728109,50.0028540051053,50.0030087643565,50.0025867406532,50.0019976194167,50.0032256049662,50.0037627469236,50.0041339145757,50.0063653746843,50.0079998406681,50.0086525159593,50.009225137963,50.0095034242533,50.009507388146,50.0094469536545,50.0090737449813,50.0088218769756,50.008149888729,50.0080633378849,50.0079577425276,50.0076671756011,50.0074505345674,50.0072150806257,50.0078179896249,50.0081751695198,50.0081765649519,50.0089356264382,50.0092963942643]}],[{&#34;lng&#34;:[14.589286993226,14.5892775225554,14.5894092824864,14.589286993226],&#34;lat&#34;:[50.0087557372285,50.0088008512361,50.0088123391332,50.0087557372285]}]],[[{&#34;lng&#34;:[14.6105159007499,14.6080540823129,14.6268319085369,14.6293861796363,14.6156860924545,14.6155992951574,14.615330076364,14.6148570363099,14.6145025515795,14.6140763275395,14.6139224309394,14.6135560586047,14.6130850459388,14.6130777277788,14.6127907471983,14.6123297742922,14.6123593333938,14.6119357284905,14.6114770146676,14.6114445328483,14.6114174369868,14.6115823469357,14.6118808983128,14.6123334193777,14.6117556721652,14.6116025769911,14.6115094181182,14.6114075291508,14.6112891322678,14.6108962861501,14.6106897313314,14.6105159007499],&#34;lat&#34;:[49.9986847467416,50.0104363824778,50.0120688797364,49.999853127086,49.9986623859204,49.9986965409752,49.9988436019374,49.9991413241223,49.9994078949184,49.9998100319362,49.9999279277248,50.0000697097442,50.0001028590819,50.0001357926521,50.0001141821197,50.0000321617215,49.9999669587221,49.999922935634,49.9997804100823,49.9998340167198,49.9998249451961,49.9996296213804,49.9993445820981,49.9989742264257,49.9987488538252,49.9988185482216,49.9988245051605,49.9987504966957,49.9985960274255,49.9985644745144,49.998647480916,49.9986847467416]}]],[[{&#34;lng&#34;:[14.6436634671389,14.6293861796363,14.6268319085369,14.6456109986968,14.6471653982848,14.6468772032439,14.6463233792988,14.6458704710499,14.6455627658894,14.6454117472454,14.6452666619201,14.6454237541098,14.645172043332,14.6447571736798,14.6438811547012,14.6431330926481,14.6427628969421,14.6430078628961,14.642483261993,14.6422180388264,14.6409555726381,14.6400816121809,14.6397221629693,14.6383561439742,14.6386429075587,14.6387955043982,14.6389904352311,14.6392847408105,14.6400401613031,14.6410246218304,14.6413007085287,14.642051607516,14.6427465725747,14.6432734669866,14.6436634671389],&#34;lat&#34;:[50.0010922546014,49.999853127086,50.0120688797364,50.0136983428762,50.006251351674,50.0059730528109,50.0057399672732,50.0053741010402,50.0048049025815,50.0048135820955,50.0048545287437,50.0052267762157,50.0056160153761,50.0059034683634,50.0066096273629,50.0065247980357,50.0065516634813,50.0061982224207,50.0061360332735,50.0061273650235,50.00621400783,50.0063997517038,50.0064277212189,50.00585359512,50.005764526783,50.005695753097,50.0055840184157,50.0053651427264,50.0045775158148,50.0036278551005,50.0033222056903,50.0025848930079,50.001849076659,50.0013532497093,50.0010922546014]}]],[[{&#34;lng&#34;:[14.6471653982848,14.6456109986968,14.6643913502623,14.664753995281,14.6642628197254,14.6638113707017,14.6632603467913,14.663152496889,14.6631572711999,14.6631048870368,14.6627715172085,14.6626041373398,14.662361276432,14.6620175438363,14.6616967353846,14.6616518221851,14.6613443547926,14.6617499775832,14.6621265245043,14.6622664770264,14.6626006752517,14.6628508688666,14.662842867496,14.6629455107335,14.662736306794,14.6629625249057,14.6629703222249,14.6629309798909,14.6622359995178,14.6616859016717,14.6617735026619,14.6620289964448,14.662682551403,14.66243431627,14.6619491377775,14.6618782459526,14.6615397589261,14.6612808302093,14.6608661619671,14.6605877235991,14.6605120260934,14.6588570732872,14.6578522500646,14.6498715968252,14.6471653982848],&#34;lat&#34;:[50.006251351674,50.0136983428762,50.0153247717624,50.0135843366157,50.0136777020877,50.0136511596575,50.0136592721998,50.0134107126533,50.0132668819543,50.013231141479,50.0132432983272,50.0130176186847,50.012991339784,50.0128789467393,50.0128902823217,50.0128538268544,50.0124695081063,50.0123146474519,50.0121925591678,50.012123567918,50.0118425922333,50.0117113816524,50.0115775130254,50.0112822132908,50.0109370649645,50.010729026826,50.0106612083997,50.010579784952,50.0098832408437,50.009371054105,50.0092418309385,50.0086413353372,50.0084732791038,50.008147974066,50.0074364697856,50.0073713659179,50.0072495333133,50.0071309574674,50.0068782419755,50.0066776882411,50.0065917552619,50.0052999572835,50.0044198713911,50.008864431209,50.006251351674]}]],[[{&#34;lng&#34;:[14.664753995281,14.6643913502623,14.6689107689098,14.6686589790304,14.6686118243702,14.6685944308474,14.6686156344059,14.6680399765806,14.6673431897944,14.6671449953574,14.6667909303114,14.6660777760173,14.6654816773582,14.6653706534678,14.6652300060272,14.664753995281],&#34;lat&#34;:[50.0135843366157,50.0153247717624,50.0157156963328,50.0146971877904,50.0144024477173,50.0140736311654,50.0135047549191,50.013546683973,50.01364227124,50.0132731392892,50.0132826102956,50.0128897948941,50.0134406905933,50.0134809810061,50.0134938514326,50.0135843366157]}]],[[{&#34;lng&#34;:[14.3075019076595,14.3239099407287,14.3253159538901,14.3216054975229,14.3181674235374,14.3179707622612,14.3178375128223,14.3177662394322,14.317563320767,14.317454596949,14.3173017590982,14.3173888502013,14.3174029001358,14.3172785594013,14.3165404629454,14.3154426853108,14.3151853762955,14.3147822932716,14.3146956636053,14.314561965984,14.314369613133,14.314175420297,14.314067333349,14.3140284064248,14.3127937164707,14.3119005596285,14.3116300845042,14.3101697956475,14.3100424832473,14.3099383920664,14.3098117924582,14.3095857497763,14.308561362439,14.3083591927002,14.3080488278279,14.3077101344221,14.3072938378464,14.3076654346258,14.3077679617123,14.30754135626,14.3075019076595],&#34;lat&#34;:[49.9963236676976,49.9977939845756,49.9912680797391,49.9899689431783,49.988971394391,49.9895558075972,49.9897898743061,49.9898109026093,49.9899468597812,49.9899920376478,49.9901353869746,49.9902787216348,49.9904408380718,49.990624413637,49.9912415549866,49.9920547625811,49.9923063952126,49.9928879207717,49.9930976600213,49.9935334839472,49.9938690972389,49.9943059443483,49.9946223306645,49.9948615816463,49.994657228554,49.9944709522131,49.9943944160994,49.9939167172367,49.9941491329421,49.9942621699664,49.9943920697252,49.9945442804151,49.9948226158335,49.9948974432657,49.9950481727962,49.995302752133,49.9955469221864,49.9962674449607,49.9963183072163,49.9963118740337,49.9963236676976]}]],[[{&#34;lng&#34;:[14.3253159538901,14.3239099407287,14.34267316027,14.3452986455206,14.3359801957447,14.3358407436982,14.3356263040441,14.3353207140535,14.3351586785935,14.3347237321828,14.3348896780346,14.3349379071563,14.3348549698983,14.3353818785252,14.3356372857995,14.3358585223847,14.3369152253742,14.3373488477022,14.3377799309633,14.3386620241743,14.3391698237805,14.3399781307585,14.3403677524619,14.3410565329106,14.3416308223409,14.3419605611865,14.3421263118304,14.3423604752276,14.3425461990456,14.3427967106107,14.3428223974493,14.33865763954,14.3387059326217,14.3382725961837,14.3380234127018,14.3378063093824,14.3377477469433,14.3375734906857,14.3371527188706,14.3367071470905,14.3364107631262,14.3358705358809,14.3355080013323,14.3350481950746,14.3346880649917,14.3340085748422,14.333206399419,14.3330252377188,14.332366677395,14.3317749602821,14.331107125413,14.3305260777769,14.3283116558451,14.3277375043844,14.3272012207881,14.326919501885,14.326830727765,14.3267368212847,14.3265384512574,14.3253159538901],&#34;lat&#34;:[49.9912680797391,49.9977939845756,49.9994723965909,49.987262916373,49.9864297553892,49.9865269263919,49.9865165491216,49.9865476710222,49.9865221012067,49.9870143121901,49.9875110793642,49.9878090491753,49.9880642401974,49.9887430739867,49.9888850163716,49.9889397538367,49.9889965066658,49.9890496306453,49.989131573506,49.9893769362093,49.9894851582237,49.9896906878916,49.9897952374414,49.9900262907654,49.9902718856648,49.9904643916655,49.9905408423096,49.9906160562286,49.9906605248327,49.9906859122752,49.9907085414203,49.991631000256,49.9916886027082,49.9920561574345,49.9924172128653,49.993099026855,49.9932115237157,49.9933663236099,49.9935968426864,49.9937233831946,49.9938613593847,49.9939356794052,49.993949186065,49.9939265781943,49.9938576010196,49.9935923951387,49.9933705828807,49.9933336788687,49.9931394139629,49.9929375095045,49.9927536627466,49.9925467145914,49.991824663347,49.9916256692144,49.9913737808002,49.9911781751251,49.9910843539869,49.9911196102863,49.9916960695554,49.9912680797391]}]],[[{&#34;lng&#34;:[14.3452986455206,14.34267316027,14.3614376824324,14.36405851094,14.3452986455206],&#34;lat&#34;:[49.987262916373,49.9994723965909,50.0011477756947,49.9889378765479,49.987262916373]}]],[[{&#34;lng&#34;:[14.36405851094,14.3614376824324,14.3802035046829,14.3828196757223,14.36405851094],&#34;lat&#34;:[49.9889378765479,50.0011477756947,50.0028201217364,49.9906098046031,49.9889378765479]}]],[[{&#34;lng&#34;:[14.3828196757223,14.3802035046829,14.3989706244886,14.401582137337,14.3828196757223],&#34;lat&#34;:[49.9906098046031,50.0028201217364,50.0044894345664,49.9922787003891,49.9906098046031]}]],[[{&#34;lng&#34;:[14.401582137337,14.3989706244886,14.4177390393165,14.4203458932536,14.401582137337],&#34;lat&#34;:[49.9922787003891,50.0044894345664,50.0061557140365,49.9939445637568,49.9922787003891]}]],[[{&#34;lng&#34;:[14.4203458932536,14.4177390393165,14.4365087466337,14.4391109409417,14.4203458932536],&#34;lat&#34;:[49.9939445637568,50.0061557140365,50.0078189599993,49.9956073945586,49.9939445637568]}]],[[{&#34;lng&#34;:[14.4391109409417,14.4365087466337,14.4552797439071,14.4578772778708,14.4391109409417],&#34;lat&#34;:[49.9956073945586,50.0078189599993,50.0094791723087,49.9972671926479,49.9956073945586]}]],[[{&#34;lng&#34;:[14.4578772778708,14.4552797439071,14.4740520286037,14.4766449015102,14.4578772778708],&#34;lat&#34;:[49.9972671926479,50.0094791723087,50.0111363508195,49.9989239578792,49.9972671926479]}]],[[{&#34;lng&#34;:[14.4766449015102,14.4740520286037,14.4928255981904,14.4954138093295,14.4766449015102],&#34;lat&#34;:[49.9989239578792,50.0111363508195,50.0127904953876,50.000577690108,49.9989239578792]}]],[[{&#34;lng&#34;:[14.4954138093295,14.4928255981904,14.5116004501344,14.5141839987981,14.4954138093295],&#34;lat&#34;:[50.000577690108,50.0127904953876,50.0144416058703,50.002228389191,50.000577690108]}]],[[{&#34;lng&#34;:[14.5265696815491,14.5141839987981,14.5116004501344,14.5303765819024,14.5314064160837,14.5310592466171,14.529541302385,14.529274993634,14.5275404423902,14.5272434758056,14.5270253486503,14.5267427687983,14.5262074889149,14.5249352611747,14.5237761264778,14.5231546381728,14.5224989568703,14.5220929186774,14.5218351493732,14.5212669071485,14.5210617881356,14.5213498218737,14.5216175508296,14.5222131216032,14.5225349446846,14.5231015164636,14.5233300260559,14.5235064302059,14.523774931482,14.5240177441177,14.5241969526755,14.5246476535702,14.5256716843831,14.5265696815491],&#34;lat&#34;:[50.0033158956034,50.002228389191,50.0144416058703,50.0160896821256,50.0112131268178,50.0111505331426,50.0108606054561,50.0108541255856,50.0109117686783,50.0107284610525,50.0105132316103,50.0103411660812,50.0100515584888,50.0094492839339,50.0087970279316,50.0084917610549,50.0081857574269,50.0080689926983,50.0080215022228,50.0078441270255,50.0077953574277,50.0075657462501,50.0073868922637,50.0070565101325,50.0068581746003,50.0064264248302,50.006225886313,50.0059887420937,50.0057555068297,50.0054972401987,50.0052667842783,50.0048208675259,50.0039482312583,50.0033158956034]}]],[[{&#34;lng&#34;:[14.5314064160837,14.5303765819024,14.5491539909616,14.5511398150826,14.5509197121969,14.5497449160541,14.5462727679114,14.5460340571768,14.5457303248344,14.5455646793613,14.544829737716,14.5446040577352,14.5432572165962,14.5427630887746,14.5424276618676,14.5421724604427,14.541750460257,14.5415617949826,14.5414359673087,14.5411927581167,14.5409997977797,14.5404502974009,14.5380178515108,14.5355521328506,14.5353420163692,14.5349625905718,14.5340724301301,14.5336245851719,14.5314064160837],&#34;lat&#34;:[50.0112131268178,50.0160896821256,50.0177347240128,50.0083130369892,50.0080598994332,50.0082823643219,50.0088418425595,50.0088414464757,50.0087213880019,50.0086782995089,50.0084938892108,50.0084717650204,50.0087286434845,50.0087282804503,50.008773213331,50.0088536653624,50.0091821963582,50.0093830792535,50.0095891049135,50.0098309427045,50.0099653912948,50.010164695598,50.0109049589729,50.0118244682606,50.0117819135837,50.0117389448589,50.0116667180399,50.0116130281093,50.0112131268178]}]],[[{&#34;lng&#34;:[14.5511398150826,14.5491539909616,14.5679326747789,14.5702307109757,14.5701029294904,14.5689222969357,14.568608143736,14.5683847214617,14.5680872753624,14.5680201921817,14.5680466442238,14.5680049558057,14.567808912885,14.5676943943982,14.5675939637192,14.5669146053413,14.5665359576913,14.5644662721769,14.5643048415791,14.5641468423538,14.5642095182838,14.5642317280838,14.5638112279125,14.5637640984599,14.5636559865041,14.5636250012061,14.5633289453476,14.5630359264601,14.562819880463,14.5605038985266,14.5591582827829,14.5582595700121,14.5578755630327,14.5575603234128,14.5568366169528,14.5564396406489,14.5561432062017,14.5553982632813,14.5551189484526,14.5548430940544,14.5546688857271,14.5543904430476,14.5542996749044,14.5543335465545,14.5541235237387,14.5540897831935,14.5541475105375,14.5544407726513,14.5545211051528,14.5545991379013,14.5546010275545,14.5543345098183,14.5540302783668,14.5539450543418,14.5537597738399,14.5530829870887,14.55367397433,14.553858377561,14.5537924659161,14.5536229226951,14.5535973447639,14.5535903420789,14.5535346167689,14.5534204461482,14.5531017736182,14.5525924389706,14.5516071501483,14.551296261258,14.5512415682791,14.5511398150826],&#34;lat&#34;:[50.0083130369892,50.0177347240128,50.0193767313921,50.0084532615509,50.0084048492736,50.0078792439083,50.0076479146283,50.0074243303354,50.0076710906837,50.007984616935,50.0083828963981,50.0085897593905,50.0090498061685,50.0092655490539,50.0095615532194,50.0095074533528,50.0095250863105,50.0097257481579,50.0097555544042,50.0098085257815,50.0098505705848,50.0099323593158,50.0106592368391,50.0107714406254,50.0112489698028,50.011300522343,50.0115237131066,50.0116247669849,50.0116591434682,50.0118065468036,50.0119213515572,50.0118649888942,50.0118544521306,50.0118657167669,50.0119872495411,50.011978114339,50.0119930163448,50.0121037000464,50.0120506831835,50.0120273671999,50.0120609432126,50.0121635245927,50.0122294445272,50.0121134503534,50.0118491772388,50.0117012268945,50.0115669049222,50.0114026491961,50.011340807756,50.0112451015341,50.0110583479892,50.0111444597412,50.0111295470962,50.0112373270687,50.0113675662788,50.0110712514472,50.0102069673832,50.009986640333,50.0098724419781,50.0097836561649,50.0097446694225,50.009629545954,50.0095358379543,50.0095243961138,50.0093475211189,50.0091026011248,50.0086862703389,50.008426409247,50.0084300610152,50.0083130369892]}]],[[{&#34;lng&#34;:[14.5702307109757,14.5679326747789,14.5867126308213,14.5892775225554,14.5891047927773,14.5890026975995,14.5886453673722,14.5884945838092,14.58793440144,14.5873267231322,14.5871545075795,14.5859924918981,14.5846262553004,14.5821062471853,14.582060272328,14.5817812248147,14.5820608952025,14.582107948544,14.5820047052852,14.5820125374572,14.5821526996007,14.5824609980406,14.5785700873476,14.5778358630177,14.5763472055828,14.5761573248773,14.5759863433304,14.5753167954266,14.5750752590404,14.5747757055617,14.5746106804171,14.5745250889529,14.574477635249,14.5743544262607,14.5741515166371,14.5734332166533,14.5730813553109,14.5723888962877,14.572274535033,14.5721156735456,14.5720116751034,14.5719813215434,14.5718414491298,14.5717145639496,14.5711945157648,14.5702307109757],&#34;lat&#34;:[50.0084532615509,50.0193767313921,50.0210157041253,50.0088008512361,50.0087857910215,50.0088319532888,50.0090720846057,50.0092404006289,50.0100979653106,50.0112889098546,50.0115250383015,50.0113575581546,50.0112071846385,50.0111202721098,50.0110509333219,50.0110234110534,50.0121798847442,50.0126354760653,50.0139612380006,50.0141571781301,50.0149671279795,50.0164358555127,50.0146919973578,50.0143405661917,50.0136696731721,50.0135688968798,50.0134465422021,50.0127307242107,50.0125227250834,50.0123000420482,50.0121239457385,50.0119591398647,50.0117200871161,50.0115687813742,50.0114188656357,50.0109525573587,50.0106861034154,50.0100528246509,50.009927785693,50.009620022459,50.0094825501763,50.0093724695163,50.0091605464588,50.0090408549142,50.0088184083811,50.0084532615509]}]],[[{&#34;lng&#34;:[14.5894092824864,14.5892775225554,14.5867126308213,14.605493856556,14.6080540823129,14.5949627464929,14.595031685396,14.5944759342923,14.5939197951621,14.5937625223315,14.5929453920469,14.5928070929884,14.5926275711748,14.5920007761633,14.5919056708872,14.591818419727,14.5911571887453,14.5894092824864],&#34;lat&#34;:[50.0088123391332,50.0088008512361,50.0210157041253,50.0226516420745,50.0104363824778,50.0092963942643,50.0094200690056,50.0101228917104,50.0097405384662,50.0096714867797,50.0094460299797,50.0094475860445,50.0094845634116,50.009814631548,50.0098317465792,50.0098114390387,50.0096213334742,50.0088123391332]}]],[[{&#34;lng&#34;:[14.6080540823129,14.605493856556,14.62427634945,14.6268319085369,14.6080540823129],&#34;lat&#34;:[50.0104363824778,50.0226516420745,50.0242845451036,50.0120688797364,50.0104363824778]}]],[[{&#34;lng&#34;:[14.6268319085369,14.62427634945,14.6430601069704,14.6456109986968,14.6268319085369],&#34;lat&#34;:[50.0120688797364,50.0242845451036,50.025914413077,50.0136983428762,50.0120688797364]}]],[[{&#34;lng&#34;:[14.6624140055101,14.6643913502623,14.6456109986968,14.6430601069704,14.6598677687857,14.6614156379136,14.6624140055101],&#34;lat&#34;:[50.0248123750323,50.0153247717624,50.0136983428762,50.025914413077,50.0273701494743,50.0258290529604,50.0248123750323]}]],[[{&#34;lng&#34;:[14.6689107689098,14.6643913502623,14.6624140055101,14.6681016425,14.6696047423043,14.6695052840888,14.6690848736652,14.669032800347,14.6689433777947,14.6689107689098],&#34;lat&#34;:[50.0157156963328,50.0153247717624,50.0248123750323,50.0190194414926,50.0189108302379,50.0183770624257,50.0173096954625,50.0164653218713,50.0158475984556,50.0157156963328]}]],[[{&#34;lng&#34;:[14.3002027082293,14.3025118972198,14.3048067855197,14.3046351001531,14.3042518714805,14.3040583902793,14.3039647157314,14.3037699295368,14.3034713858473,14.3033220818878,14.3031646671994,14.3030212660059,14.3028761315729,14.3026249746303,14.3023578620351,14.3022861508124,14.3018743406594,14.3015945752985,14.3013768755434,14.3013538013693,14.3011030905726,14.300890421598,14.3007910412818,14.3006314920575,14.3006307703746,14.3005916623316,14.3005923163159,14.3008256268025,14.3010592748911,14.3012563518933,14.3013439035923,14.3015016468006,14.3017086068708,14.3018255295574,14.301913155931,14.3019052390568,14.3015587985023,14.3014975731156,14.3012624128232,14.301068134753,14.3007358334885,14.3004148142896,14.2998377345278,14.2997281472293,14.2996172560476,14.299442370616,14.2993054231656,14.299173735585,14.2990373235789,14.2988338685741,14.298516969736,14.2975170062152,14.2974079088585,14.2969576372227,14.2966102250459,14.2964106473601,14.2962387985787,14.2959885762752,14.2958581369266,14.2956018259681,14.2954679917099,14.2951842776813,14.2949050785694,14.2949150236073,14.2957982416421,14.2960069974762,14.2964256536477,14.2965749228114,14.2967500062716,14.2972523659394,14.2981108209417,14.2985663751292,14.2988420334163,14.2989997228126,14.2991723411964,14.2994621095315,14.3005975373984,14.3002474435309,14.3001982689016,14.3002027082293],&#34;lat&#34;:[50.0081139243675,50.0083210922553,49.9976932614849,49.997691851466,49.9976626474849,49.9976227770004,49.9976483248758,49.9976536357957,49.9975994366384,49.9976106428609,49.9976424544279,49.9976439317687,49.9975999543647,49.9975852270358,49.9976169992347,49.9976406129776,49.9976818234653,49.9977480443877,49.997843800015,49.9978234827102,49.9978679807317,49.9981634491426,49.9981814926167,49.9982844626322,49.9983999608695,49.9984551869321,49.9986621324481,49.9989407937541,49.999137056424,49.9992450668378,49.9992635442713,49.9993678431236,49.9997307413998,49.9998088634797,49.9999717786474,50.0000273508749,50.0000820528727,50.0001118725883,50.0001416992713,50.0000911326446,50.0000347145149,50.0000382249626,50.0000704997798,50.0001162224723,50.0003016295513,50.0004299117888,50.0004477602536,50.0004210536222,50.000439676075,50.0005209111177,50.0005750787527,50.0007009274467,50.0008010697998,50.0010807435602,50.0012454617127,50.0014169141382,50.0015291247235,50.0018019713347,50.0018965655392,50.0020444045331,50.00217164709,50.0023198394216,50.0022894165397,50.0023444148736,50.0024950623273,50.0025516585844,50.0027768860722,50.0028356759111,50.0028708185815,50.0029172735138,50.0030639541964,50.0033198990819,50.0035910162366,50.0039850832858,50.0041196781032,50.0042218465037,50.0044589947086,50.0066456991308,50.0077399060267,50.0081139243675]}]],[[{&#34;lng&#34;:[14.3117473526757,14.3212784694731,14.3239099407287,14.3075019076595,14.3074553996738,14.3071707279095,14.3070481545607,14.3068553436582,14.3067033925687,14.3064566466839,14.3064682389715,14.3063100461304,14.3059901811781,14.3055156480768,14.3052561899455,14.3051341570828,14.3048067855197,14.3025118972198,14.305642272835,14.3064954528776,14.3068928421546,14.3088582017704,14.3092090269716,14.3099389040786,14.3108402955493,14.3115254005053,14.3114443352445,14.3113830899613,14.3114481119997,14.3114927121154,14.3117473526757],&#34;lat&#34;:[50.009149170158,50.0100029578157,49.9977939845756,49.9963236676976,49.9963375718305,49.9966869583019,49.9968927454425,49.9970964089857,49.997193622022,49.9972785200519,49.9975353752041,49.9976347514645,49.9977249826934,49.9977566765035,49.9977288644325,49.9976959494206,49.9976932614849,50.0083210922553,50.0086018563669,50.0080316845827,50.0079199836649,50.0071931288672,50.0071248145095,50.0070805873419,50.0070776845684,50.0070568458795,50.0072255988505,50.0074682977163,50.0080899629247,50.0083278044933,50.009149170158]}]],[[{&#34;lng&#34;:[14.3239099407287,14.3212784694731,14.3400463476107,14.34267316027,14.3239099407287],&#34;lat&#34;:[49.9977939845756,50.0100029578157,50.0116817896723,49.9994723965909,49.9977939845756]}]],[[{&#34;lng&#34;:[14.34267316027,14.3400463476107,14.3588155290971,14.3614376824324,14.34267316027],&#34;lat&#34;:[49.9994723965909,50.0116817896723,50.0133575876737,50.0011477756947,49.9994723965909]}]],[[{&#34;lng&#34;:[14.3614376824324,14.3588155290971,14.377586011397,14.3802035046829,14.3614376824324],&#34;lat&#34;:[50.0011477756947,50.0133575876737,50.0150303516696,50.0028201217364,50.0011477756947]}]],[[{&#34;lng&#34;:[14.3802035046829,14.377586011397,14.3963577919749,14.3989706244886,14.3802035046829],&#34;lat&#34;:[50.0028201217364,50.0150303516696,50.016700081511,50.0044894345664,50.0028201217364]}]],[[{&#34;lng&#34;:[14.3989706244886,14.3963577919749,14.4151308682954,14.4177390393165,14.3989706244886],&#34;lat&#34;:[50.0044894345664,50.016700081511,50.01836677705,50.0061557140365,50.0044894345664]}]],[[{&#34;lng&#34;:[14.4177390393165,14.4151308682954,14.4339052378228,14.4365087466337,14.4177390393165],&#34;lat&#34;:[50.0061557140365,50.01836677705,50.0200304381397,50.0078189599993,50.0061557140365]}]],[[{&#34;lng&#34;:[14.4365087466337,14.4339052378228,14.4526808980218,14.4552797439071,14.4365087466337],&#34;lat&#34;:[50.0078189599993,50.0200304381397,50.0216910646342,50.0094791723087,50.0078189599993]}]],[[{&#34;lng&#34;:[14.4552797439071,14.4526808980218,14.4714578463568,14.4740520286037,14.4552797439071],&#34;lat&#34;:[50.0094791723087,50.0216910646342,50.0233486563889,50.0111363508195,50.0094791723087]}]],[[{&#34;lng&#34;:[14.4740520286037,14.4714578463568,14.4902360802922,14.4928255981904,14.4740520286037],&#34;lat&#34;:[50.0111363508195,50.0233486563889,50.0250032132601,50.0127904953876,50.0111363508195]}]],[[{&#34;lng&#34;:[14.4928255981904,14.4902360802922,14.5090155972927,14.5116004501344,14.4928255981904],&#34;lat&#34;:[50.0127904953876,50.0250032132601,50.0266547351054,50.0144416058703,50.0127904953876]}]],[[{&#34;lng&#34;:[14.5116004501344,14.5090155972927,14.5277963948226,14.5303765819024,14.5116004501344],&#34;lat&#34;:[50.0144416058703,50.0266547351054,50.0283032217835,50.0160896821256,50.0144416058703]}]],[[{&#34;lng&#34;:[14.5303765819024,14.5277963948226,14.5465784703464,14.5491539909616,14.5303765819024],&#34;lat&#34;:[50.0160896821256,50.0283032217835,50.0299486731538,50.0177347240128,50.0160896821256]}]],[[{&#34;lng&#34;:[14.5491539909616,14.5465784703464,14.5653618213287,14.5679326747789,14.5491539909616],&#34;lat&#34;:[50.0177347240128,50.0299486731538,50.0315910890773,50.0193767313921,50.0177347240128]}]],[[{&#34;lng&#34;:[14.5679326747789,14.5653618213287,14.584146445234,14.5867126308213,14.5679326747789],&#34;lat&#34;:[50.0193767313921,50.0315910890773,50.0332304694157,50.0210157041253,50.0193767313921]}]],[[{&#34;lng&#34;:[14.5867126308213,14.584146445234,14.6029323395269,14.605493856556,14.5867126308213],&#34;lat&#34;:[50.0210157041253,50.0332304694157,50.034866814032,50.0226516420745,50.0210157041253]}]],[[{&#34;lng&#34;:[14.605493856556,14.6029323395269,14.621719501672,14.62427634945,14.605493856556],&#34;lat&#34;:[50.0226516420745,50.034866814032,50.0365001227903,50.0242845451036,50.0226516420745]}]],[[{&#34;lng&#34;:[14.62427634945,14.621719501672,14.6405079291339,14.6430601069704,14.62427634945],&#34;lat&#34;:[50.0242845451036,50.0365001227903,50.0381303955557,50.025914413077,50.0242845451036]}]],[[{&#34;lng&#34;:[14.6598677687857,14.6430601069704,14.6405079291339,14.6592976193774,14.6596917514064,14.6589332423845,14.6582733314269,14.6578277919686,14.6570262187154,14.6569761365824,14.6567702457557,14.6564690615251,14.6561958478609,14.6598677687857],&#34;lat&#34;:[50.0273701494743,50.025914413077,50.0381303955557,50.0397576321943,50.0378680088788,50.037885799103,50.0378601777425,50.0378940180969,50.0378877919819,50.0366728911082,50.0341179967446,50.0323784981268,50.0310255266167,50.0273701494743]}]],[[{&#34;lng&#34;:[14.6596917514064,14.6592976193774,14.6647333522924,14.6655846557453,14.6667517201875,14.666920232389,14.6662806591241,14.6651678701134,14.664478384426,14.6618630760912,14.6608931058086,14.6604370338031,14.6596917514064],&#34;lat&#34;:[50.0378680088788,50.0397576321943,50.0402277944094,50.0395925600201,50.0387691347422,50.0385979133332,50.0384997069194,50.0383647536021,50.0382465264086,50.0379638155812,50.0378721980499,50.0378505240453,50.0378680088788]}]],[[{&#34;lng&#34;:[14.3017914570922,14.3025118972198,14.3002027082293,14.3002043287259,14.300250860626,14.3003200045133,14.3004782453275,14.300861281414,14.3017914570922],&#34;lat&#34;:[50.0116565359641,50.0083210922553,50.0081139243675,50.0082504515435,50.0091154927322,50.0098158904645,50.0110095906573,50.0118931089773,50.0116565359641]}]],[[{&#34;lng&#34;:[14.305642272835,14.3025118972198,14.3017914570922,14.3025180773892,14.303007346461,14.303133279713,14.3033828668503,14.3054639908301,14.3056394782042,14.305642272835],&#34;lat&#34;:[50.0086018563669,50.0083210922553,50.0116565359641,50.0114717266999,50.011294837559,50.0112074548609,50.0109747508721,50.0087464870011,50.0086037239584,50.0086018563669]}],[{&#34;lng&#34;:[14.3165047109645,14.3186456674836,14.3212784694731,14.3117473526757,14.3117907842892,14.3121066226178,14.3132436148643,14.3132585947399,14.3132170916117,14.3131360336895,14.3130323707935,14.3128496703153,14.3127381897416,14.3126763142986,14.3127651439577,14.3129382090856,14.3133504258056,14.31463758771,14.3147648328597,14.3149726736298,14.3151988000628,14.315227359588,14.3153004103122,14.3155103652262,14.3155964922574,14.3161308566614,14.3166047352692,14.3167421303117,14.3167579551542,14.316736527364,14.3165047109645],&#34;lat&#34;:[50.022020129308,50.0222118435601,50.0100029578157,50.009149170158,50.0092892598072,50.0099425710365,50.012123359085,50.0123144266647,50.0123879596831,50.0124600363549,50.0126218637596,50.0127719793217,50.0129027863301,50.0130230598877,50.0131924223649,50.0133304796537,50.0135621329019,50.0140524557114,50.0141247667797,50.0144516660389,50.0150640633145,50.0156460531063,50.016297387793,50.0172806118537,50.0175618390813,50.0185884595418,50.0199915579002,50.0208815849835,50.0210322394624,50.0212347501394,50.022020129308]}]],[[{&#34;lng&#34;:[14.3212784694731,14.3186456674836,14.3374182068011,14.3400463476107,14.3212784694731],&#34;lat&#34;:[50.0100029578157,50.0222118435601,50.0238910952269,50.0116817896723,50.0100029578157]}]],[[{&#34;lng&#34;:[14.3400463476107,14.3374182068011,14.3561920501953,14.3588155290971,14.3400463476107],&#34;lat&#34;:[50.0116817896723,50.0238910952269,50.025567312094,50.0133575876737,50.0116817896723]}]],[[{&#34;lng&#34;:[14.3588155290971,14.3561920501953,14.3749671951282,14.377586011397,14.3588155290971],&#34;lat&#34;:[50.0133575876737,50.025567312094,50.0272404940118,50.0150303516696,50.0133575876737]}]],[[{&#34;lng&#34;:[14.377586011397,14.3749671951282,14.393743639062,14.3963577919749,14.377586011397],&#34;lat&#34;:[50.0150303516696,50.0272404940118,50.0289106408314,50.016700081511,50.0150303516696]}]],[[{&#34;lng&#34;:[14.3963577919749,14.393743639062,14.4125213794587,14.4151308682954,14.3963577919749],&#34;lat&#34;:[50.016700081511,50.0289106408314,50.0305777524053,50.01836677705,50.016700081511]}]],[[{&#34;lng&#34;:[14.4151308682954,14.4125213794587,14.4313004137802,14.4339052378228,14.4151308682954],&#34;lat&#34;:[50.01836677705,50.0305777524053,50.0322418285872,50.0200304381397,50.01836677705]}]],[[{&#34;lng&#34;:[14.4339052378228,14.4313004137802,14.4500807394885,14.4526808980218,14.4339052378228],&#34;lat&#34;:[50.0200304381397,50.0322418285872,50.0339028692315,50.0216910646342,50.0200304381397]}]],[[{&#34;lng&#34;:[14.4526808980218,14.4500807394885,14.4688623540457,14.4714578463568,14.4526808980218],&#34;lat&#34;:[50.0216910646342,50.0339028692315,50.0355608741941,50.0233486563889,50.0216910646342]}]],[[{&#34;lng&#34;:[14.4714578463568,14.4688623540457,14.4876452549136,14.4902360802922,14.4714578463568],&#34;lat&#34;:[50.0233486563889,50.0355608741941,50.0372158433318,50.0250032132601,50.0233486563889]}]],[[{&#34;lng&#34;:[14.4902360802922,14.4876452549136,14.5064294395544,14.5090155972927,14.4902360802922],&#34;lat&#34;:[50.0250032132601,50.0372158433318,50.0388677765023,50.0266547351054,50.0250032132601]}]],[[{&#34;lng&#34;:[14.5090155972927,14.5064294395544,14.5252149054298,14.5277963948226,14.5090155972927],&#34;lat&#34;:[50.0266547351054,50.0388677765023,50.0405166735649,50.0283032217835,50.0266547351054]}]],[[{&#34;lng&#34;:[14.5277963948226,14.5252149054298,14.544001650002,14.5465784703464,14.5277963948226],&#34;lat&#34;:[50.0283032217835,50.0405166735649,50.0421625343797,50.0299486731538,50.0283032217835]}]],[[{&#34;lng&#34;:[14.5465784703464,14.544001650002,14.562789670733,14.5653618213287,14.5465784703464],&#34;lat&#34;:[50.0299486731538,50.0421625343797,50.0438053588078,50.0315910890773,50.0299486731538]}]],[[{&#34;lng&#34;:[14.5653618213287,14.562789670733,14.5815789650849,14.584146445234,14.5653618213287],&#34;lat&#34;:[50.0315910890773,50.0438053588078,50.0454451467113,50.0332304694157,50.0315910890773]}]],[[{&#34;lng&#34;:[14.584146445234,14.5815789650849,14.6003695305197,14.6029323395269,14.584146445234],&#34;lat&#34;:[50.0332304694157,50.0454451467113,50.047081897954,50.034866814032,50.0332304694157]}]],[[{&#34;lng&#34;:[14.6029323395269,14.6003695305197,14.6191613644995,14.621719501672,14.6029323395269],&#34;lat&#34;:[50.034866814032,50.047081897954,50.0487156124,50.0365001227903,50.034866814032]}]],[[{&#34;lng&#34;:[14.621719501672,14.6191613644995,14.6379544644865,14.6405079291339,14.621719501672],&#34;lat&#34;:[50.0365001227903,50.0487156124,50.0503462899151,50.0381303955557,50.0365001227903]}]],[[{&#34;lng&#34;:[14.6579113414797,14.6592976193774,14.6405079291339,14.6379544644865,14.6407322285756,14.6407365646022,14.6407256830256,14.6408022313923,14.6408729972123,14.6410458730288,14.6410533423299,14.6408551346055,14.6406669834242,14.6402892659487,14.6404156497319,14.6413474766863,14.6418083087462,14.6425223658554,14.6428261454252,14.6430065292445,14.6437539608276,14.6437228727196,14.6437263304797,14.6437769646552,14.6438618259739,14.6441079837391,14.644347036923,14.6449791132267,14.6464322194712,14.6468798108804,14.6475572950223,14.6480156525879,14.6481933419809,14.6485592328383,14.6487841148193,14.6491432476864,14.6496760670371,14.6501781706457,14.6504321031376,14.6509631633466,14.652046752947,14.6525988859954,14.6527240347921,14.6528742171032,14.6531102146917,14.653444467627,14.6536579753965,14.6539371706885,14.6543922467642,14.6549090583995,14.6552172054518,14.6565613754716,14.6570689019426,14.6574418336142,14.6579113414797],&#34;lat&#34;:[50.0464028046093,50.0397576321943,50.0381303955557,50.0503462899151,50.0505870496225,50.0505466507117,50.0503931127531,50.0497680470719,50.049511720135,50.0490513170035,50.0489185118054,50.0486865050131,50.0486005232434,50.0484838691854,50.0482533196369,50.0471154943036,50.0465755338174,50.0457891596101,50.0454815351624,50.0452661883077,50.0442382967659,50.0439474692278,50.0436699781783,50.0432711971134,50.0429573944449,50.0422538550961,50.0422882671555,50.0424440957778,50.0429390377231,50.0431304032426,50.0434486396046,50.0437389113976,50.0438735994183,50.0442268946342,50.0445268799566,50.0451527483004,50.0457220758127,50.0461862255749,50.0463923757776,50.0467664928675,50.0474457233451,50.0480166131814,50.0481696051584,50.0484557640257,50.0487411856088,50.0490256758982,50.049171163785,50.049324604332,50.0490707821204,50.0487088104409,50.048424489274,50.0472924092936,50.046945049869,50.0466958151067,50.0464028046093]}]],[[{&#34;lng&#34;:[14.6647333522924,14.6592976193774,14.6579113414797,14.658840272379,14.6602164542374,14.6604332629884,14.660565301557,14.6607336078885,14.6615493964818,14.6627833895952,14.6631466446595,14.663799474958,14.6647333522924],&#34;lat&#34;:[50.0402277944094,50.0397576321943,50.0464028046093,50.0458230612457,50.0450283848426,50.0447426852349,50.0443993944737,50.0441104971413,50.043088529187,50.0418111566751,50.0414627323882,50.0409246181512,50.0402277944094]}]],[[{&#34;lng&#34;:[14.2826528057249,14.2972356382772,14.2990702267431,14.2989368561627,14.2986091698757,14.2982321178132,14.2981209713852,14.297935264758,14.2978913933453,14.2978289803417,14.2977953887106,14.29769455473,14.2976122793651,14.2976489881848,14.2976211958222,14.2976522439243,14.297670159061,14.2973639293786,14.2966743493127,14.2963847966182,14.2952927867707,14.2944471901179,14.2928965712277,14.2916767607097,14.2910229040387,14.2908230567565,14.2907469975021,14.2906627098812,14.2898523495613,14.2894028454379,14.2889402981833,14.2888153593866,14.2881354683606,14.2873788164723,14.2872899201388,14.2868188560124,14.286113447594,14.2859672423523,14.285917132617,14.2859075493099,14.2858671088184,14.2851569711042,14.283168451375,14.2826528057249],&#34;lat&#34;:[50.0314288366769,50.0327379343794,50.0242508846173,50.0241167297998,50.024057105118,50.0240433410446,50.0240132166312,50.0237250329531,50.0235994516978,50.0235987543585,50.0234907988354,50.0235159763635,50.0235139507867,50.0236361662045,50.0237725663124,50.0239855078506,50.0246653333081,50.0247182904112,50.0250258050562,50.0251117569706,50.02524317183,50.0253884300173,50.025840064297,50.0263231009437,50.0264970775049,50.0265747294979,50.0265654503526,50.0266163466832,50.0268734034162,50.0270465638418,50.0273594446392,50.0273715574862,50.0277184817771,50.0280677695985,50.028038997652,50.028320150599,50.028816742977,50.0289036540275,50.0289164022102,50.028952217458,50.0289606594544,50.0294659919457,50.0310532723652,50.0314288366769]}]],[[{&#34;lng&#34;:[14.2990702267431,14.2972356382772,14.3160115340158,14.3186456674836,14.3165047109645,14.3164872846854,14.3161235929577,14.3160235607103,14.3159192339734,14.3157622768034,14.31569293206,14.3158487199098,14.3159121658712,14.315957105007,14.3159396714569,14.3156205180509,14.3102853643929,14.310071924742,14.3095332966193,14.3089567319106,14.3088794408886,14.307837120841,14.3071082657671,14.3070970247062,14.3070010376699,14.3070077460471,14.306189124931,14.3053463369836,14.3047985158981,14.3042447663584,14.3025687284554,14.3020156181435,14.3003875943102,14.3003135146604,14.3001523674381,14.2998736127046,14.2993880339928,14.2992226932424,14.2991874446286,14.2990702267431],&#34;lat&#34;:[50.0242508846173,50.0327379343794,50.0344206414191,50.0222118435601,50.022020129308,50.0220791673734,50.0229491919455,50.0231365839807,50.0232446153673,50.0232191205014,50.0233419949658,50.0233938012887,50.0234360665597,50.0235640926306,50.0236742778388,50.0237468204659,50.0240810665386,50.0241148643655,50.0241244232424,50.0241889502295,50.0242199697497,50.0242710720885,50.0243295661542,50.0243555197917,50.0243719709387,50.0244028922676,50.0244477063853,50.0245332867155,50.0246042743223,50.0246074607273,50.0246619753709,50.0246595802232,50.0247279014433,50.0246912090031,50.0245638252351,50.0244701028118,50.024479924429,50.0244971383205,50.0243687910139,50.0242508846173]}]],[[{&#34;lng&#34;:[14.3186456674836,14.3160115340158,14.3347887370994,14.3374182068011,14.3186456674836],&#34;lat&#34;:[50.0222118435601,50.0344206414191,50.0361003128645,50.0238910952269,50.0222118435601]}]],[[{&#34;lng&#34;:[14.3374182068011,14.3347887370994,14.3535672449876,14.3561920501953,14.3374182068011],&#34;lat&#34;:[50.0238910952269,50.0361003128645,50.0377769485652,50.025567312094,50.0238910952269]}]],[[{&#34;lng&#34;:[14.3561920501953,14.3535672449876,14.3723470551399,14.3749671951282,14.3561920501953],&#34;lat&#34;:[50.025567312094,50.0377769485652,50.0394505483717,50.0272404940118,50.025567312094]}]],[[{&#34;lng&#34;:[14.3749671951282,14.3723470551399,14.3911281650159,14.393743639062,14.3749671951282],&#34;lat&#34;:[50.0272404940118,50.0394505483717,50.0411211121359,50.0289106408314,50.0272404940118]}]],[[{&#34;lng&#34;:[14.393743639062,14.3911281650159,14.4099105720751,14.4125213794587,14.393743639062],&#34;lat&#34;:[50.0289106408314,50.0411211121359,50.0427886397105,50.0305777524053,50.0289106408314]}]],[[{&#34;lng&#34;:[14.4125213794587,14.4099105720751,14.4286942737769,14.4313004137802,14.4125213794587],&#34;lat&#34;:[50.0305777524053,50.0427886397105,50.0444531309496,50.0322418285872,50.0305777524053]}]],[[{&#34;lng&#34;:[14.4313004137802,14.4286942737769,14.4474792675809,14.4500807394885,14.4313004137802],&#34;lat&#34;:[50.0322418285872,50.0444531309496,50.0461145857081,50.0339028692315,50.0322418285872]}]],[[{&#34;lng&#34;:[14.4500807394885,14.4474792675809,14.4662655509465,14.4688623540457,14.4500807394885],&#34;lat&#34;:[50.0339028692315,50.0461145857081,50.0477730038421,50.0355608741941,50.0339028692315]}]],[[{&#34;lng&#34;:[14.4688623540457,14.4662655509465,14.4850531213332,14.4876452549136,14.4688623540457],&#34;lat&#34;:[50.0355608741941,50.0477730038421,50.049428385209,50.0372158433318,50.0355608741941]}]],[[{&#34;lng&#34;:[14.4876452549136,14.4850531213332,14.5038419762006,14.5064294395544,14.4876452549136],&#34;lat&#34;:[50.0372158433318,50.049428385209,50.051080729667,50.0388677765023,50.0372158433318]}]],[[{&#34;lng&#34;:[14.5064294395544,14.5038419762006,14.5226321130079,14.5252149054298,14.5064294395544],&#34;lat&#34;:[50.0388677765023,50.051080729667,50.0527300370757,50.0405166735649,50.0388677765023]}]],[[{&#34;lng&#34;:[14.5252149054298,14.5226321130079,14.5414235292148,14.544001650002,14.5252149054298],&#34;lat&#34;:[50.0405166735649,50.0527300370757,50.0543763072957,50.0421625343797,50.0405166735649]}]],[[{&#34;lng&#34;:[14.544001650002,14.5414235292148,14.5602162222808,14.562789670733,14.544001650002],&#34;lat&#34;:[50.0421625343797,50.0543763072957,50.0560195401883,50.0438053588078,50.0421625343797]}]],[[{&#34;lng&#34;:[14.562789670733,14.5602162222808,14.5790101896654,14.5815789650849,14.562789670733],&#34;lat&#34;:[50.0438053588078,50.0560195401883,50.0576597356166,50.0454451467113,50.0438053588078]}]],[[{&#34;lng&#34;:[14.5815789650849,14.5790101896654,14.5978054288283,14.6003695305197,14.5815789650849],&#34;lat&#34;:[50.0454451467113,50.0576597356166,50.0592968934442,50.047081897954,50.0454451467113]}]],[[{&#34;lng&#34;:[14.6003695305197,14.5978054288283,14.6166019372289,14.6191613644995,14.6003695305197],&#34;lat&#34;:[50.047081897954,50.0592968934442,50.060931013536,50.0487156124,50.047081897954]}]],[[{&#34;lng&#34;:[14.6191613644995,14.6166019372289,14.6353997123271,14.6379544644865,14.6191613644995],&#34;lat&#34;:[50.0487156124,50.060931013536,50.062562095758,50.0503462899151,50.0487156124]}]],[[{&#34;lng&#34;:[14.6407322285756,14.6379544644865,14.6353997123271,14.6541987515825,14.6547767279265,14.6545938796331,14.6540684950262,14.6537585066131,14.6530380355572,14.6521028224007,14.6515206892417,14.6516735299461,14.6522052103791,14.6449070975674,14.645896765383,14.6448491354916,14.6440828248995,14.643693965898,14.6434962500001,14.6431184860903,14.6426502215687,14.6402616265575,14.6404299088374,14.6406705700058,14.640741828589,14.6408344718838,14.6409665128881,14.6411535053913,14.6413287589731,14.6413983306575,14.6414190051861,14.6413518392117,14.641284251432,14.6410964147424,14.6407446360417,14.6406987781678,14.6406962665513,14.6407322285756],&#34;lat&#34;:[50.0505870496225,50.0503462899151,50.062562095758,50.0641901399776,50.0614218760522,50.0614304986989,50.0615102344347,50.0616585017969,50.06177487759,50.0619801687991,50.0620238657471,50.0611732548482,50.0596084403132,50.0601269393581,50.0588059225867,50.0585707630052,50.0583300226224,50.0581590778563,50.0578934644264,50.0576263153121,50.0574901296955,50.0569653742731,50.0562662446017,50.0550590834595,50.0549305348606,50.0548580920873,50.054822993252,50.0548135219495,50.0548285261114,50.0547026444122,50.0542012909216,50.0531899067237,50.0528276934228,50.0522102913139,50.0515103674727,50.0513111590297,50.0509221064494,50.0505870496225]}]],[[{&#34;lng&#34;:[14.6547767279265,14.6541987515825,14.6698360982548,14.669766127498,14.66894810472,14.6682284791293,14.6672061962808,14.6670927017496,14.6666556317902,14.6664039480523,14.6653345109887,14.6641224367802,14.6636100569307,14.6630188386153,14.6618641813803,14.6615622154597,14.6608736549083,14.6605116857284,14.6600572426293,14.6593776235589,14.6588214170667,14.6584786473572,14.6582396957627,14.6578665696798,14.6580912383952,14.6585050032235,14.6584849537793,14.6590144902746,14.6588596851082,14.6583848418426,14.6581724683793,14.6579440596706,14.6568028402164,14.6564352899094,14.6560309881651,14.6557068633612,14.6547767279265],&#34;lat&#34;:[50.0614218760522,50.0641901399776,50.0655419759582,50.0655082429365,50.0650670891996,50.0645873470757,50.0638552901506,50.0639312108478,50.0638713091677,50.063857725385,50.063655357164,50.0633544675108,50.0632644575153,50.0632179787531,50.0631539941012,50.0630801696346,50.0628545310017,50.0627717959562,50.0627067369075,50.0625267674086,50.0624266851641,50.0624059318412,50.062354330698,50.062192058892,50.0619967579537,50.0620271000596,50.061760556846,50.0618107982057,50.0614971301465,50.0615332653103,50.0611362355058,50.0613474515321,50.0613394596736,50.0613584684341,50.061330751377,50.0613780088056,50.0614218760522]}]],[[{&#34;lng&#34;:[14.269346575244,14.2758162562178,14.2778080730972,14.2774137140647,14.2761812275955,14.2752599784261,14.2742112374043,14.2728945113368,14.2723858700548,14.2719302213652,14.2711442295986,14.2701695192939,14.270085962914,14.2696414180511,14.2695599431219,14.2695758129506,14.269346575244],&#34;lat&#34;:[50.0426784244979,50.0432600591483,50.0340668003849,50.0342532048738,50.0347421438398,50.035187241308,50.0357978073511,50.036758303071,50.0371918193377,50.0376675939342,50.0386528298436,50.0401767830366,50.0403534707102,50.0416197019155,50.0418030224505,50.0419996364443,50.0426784244979]}]],[[{&#34;lng&#34;:[14.2778080730972,14.2758162562178,14.2945955069626,14.2972356382772,14.2826528057249,14.2824499972269,14.2821335304642,14.2818536212,14.2817886463269,14.2817560832024,14.2810546600943,14.280642625379,14.2798993208877,14.2781463673204,14.2778080730972],&#34;lat&#34;:[50.0340668003849,50.0432600591483,50.0449462232704,50.0327379343794,50.0314288366769,50.0315765475713,50.0319719808605,50.0321113320377,50.0321133019375,50.0321302578236,50.0325740789612,50.0328067749186,50.0331712056032,50.0339068942278,50.0340668003849]}]],[[{&#34;lng&#34;:[14.2972356382772,14.2945955069626,14.3133760683256,14.3160115340158,14.2972356382772],&#34;lat&#34;:[50.0327379343794,50.0449462232704,50.046629351003,50.0344206414191,50.0327379343794]}]],[[{&#34;lng&#34;:[14.3160115340158,14.3133760683256,14.332157937764,14.3347887370994,14.3160115340158],&#34;lat&#34;:[50.0344206414191,50.046629351003,50.0483094421953,50.0361003128645,50.0344206414191]}]],[[{&#34;lng&#34;:[14.3347887370994,14.332157937764,14.350941112735,14.3535672449876,14.3347887370994],&#34;lat&#34;:[50.0361003128645,50.0483094421953,50.0499864966969,50.0377769485652,50.0361003128645]}]],[[{&#34;lng&#34;:[14.3535672449876,14.350941112735,14.3697255906954,14.3723470551399,14.3535672449876],&#34;lat&#34;:[50.0377769485652,50.0499864966969,50.0516605143589,50.0394505483717,50.0377769485652]}]],[[{&#34;lng&#34;:[14.3723470551399,14.3697255906954,14.3885113691025,14.3911281650159,14.3723470551399],&#34;lat&#34;:[50.0394505483717,50.0516605143589,50.0533314950336,50.0411211121359,50.0394505483717]}]],[[{&#34;lng&#34;:[14.3911281650159,14.3885113691025,14.407298445413,14.4099105720751,14.3911281650159],&#34;lat&#34;:[50.0411211121359,50.0533314950336,50.0549994385741,50.0427886397105,50.0411211121359]}]],[[{&#34;lng&#34;:[14.4099105720751,14.407298445413,14.4260868170841,14.4286942737769,14.4099105720751],&#34;lat&#34;:[50.0427886397105,50.0549994385741,50.0566643448349,50.0444531309496,50.0427886397105]}]],[[{&#34;lng&#34;:[14.4286942737769,14.4260868170841,14.4448764815726,14.4474792675809,14.4286942737769],&#34;lat&#34;:[50.0444531309496,50.0566643448349,50.0583262136713,50.0461145857081,50.0444531309496]}]],[[{&#34;lng&#34;:[14.4474792675809,14.4448764815726,14.4636674363356,14.4662655509465,14.4474792675809],&#34;lat&#34;:[50.0461145857081,50.0583262136713,50.0599850449399,50.0477730038421,50.0461145857081]}]],[[{&#34;lng&#34;:[14.4662655509465,14.4636674363356,14.4824596788299,14.4850531213332,14.4662655509465],&#34;lat&#34;:[50.0477730038421,50.0599850449399,50.0616408384985,50.049428385209,50.0477730038421]}]],[[{&#34;lng&#34;:[14.4850531213332,14.4824596788299,14.5012532065127,14.5038419762006,14.4850531213332],&#34;lat&#34;:[50.049428385209,50.0616408384985,50.0632935942058,50.051080729667,50.049428385209]}]],[[{&#34;lng&#34;:[14.5038419762006,14.5012532065127,14.5200480168407,14.5226321130079,14.5038419762006],&#34;lat&#34;:[50.051080729667,50.0632935942058,50.0649433119217,50.0527300370757,50.051080729667]}]],[[{&#34;lng&#34;:[14.5226321130079,14.5200480168407,14.5388441072711,14.5414235292148,14.5226321130079],&#34;lat&#34;:[50.0527300370757,50.0649433119217,50.0665899915072,50.0543763072957,50.0527300370757]}]],[[{&#34;lng&#34;:[14.5414235292148,14.5388441072711,14.5576414752609,14.5602162222808,14.5414235292148],&#34;lat&#34;:[50.0543763072957,50.0665899915072,50.0682336328242,50.0560195401883,50.0543763072957]}]],[[{&#34;lng&#34;:[14.5602162222808,14.5576414752609,14.576440118267,14.5790101896654,14.5602162222808],&#34;lat&#34;:[50.0560195401883,50.0682336328242,50.069874235736,50.0576597356166,50.0560195401883]}]],[[{&#34;lng&#34;:[14.5790101896654,14.576440118267,14.5952400337467,14.5978054288283,14.5790101896654],&#34;lat&#34;:[50.0576597356166,50.069874235736,50.0715118001068,50.0592968934442,50.0576597356166]}]],[[{&#34;lng&#34;:[14.5978054288283,14.5952400337467,14.6140412191569,14.6166019372289,14.5978054288283],&#34;lat&#34;:[50.0592968934442,50.0715118001068,50.073146325802,50.060931013536,50.0592968934442]}]],[[{&#34;lng&#34;:[14.6166019372289,14.6140412191569,14.6328436719549,14.6353997123271,14.6166019372289],&#34;lat&#34;:[50.060931013536,50.073146325802,50.074777812688,50.062562095758,50.060931013536]}]],[[{&#34;lng&#34;:[14.6353997123271,14.6328436719549,14.6516473895978,14.6541987515825,14.6353997123271],&#34;lat&#34;:[50.062562095758,50.074777812688,50.0764062606324,50.0641901399776,50.062562095758]}]],[[{&#34;lng&#34;:[14.6698360982548,14.6541987515825,14.6516473895978,14.6704523695429,14.6727839182272,14.6726083734324,14.6709075503434,14.6698360982548],&#34;lat&#34;:[50.0655419759582,50.0641901399776,50.0764062606324,50.0780316695037,50.0668473937256,50.0667676619951,50.0660585136574,50.0655419759582]}]],[[{&#34;lng&#34;:[14.6727839182272,14.6704523695429,14.6892586092476,14.6908414978973,14.6893811734052,14.6892930000102,14.6892080570089,14.6859057320751,14.6836772745095,14.6834779058693,14.6828564529587,14.6821517431695,14.6800937805328,14.6799773330515,14.6788881842544,14.6774774512824,14.6772543451881,14.6767625771116,14.6763875913121,14.6756941495344,14.6750366900126,14.6748351877083,14.6738395093955,14.6730929808836,14.6727839182272],&#34;lat&#34;:[50.0668473937256,50.0780316695037,50.0796540391717,50.0720473737505,50.071392139596,50.0713356434927,50.0712507619787,50.0703312330909,50.0696719596423,50.0697386749994,50.0693970512281,50.0692055421118,50.0691099079027,50.0691668991027,50.0686978090641,50.0681751879217,50.0680371837908,50.0682551847675,50.0681304686243,50.0678234993426,50.0676381061202,50.0676277860688,50.0672407345733,50.0669877674367,50.0668473937256]}]],[[{&#34;lng&#34;:[14.6908414978973,14.6892586092476,14.7044413097021,14.7039947221825,14.702662367074,14.701827279236,14.7001009752278,14.7000623291689,14.6984407016897,14.6967049048851,14.6960919777212,14.6943762417895,14.693513692864,14.6932028124965,14.6909311896852,14.6908414978973],&#34;lat&#34;:[50.0720473737505,50.0796540391717,50.0809615184469,50.0798362771145,50.0766191874484,50.0766371110212,50.0723579243139,50.0721980276684,50.0721400299361,50.0720291778216,50.0720133938434,50.071925370306,50.0719014929839,50.0719114447781,50.0720876164483,50.0720473737505]}]],[[{&#34;lng&#34;:[14.2630605615913,14.2731701218624,14.2758162562178,14.269346575244,14.269296197944,14.2692308130263,14.268731473337,14.2687121570424,14.2695924798196,14.2698592068693,14.2699503519748,14.2700190580253,14.2702401937039,14.2702462480614,14.2701899556647,14.2703647909977,14.270564963689,14.2709260307603,14.270905002354,14.271071378654,14.2705680362369,14.270537145961,14.2707632958647,14.2709842856742,14.2711475932872,14.2711134909598,14.2710636194794,14.2706333995736,14.270706322477,14.2706398375447,14.2705159428214,14.2703710420413,14.2700168685109,14.2697793722867,14.269348005205,14.2687983936812,14.2682439411773,14.2683334619432,14.2694848778412,14.2700771823231,14.2703741141412,14.2706331676945,14.2708581673034,14.2710711773616,14.2712669538829,14.2719523917618,14.2723366103019,14.2727061889461,14.2726952826798,14.2725777167217,14.2723091127043,14.272132533842,14.2717632403057,14.2715682859836,14.2715212299845,14.2715306227218,14.2717029738,14.2715847972784,14.2709541739413,14.2701866440911,14.269998328753,14.2684856853729,14.2674256318878,14.2658888953606,14.2643772904769,14.2641034291927,14.2630605615913],&#34;lat&#34;:[50.0545588062631,50.055467837798,50.0432600591483,50.0426784244979,50.0428275923917,50.0429145849148,50.043113616093,50.0434159177081,50.0434674864058,50.0434700468803,50.0434423831573,50.0436664441514,50.0441913627748,50.0442421109607,50.0443710469545,50.0449437301874,50.0453995818695,50.0460405734742,50.0460608341625,50.0463923576361,50.0463697978829,50.0465610265419,50.0466766835662,50.0466906516856,50.0468360635874,50.0470122055902,50.0471700439793,50.0478271341596,50.0478471266698,50.0479840435221,50.0481399472903,50.0482808893802,50.048515678453,50.0486122530097,50.0487309766656,50.0487773324828,50.0487705953442,50.0492178619378,50.0492563977864,50.0492934039909,50.0493278178813,50.0493776178149,50.0494414229562,50.0495325651647,50.0496407683542,50.0502002470346,50.0504687353335,50.0506909680243,50.050777684931,50.0509037471197,50.0515150904409,50.0520076081662,50.0526670943223,50.0531597758807,50.0534288058885,50.0536911082078,50.0543983747985,50.0544231578816,50.054418217143,50.0542838533515,50.0542224391202,50.0535253892766,50.053134108594,50.0527498756349,50.0524123656306,50.0529596773315,50.0545588062631]}]],[[{&#34;lng&#34;:[14.2758162562178,14.2731701218624,14.2919540400898,14.2945955069626,14.2758162562178],&#34;lat&#34;:[50.0432600591483,50.055467837798,50.0571544235289,50.0449462232704,50.0432600591483]}]],[[{&#34;lng&#34;:[14.2945955069626,14.2919540400898,14.3107392696685,14.3133760683256,14.2945955069626],&#34;lat&#34;:[50.0449462232704,50.0571544235289,50.0588379719229,50.046629351003,50.0449462232704]}]],[[{&#34;lng&#34;:[14.3133760683256,14.3107392696685,14.3295258080532,14.332157937764,14.3133760683256],&#34;lat&#34;:[50.046629351003,50.0588379719229,50.0605184828296,50.0483094421953,50.046629351003]}]],[[{&#34;lng&#34;:[14.332157937764,14.3295258080532,14.3483136526982,14.350941112735,14.332157937764],&#34;lat&#34;:[50.0483094421953,50.0605184828296,50.0621959560991,50.0499864966969,50.0483094421953]}]],[[{&#34;lng&#34;:[14.350941112735,14.3483136526982,14.3671028010582,14.3697255906954,14.350941112735],&#34;lat&#34;:[50.0499864966969,50.0621959560991,50.0638703915829,50.0516605143589,50.0499864966969]}]],[[{&#34;lng&#34;:[14.3697255906954,14.3671028010582,14.3858932505876,14.3885113691025,14.3697255906954],&#34;lat&#34;:[50.0516605143589,50.0638703915829,50.0655417891335,50.0533314950336,50.0516605143589]}]],[[{&#34;lng&#34;:[14.3885113691025,14.3858932505876,14.404684998741,14.407298445413,14.3885113691025],&#34;lat&#34;:[50.0533314950336,50.0655417891335,50.0672101486048,50.0549994385741,50.0533314950336]}]],[[{&#34;lng&#34;:[14.407298445413,14.404684998741,14.4234780429727,14.4260868170841,14.407298445413],&#34;lat&#34;:[50.0549994385741,50.0672101486048,50.0688754698514,50.0566643448349,50.0549994385741]}]],[[{&#34;lng&#34;:[14.4260868170841,14.4234780429727,14.4422723807372,14.4448764815726,14.4260868170841],&#34;lat&#34;:[50.0566643448349,50.0688754698514,50.0705377527292,50.0583262136713,50.0566643448349]}]],[[{&#34;lng&#34;:[14.4448764815726,14.4422723807372,14.4610680094889,14.4636674363356,14.4448764815726],&#34;lat&#34;:[50.0583262136713,50.0705377527292,50.0721969970952,50.0599850449399,50.0583262136713]}]],[[{&#34;lng&#34;:[14.4636674363356,14.4610680094889,14.4798649266824,14.4824596788299,14.4636674363356],&#34;lat&#34;:[50.0599850449399,50.0721969970952,50.0738532028074,50.0616408384985,50.0599850449399]}]],[[{&#34;lng&#34;:[14.4824596788299,14.4798649266824,14.4986631297719,14.5012532065127,14.4824596788299],&#34;lat&#34;:[50.0616408384985,50.0738532028074,50.0755063697253,50.0632935942058,50.0616408384985]}]],[[{&#34;lng&#34;:[14.5012532065127,14.4986631297719,14.5174626162121,14.5200480168407,14.5012532065127],&#34;lat&#34;:[50.0632935942058,50.0755063697253,50.0771564977089,50.0649433119217,50.0632935942058]}]],[[{&#34;lng&#34;:[14.5200480168407,14.5174626162121,14.5362633834574,14.5388441072711,14.5200480168407],&#34;lat&#34;:[50.0649433119217,50.0771564977089,50.0788035866198,50.0665899915072,50.0649433119217]}]],[[{&#34;lng&#34;:[14.5388441072711,14.5362633834574,14.5550654289623,14.5576414752609,14.5388441072711],&#34;lat&#34;:[50.0665899915072,50.0788035866198,50.0804476363204,50.0682336328242,50.0665899915072]}]],[[{&#34;lng&#34;:[14.5576414752609,14.5550654289623,14.5738687501812,14.576440118267,14.5576414752609],&#34;lat&#34;:[50.0682336328242,50.0804476363204,50.0820886466742,50.069874235736,50.0682336328242]}]],[[{&#34;lng&#34;:[14.576440118267,14.5738687501812,14.5926733445689,14.5952400337467,14.576440118267],&#34;lat&#34;:[50.069874235736,50.0820886466742,50.0837266175462,50.0715118001068,50.069874235736]}]],[[{&#34;lng&#34;:[14.5952400337467,14.5926733445689,14.6114792095799,14.6140412191569,14.5952400337467],&#34;lat&#34;:[50.0715118001068,50.0837266175462,50.0853615488019,50.073146325802,50.0715118001068]}]],[[{&#34;lng&#34;:[14.6140412191569,14.6114792095799,14.6302863426688,14.6328436719549,14.6140412191569],&#34;lat&#34;:[50.073146325802,50.0853615488019,50.0869934403083,50.074777812688,50.073146325802]}]],[[{&#34;lng&#34;:[14.6328436719549,14.6302863426688,14.6490947412905,14.6516473895978,14.6328436719549],&#34;lat&#34;:[50.074777812688,50.0869934403083,50.0886222919333,50.0764062606324,50.074777812688]}]],[[{&#34;lng&#34;:[14.6516473895978,14.6490947412905,14.6679044028995,14.6704523695429,14.6516473895978],&#34;lat&#34;:[50.0764062606324,50.0886222919333,50.0902481035462,50.0780316695037,50.0764062606324]}]],[[{&#34;lng&#34;:[14.6704523695429,14.6679044028995,14.6867153249508,14.6892586092476,14.6704523695429],&#34;lat&#34;:[50.0780316695037,50.0902481035462,50.0918708750168,50.0796540391717,50.0780316695037]}]],[[{&#34;lng&#34;:[14.7044413097021,14.6892586092476,14.6867153249508,14.7000366172167,14.7001835655101,14.7003968437683,14.701187586518,14.7016211927103,14.7026630412502,14.7033197204018,14.7039888998007,14.7047639299252,14.704812893922,14.7051699496562,14.7054174129482,14.7053657995027,14.7053426848745,14.7054402247487,14.7053982889403,14.7061746260203,14.7068580249819,14.7061130015049,14.7052667175187,14.7050499637133,14.7044413097021],&#34;lat&#34;:[50.0809615184469,50.0796540391717,50.0918708750168,50.0930181654288,50.0929852953505,50.0929042308192,50.0926886264162,50.0925495071281,50.0922552648545,50.0919973612252,50.0918115566765,50.0911062821556,50.0909351501676,50.0907537841405,50.0902401499588,50.0898528194426,50.0894029914323,50.0889187315865,50.0883735800357,50.0874743842162,50.087088142761,50.0852863994143,50.0829634162533,50.0824950214835,50.0809615184469]}]],[[{&#34;lng&#34;:[14.2524682653252,14.253641279709,14.2536392044705,14.2529834477591,14.2513672049613,14.2509177135485,14.2508157089604,14.2504672527048,14.2501751845927,14.2495256429242,14.2490940467645,14.2486788471537,14.2482507307382,14.2481563330996,14.2478098473889,14.2478931049274,14.247761710283,14.2476296112782,14.2476792990818,14.2487140671141,14.2493392080853,14.251401519822,14.2524682653252],&#34;lat&#34;:[50.0626127646572,50.0572136276557,50.0572135993989,50.0571618155491,50.0569745043185,50.0568495893053,50.0569166636673,50.0574300042873,50.0577032968851,50.0580251910205,50.0581488240872,50.0582294467508,50.0583370486828,50.0583885555524,50.0598022317483,50.0611793588283,50.0618934625305,50.0623039080211,50.0623283574281,50.0623562009368,50.0623934429335,50.0625537533492,50.0626127646572]}]],[[{&#34;lng&#34;:[14.2590585350494,14.2705226486081,14.2731701218624,14.2630605615913,14.2623747652163,14.2615041449306,14.260590480577,14.2581866351945,14.2573006121673,14.256832843201,14.2566260995169,14.25656931399,14.2559647611118,14.2558861837913,14.2557576393597,14.2556673721292,14.2542212895667,14.253641279709,14.2524682653252,14.2527086902293,14.2529241696959,14.2533785955537,14.2536699135665,14.2538934253664,14.2542209544752,14.2552617340536,14.2559404758175,14.2563306506947,14.2569170316568,14.2576043145301,14.2585445271398,14.258785896836,14.2589228329615,14.2590585350494],&#34;lat&#34;:[50.0666446263992,50.0676755274581,50.055467837798,50.0545588062631,50.0556103404348,50.0553921997597,50.0552164793706,50.0546433566929,50.0545027790404,50.0552477913681,50.0555115269337,50.0556171747825,50.0563426095839,50.0564771630171,50.0567833443458,50.0571671442113,50.0572215237396,50.0572136276557,50.0626127646572,50.0626260633532,50.062620952152,50.0626455246651,50.0628106564383,50.0630931530063,50.063227951838,50.0635268202658,50.0637458834231,50.0638844982456,50.0641197542104,50.064260590878,50.0644187359073,50.0645035513684,50.0658765730791,50.0666446263992]}]],[[{&#34;lng&#34;:[14.2731701218624,14.2705226486081,14.289311236912,14.2919540400898,14.2731701218624],&#34;lat&#34;:[50.055467837798,50.0676755274581,50.0693625347662,50.0571544235289,50.055467837798]}]],[[{&#34;lng&#34;:[14.2919540400898,14.289311236912,14.3081011373003,14.3107392696685,14.2919540400898],&#34;lat&#34;:[50.0571544235289,50.0693625347662,50.0710465037897,50.0588379719229,50.0571544235289]}]],[[{&#34;lng&#34;:[14.3107392696685,14.3081011373003,14.326892347225,14.3295258080532,14.3107392696685],&#34;lat&#34;:[50.0588379719229,50.0710465037897,50.0727274343779,50.0605184828296,50.0588379719229]}]],[[{&#34;lng&#34;:[14.3295258080532,14.326892347225,14.3456848641381,14.3483136526982,14.3295258080532],&#34;lat&#34;:[50.0605184828296,50.0727274343779,50.0744053263818,50.0621959560991,50.0605184828296]}]],[[{&#34;lng&#34;:[14.3483136526982,14.3456848641381,14.3644786854915,14.3671028010582,14.3483136526982],&#34;lat&#34;:[50.0621959560991,50.0744053263818,50.0760801796532,50.0638703915829,50.0621959560991]}]],[[{&#34;lng&#34;:[14.3671028010582,14.3644786854915,14.3832738087374,14.3858932505876,14.3671028010582],&#34;lat&#34;:[50.0638703915829,50.0760801796532,50.0777519940451,50.0655417891335,50.0638703915829]}]],[[{&#34;lng&#34;:[14.3858932505876,14.3832738087374,14.4020702313275,14.404684998741,14.3858932505876],&#34;lat&#34;:[50.0655417891335,50.0777519940451,50.0794207694115,50.0672101486048,50.0655417891335]}]],[[{&#34;lng&#34;:[14.404684998741,14.4020702313275,14.4208679507138,14.4234780429727,14.404684998741],&#34;lat&#34;:[50.0672101486048,50.0794207694115,50.0810865056075,50.0688754698514,50.0672101486048]}]],[[{&#34;lng&#34;:[14.4234780429727,14.4208679507138,14.4396669643483,14.4422723807372,14.4234780429727],&#34;lat&#34;:[50.0688754698514,50.0810865056075,50.0827492024897,50.0705377527292,50.0688754698514]}]],[[{&#34;lng&#34;:[14.4422723807372,14.4396669643483,14.4584672696828,14.4610680094889,14.4422723807372],&#34;lat&#34;:[50.0705377527292,50.0827492024897,50.0844088599153,50.0721969970952,50.0705377527292]}]],[[{&#34;lng&#34;:[14.4610680094889,14.4584672696828,14.4772688641693,14.4798649266824,14.4610680094889],&#34;lat&#34;:[50.0721969970952,50.0844088599153,50.0860654777429,50.0738532028074,50.0721969970952]}]],[[{&#34;lng&#34;:[14.4798649266824,14.4772688641693,14.4960717452597,14.4986631297719,14.4798649266824],&#34;lat&#34;:[50.0738532028074,50.0860654777429,50.0877190558322,50.0755063697253,50.0738532028074]}]],[[{&#34;lng&#34;:[14.4986631297719,14.4960717452597,14.514875910406,14.5174626162121,14.4986631297719],&#34;lat&#34;:[50.0755063697253,50.0877190558322,50.0893695940437,50.0771564977089,50.0755063697253]}]],[[{&#34;lng&#34;:[14.5174626162121,14.514875910406,14.53368135706,14.5362633834574,14.5174626162121],&#34;lat&#34;:[50.0771564977089,50.0893695940437,50.0910170922395,50.0788035866198,50.0771564977089]}]],[[{&#34;lng&#34;:[14.5362633834574,14.53368135706,14.5524880826739,14.5550654289623,14.5362633834574],&#34;lat&#34;:[50.0788035866198,50.0910170922395,50.0926615502823,50.0804476363204,50.0788035866198]}]],[[{&#34;lng&#34;:[14.5550654289623,14.5524880826739,14.5712960846996,14.5738687501812,14.5550654289623],&#34;lat&#34;:[50.0804476363204,50.0926615502823,50.0943029680364,50.0820886466742,50.0804476363204]}]],[[{&#34;lng&#34;:[14.5738687501812,14.5712960846996,14.5901053605892,14.5926733445689,14.5738687501812],&#34;lat&#34;:[50.0820886466742,50.0943029680364,50.0959413453667,50.0837266175462,50.0820886466742]}]],[[{&#34;lng&#34;:[14.5926733445689,14.5901053605892,14.6089159077947,14.6114792095799,14.5926733445689],&#34;lat&#34;:[50.0837266175462,50.0959413453667,50.0975766821396,50.0853615488019,50.0837266175462]}]],[[{&#34;lng&#34;:[14.6114792095799,14.6089159077947,14.6277277237684,14.6302863426688,14.6114792095799],&#34;lat&#34;:[50.0853615488019,50.0975766821396,50.0992089782225,50.0869934403083,50.0853615488019]}]],[[{&#34;lng&#34;:[14.6302863426688,14.6277277237684,14.6465408059623,14.6490947412905,14.6302863426688],&#34;lat&#34;:[50.0869934403083,50.0992089782225,50.1008382334835,50.0886222919333,50.0869934403083]}]],[[{&#34;lng&#34;:[14.6490947412905,14.6465408059623,14.6653551518288,14.6679044028995,14.6490947412905],&#34;lat&#34;:[50.0886222919333,50.1008382334835,50.1024644477924,50.0902481035462,50.0886222919333]}]],[[{&#34;lng&#34;:[14.6847842415762,14.6867153249508,14.6679044028995,14.6653551518288,14.6723124640743,14.6738769584359,14.6748258531499,14.6756268228613,14.6765300146794,14.676875237178,14.6784278491377,14.6847842415762],&#34;lat&#34;:[50.1011427931939,50.0918708750168,50.0902481035462,50.1024644477924,50.1030650039511,50.1025587636024,50.1022923687726,50.1020467725152,50.101847272627,50.1017148502002,50.1016136216973,50.1011427931939]}]],[[{&#34;lng&#34;:[14.7000366172167,14.6867153249508,14.6847842415762,14.6900543860222,14.690400695861,14.6912678881192,14.6902503156625,14.6887177469879,14.6886262904002,14.6886913336156,14.6887133730766,14.6887653277074,14.6895188045254,14.6901561982402,14.6906021134051,14.6912165412882,14.6915923059954,14.6927633053538,14.6932663476552,14.6935755820638,14.693829666326,14.6939918685628,14.6941533876486,14.6942654735234,14.6947154405195,14.6955149976626,14.6958613627952,14.6961995262327,14.69685843795,14.6972521151926,14.697911936832,14.6984745416563,14.6987321583073,14.6994645185828,14.6998564461554,14.7000366172167],&#34;lat&#34;:[50.0930181654288,50.0918708750168,50.1011427931939,50.1007521549036,50.1006968960728,50.0999638815916,50.0995854986999,50.0989130949653,50.0982165184616,50.0975255339107,50.0964708026279,50.0963695977603,50.096171716552,50.095980703595,50.0958728870203,50.0957521898363,50.0957171559343,50.0955300904448,50.0951951414013,50.094931582523,50.0947690447237,50.0946882181805,50.0945720454279,50.0943552789151,50.0943728901374,50.094477114446,50.0944511486167,50.0944008904657,50.0941698794246,50.0939700057059,50.0937426964488,50.0934837935418,50.0933997447959,50.0931991726946,50.0930584666161,50.0930181654288]}]],[[{&#34;lng&#34;:[14.2693986027507,14.2705226486081,14.2590585350494,14.2591563743787,14.2591814370096,14.2584070050418,14.2583288926718,14.2582606184578,14.2582996165172,14.2580600455707,14.2578705549159,14.2579547349855,14.2581238606232,14.2668256413766,14.2693986027507],&#34;lat&#34;:[50.0728566897612,50.0676755274581,50.0666446263992,50.0671983668127,50.0676018953717,50.0678380731263,50.0679054891676,50.068641975521,50.0691248346037,50.0696044172916,50.0709119355191,50.0712127486751,50.0715965569827,50.072707794534,50.0728566897612]}]],[[{&#34;lng&#34;:[14.2884177747606,14.289311236912,14.2705226486081,14.2693986027507,14.2732909796441,14.2748785410284,14.2753722208186,14.2756921714385,14.276372647251,14.2769704297593,14.2773753393897,14.2778599288708,14.2781908393768,14.2783201825112,14.2786206100297,14.2785219805635,14.2784154629343,14.2784426556434,14.2783416398977,14.2783414809083,14.2782625851239,14.278175181845,14.2781259843713,14.2779817230547,14.2780325948007,14.2779646712628,14.277862173384,14.2776534918788,14.2780981769768,14.2778485514705,14.2776276098736,14.277333688591,14.2776578105296,14.2783226890197,14.2791161498637,14.2797787329602,14.2803952058759,14.2811654811774,14.2818802507611,14.2820783860212,14.2822496396404,14.2825047075577,14.2827583870788,14.2835980046482,14.2845545422429,14.2849925324597,14.2853934408409,14.2867923314726,14.2883783705722,14.2884177747606],&#34;lat&#34;:[50.0734883592321,50.0693625347662,50.0676755274581,50.0728566897612,50.0730818285004,50.07313728945,50.0731666536453,50.0728295357992,50.0723096423011,50.071985672955,50.0717900866357,50.0714709275865,50.0711579391124,50.0709516758009,50.0709972637018,50.0712212643272,50.0712734315374,50.0714342888666,50.0715001135743,50.0715854348872,50.0716110319783,50.071809259768,50.0718279914794,50.0719566578052,50.0719952695161,50.0720808604606,50.0721470057432,50.07219544509,50.0723629272511,50.0725579355476,50.0727605123754,50.0730654743816,50.0730668923279,50.0730190192516,50.073061214416,50.073144307432,50.073192844869,50.073355045952,50.0738059386028,50.0739721517336,50.0741550157469,50.0743839844427,50.0742678571356,50.0739558472085,50.0736679416907,50.0736092923271,50.0735740037142,50.07355817318,50.0734916641091,50.0734883592321]}],[{&#34;lng&#34;:[14.2849373267993,14.2866670966822,14.28747293832,14.2850816728285,14.2851088385158,14.2853070613012,14.2853403872985,14.2854056755477,14.2850259988411,14.2849373267993],&#34;lat&#34;:[50.0814153741355,50.0815705565943,50.0778506413442,50.0783401891336,50.0792207536742,50.0807123714756,50.081160189203,50.0812886012473,50.0813870778718,50.0814153741355]}]],[[{&#34;lng&#34;:[14.28747293832,14.2866670966822,14.3054616704765,14.3081011373003,14.289311236912,14.2884177747606,14.2890765775284,14.2902635434714,14.2903715159507,14.2904601598829,14.2904895815234,14.2904451027718,14.2901909027429,14.2902012336018,14.2901618094431,14.290044956599,14.2899022188028,14.2897148252865,14.289542235566,14.2892876747814,14.2894072337167,14.2894456722928,14.2880013796834,14.2879922020449,14.28747293832],&#34;lat&#34;:[50.0778506413442,50.0815705565943,50.0832549462146,50.0710465037897,50.0693625347662,50.0734883592321,50.0734331026006,50.0732572390333,50.0734979592271,50.0739484641239,50.0745747643627,50.0750146915606,50.0750193092156,50.07530056581,50.0755217116512,50.0760255029285,50.076306830058,50.0765696272015,50.0767184606625,50.0768354311668,50.0770063821559,50.0772158107615,50.0772897041571,50.0777443281346,50.0778506413442]}]],[[{&#34;lng&#34;:[14.3081011373003,14.3054616704765,14.3242575545377,14.326892347225,14.3081011373003],&#34;lat&#34;:[50.0710465037897,50.0832549462146,50.0849362964513,50.0727274343779,50.0710465037897]}]],[[{&#34;lng&#34;:[14.326892347225,14.3242575545377,14.3430547463153,14.3456848641381,14.326892347225],&#34;lat&#34;:[50.0727274343779,50.0849362964513,50.0866146071557,50.0744053263818,50.0727274343779]}]],[[{&#34;lng&#34;:[14.3456848641381,14.3430547463153,14.3618532432588,14.3644786854915,14.3456848641381],&#34;lat&#34;:[50.0744053263818,50.0866146071557,50.0882898781801,50.0760801796532,50.0744053263818]}]],[[{&#34;lng&#34;:[14.3644786854915,14.3618532432588,14.3806530428176,14.3832738087374,14.3644786854915],&#34;lat&#34;:[50.0760801796532,50.0882898781801,50.0899621093777,50.0777519940451,50.0760801796532]}]],[[{&#34;lng&#34;:[14.3832738087374,14.3806530428176,14.399454142441,14.4020702313275,14.3832738087374],&#34;lat&#34;:[50.0777519940451,50.0899621093777,50.0916313006032,50.0794207694115,50.0777519940451]}]],[[{&#34;lng&#34;:[14.4020702313275,14.399454142441,14.4182565395786,14.4208679507138,14.4020702313275],&#34;lat&#34;:[50.0794207694115,50.0916313006032,50.0932974517122,50.0810865056075,50.0794207694115]}]],[[{&#34;lng&#34;:[14.4208679507138,14.4182565395786,14.4370602316796,14.4396669643483,14.4208679507138],&#34;lat&#34;:[50.0810865056075,50.0932974517122,50.0949605625612,50.0827492024897,50.0810865056075]}]],[[{&#34;lng&#34;:[14.4396669643483,14.4370602316796,14.4558652161934,14.4584672696828,14.4396669643483],&#34;lat&#34;:[50.0827492024897,50.0949605625612,50.0966206330083,50.0844088599153,50.0827492024897]}]],[[{&#34;lng&#34;:[14.4584672696828,14.4558652161934,14.4746714905695,14.4772688641693,14.4584672696828],&#34;lat&#34;:[50.0844088599153,50.0966206330083,50.0982776629123,50.0860654777429,50.0844088599153]}]],[[{&#34;lng&#34;:[14.4772688641693,14.4746714905695,14.4934790522573,14.4960717452597,14.4772688641693],&#34;lat&#34;:[50.0860654777429,50.0982776629123,50.0999316521334,50.0877190558322,50.0860654777429]}]],[[{&#34;lng&#34;:[14.4960717452597,14.4934790522573,14.5122878987062,14.514875910406,14.4960717452597],&#34;lat&#34;:[50.0877190558322,50.0999316521334,50.1015826005327,50.0893695940437,50.0877190558322]}]],[[{&#34;lng&#34;:[14.514875910406,14.5122878987062,14.5310980273655,14.53368135706,14.514875910406],&#34;lat&#34;:[50.0893695940437,50.1015826005327,50.1032305079723,50.0910170922395,50.0893695940437]}]],[[{&#34;lng&#34;:[14.53368135706,14.5310980273655,14.5499094356849,14.5524880826739,14.53368135706],&#34;lat&#34;:[50.0910170922395,50.1032305079723,50.1048753743159,50.0926615502823,50.0910170922395]}]],[[{&#34;lng&#34;:[14.5524880826739,14.5499094356849,14.5687221211137,14.5712960846996,14.5524880826739],&#34;lat&#34;:[50.0926615502823,50.1048753743159,50.1065171994277,50.0943029680364,50.0926615502823]}]],[[{&#34;lng&#34;:[14.5712960846996,14.5687221211137,14.5875360811015,14.5901053605892,14.5712960846996],&#34;lat&#34;:[50.0943029680364,50.1065171994277,50.1081559831735,50.0959413453667,50.0943029680364]}]],[[{&#34;lng&#34;:[14.5901053605892,14.5875360811015,14.606351313098,14.6089159077947,14.5901053605892],&#34;lat&#34;:[50.0959413453667,50.1081559831735,50.1097917254199,50.0975766821396,50.0959413453667]}]],[[{&#34;lng&#34;:[14.6089159077947,14.606351313098,14.6251678145526,14.6277277237684,14.6089159077947],&#34;lat&#34;:[50.0975766821396,50.1097917254199,50.1114244260346,50.0992089782225,50.0975766821396]}]],[[{&#34;lng&#34;:[14.6277277237684,14.6251678145526,14.6439855829151,14.6465408059623,14.6277277237684],&#34;lat&#34;:[50.0992089782225,50.1114244260346,50.1130540848865,50.1008382334835,50.0992089782225]}]],[[{&#34;lng&#34;:[14.6651589532528,14.6653551518288,14.6465408059623,14.6439855829151,14.6578847751641,14.6574916304079,14.6575009103578,14.6568324064931,14.6575083689373,14.6596696330246,14.660693565758,14.6607770650105,14.6608862078249,14.6611309706234,14.6616253472539,14.6619183793071,14.6628246463071,14.663750686832,14.6645127278753,14.664717840544,14.6651589532528],&#34;lat&#34;:[50.1034043981638,50.1024644477924,50.1008382334835,50.1130540848865,50.1142557612489,50.1130503205254,50.1121936536804,50.1099601023866,50.1065707618485,50.1065787860489,50.1066043747832,50.1065152454492,50.1062911668351,50.1059026275908,50.1052224929669,50.10505666218,50.1045998866587,50.1041084364601,50.1036586075189,50.1037820972946,50.1034043981638]}]],[[{&#34;lng&#34;:[14.6723124640743,14.6653551518288,14.6651589532528,14.6659560738767,14.6674324511171,14.6680726546448,14.66866653821,14.6689148449692,14.669004734513,14.6690517107489,14.6708333809348,14.6711232750885,14.6718760373613,14.6719615502929,14.6723124640743],&#34;lat&#34;:[50.1030650039511,50.1024644477924,50.1034043981638,50.1027218508671,50.1033654989969,50.103685840008,50.1040416410513,50.1037175360477,50.1035314338474,50.1033414460495,50.1032622613796,50.1032255016545,50.1030482500819,50.1031785485649,50.1030650039511]}]],[[{&#34;lng&#34;:[14.2611393244931,14.2652236824045,14.2663764717092,14.265537509505,14.2652230773552,14.2649586085292,14.2611672460244,14.2611393244931],&#34;lat&#34;:[50.0917234896395,50.0920906382576,50.0867812673053,50.0871883323269,50.0873679672953,50.087338930467,50.0871750219157,50.0917234896395]}]],[[{&#34;lng&#34;:[14.2663764717092,14.2652236824045,14.2840216186533,14.2866670966822,14.2849373267993,14.2846440713632,14.2839345244036,14.2831546943478,14.2826806486684,14.2819869092547,14.2817116726282,14.2786027316452,14.2775667059072,14.2771080151719,14.2753263678972,14.2746479285051,14.2745695104136,14.2745562328694,14.2745835018422,14.2745496466842,14.2744207245667,14.2736982638025,14.2734198411358,14.2727863694932,14.2727022981717,14.271744948302,14.2710318508285,14.2705861076465,14.2696464093727,14.2687993079285,14.2683441302751,14.2663764717092],&#34;lat&#34;:[50.0867812673053,50.0920906382576,50.0937784886248,50.0815705565943,50.0814153741355,50.0815089545831,50.0816713354209,50.0817289983157,50.0817427431662,50.081722789354,50.0816979969037,50.081281941159,50.0811911953615,50.0811731601725,50.0811514348818,50.0843346346172,50.0846180976612,50.0849264750971,50.0853601428991,50.0858609478176,50.0861625712773,50.087203426855,50.0876985181962,50.0876734894684,50.0876577689738,50.0867934927863,50.0862166914619,50.0861803691923,50.0861413371454,50.0861242351035,50.0858265071822,50.0867812673053]}]],[[{&#34;lng&#34;:[14.2866670966822,14.2840216186533,14.3028208684526,14.3054616704765,14.2866670966822],&#34;lat&#34;:[50.0815705565943,50.0937784886248,50.0954632988091,50.0832549462146,50.0815705565943]}]],[[{&#34;lng&#34;:[14.3054616704765,14.3028208684526,14.3216214292494,14.3242575545377,14.3054616704765],&#34;lat&#34;:[50.0832549462146,50.0954632988091,50.0971450686607,50.0849362964513,50.0832549462146]}]],[[{&#34;lng&#34;:[14.3242575545377,14.3216214292494,14.3404232984907,14.3430547463153,14.3242575545377],&#34;lat&#34;:[50.0849362964513,50.0971450686607,50.0988237980314,50.0866146071557,50.0849362964513]}]],[[{&#34;lng&#34;:[14.3430547463153,14.3404232984907,14.3592264736233,14.3618532432588,14.3430547463153],&#34;lat&#34;:[50.0866146071557,50.0988237980314,50.1004994867737,50.0882898781801,50.0866146071557]}]],[[{&#34;lng&#34;:[14.3618532432588,14.3592264736233,14.3780309520941,14.3806530428176,14.3618532432588],&#34;lat&#34;:[50.0882898781801,50.1004994867737,50.1021721347414,50.0899621093777,50.0882898781801]}]],[[{&#34;lng&#34;:[14.3806530428176,14.3780309520941,14.3968367313501,14.399454142441,14.3806530428176],&#34;lat&#34;:[50.0899621093777,50.1021721347414,50.1038417417896,50.0916313006032,50.0899621093777]}]],[[{&#34;lng&#34;:[14.399454142441,14.3968367313501,14.4156438088379,14.4182565395786,14.399454142441],&#34;lat&#34;:[50.0916313006032,50.1038417417896,50.1055083077741,50.0932974517122,50.0916313006032]}]],[[{&#34;lng&#34;:[14.4182565395786,14.4156438088379,14.4344521820046,14.4370602316796,14.4182565395786],&#34;lat&#34;:[50.0932974517122,50.1055083077741,50.1071718325522,50.0949605625612,50.0932974517122]}]],[[{&#34;lng&#34;:[14.4370602316796,14.4344521820046,14.453261848297,14.4558652161934,14.4370602316796],&#34;lat&#34;:[50.0949605625612,50.1071718325522,50.1088323159822,50.0966206330083,50.0949605625612]}]],[[{&#34;lng&#34;:[14.4558652161934,14.453261848297,14.4720728051618,14.4746714905695,14.4558652161934],&#34;lat&#34;:[50.0966206330083,50.1088323159822,50.1104897579235,50.0982776629123,50.0966206330083]}]],[[{&#34;lng&#34;:[14.4746714905695,14.4720728051618,14.4908850500461,14.4934790522573,14.4746714905695],&#34;lat&#34;:[50.0982776629123,50.1104897579235,50.1121441582363,50.0999316521334,50.0982776629123]}]],[[{&#34;lng&#34;:[14.4934790522573,14.4908850500461,14.5096985803966,14.5122878987062,14.4934790522573],&#34;lat&#34;:[50.0999316521334,50.1121441582363,50.1137955167826,50.1015826005327,50.0999316521334]}]],[[{&#34;lng&#34;:[14.5122878987062,14.5096985803966,14.5285133936604,14.5310980273655,14.5122878987062],&#34;lat&#34;:[50.1015826005327,50.1137955167826,50.1154438334249,50.1032305079723,50.1015826005327]}]],[[{&#34;lng&#34;:[14.5310980273655,14.5285133936604,14.5473294872842,14.5499094356849,14.5310980273655],&#34;lat&#34;:[50.1032305079723,50.1154438334249,50.1170891080268,50.1048753743159,50.1032305079723]}]],[[{&#34;lng&#34;:[14.5499094356849,14.5473294872842,14.5661468587152,14.5687221211137,14.5499094356849],&#34;lat&#34;:[50.1048753743159,50.1170891080268,50.1187313404538,50.1065171994277,50.1048753743159]}]],[[{&#34;lng&#34;:[14.5687221211137,14.5661468587152,14.5849655054003,14.5875360811015,14.5687221211137],&#34;lat&#34;:[50.1065171994277,50.1187313404538,50.1203705305714,50.1081559831735,50.1065171994277]}]],[[{&#34;lng&#34;:[14.5875360811015,14.5849655054003,14.6037854247865,14.606351313098,14.5875360811015],&#34;lat&#34;:[50.1081559831735,50.1203705305714,50.1220066782469,50.1097917254199,50.1081559831735]}]],[[{&#34;lng&#34;:[14.606351313098,14.6037854247865,14.622606614321,14.6251678145526,14.606351313098],&#34;lat&#34;:[50.1097917254199,50.1220066782469,50.1236397833487,50.1114244260346,50.1097917254199]}]],[[{&#34;lng&#34;:[14.6417855982609,14.6439855829151,14.6251678145526,14.622606614321,14.6352411860944,14.6351911479267,14.6352747194866,14.6363168928975,14.6367550823965,14.6385171162014,14.6398428780269,14.6403771694075,14.6405681151346,14.6407014350894,14.6417855982609],&#34;lat&#34;:[50.1235666311013,50.1130540848865,50.1114244260346,50.1236397833487,50.1247343103346,50.1240435683247,50.1239888406278,50.1239407111,50.1238980816901,50.1236778193844,50.1242384449122,50.1237205761419,50.1236301387873,50.1235999431807,50.1235666311013]}]],[[{&#34;lng&#34;:[14.6578847751641,14.6439855829151,14.6417855982609,14.6445043759311,14.645455575062,14.6458493777338,14.6460809503733,14.6466530759122,14.6475932011835,14.6501466772663,14.6522431223259,14.65242626803,14.6525231639992,14.6529576579958,14.6547904062788,14.657935942419,14.6591886343824,14.6586771201505,14.6596562527195,14.6594298811447,14.658972219671,14.6589334745612,14.658449751665,14.658094934038,14.6578847751641],&#34;lat&#34;:[50.1142557612489,50.1130540848865,50.1235666311013,50.123483049164,50.1234804049152,50.1235331510884,50.123594455444,50.1238133065055,50.1242534860102,50.1235411998037,50.1236065609608,50.1235958079957,50.123585221984,50.1234811601071,50.1231885714771,50.1228035209018,50.1226739485298,50.1205901600743,50.1207323352548,50.119569014701,50.1178184556181,50.1178195540357,50.1162188719268,50.1149001143071,50.1142557612489]}]],[[{&#34;lng&#34;:[14.2347933543105,14.2406714494673,14.2389492077663,14.2386654273061,14.2385141064269,14.2382503106952,14.2378952666425,14.2377953503779,14.2374379331286,14.2370262519986,14.2367444409967,14.2364768045103,14.236114859194,14.2347933543105],&#34;lat&#34;:[50.1017980367995,50.1023276252394,50.102108678034,50.1020162920331,50.1019262157184,50.101642886079,50.1013689457756,50.1013118265495,50.1011764878018,50.1011062558661,50.1010988396613,50.1011390941608,50.101237125054,50.1017980367995]}],[{&#34;lng&#34;:[14.2259383939114,14.2294830173283,14.2267427825244,14.2266002630014,14.2264703625084,14.2263492524321,14.2262503415848,14.2261788216014,14.2259383939114],&#34;lat&#34;:[50.1009996637782,50.10131933509,50.1004947988159,50.10047259187,50.1004915626144,50.100533661565,50.1005950121156,50.1006699097327,50.1009996637782]}]],[[{&#34;lng&#34;:[14.2506105503798,14.2625721879561,14.2652236824045,14.2611393244931,14.2611189796374,14.2611058917129,14.2610730795335,14.260905853584,14.2607930299242,14.2606734979466,14.2603381434942,14.2577257274362,14.2560759003811,14.2554226579117,14.2550698920802,14.2548665203169,14.2545116752161,14.2543427666734,14.2542430653731,14.2541435658985,14.2540691431492,14.2541373409243,14.2542553142677,14.2543961546353,14.2547360206948,14.2552028066161,14.2562721917035,14.2584177527453,14.2513809186515,14.2506105503798],&#34;lat&#34;:[50.1032223883358,50.1042980586219,50.0920906382576,50.0917234896395,50.0950372119772,50.0959354426559,50.0963703498649,50.0965125555981,50.0965888388764,50.0966427314568,50.0966863894356,50.0967199367688,50.0967641132364,50.0967963224208,50.0968719904111,50.0969427574437,50.0971428862301,50.0972764909338,50.0973936238805,50.0975591630669,50.0978612318203,50.0981460813379,50.0983487058233,50.0985078133894,50.0987408396537,50.0989068399656,50.0991062474182,50.0994635165868,50.1028618402459,50.1032223883358]}],[{&#34;lng&#34;:[14.2470667447345,14.2472891213702,14.2472480936184,14.2470667447345],&#34;lat&#34;:[50.1029034601169,50.1029234764185,50.1028627801554,50.1029034601169]}]],[[{&#34;lng&#34;:[14.2652236824045,14.2625721879561,14.2813748020783,14.2840216186533,14.2652236824045],&#34;lat&#34;:[50.0920906382576,50.1042980586219,50.1059863304701,50.0937784886248,50.0920906382576]}]],[[{&#34;lng&#34;:[14.2840216186533,14.2813748020783,14.3001787304843,14.3028208684526,14.2840216186533],&#34;lat&#34;:[50.0937784886248,50.1059863304701,50.1076715611851,50.0954632988091,50.0937784886248]}]],[[{&#34;lng&#34;:[14.3028208684526,14.3001787304843,14.3189839706183,14.3216214292494,14.3028208684526],&#34;lat&#34;:[50.0954632988091,50.1076715611851,50.1093537506176,50.0971450686607,50.0954632988091]}]],[[{&#34;lng&#34;:[14.3216214292494,14.3189839706183,14.3377905199249,14.3404232984907,14.3216214292494],&#34;lat&#34;:[50.0971450686607,50.1093537506176,50.1110328986198,50.0988237980314,50.0971450686607]}]],[[{&#34;lng&#34;:[14.3404232984907,14.3377905199249,14.3565983758483,14.3592264736233,14.3404232984907],&#34;lat&#34;:[50.0988237980314,50.1110328986198,50.1127090050446,50.1004994867737,50.0988237980314]}]],[[{&#34;lng&#34;:[14.3592264736233,14.3565983758483,14.3754075358329,14.3780309520941,14.3592264736233],&#34;lat&#34;:[50.1004994867737,50.1127090050446,50.1143820697462,50.1021721347414,50.1004994867737]}]],[[{&#34;lng&#34;:[14.3780309520941,14.3754075358329,14.394217997323,14.3968367313501,14.3780309520941],&#34;lat&#34;:[50.1021721347414,50.1143820697462,50.1160520925802,50.1038417417896,50.1021721347414]}]],[[{&#34;lng&#34;:[14.3968367313501,14.394217997323,14.413029757763,14.4156438088379,14.3968367313501],&#34;lat&#34;:[50.1038417417896,50.1160520925802,50.1177190734028,50.1055083077741,50.1038417417896]}]],[[{&#34;lng&#34;:[14.4156438088379,14.413029757763,14.4318428145971,14.4344521820046,14.4156438088379],&#34;lat&#34;:[50.1055083077741,50.1177190734028,50.1193830120717,50.1071718325522,50.1055083077741]}]],[[{&#34;lng&#34;:[14.4344521820046,14.4318428145971,14.4506571652697,14.453261848297,14.4344521820046],&#34;lat&#34;:[50.1071718325522,50.1193830120717,50.1210439084455,50.1088323159822,50.1071718325522]}]],[[{&#34;lng&#34;:[14.453261848297,14.4506571652697,14.469472807225,14.4720728051618,14.453261848297],&#34;lat&#34;:[50.1088323159822,50.1210439084455,50.1227017623841,50.1104897579235,50.1088323159822]}]],[[{&#34;lng&#34;:[14.4720728051618,14.469472807225,14.4882897379075,14.4908850500461,14.4720728051618],&#34;lat&#34;:[50.1104897579235,50.1227017623841,50.1243565737485,50.1121441582363,50.1104897579235]}]],[[{&#34;lng&#34;:[14.4908850500461,14.4882897379075,14.5071079547614,14.5096985803966,14.4908850500461],&#34;lat&#34;:[50.1121441582363,50.1243565737485,50.1260083424006,50.1137955167826,50.1121441582363]}]],[[{&#34;lng&#34;:[14.5096985803966,14.5071079547614,14.5259274552311,14.5285133936604,14.5096985803966],&#34;lat&#34;:[50.1137955167826,50.1260083424006,50.1276570682035,50.1154438334249,50.1137955167826]}]],[[{&#34;lng&#34;:[14.5285133936604,14.5259274552311,14.5447482367611,14.5473294872842,14.5285133936604],&#34;lat&#34;:[50.1154438334249,50.1276570682035,50.1293027510216,50.1170891080268,50.1154438334249]}]],[[{&#34;lng&#34;:[14.5473294872842,14.5447482367611,14.5635702967957,14.5661468587152,14.5473294872842],&#34;lat&#34;:[50.1170891080268,50.1293027510216,50.1309453907202,50.1187313404538,50.1170891080268]}]],[[{&#34;lng&#34;:[14.5661468587152,14.5635702967957,14.5823936327796,14.5849655054003,14.5661468587152],&#34;lat&#34;:[50.1187313404538,50.1309453907202,50.1325849871657,50.1203705305714,50.1187313404538]}]],[[{&#34;lng&#34;:[14.6023152119061,14.6037854247865,14.5849655054003,14.5823936327796,14.5955324472075,14.5961244165041,14.5974337346342,14.5983127926305,14.5994084452555,14.6005910711489,14.6009485233766,14.6011360144758,14.6013792094454,14.6016703536935,14.6023152119061],&#34;lat&#34;:[50.1290028345597,50.1220066782469,50.1203705305714,50.1325849871657,50.1337275673263,50.1331722319629,50.1320029323564,50.1312584990313,50.1304316247425,50.1295943353587,50.1293777004196,50.1292914648772,50.1292155112244,50.1291464437576,50.1290028345597]}]],[[{&#34;lng&#34;:[14.62170692665,14.622606614321,14.6037854247865,14.6023152119061,14.607273496553,14.6075856207363,14.6077787193437,14.6085904111469,14.6087079854261,14.6206144506854,14.6206635102356,14.6215783622078,14.62170692665],&#34;lat&#34;:[50.1279292599175,50.1236397833487,50.1220066782469,50.1290028345597,50.1278984822136,50.1278053657508,50.1277131663029,50.1271955388307,50.127186056881,50.1295061972721,50.1295696930712,50.1279043819117,50.1279292599175]}]],[[{&#34;lng&#34;:[14.6352411860944,14.622606614321,14.62170692665,14.6217371758303,14.6218452059467,14.6323738340305,14.6325654760572,14.6330230458452,14.6333953534974,14.6337574830757,14.6343489273781,14.6345145409346,14.6346054551784,14.6348026984796,14.6348713513272,14.63521605428,14.6354925594908,14.6355154737216,14.6352458678274,14.6352411860944],&#34;lat&#34;:[50.1247343103346,50.1236397833487,50.1279292599175,50.1279351132945,50.1279004768522,50.1299738037138,50.1298566734355,50.1293392598759,50.1290138697793,50.1287767772095,50.1283073304645,50.1281358702892,50.1280286152303,50.1276691054957,50.1275913128168,50.1268289729054,50.1264453883811,50.1262153979417,50.1247989373553,50.1247343103346]}]],[[{&#34;lng&#34;:[14.2294830173283,14.2259383939114,14.2250817740659,14.224984106209,14.2245171982793,14.2245093675583,14.2246036040314,14.2253475297803,14.2255391719118,14.225667719841,14.2259897893738,14.2272146286975,14.227955900918,14.2285955883901,14.2305749127483,14.2307174140491,14.2308316681826,14.2308812600219,14.2309299239203,14.2310102015195,14.2310882103047,14.2363973952817,14.2364874270839,14.2366783921654,14.2368530682065,14.2369687196047,14.2371799534019,14.237276105176,14.2372688922696,14.2374071628369,14.2374976603598,14.2375950854956,14.237785329826,14.2392440334797,14.2393968513736,14.239481169394,14.2394734512199,14.2392742807329,14.2390644827002,14.2388776503796,14.2380074548541,14.2378161090541,14.2376834644565,14.2375968934233,14.2372675371254,14.2370878979042,14.2371293753656,14.2382276744846,14.2380877605198,14.2381782973488,14.2383675212361,14.2385976250656,14.2386984607218,14.2388798591347,14.2390245491736,14.2391973372316,14.2399872280529,14.240302676653,14.2405660960222,14.2407913774038,14.241793445444,14.2418701043901,14.2437470647338,14.2429239184347,14.2427374171072,14.2425414912142,14.2422619622066,14.2406714494673,14.2347933543105,14.2336251061061,14.2333618141429,14.2332292052552,14.2329603621288,14.231204845422,14.2294830173283],&#34;lat&#34;:[50.10131933509,50.1009996637782,50.1021745035764,50.1022566650651,50.1029931708124,50.103076990965,50.1032306669422,50.1039206905377,50.1040827872138,50.1041335128374,50.1042075943831,50.1043106161627,50.1044283076094,50.1045775063741,50.1051696960434,50.1052270307727,50.1053142290499,50.1054319157747,50.1056847032943,50.10579308108,50.1058302555875,50.1074231686472,50.1074408130309,50.1074396777628,50.1073830570484,50.1072915194708,50.1070067709912,50.1069613222443,50.1069108302409,50.1068340405989,50.1068171356723,50.1068157441415,50.1068457755166,50.1072909395485,50.1073619008317,50.1074667289507,50.1075851491997,50.107886513108,50.1080895035144,50.1082071328829,50.1086227285331,50.1087448535314,50.1088761683813,50.1090182620962,50.1097052792811,50.1103011948917,50.1105897360052,50.1115188415257,50.1115836826167,50.1116619255228,50.1115683888093,50.1117648810692,50.1118237162463,50.1118795464282,50.1118867675982,50.1118524867926,50.1115160757235,50.1114270046568,50.1113778226857,50.1113617943706,50.1113443531532,50.1113383649594,50.1027162145727,50.1026130174728,50.102567806463,50.1025419004636,50.1025298014101,50.1023276252394,50.1017980367995,50.1022938754207,50.1023491313808,50.1023591499612,50.1023439966574,50.1018373853451,50.10131933509]}]],[[{&#34;lng&#34;:[14.2472891213702,14.2470667447345,14.246693542781,14.2464214325003,14.2461495252118,14.2450651305055,14.245059712517,14.2437470647338,14.2418701043901,14.2420984955282,14.2424569954178,14.2429635088724,14.2433032573144,14.2448374938268,14.2450143601204,14.2451851993627,14.2453853543487,14.246129425704,14.2493260113108,14.2495642378677,14.2501053539349,14.2510537799192,14.2522441406648,14.2532604200625,14.2541367859323,14.2549480116578,14.255705282264,14.256150421723,14.2561849204078,14.2561693469367,14.256193105492,14.2564362489539,14.2561138568717,14.2563020230281,14.2572352883578,14.2587486736319,14.2591249357655,14.2601187758927,14.2605400458869,14.2625721879561,14.2506105503798,14.2499120479004,14.2469834429238,14.2470522600636,14.2472962517684,14.2472891213702],&#34;lat&#34;:[50.1029234764185,50.1029034601169,50.1029871752189,50.1030038983826,50.1029904968602,50.1028630056061,50.1028807670501,50.1027162145727,50.1113383649594,50.1113205239363,50.1112522094466,50.1110649430295,50.1108869005128,50.1101490977605,50.1100824029737,50.1100570175571,50.1100526088632,50.1101605275297,50.1107379858146,50.110801274081,50.1108713852783,50.111067289069,50.1113471345019,50.1115978750532,50.1118376562576,50.1121082497808,50.1124595053458,50.1126185503367,50.1126728552855,50.1128197977019,50.1129332378894,50.1132382592852,50.1133613383334,50.1136133911641,50.1146436440014,50.1141433741344,50.114047190821,50.1135233576555,50.1136497543532,50.1042980586219,50.1032223883358,50.1035492926649,50.1031838595208,50.1029966769407,50.1029340250788,50.1029234764185]}]],[[{&#34;lng&#34;:[14.2743944866609,14.2787266462101,14.2813748020783,14.2625721879561,14.2605400458869,14.2743944866609],&#34;lat&#34;:[50.1178053804127,50.1181940817425,50.1059863304701,50.1042980586219,50.1136497543532,50.1178053804127]}]],[[{&#34;lng&#34;:[14.2957043293509,14.2975352558269,14.3001787304843,14.2813748020783,14.2787266462101,14.2803704522822,14.2820808596806,14.2840894590083,14.2847373874844,14.284861135981,14.285637856621,14.2859922291548,14.2862515208601,14.2871759134502,14.2879556178617,14.2884268607467,14.2888832342437,14.2892198676484,14.2894022706344,14.2896453030668,14.2901969428,14.2906681048075,14.2912103611102,14.2919874296416,14.2921400403821,14.2923186139268,14.2924154455054,14.2925866900288,14.2926722040822,14.2939215258532,14.2940080970213,14.2943981967977,14.2957043293509],&#34;lat&#34;:[50.1197157818489,50.1198797329545,50.1076715611851,50.1059863304701,50.1181940817425,50.118341527725,50.1173059932516,50.1159936675512,50.1155487442171,50.1155451326851,50.1158728569269,50.1159314057629,50.1159401259474,50.1160198097906,50.1161482492882,50.1162994209554,50.1164801239278,50.1166596242681,50.1167299843694,50.1169003698013,50.1172291319289,50.1174765110871,50.1177085623399,50.1181600920792,50.1183849169078,50.1183954670338,50.1183571180682,50.1184281982326,50.1184362210459,50.1190299864724,50.1190650660434,50.1191341393548,50.1197157818489]}]],[[{&#34;lng&#34;:[14.3001787304843,14.2975352558269,14.3163451779025,14.3189839706183,14.3001787304843],&#34;lat&#34;:[50.1076715611851,50.1198797329545,50.1215623419335,50.1093537506176,50.1076715611851]}]],[[{&#34;lng&#34;:[14.3365489847392,14.3377905199249,14.3189839706183,14.3163451779025,14.3168259333385,14.3169002566827,14.3170979032318,14.317171725004,14.3176850087619,14.3176888610952,14.3176452255746,14.3177390969498,14.3180498821771,14.3182285774653,14.3187510266735,14.320288180247,14.3204196420958,14.320593041829,14.3207465350891,14.3206815384605,14.3216439985126,14.3225377012207,14.3245110294202,14.3262316511778,14.3266946677989,14.3270949516442,14.327283957476,14.3274669387023,14.3277177467373,14.3284956385117,14.328901886708,14.3295825285348,14.329897750518,14.3310017260569,14.3317390144176,14.3321191599919,14.3328213325224,14.3331209820048,14.3332616819582,14.3346317128644,14.3356421390508,14.3365489847392],&#34;lat&#34;:[50.1167881521403,50.1110328986198,50.1093537506176,50.1215623419335,50.1216053056701,50.121484438927,50.1212454804233,50.121083598969,50.1190676954371,50.1190335452105,50.1189415033502,50.1188533981625,50.1189818395318,50.1186443301602,50.118122673226,50.1168813318747,50.1167315882806,50.1161636724108,50.1155147319636,50.1153196601522,50.1154909730661,50.1157035197119,50.1161384775312,50.1164337363447,50.1165711175687,50.1167329416675,50.1167905739906,50.1168198914451,50.1168299383448,50.1167879153023,50.1167443007855,50.1167512301484,50.1167238141554,50.1166877332903,50.1166297200923,50.1166442206503,50.1166285430977,50.1165934666234,50.116590407682,50.1166441148902,50.116713744473,50.1167881521403]}]],[[{&#34;lng&#34;:[14.3558427846671,14.3565983758483,14.3377905199249,14.3365489847392,14.3382176338075,14.3389135934718,14.3394452617335,14.3397378844221,14.3401108084341,14.3410412121365,14.3412087270944,14.3413445276763,14.3424585911079,14.3432714500291,14.3440785834328,14.3461261860577,14.3471095566698,14.34832279914,14.348659875986,14.3490713963373,14.350105516415,14.3502385347733,14.3519479942812,14.3532251035524,14.3537808559771,14.3540861768089,14.3546652310347,14.3548381302311,14.3553487531703,14.3558427846671],&#34;lat&#34;:[50.116218143481,50.1127090050446,50.1110328986198,50.1167881521403,50.1169250475233,50.116942727419,50.116975980182,50.1169433456086,50.1168695805536,50.1166321190351,50.1166199153021,50.1166238530162,50.1167745532267,50.1167875615405,50.1167498576976,50.116563281458,50.1165147580241,50.1164888864693,50.1164968620451,50.1165426029898,50.1164806035475,50.116497445486,50.1162872731019,50.1161843490764,50.1161784719916,50.116198853205,50.1163154978978,50.1163254462914,50.1162420205887,50.116218143481]}]],[[{&#34;lng&#34;:[14.3559766653696,14.3727827932998,14.3754075358329,14.3565983758483,14.3558427846671,14.3569478219312,14.358272155601,14.3587578955965,14.3592717121962,14.3598720597972,14.3602022177222,14.3608579274142,14.3612944495176,14.361536604649,14.3616506355958,14.3604833215223,14.3618698017501,14.3609304132647,14.3604764371582,14.3601914336007,14.3594750126364,14.3588863043504,14.3578472765749,14.3559357888357,14.3557381907454,14.3557164511065,14.3559766653696],&#34;lat&#34;:[50.1250971684448,50.1265919140025,50.1143820697462,50.1127090050446,50.116218143481,50.1161647280872,50.1161373885279,50.1161039253093,50.1161138037191,50.1160823681614,50.1160994966347,50.1160961278728,50.1162257406106,50.1163435023009,50.1163187035886,50.1175840583892,50.1180223961056,50.1183204858766,50.1188260556577,50.1192522629234,50.1203945389646,50.1213887002216,50.1225844963555,50.1243881085068,50.1245484247368,50.1247280262689,50.1250971684448]}]],[[{&#34;lng&#34;:[14.3754075358329,14.3727827932998,14.3915979396285,14.394217997323,14.3754075358329],&#34;lat&#34;:[50.1143820697462,50.1265919140025,50.1282623525849,50.1160520925802,50.1143820697462]}]],[[{&#34;lng&#34;:[14.394217997323,14.3915979396285,14.4104143856248,14.413029757763,14.394217997323],&#34;lat&#34;:[50.1160520925802,50.1282623525849,50.1299297482076,50.1177190734028,50.1160520925802]}]],[[{&#34;lng&#34;:[14.413029757763,14.4104143856248,14.4292321287307,14.4318428145971,14.413029757763],&#34;lat&#34;:[50.1177190734028,50.1299297482076,50.1315941007285,50.1193830120717,50.1177190734028]}]],[[{&#34;lng&#34;:[14.4318428145971,14.4292321287307,14.4480511663878,14.4506571652697,14.4318428145971],&#34;lat&#34;:[50.1193830120717,50.1315941007285,50.1332554100068,50.1210439084455,50.1193830120717]}]],[[{&#34;lng&#34;:[14.4506571652697,14.4480511663878,14.4668714960379,14.469472807225,14.4506571652697],&#34;lat&#34;:[50.1210439084455,50.1332554100068,50.1349136759027,50.1227017623841,50.1210439084455]}]],[[{&#34;lng&#34;:[14.469472807225,14.4668714960379,14.4856931151228,14.4882897379075,14.469472807225],&#34;lat&#34;:[50.1227017623841,50.1349136759027,50.1365688982776,50.1243565737485,50.1227017623841]}]],[[{&#34;lng&#34;:[14.4882897379075,14.4856931151228,14.5045160210843,14.5071079547614,14.4882897379075],&#34;lat&#34;:[50.1243565737485,50.1365688982776,50.1382210769938,50.1260083424006,50.1243565737485]}]],[[{&#34;lng&#34;:[14.5071079547614,14.5045160210843,14.5233402113643,14.5259274552311,14.5071079547614],&#34;lat&#34;:[50.1260083424006,50.1382210769938,50.1398702119152,50.1276570682035,50.1260083424006]}]],[[{&#34;lng&#34;:[14.5259274552311,14.5233402113643,14.5421656834046,14.5447482367611,14.5259274552311],&#34;lat&#34;:[50.1276570682035,50.1398702119152,50.1415163029063,50.1293027510216,50.1276570682035]}]],[[{&#34;lng&#34;:[14.5447482367611,14.5421656834046,14.5609924346471,14.5635702967957,14.5447482367611],&#34;lat&#34;:[50.1293027510216,50.1415163029063,50.1431593498329,50.1309453907202,50.1293027510216]}]],[[{&#34;lng&#34;:[14.5635702967957,14.5609924346471,14.5798204625337,14.5823936327796,14.5635702967957],&#34;lat&#34;:[50.1309453907202,50.1431593498329,50.144799352562,50.1325849871657,50.1309453907202]}]],[[{&#34;lng&#34;:[14.5955324472075,14.5823936327796,14.5798204625337,14.5879752573608,14.5878043259914,14.5881325149577,14.588083310146,14.588701393731,14.5894444498305,14.5900580877429,14.5913455704446,14.5914335026772,14.5912662056462,14.5911394440097,14.5909688342041,14.5902242537699,14.5899726190673,14.5898085455581,14.5909831167174,14.5914599288469,14.5914618118558,14.5920486759686,14.5924081334522,14.5926016406796,14.5927784564776,14.5936160655685,14.5939470236453,14.5952875452396,14.5955173898966,14.5955324472075],&#34;lat&#34;:[50.1337275673263,50.1325849871657,50.144799352562,50.1455086912771,50.1453151239891,50.1449017177786,50.1444715576704,50.1440230225437,50.1437245280706,50.1434579666919,50.1429519322237,50.1427628762236,50.1423973055884,50.1420276377837,50.1417086840272,50.1403834629681,50.1400202644805,50.1397434305355,50.1395272677977,50.1395000358725,50.1393877868974,50.1390992041944,50.1388125368905,50.1385926463727,50.1383105168803,50.136464416124,50.1358226088498,50.1339929040806,50.1337416926108,50.1337275673263]}]],[[{&#34;lng&#34;:[14.2785412030486,14.2787266462101,14.2743944866609,14.2785412030486],&#34;lat&#34;:[50.1190487226631,50.1181940817425,50.1178053804127,50.1190487226631]}]],[[{&#34;lng&#34;:[14.2803704522822,14.2787266462101,14.2785412030486,14.2789131486818,14.2799684152384,14.2803704522822],&#34;lat&#34;:[50.118341527725,50.1181940817425,50.1190487226631,50.1191602356326,50.1185849234564,50.118341527725]}],[{&#34;lng&#34;:[14.2973373054647,14.2975352558269,14.2957043293509,14.2957490725576,14.2968250433097,14.2970736129962,14.2972459895689,14.2973373054647],&#34;lat&#34;:[50.1207936609736,50.1198797329545,50.1197157818489,50.1197357062305,50.1203361496251,50.1205091898939,50.1206722300453,50.1207936609736]}],[{&#34;lng&#34;:[14.2963463305848,14.2972397633059,14.2970247984577,14.2959895271092,14.2958271396744,14.2957151423368,14.295610979032,14.2953947464086,14.2951995963283,14.2949283896776,14.2947607577653,14.2947980423157,14.2950271308952,14.2954046614715,14.2963463305848],&#34;lat&#34;:[50.1253684200405,50.1212439958674,50.1213961723659,50.1222606399521,50.1224646935108,50.1227190117182,50.1230753412865,50.1240955740522,50.1247317049767,50.124792115025,50.1248632523474,50.1248925539672,50.124888377211,50.1249902683051,50.1253684200405]}]],[[{&#34;lng&#34;:[14.3161060252635,14.3163451779025,14.2975352558269,14.2973373054647,14.2975244198495,14.2972397633059,14.2963463305848,14.2971193867828,14.2973077739455,14.2974667945893,14.2975775057869,14.2977079195481,14.2978216935811,14.2979777634044,14.2988243857129,14.2989733279412,14.2992638257886,14.2996902544463,14.2998962082338,14.3002911117855,14.3007446187463,14.3009655636697,14.3011088024253,14.3011155476133,14.300483961031,14.30084823275,14.300534525661,14.3013798530648,14.3022345413013,14.302392601532,14.3023758545017,14.3025286424863,14.3029580757917,14.304353015622,14.3041198740056,14.3048378303665,14.3050965046943,14.305327410631,14.3056875740913,14.3059533408327,14.3061991200804,14.3062837147064,14.3062746845581,14.3062369102034,14.3062509712157,14.3063947995964,14.306489961409,14.3071111570282,14.3076290822569,14.3079834917879,14.308321958662,14.3086743732112,14.3090762335421,14.3096867599104,14.3100585081664,14.3102527268057,14.3104018821951,14.3104637827574,14.3107264133735,14.3109071923765,14.3118010937838,14.3132841494812,14.3144204944408,14.3148321054844,14.3158865550297,14.3158144681983,14.3158587109698,14.3157714015366,14.3161060252635],&#34;lat&#34;:[50.122668491706,50.1215623419335,50.1198797329545,50.1207936609736,50.1210424815842,50.1212439958674,50.1253684200405,50.1256788507033,50.1257680662133,50.1257607884694,50.1257913983695,50.1258692500831,50.1258524753617,50.1259487829535,50.1261869719365,50.1263246700964,50.1263147257375,50.1263708685379,50.1265556982192,50.1266902630271,50.1270589206795,50.1274556027584,50.1274442755776,50.1275083327563,50.1278380676013,50.128512557524,50.1287906750362,50.1297406936115,50.1296589470909,50.1299163721729,50.1300980623789,50.1301587556984,50.1299076894084,50.129451695774,50.129604313759,50.1297568675099,50.1299716367911,50.1300361367368,50.1302074226978,50.1300319384142,50.1296284513638,50.1293902852514,50.1293152222445,50.1292953222354,50.129246017281,50.1292437219505,50.129215741151,50.1289097368801,50.1286052059458,50.1284376468286,50.1283189512489,50.128235633977,50.1281691735659,50.1281459703057,50.1280992359019,50.1279723580914,50.1278481683984,50.1279667189953,50.1281136554384,50.1281363539046,50.1281870393274,50.1283962241017,50.1285103154377,50.1285598707291,50.1236835594359,50.1231133115563,50.1230628004618,50.1230238616307,50.122668491706]}]],[[{&#34;lng&#34;:[14.3168259333385,14.3163451779025,14.3161060252635,14.3162343550137,14.3163441451852,14.3168259333385],&#34;lat&#34;:[50.1216053056701,50.1215623419335,50.122668491706,50.122532204039,50.1223887873778,50.1216053056701]}],[{&#34;lng&#34;:[14.3158865550297,14.3148321054844,14.3159537883651,14.3156523367182,14.3157131329406,14.3157580690384,14.3157618528924,14.3158398397809,14.315881265709,14.3159040690827,14.3158865550297],&#34;lat&#34;:[50.1236835594359,50.1285598707291,50.1286949061375,50.1271804364166,50.1254704916562,50.1254703318137,50.1253868845043,50.1252253752899,50.1249743623587,50.1238221034937,50.1236835594359]}]],[[{&#34;lng&#34;:[14.3542496014227,14.3701567237607,14.3727827932998,14.3559766653696,14.3561663387521,14.3577312767606,14.3590403613387,14.3601172967032,14.3583331933425,14.3575181190882,14.357160349651,14.3569491419962,14.356919625639,14.3567909082647,14.3562303450072,14.3560174569626,14.3559366625558,14.3554782694023,14.3544945296439,14.3542496014227],&#34;lat&#34;:[50.1373869438697,50.1388016671209,50.1265919140025,50.1250971684448,50.1253662367641,50.1273928653165,50.1286554850912,50.129598441243,50.1297310587899,50.1297247861501,50.1313558166234,50.1314815230678,50.1323017084715,50.1335699918668,50.1367118734877,50.1366794036432,50.1367384741674,50.1365915710406,50.1363339157899,50.1373869438697]}]],[[{&#34;lng&#34;:[14.3727827932998,14.3701567237607,14.3889765575348,14.3915979396285,14.3727827932998],&#34;lat&#34;:[50.1265919140025,50.1388016671209,50.140472521414,50.1282623525849,50.1265919140025]}]],[[{&#34;lng&#34;:[14.3915979396285,14.3889765575348,14.4077976916944,14.4104143856248,14.3915979396285],&#34;lat&#34;:[50.1282623525849,50.140472521414,50.1421403317982,50.1299297482076,50.1282623525849]}]],[[{&#34;lng&#34;:[14.4104143856248,14.4077976916944,14.4266201236789,14.4292321287307,14.4104143856248],&#34;lat&#34;:[50.1299297482076,50.1421403317982,50.143805098132,50.1315941007285,50.1299297482076]}]],[[{&#34;lng&#34;:[14.4292321287307,14.4266201236789,14.4454438509274,14.4480511663878,14.4292321287307],&#34;lat&#34;:[50.1315941007285,50.143805098132,50.1454668202749,50.1332554100068,50.1315941007285]}]],[[{&#34;lng&#34;:[14.4480511663878,14.4454438509274,14.4642688708792,14.4668714960379,14.4480511663878],&#34;lat&#34;:[50.1332554100068,50.1454668202749,50.1471254980874,50.1349136759027,50.1332554100068]}]],[[{&#34;lng&#34;:[14.4668714960379,14.4642688708792,14.4830951809735,14.4856931151228,14.4668714960379],&#34;lat&#34;:[50.1349136759027,50.1471254980874,50.1487811314316,50.1365688982776,50.1349136759027]}]],[[{&#34;lng&#34;:[14.4856931151228,14.4830951809735,14.5019227786495,14.5045160210843,14.4856931151228],&#34;lat&#34;:[50.1365688982776,50.1487811314316,50.1504337201701,50.1382210769938,50.1365688982776]}]],[[{&#34;lng&#34;:[14.5045160210843,14.5019227786495,14.5207516613465,14.5233402113643,14.5045160210843],&#34;lat&#34;:[50.1382210769938,50.1504337201701,50.1520832641671,50.1398702119152,50.1382210769938]}]],[[{&#34;lng&#34;:[14.5233402113643,14.5207516613465,14.5395818265039,14.5421656834046,14.5233402113643],&#34;lat&#34;:[50.1398702119152,50.1520832641671,50.1537297632878,50.1415163029063,50.1398702119152]}]],[[{&#34;lng&#34;:[14.5421656834046,14.5395818265039,14.558413271561,14.5609924346471,14.5421656834046],&#34;lat&#34;:[50.1415163029063,50.1537297632878,50.1553732173982,50.1431593498329,50.1415163029063]}]],[[{&#34;lng&#34;:[14.5786625797667,14.5798204625337,14.5609924346471,14.558413271561,14.5611597895927,14.5605590498479,14.5628568916185,14.5633056191045,14.5652781366879,14.5660010604315,14.5662316113042,14.5674062723944,14.5671945232991,14.5676240236704,14.567872450745,14.568664998334,14.5688133159276,14.5688605620518,14.57070481775,14.5726992812953,14.5736732620779,14.5784022053591,14.5786082986573,14.5786625797667],&#34;lat&#34;:[50.1502935696354,50.144799352562,50.1431593498329,50.1553732173982,50.1556126472152,50.1554368453567,50.1511472010793,50.1502423241299,50.1507702560069,50.1512777453335,50.1517209183049,50.151304358385,50.1510671556483,50.1508472568428,50.1508002133306,50.1509216056962,50.1504769633145,50.1501098022674,50.1501327029348,50.1501102223557,50.1500066673971,50.1508854625802,50.1502734556284,50.1502935696354]}]],[[{&#34;lng&#34;:[14.5879752573608,14.5798204625337,14.5786625797667,14.5819143095337,14.5837790240549,14.5842473959269,14.5841939622708,14.5844271642424,14.5850010396251,14.5858715779017,14.5869876900266,14.5874192721937,14.5891853046257,14.589363278502,14.5893995000925,14.5912923597142,14.592298629409,14.5926755584484,14.5935542752403,14.5941182715751,14.5943541106827,14.5970333646753,14.5971594620504,14.5971531094433,14.596288201719,14.595421669563,14.595249426669,14.5948123972762,14.5942915871043,14.5935723241361,14.5930955568877,14.5926336985922,14.5929751195362,14.592592859041,14.5932531614659,14.5923138943181,14.5917918746775,14.5912668194199,14.5905820312109,14.5898906201181,14.5894771678096,14.5890319387863,14.5885059313832,14.5883594522374,14.5882640119681,14.5883943055129,14.588297490183,14.5881408682326,14.5879752573608],&#34;lat&#34;:[50.1455086912771,50.144799352562,50.1502935696354,50.1514984295599,50.1527534624615,50.1532422182932,50.1535065850363,50.153714765139,50.1537121386847,50.1538423644538,50.1540436534443,50.1541661867615,50.1542438578806,50.1542194967017,50.1543653610719,50.1542175842441,50.1540123386941,50.153952458709,50.1538600533449,50.1538909084941,50.153866668885,50.1541201324415,50.1535207968754,50.1535166270591,50.1524596525514,50.151793742522,50.1514319285793,50.1509119241953,50.150525720789,50.1501432298554,50.1495558908114,50.1485207409372,50.1484690282877,50.1479748199002,50.1477020408668,50.1474205415346,50.1474381388599,50.1473219187492,50.1472427994508,50.1471844223498,50.1473140608241,50.1473035721632,50.1472260871647,50.1470486801353,50.1465852852493,50.1461233714286,50.1459334053901,50.1456962317544,50.1455086912771]}]],[[{&#34;lng&#34;:[14.5971594620504,14.5970333646753,14.5980595665537,14.5983951949387,14.5990788939913,14.5991268225104,14.5987630148234,14.5987239030687,14.59842087427,14.5977697617374,14.5971594620504],&#34;lat&#34;:[50.1535207968754,50.1541201324415,50.1542171964591,50.1542354559335,50.1542040998629,50.153968197334,50.1540510122988,50.1540791898146,50.1541033191778,50.1539213892238,50.1535207968754]}]],[[{&#34;lng&#34;:[14.3682931503924,14.3701567237607,14.3542496014227,14.3541993058412,14.3546250902441,14.3550348852521,14.3554227959818,14.3560785000917,14.3574711903226,14.3575059443845,14.3578637191711,14.3578345474825,14.3575831986403,14.3561211754982,14.3561653819129,14.3566363265575,14.3566927648196,14.3578335774863,14.3587944516547,14.360138965351,14.3610313578722,14.3615613876528,14.3622023969705,14.3650225503148,14.3655216573289,14.3657798202538,14.3665451861272,14.3668746422615,14.3674591498827,14.3680224262289,14.3682931503924],&#34;lat&#34;:[50.1474624421531,50.1388016671209,50.1373869438697,50.1376031755652,50.1377664237718,50.1379639190216,50.1387395641728,50.1390667712916,50.1393747736842,50.1393648852379,50.1406484951786,50.1406442659617,50.1407056818234,50.1407062083258,50.1412496668532,50.1411582340749,50.1414718666886,50.1423508843608,50.1435126868965,50.1441171601027,50.1451146377186,50.1460659943496,50.146683117741,50.1476923853721,50.1479014016905,50.1481089676642,50.1476815035809,50.1475401451593,50.1474600289393,50.1474313027231,50.1474624421531]}]],[[{&#34;lng&#34;:[14.3879187866166,14.3889765575348,14.3701567237607,14.3682931503924,14.3690495979937,14.3707908499174,14.3712723996809,14.3716570669477,14.3718335339188,14.3719592218062,14.3721511966309,14.3724861506233,14.3724998854866,14.3724574906149,14.3730810515636,14.373753968094,14.3751139988801,14.3755838758073,14.3758228017946,14.3761060225782,14.3773263295074,14.3781295114678,14.3785148181758,14.3794443111781,14.3803804126738,14.3809693684384,14.3815091265971,14.3818382249852,14.3818759078069,14.3834482117932,14.3840353516689,14.3849536094384,14.38499036781,14.3858716557512,14.3860131795743,14.386276473624,14.3866069000661,14.3868433867403,14.387152899185,14.3877759809179,14.3874658560864,14.3875005135605,14.3878052048122,14.3879187866166],&#34;lat&#34;:[50.1453977532262,50.140472521414,50.1388016671209,50.1474624421531,50.1475494472624,50.1478045456055,50.1479245681326,50.1480497782497,50.1480607347538,50.1480431274087,50.1479774030209,50.1477815147804,50.1477537816739,50.1475700277572,50.1474842766835,50.1473496271604,50.1473669423144,50.1471248484432,50.1470318836054,50.1470626607623,50.1469421072899,50.146669875522,50.146568752594,50.146478270976,50.1464595285289,50.1465917655051,50.1469332004386,50.1470304803323,50.1469550418777,50.1470294917686,50.1471005587978,50.147002501413,50.1469826180726,50.1460231121849,50.1460941185427,50.1464858809911,50.1463751457566,50.1463144371889,50.1461826954308,50.1458608445581,50.1455568729618,50.14550993694,50.1454203340278,50.1453977532262]}]],[[{&#34;lng&#34;:[14.4067400291213,14.4077976916944,14.3889765575348,14.3879187866166,14.3883475604078,14.3888989514824,14.3894015755373,14.391190044303,14.391215832178,14.3912744735606,14.3919650755638,14.3922699006253,14.3921251570661,14.3931418913872,14.3937548348452,14.3947147384542,14.3949770067861,14.3953517943322,14.3957875938748,14.39573228193,14.3962706168358,14.3964278217744,14.3967740676361,14.3971238877133,14.3971099214517,14.3992226129034,14.3992873110621,14.3992223254992,14.3993656343804,14.3993207111767,14.3993263761026,14.3996474032052,14.3999576789098,14.4000397374292,14.4001619902243,14.4000490625828,14.400855260041,14.401132642628,14.401485726412,14.4020071371343,14.4022382050963,14.4024875547187,14.4029963364205,14.4034078274654,14.4036844190491,14.4039441345367,14.4041670427147,14.4050884981639,14.4052794359383,14.4058894131807,14.4062280030415,14.4067400291213],&#34;lat&#34;:[50.1470740494798,50.1421403317982,50.140472521414,50.1453977532262,50.1453125090168,50.1451053712715,50.1447767332297,50.1440367872293,50.1436706709929,50.1435264775201,50.142723386101,50.1420745103061,50.1418606388733,50.1414163806137,50.1413261389012,50.141492648203,50.1415050961951,50.1418829377797,50.1421278670704,50.1424073185827,50.1424423268771,50.1423909109323,50.1425214349345,50.1432237066716,50.1435981278165,50.1434506106104,50.1435881274288,50.1436026999718,50.1439248002526,50.1440927206324,50.1441637444445,50.1453526503533,50.1466865448683,50.1471329133339,50.1478547603568,50.1479821677606,50.1478729702224,50.1478618715924,50.1478191767277,50.1477417448076,50.1476469440831,50.1476190194627,50.1476959357697,50.1476680284888,50.1475828846563,50.1474545870903,50.1474313968232,50.1472291842355,50.1472121463856,50.1471998083583,50.1471186053303,50.1470740494798]}]],[[{&#34;lng&#34;:[14.4246558029032,14.4266201236789,14.4077976916944,14.4067400291213,14.4069125080931,14.4071959974399,14.4077957212892,14.4079312299621,14.4081103311804,14.4088025308887,14.4092280921524,14.4100064353609,14.4102759966524,14.4110665079029,14.411182065102,14.4112626013622,14.4114620172714,14.4116005880554,14.411832509231,14.412005688905,14.4126472803811,14.4138151472696,14.4140932183695,14.4146480683195,14.4150621372008,14.4152987202803,14.4154972555379,14.4154925634389,14.4156583081433,14.4158387841473,14.4160059805676,14.4162618135481,14.417060382767,14.4172415121545,14.4173550853106,14.4174269892647,14.4175072847777,14.4178159011588,14.4181066054046,14.4186677368368,14.4192017821571,14.4206282203988,14.4208580158714,14.4209340906135,14.4211863187996,14.4211920156372,14.4215025074976,14.4216141592247,14.421963002646,14.4225778385602,14.4223754592553,14.4217752762916,14.4212318711937,14.4208804621495,14.4207665490891,14.4205942212297,14.4200894562388,14.4201185213329,14.4201248902456,14.4202792876715,14.4220466793755,14.4232068004045,14.4232137736549,14.4240537197689,14.4246558029032],&#34;lat&#34;:[50.1529840801622,50.143805098132,50.1421403317982,50.1470740494798,50.1470590400561,50.1470530061111,50.1476807822137,50.147681160114,50.1476178717974,50.1476891244108,50.147654183181,50.1477993065544,50.1478991273693,50.1479070945862,50.1479392837852,50.1480525070482,50.1481824210866,50.14818433707,50.1481170941191,50.1481414025643,50.1483051738222,50.1482467647685,50.1482778987426,50.1482169825362,50.1483695074402,50.1484288245889,50.1484488357794,50.1484634865529,50.1484334938268,50.1484270394763,50.1483731238959,50.148392030007,50.1485555914987,50.148648299911,50.1489838907099,50.1490722033654,50.1491061691773,50.1491378156809,50.1491937450808,50.1493653401885,50.1494827141497,50.149551194702,50.1495156029875,50.1494723210723,50.1494579522803,50.1496490451573,50.1496132342823,50.149633359284,50.1498254692887,50.1499085836411,50.1499942492616,50.1500544633529,50.1501938427051,50.1503389367295,50.1504091865852,50.1509171659431,50.1530402723324,50.153041752651,50.1530660939818,50.1530825562863,50.1529847521392,50.1528711921678,50.1528940437425,50.1529280664697,50.1529840801622]}]],[[{&#34;lng&#34;:[14.4285903463474,14.4428352181651,14.4454438509274,14.4266201236789,14.4246558029032,14.4250838400927,14.42621748515,14.4262968034598,14.4277519547292,14.4277078031856,14.4290529710913,14.4289634709549,14.4290386761784,14.4292573985694,14.4285903463474],&#34;lat&#34;:[50.1564209212078,50.1576781388589,50.1454668202749,50.143805098132,50.1529840801622,50.1530238998386,50.1532240738012,50.15311745503,50.1532218632923,50.1533932122922,50.1535865399714,50.1537731239058,50.1540474946002,50.1540808784637,50.1564209212078]}]],[[{&#34;lng&#34;:[14.4615357617649,14.4616649310279,14.4642688708792,14.4454438509274,14.4428352181651,14.4437980847017,14.4461440105022,14.4519415052017,14.4522207559275,14.46051264292,14.4615357617649],&#34;lat&#34;:[50.1593258581791,50.1593372285471,50.1471254980874,50.1454668202749,50.1576781388589,50.1577630538639,50.1578233206911,50.1579064087807,50.1584424946187,50.1590678842601,50.1593258581791]}]],[[{&#34;lng&#34;:[14.4642688708792,14.4616649310279,14.480495934741,14.4830951809735,14.4642688708792],&#34;lat&#34;:[50.1471254980874,50.1593372285471,50.1609932728187,50.1487811314316,50.1471254980874]}]],[[{&#34;lng&#34;:[14.4830951809735,14.480495934741,14.4993282267409,14.5019227786495,14.4830951809735],&#34;lat&#34;:[50.1487811314316,50.1609932728187,50.162646271537,50.1504337201701,50.1487811314316]}]],[[{&#34;lng&#34;:[14.5019227786495,14.4993282267409,14.5181618044644,14.5207516613465,14.5019227786495],&#34;lat&#34;:[50.1504337201701,50.162646271537,50.1642962245665,50.1520832641671,50.1504337201701]}]],[[{&#34;lng&#34;:[14.5376286374017,14.5395818265039,14.5207516613465,14.5181618044644,14.5317480664581,14.5317897522501,14.5316532357761,14.5332892722459,14.5343118049766,14.5347432265867,14.5355043422535,14.5364558604056,14.5376286374017],&#34;lat&#34;:[50.1629580125669,50.1537297632878,50.1520832641671,50.1642962245665,50.1654845153043,50.1654524785689,50.1653734006306,50.1629711919977,50.1616377853353,50.1619070471792,50.1622389596701,50.1625909491984,50.1629580125669]}]],[[{&#34;lng&#34;:[14.5568239991274,14.558413271561,14.5395818265039,14.5376286374017,14.538277643148,14.5389152992886,14.5395264626373,14.5403421487732,14.5404116200225,14.5406068376225,14.5406216551025,14.5406758155807,14.5412811172496,14.5424228017015,14.5424575409204,14.5426009773038,14.5427710333589,14.5431181417605,14.5432384444088,14.5434980966241,14.5438962496583,14.5439740917961,14.5444398702595,14.5450024849667,14.5450699441861,14.5455375755915,14.5472764690796,14.5473003156108,14.5474713058492,14.5474690623427,14.5479155752947,14.5490267055069,14.5494851864258,14.5506158446426,14.5505469663634,14.5505237450882,14.5520347435343,14.5526555422257,14.5536606094103,14.5531505685567,14.5534071181601,14.5548442276885,14.5564340871362,14.5568239991274],&#34;lat&#34;:[50.1628962521978,50.1553732173982,50.1537297632878,50.1629580125669,50.1631611351047,50.1634171789606,50.1639011944832,50.1650073715928,50.1651603406845,50.1651469925056,50.1650429405505,50.1649398752625,50.1643317175952,50.1629201941845,50.1626492041533,50.1627209796631,50.1628558714384,50.1632027552971,50.1633718650849,50.1636187425174,50.163947394461,50.1640768648901,50.1640218000715,50.1640598408946,50.1641582797428,50.1644016194081,50.164948989042,50.1650613134713,50.1651297689773,50.1652438996495,50.1654502702836,50.1657067361639,50.1660182160534,50.1661944342127,50.1655514675717,50.1648963329232,50.1646945102497,50.1645742670016,50.164318042815,50.1637920322756,50.1637343801388,50.1634882448318,50.1629810324528,50.1628962521978]}]],[[{&#34;lng&#34;:[14.5611597895927,14.558413271561,14.5568239991274,14.5586909169751,14.5598000567865,14.5607004297074,14.5607020979874,14.561070118971,14.5615892706273,14.5628234747739,14.5611597895927],&#34;lat&#34;:[50.1556126472152,50.1553732173982,50.1628962521978,50.1624902979273,50.1622170591537,50.1620802251465,50.1616476641562,50.1616472564662,50.1599179444348,50.1560994889439,50.1556126472152]}]],[[{&#34;lng&#34;:[14.4428224323404,14.4428352181651,14.4285903463474,14.4282135589968,14.4360811096234,14.4361008094796,14.4363741684133,14.4367601795994,14.4428224323404],&#34;lat&#34;:[50.1577379754027,50.1576781388589,50.1564209212078,50.1577426020537,50.1591663203475,50.1591647009644,50.1585819523287,50.1575819657136,50.1577379754027]}]],[[{&#34;lng&#34;:[14.4437980847017,14.4428352181651,14.4428224323404,14.4437980847017],&#34;lat&#34;:[50.1577630538639,50.1576781388589,50.1577379754027,50.1577630538639]}],[{&#34;lng&#34;:[14.4616606404701,14.4616649310279,14.4615357617649,14.4616606404701],&#34;lat&#34;:[50.1593573448674,50.1593372285471,50.1593258581791,50.1593573448674]}]],[[{&#34;lng&#34;:[14.4786095519331,14.480495934741,14.4616649310279,14.4616606404701,14.4641993652326,14.4637955404407,14.4639230094458,14.4639200969168,14.4645261245635,14.4668453131875,14.467084760581,14.4669894724736,14.4691190419809,14.4726938892461,14.4745935527353,14.4781986463306,14.4786095519331],&#34;lat&#34;:[50.16985222218,50.1609932728187,50.1593372285471,50.1593573448674,50.1599974162504,50.1613028815176,50.1620320173097,50.1649531627047,50.1651918896753,50.1655007476207,50.1678923481827,50.1696181735143,50.1698816998753,50.1699137946754,50.1698638919468,50.1698267862024,50.16985222218]}]],[[{&#34;lng&#34;:[14.497327172163,14.4993282267409,14.480495934741,14.4786095519331,14.4802262368469,14.4800751605724,14.4795987305409,14.4817843368225,14.4841032160397,14.4874729097549,14.4922636988225,14.4953854919132,14.497327172163],&#34;lat&#34;:[50.1720609595938,50.162646271537,50.1609932728187,50.16985222218,50.1699522842699,50.1719091170733,50.1723681861684,50.1724421898063,50.1724343868531,50.1723354720357,50.1724237635417,50.1722411670921,50.1720609595938]}]],[[{&#34;lng&#34;:[14.5158910374411,14.5181618044644,14.4993282267409,14.497327172163,14.4980649300919,14.5047148868232,14.5069807309061,14.5079926069825,14.5091483738743,14.5150911407543,14.5156859493399,14.5158910374411],&#34;lat&#34;:[50.1749993107774,50.1642962245665,50.162646271537,50.1720609595938,50.1719924793873,50.1716740371494,50.1715095048352,50.1727137268256,50.1742339773135,50.1749088386965,50.174966254506,50.1749993107774]}]],[[{&#34;lng&#34;:[14.5317480664581,14.5181618044644,14.5158910374411,14.5160432101023,14.5164952784498,14.5166482174169,14.5166744699869,14.5182314910911,14.5187943184253,14.5189985328448,14.5196573989701,14.5266657196861,14.526775045302,14.5269021396449,14.5269849022947,14.5269256769683,14.526932345695,14.5271254224771,14.5274223928515,14.5277169451027,14.5287253394476,14.5296533366077,14.5308926270544,14.5325605344601,14.5322738583317,14.5322449103258,14.5320936267576,14.5317164739671,14.5315467279531,14.5313775851378,14.5314464981199,14.531551429846,14.53210064169,14.5325228553508,14.5326931850145,14.5317856878273,14.5313397185604,14.5311328366176,14.5307688428587,14.5306479772327,14.5305882484175,14.5309840605864,14.5317480664581],&#34;lat&#34;:[50.1654845153043,50.1642962245665,50.1749993107774,50.175023837831,50.1751373559752,50.1747229006202,50.1747070501192,50.1751153430595,50.1752282897363,50.1748331101161,50.1749495557809,50.1765891120627,50.1770278628738,50.1771201848231,50.1774669633294,50.17747439839,50.1775029288196,50.1774879586105,50.1774134720801,50.1773677199182,50.1772745687618,50.1772327280765,50.1772307871055,50.1772558485888,50.1763814969276,50.1761640102219,50.1750981442573,50.1733438932652,50.1728880738939,50.1725761260677,50.1722241879177,50.1710020462562,50.169516574891,50.1684437500917,50.1675462676548,50.1670554615663,50.1668867281954,50.1667897038367,50.166660798625,50.1664778315606,50.166263005706,50.1660716656555,50.1654845153043]}]]],null,null,{&#34;interactive&#34;:true,&#34;className&#34;:&#34;&#34;,&#34;stroke&#34;:false,&#34;color&#34;:&#34;#03F&#34;,&#34;weight&#34;:5,&#34;opacity&#34;:0.5,&#34;fill&#34;:true,&#34;fillColor&#34;:[&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#91CF60&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#91CF60&#34;,&#34;#D9EF8B&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#91CF60&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#91CF60&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#91CF60&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#91CF60&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#91CF60&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#91CF60&#34;,&#34;#D9EF8B&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#1A9850&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#D9EF8B&#34;,&#34;#91CF60&#34;,&#34;#D9EF8B&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#D9EF8B&#34;,&#34;#91CF60&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#91CF60&#34;,&#34;#D9EF8B&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#FEE08B&#34;,&#34;#D9EF8B&#34;,&#34;#91CF60&#34;,&#34;#1A9850&#34;,&#34;#91CF60&#34;,&#34;#D9EF8B&#34;,&#34;#91CF60&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#91CF60&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#91CF60&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#D9EF8B&#34;,&#34;#FFFFBF&#34;,&#34;#FC8D59&#34;,&#34;#D9EF8B&#34;,&#34;#FEE08B&#34;,&#34;#1A9850&#34;,&#34;#91CF60&#34;,&#34;#D9EF8B&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#91CF60&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#D9EF8B&#34;,&#34;#1A9850&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#FC8D59&#34;,&#34;#D9EF8B&#34;,&#34;#1A9850&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#D9EF8B&#34;,&#34;#91CF60&#34;,&#34;#D9EF8B&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#D9EF8B&#34;,&#34;#D73027&#34;,&#34;#FFFFBF&#34;,&#34;#D9EF8B&#34;,&#34;#FFFFBF&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#91CF60&#34;,&#34;#D9EF8B&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#D9EF8B&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#D9EF8B&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#D9EF8B&#34;,&#34;#91CF60&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#D9EF8B&#34;,&#34;#91CF60&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#91CF60&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#91CF60&#34;,&#34;#D9EF8B&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#91CF60&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#91CF60&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#91CF60&#34;,&#34;#D9EF8B&#34;,&#34;#91CF60&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#D9EF8B&#34;,&#34;#91CF60&#34;,&#34;#91CF60&#34;],&#34;fillOpacity&#34;:0.55,&#34;smoothFactor&#34;:1,&#34;noClip&#34;:false},[&#34;1 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;4 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;2 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;2 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;2 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;5 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;2 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;2 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;3 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;5 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;2 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;6 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;5 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;4 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;2 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;2 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;2 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;4 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;6 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;5 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;6 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;2 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;4 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;3 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;3 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;3 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;4 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;8 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;10 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;5 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;3 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;2 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;2 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;3 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;5 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;3 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;4 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;3 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;3 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;2 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;6 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;4 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;3 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;2 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;2 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;4 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;5 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;4 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;7 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;6 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;4 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;23 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;3 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;3 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;10 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;4 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;2 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;2 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;2 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;3 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;4 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;3 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;13 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;32 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;9 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;27 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;15 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;6 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;4 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;8 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;4 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;2 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;2 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;5 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;3 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;6 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;4 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;3 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;18 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;4 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;7 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;35 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;2 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;16 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;9 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;8 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;3 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;4 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;3 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;4 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;3 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;2 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;5 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;6 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;3 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;40 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;11 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;7 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;15 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;6 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;3 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;4 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;4 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;2 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;4 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;3 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;2 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;4 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;3 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;3 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;3 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;2 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;6 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;4 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;10 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;2 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;2 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;7 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;2 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;2 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;2 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;5 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;2 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;2 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;2 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;2 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;2 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;2 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;2 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;2 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;2 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;1 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;more&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;,&#34;0 &lt;u&gt;less&lt;\/u&gt; bars than expected&#34;],null,null,{&#34;interactive&#34;:false,&#34;permanent&#34;:false,&#34;direction&#34;:&#34;auto&#34;,&#34;opacity&#34;:1,&#34;offset&#34;:[0,0],&#34;textsize&#34;:&#34;10px&#34;,&#34;textOnly&#34;:false,&#34;className&#34;:&#34;&#34;,&#34;sticky&#34;:true},null]}],&#34;setView&#34;:[[50.07,14.46],11,[]],&#34;limits&#34;:{&#34;lat&#34;:[49.9419772862148,50.1775029288196],&#34;lng&#34;:[14.2245093675583,14.7068580249819]}},&#34;evals&#34;:[],&#34;jsHooks&#34;:[]}&lt;/script&gt;
&lt;/div&gt;
&lt;div id=&#34;conclusion&#34; class=&#34;section level3&#34;&gt;
&lt;h3&gt;Conclusion&lt;/h3&gt;
&lt;p&gt;The main point from my analysis are that:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;there seems to be &lt;em&gt;more&lt;/em&gt; bars than expected in Letná, Smíchov and Karlín (locations well known for active night life)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;there seem to be &lt;em&gt;less&lt;/em&gt; than expected bars on Petřín hill (a big park by the Prague Castle) and on Olšany (a major cemetery)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;the number of bars in the touristy parts (around Old Town Square) is, despite being high in absolute figures, broadly &lt;em&gt;in line&lt;/em&gt; with expectations&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Neither of these findings is particularly surprising, but this was to be expected with such a simple model. Perhaps in some future version I can improve on it, for example by incorporating information on parkland and / or building density from satellite data.&lt;/p&gt;
&lt;p&gt;More important than the actual result is the fac that the model is in line with expectations, and demonstrates the feasibility of a more serious modeling work in different settings.&lt;/p&gt;
&lt;/div&gt;
</description>
  </item>
  
<item>
  <title>Adjusting Bounding Box of a Map in R</title>
  <link>https://www.jla-data.net/eng/adjusting-bounding-box-of-a-tmap-map/</link>
  <pubDate>Fri, 16 Nov 2018 00:00:00 +0000</pubDate>
  
<guid>https://www.jla-data.net/eng/adjusting-bounding-box-of-a-tmap-map/</guid>
  <description>


&lt;p&gt;I am a great fan of R package &lt;a href=&#34;https://github.com/mtennekes/tmap&#34;&gt;&lt;code&gt;tmap&lt;/code&gt;&lt;/a&gt;. In my personal opinion it is the most effective tool to visualize and communicate spatial data analysis in R context.&lt;/p&gt;
&lt;p&gt;I had one issue with it though - I struggled with titles. The package is set up in a way that the map title can overlap with the map itself. Most of the times this is not a problem, but sometimes the title can get out of hand - such a as in this (exaggerated) example:&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;library(magrittr)
library(tmap)
library(sf)

hranice &amp;lt;- st_read(system.file(&amp;quot;shape/nc.shp&amp;quot;, package = &amp;quot;sf&amp;quot;), quiet = T) 

# draw an ugly chart
tm_shape(hranice) + tm_polygons(col = &amp;quot;red&amp;quot;) +
  tm_layout(title = &amp;quot;A Big, Fat Title...&amp;quot;, frame = T, title.size = 5)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;https://www.jla-data.net/ENG/2018-11-16-adjusting-bounding-box-of-a-tmap-map_files/figure-html/bad-1.png&#34; width=&#34;100%&#34; /&gt;&lt;/p&gt;
&lt;p&gt;The solution to this problem is using the &lt;code&gt;bbox&lt;/code&gt; parameter of the &lt;code&gt;tmap::tm_shape()&lt;/code&gt; call.&lt;/p&gt;
&lt;p&gt;In the following example I first store the bounding box of the NC map, then extend it by 50% in the northerly direction and finally convert it into a &lt;code&gt;sf&lt;/code&gt; polygon to be used as a boudning box of the &lt;code&gt;tmap::tm_shape()&lt;/code&gt; call.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;bbox_new &amp;lt;- st_bbox(hranice) # current bounding box

xrange &amp;lt;- bbox_new$xmax - bbox_new$xmin # range of x values
yrange &amp;lt;- bbox_new$ymax - bbox_new$ymin # range of y values

# bbox_new[1] &amp;lt;- bbox_new[1] - (0.5 * xrange) # xmin - left
# bbox_new[3] &amp;lt;- bbox_new[3] + (0.5 * xrange) # xmax - right
# bbox_new[2] &amp;lt;- bbox_new[2] - (0.5 * yrange) # ymin - bottom
  bbox_new[4] &amp;lt;- bbox_new[4] + (0.5 * yrange) # ymax - top

bbox_new &amp;lt;- bbox_new %&amp;gt;%  # take the bounding box ...
  st_as_sfc() # ... and make it a sf polygon

# draw a prettier chart
tm_shape(hranice, bbox = bbox_new) + tm_polygons(col = &amp;quot;red&amp;quot;) +
  tm_layout(title = &amp;quot;A Big, Fat Title...&amp;quot;, frame = T, title.size = 5)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;https://www.jla-data.net/ENG/2018-11-16-adjusting-bounding-box-of-a-tmap-map_files/figure-html/good-1.png&#34; width=&#34;100%&#34; /&gt;&lt;/p&gt;
&lt;p&gt;While maps drawn via the &lt;code&gt;ggplot2&lt;/code&gt; package do not suffer from the same problem - the title is drawn outside of the plot area, for better or worse - their bounding box can be also manipulated.&lt;/p&gt;
&lt;p&gt;To do so it is necessary to use the &lt;code&gt;xlim&lt;/code&gt; and &lt;code&gt;ylim&lt;/code&gt; parameters of the &lt;code&gt;ggplot2::coords_sf()&lt;/code&gt; call, as demonstrated by the following example:&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;library(ggplot2)

ggplot(hranice) +
  geom_sf( fill = &amp;#39;red&amp;#39;) +
  coord_sf(xlim = st_coordinates(bbox_new)[c(1,2),1], # min &amp;amp; max of x values
           ylim = st_coordinates(bbox_new)[c(2,3),2]) + # min &amp;amp; max of y values
  ggtitle(&amp;#39;a ggplot2 title&amp;#39;)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;https://www.jla-data.net/ENG/2018-11-16-adjusting-bounding-box-of-a-tmap-map_files/figure-html/ggplot-1.png&#34; width=&#34;100%&#34; /&gt;&lt;/p&gt;
</description>
  </item>
  
<item>
  <title>Creating and Pruning Random Points and  Polygons</title>
  <link>https://www.jla-data.net/eng/creating-and-pruning-random-points-and-polygons/</link>
  <pubDate>Thu, 01 Nov 2018 00:00:00 +0000</pubDate>
  
<guid>https://www.jla-data.net/eng/creating-and-pruning-random-points-and-polygons/</guid>
  <description>


&lt;p&gt;In my R practice I have encountered a need to create random points and polygons. In workflows built on &lt;code&gt;sf&lt;/code&gt; package the first is usually done by utilizing the &lt;a href=&#34;https://www.rdocumentation.org/packages/sf/versions/0.7-1/topics/st_sample&#34;&gt;&lt;code&gt;sf::st_sample()&lt;/code&gt;&lt;/a&gt; function, and the second by running &lt;a href=&#34;https://www.rdocumentation.org/packages/sf/versions/0.7-1/topics/geos_unary&#34;&gt;&lt;code&gt;sf::st_voronoi()&lt;/code&gt;&lt;/a&gt; on the random points.&lt;/p&gt;
&lt;p&gt;I have however encountered a problem with the randomly generated points: they tend to cluster in some parts of the map. This is a logical outcome of their randomness - being random, how could they be orderly placed? - and in IT speak a feature, not a bug.&lt;/p&gt;
&lt;p&gt;Having the points too close together, and as result the polygons too small, imposes a cost though - to have a sufficient coverage of the area of interest many points and polygons must be generated, and this increases computational workload in later parts of analysis.&lt;/p&gt;
&lt;p&gt;I have therefore found it advantageous to prune the random points by imposing a minimal distance between them &lt;em&gt;before&lt;/em&gt; the Voronoi tessellation is performed.&lt;/p&gt;
&lt;p&gt;In this example I would like to demonstrate the process by generating random points and polygons in the city of Prague.&lt;/p&gt;
&lt;p&gt;The first chunk of code sets to create 700 random points inside the polygon of city boundaries of Prague (note how the &lt;code&gt;st_sample()&lt;/code&gt; function is likely to come up with different number of points than requested; this is rarely a problem).&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;library(tidyverse)
library(RCzechia)
library(sf)

praha &amp;lt;- RCzechia::obce_polygony() %&amp;gt;% # Czech municipal boundaries
  filter(NAZ_OBEC == &amp;#39;Praha&amp;#39;) %&amp;gt;% # ... one of which is Prague
  st_transform(5514) # from default WGS84 to a metric CRS

prazske_body &amp;lt;- st_sample(praha, 700) %&amp;gt;% # random points, as a list ...
  st_sf() %&amp;gt;%  # ... to data frame ...
  st_transform(5514)  # ... and a metric CRS

obrazek &amp;lt;- ggplot() +
  geom_sf(data = praha, col = &amp;#39;gray40&amp;#39;, fill = NA, lwd = 1) +
  geom_sf(data = prazske_body, pch = 3, col = &amp;#39;red&amp;#39;, alpha = 0.67) +
  theme_bw() +
  ggtitle(paste(nrow(prazske_body), &amp;#39;random points&amp;#39;))

plot(obrazek)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;https://www.jla-data.net/ENG/2018-11-01-creating-and-pruning-random-polygons_files/figure-html/random-points-1.png&#34; width=&#34;672&#34; /&gt;&lt;/p&gt;
&lt;p&gt;Many of the random points are close together; pruning them will be the task for the second chunk of code:&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;i &amp;lt;- 1 # iterator start

buffer_size &amp;lt;- 750 # minimal distance to be enforced (in meters)

repeat( {
  #  create buffer around i-th point
  buffer &amp;lt;- st_buffer(prazske_body[i,], buffer_size ) 
  
  offending &amp;lt;- prazske_body %&amp;gt;%  # start with the intersection of master points... 
    st_intersects(buffer, sparse = F) # ... and the buffer, as a vector
  
  # i-th point is not really offending - it is the origin (not to be excluded)
  offending[i] &amp;lt;- FALSE
  
  # if there are any offending points left - re-assign the master points, 
  # with the offending ones excluded / this is the main pruning part :)
  prazske_body &amp;lt;- prazske_body[!offending,] 
  
  if ( i &amp;gt;= nrow(prazske_body)) {
      # the end was reached; no more points to process
      break 
    } else {
      # rinse &amp;amp; repeat
      i &amp;lt;- i + 1 
    }
  
} )

obrazek &amp;lt;- ggplot() +
  geom_sf(data = praha, col = &amp;#39;gray40&amp;#39;, fill = NA, lwd = 1) +
  geom_sf(data = prazske_body, pch = 3, col = &amp;#39;red&amp;#39;, alpha = 0.67) +
  theme_bw() +
  ggtitle(paste(nrow(prazske_body), &amp;#39;pruned points&amp;#39;))

plot(obrazek)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;https://www.jla-data.net/ENG/2018-11-01-creating-and-pruning-random-polygons_files/figure-html/pruning-1.png&#34; width=&#34;672&#34; /&gt;&lt;/p&gt;
&lt;p&gt;The second piece of code imposed a minimal distance around points by performing &lt;a href=&#34;(https://www.rdocumentation.org/packages/sf/versions/0.7-1/topics/st_buffer)&#34;&gt;&lt;code&gt;st_buffer()&lt;/code&gt;&lt;/a&gt; of size 750 meters around each point, and elimiating any offending points.&lt;/p&gt;
&lt;p&gt;An interesting side note is that as the number of rows in the data.frame changes during calculation it is not practical to iterate via a &lt;code&gt;for()&lt;/code&gt; cycle, but rather via &lt;code&gt;repeat()&lt;/code&gt; and &lt;code&gt;break&lt;/code&gt; cycle.&lt;/p&gt;
&lt;p&gt;The final chunk of code performs the Voronoi tessellation &amp;amp; presents te result.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;prazske_polygony &amp;lt;- prazske_body %&amp;gt;%  # consider the master points
  st_geometry() %&amp;gt;% # ... as geometry only (= throw away the data items)
  st_union() %&amp;gt;% # unite them ...
  st_voronoi() %&amp;gt;% # ... and perform the voronoi tessellation
  st_collection_extract(type = &amp;quot;POLYGON&amp;quot;) %&amp;gt;% # select the polygons
  st_sf(crs = 5514) %&amp;gt;% # set metric crs
  st_intersection(praha) %&amp;gt;% # limit to Prague city boundaries
  st_join(prazske_body) %&amp;gt;% # &amp;amp; re-connect the data items
  st_set_agr(&amp;quot;aggregate&amp;quot;) # clean up

obrazek &amp;lt;- ggplot() +
  geom_sf(data = prazske_polygony, col = &amp;#39;gray60&amp;#39;, fill = NA) +
  geom_sf(data = praha, col = &amp;#39;gray25&amp;#39;, fill = NA, lwd = 1) +
  geom_sf(data = prazske_body, pch = 3, col = &amp;#39;red&amp;#39;, alpha = 0.67) +
  theme_bw() +
  ggtitle(paste(nrow(prazske_body), &amp;#39;points and polygons&amp;#39;))
  
plot(obrazek)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;https://www.jla-data.net/ENG/2018-11-01-creating-and-pruning-random-polygons_files/figure-html/polygony,%20options-1.png&#34; width=&#34;672&#34; /&gt;&lt;/p&gt;
</description>
  </item>
  
<item>
  <title>Unbearable Lightness of SQL Code Chunks</title>
  <link>https://www.jla-data.net/eng/unbearable-lightness-of-sql-chunks/</link>
  <pubDate>Tue, 17 Apr 2018 00:00:00 +0000</pubDate>
  
<guid>https://www.jla-data.net/eng/unbearable-lightness-of-sql-chunks/</guid>
  <description>


&lt;p&gt;Using code chunks with R code in &lt;a href=&#34;https://rmarkdown.rstudio.com/&#34;&gt;RMarkdown&lt;/a&gt; documents is a well understood (and much appreciated!) topic. In this post I would like to draw attention to a slightly different aspect of RMarkdown, that is the option of writing code chunks in different programming lanugages.&lt;/p&gt;
&lt;p&gt;I yet have to find the need to mix and match R and Python code in a single document, but I have found it advantageous to use SQL code chunks.&lt;/p&gt;
&lt;p&gt;Like it or not SQL is the de facto language of data, and SQL code is immediately clear to any old BI hand - much more so than a &lt;code&gt;dplyr&lt;/code&gt; pipeline. In addition it allows me to use features of SQL language that do not translate easily to R code.&lt;/p&gt;
&lt;p&gt;The first task is creating a database connection; this needs to be done in a R (or Python, but let us stick to R) code chunk.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;library(odbc)
con &amp;lt;- dbConnect(odbc::odbc(), 
                 driver = &amp;quot;PostgreSQL Unicode&amp;quot;, 
                 server = &amp;quot;db.jla-data.net&amp;quot;, 
                 port = 5432, 
                 uid = &amp;quot;babisobot&amp;quot;, # user babisobot has select rights only ...
                 password = &amp;quot;babisobot&amp;quot;, # ... so his password need not be too secret :)
                 database = &amp;quot;dbase&amp;quot;)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The next chunk is declared as SQL &lt;code&gt;{sql ... }&lt;/code&gt; and and it is necessary to specify both &lt;code&gt;connection = con&lt;/code&gt; and &lt;code&gt;output.var = &amp;quot;frmVystup&amp;quot;&lt;/code&gt; in the header (i.e. in the curly braces). The quotation marks around output variable are important.&lt;/p&gt;
&lt;pre class=&#34;sql&#34;&gt;&lt;code&gt;select 
  date_trunc(&amp;#39;day&amp;#39;, saved) date,
  count(1) volume
from 
  babisobot 
group by 
  date_trunc(&amp;#39;day&amp;#39;, saved)
order by 
  2 desc
limit 5&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now that I have the result of SQL script safely stored in variable &lt;code&gt;frmVystup&lt;/code&gt; I can use it in my futher work in R. For this proof of concept showing the data frame in a simple &lt;code&gt;kable&lt;/code&gt; is enough.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;library(kableExtra)

kable(frmVystup, # the variable created in previous chunk
      format = &amp;#39;html&amp;#39;,
      booktabs = T,
      align = c(&amp;#39;l&amp;#39;, &amp;#39;r&amp;#39;)) %&amp;gt;%
  kable_styling(full_width = F) %&amp;gt;%
  column_spec(1, width = &amp;quot;6cm&amp;quot;) &lt;/code&gt;&lt;/pre&gt;
&lt;table class=&#34;table&#34; style=&#34;width: auto !important; margin-left: auto; margin-right: auto;&#34;&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th style=&#34;text-align:left;&#34;&gt;
date
&lt;/th&gt;
&lt;th style=&#34;text-align:right;&#34;&gt;
volume
&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td style=&#34;text-align:left;width: 6cm; &#34;&gt;
2018-03-25
&lt;/td&gt;
&lt;td style=&#34;text-align:right;&#34;&gt;
3363
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&#34;text-align:left;width: 6cm; &#34;&gt;
2018-04-06
&lt;/td&gt;
&lt;td style=&#34;text-align:right;&#34;&gt;
1753
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&#34;text-align:left;width: 6cm; &#34;&gt;
2018-04-10
&lt;/td&gt;
&lt;td style=&#34;text-align:right;&#34;&gt;
1741
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&#34;text-align:left;width: 6cm; &#34;&gt;
2018-03-27
&lt;/td&gt;
&lt;td style=&#34;text-align:right;&#34;&gt;
1537
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&#34;text-align:left;width: 6cm; &#34;&gt;
2018-04-11
&lt;/td&gt;
&lt;td style=&#34;text-align:right;&#34;&gt;
1505
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;The last, but not least, thing is not forgetting about closing the database connection on exit.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;dbDisconnect(con) # because it is good manners to shut the door and turn off the light&lt;/code&gt;&lt;/pre&gt;
</description>
  </item>
  
<item>
  <title>Dissolving Polygons in sf</title>
  <link>https://www.jla-data.net/eng/dissolving-polygons-in-sf-environment/</link>
  <pubDate>Wed, 14 Feb 2018 00:00:00 +0000</pubDate>
  
<guid>https://www.jla-data.net/eng/dissolving-polygons-in-sf-environment/</guid>
  <description>


&lt;p&gt;Creating new polygons by dissolving borders of existing ones is a common use case - especially so when working in a sales environment, where sales areas frequently combine lower level units in a seemingly arbitrary fashion.&lt;/p&gt;
&lt;p&gt;In this walkthrough I would like to share the process in a workflow I built on the &lt;a href=&#34;https://r-spatial.github.io/sf/&#34;&gt;sf&lt;/a&gt; package.&lt;/p&gt;
&lt;p&gt;For my example I decided to split the shapefile of the city of &lt;a href=&#34;https://en.wikipedia.org/wiki/Prague&#34;&gt;Prague&lt;/a&gt; into two areas - the &lt;em&gt;center&lt;/em&gt; and the &lt;em&gt;outskirts&lt;/em&gt; based on a shapefile containing the 57 inner neighbourhoods.&lt;/p&gt;
&lt;p&gt;The shapefile for Prague is from my package &lt;a href=&#34;https://github.com/jlacko/RCzechia&#34;&gt;RCzechia&lt;/a&gt; (available on GitHub, but not really necessary - the technique will work with any shapefile), the other packages are the usual suspects for tidy and spatial work.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;library(sf) 
library(tidyverse)
library(RCzechia) # for the shapefile of Prague; available on CRAN
library(ggmap) # for geocoding
library(tmap) # for drawing charts

krovak &amp;lt;- 5514 
# the official Czech CRS - with meters as units; necessary to calculate buffers ¨
# (WGS84 is in decimal degrees)

frmPraha &amp;lt;- casti() %&amp;gt;% # read in all city neigbouhrhoods
  filter(NAZ_OBEC == &amp;quot;Praha&amp;quot;) %&amp;gt;% # select the 57 relevant to Prague
  st_transform(crs = krovak) # convert CRS from WGS84 to the metric one&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;For calculating the central parts I needed to determine the geographical center of Prague. Partly for personal reasons, and partly out of desire to see Google sweat, I chose the &lt;a href=&#34;https://www.tripadvisor.com/Attraction_Review-g274707-d8449625-Reviews-Winston_Churchill_Statue-Prague_Bohemia.html&#34;&gt;statue of Winston Churchill&lt;/a&gt; standing in front of the &lt;a href=&#34;https://en.wikipedia.org/wiki/University_of_Economics,_Prague&#34;&gt;Prague School of Economics&lt;/a&gt; - hello, Alma Mater!&lt;/p&gt;
&lt;p&gt;As for the definition of “central parts” of Prague I decided that any city neighbourhood that intesects a 5 kilometers circle around the statue of sir Winston is a part of the city center. And one that does not is not.&lt;/p&gt;
&lt;p&gt;Note that I am using a coordinate reference system different from the usual &lt;a href=&#34;https://epsg.io/4326&#34;&gt;WGS84&lt;/a&gt; - the reason is that I will be working with buffers, and buffers do not enjoy working with decimal degrees (the unit of WGS84). It is better to transform to another CRS (and remember there is always a way back).&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;winston &amp;lt;- geocode(&amp;quot;socha winstona churchilla praha&amp;quot;, output = &amp;quot;latlon&amp;quot;) %&amp;gt;% 
  # lat long position of the statue of sir Winston, as data.frame
  # a word of warning - for ggmap::geocode() to work a Google API
  # has to be set up - see ?register_google for details
  st_as_sf(coords = c(&amp;quot;lon&amp;quot;, &amp;quot;lat&amp;quot;), crs = 4326) %&amp;gt;% 
  # convert from data.frame to sf object, crs = WGS84
  st_transform(crs = krovak) # crs to the Czech metric one
 
bublina &amp;lt;- st_buffer(winston, dist = 5000) 
# set buffer 5 kilometers around sir Winston&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;To calculate the intersection of the five kilometer buffer around sir Winston and the 57 city neighbourhoods I used the &lt;code&gt;st_intersects()&lt;/code&gt; function. I found it important to use the &lt;code&gt;sparse = F&lt;/code&gt; setting, as it forces the function to return a vector that can be put back in the data frame.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;frmPraha$centrum &amp;lt;- st_intersects(frmPraha, bublina, sparse = F) 
# new column; boolean value for in buffer / out of buffer; the sparse = F is important
# otherwise the result would be a list

# now a simple chart
tm_shape(frmPraha) + tm_borders(col = &amp;quot;grey40&amp;quot;) + tm_fill(col = &amp;quot;centrum&amp;quot;) +
  tm_shape(winston) + tm_dots(size = 1/3, col = &amp;quot;red&amp;quot;, shape = 4) + # sir Winston
  tm_shape(bublina) + tm_borders(col = &amp;quot;red&amp;quot;) # the 5 km bubble&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;https://www.jla-data.net/ENG/2018-02-14-dissolving-polygons-in-sf-environment_files/figure-html/baseline-1.png&#34; width=&#34;672&#34; /&gt; Now that I have a rough idea what the end result &lt;em&gt;should&lt;/em&gt; look like comes the time for actual work. It will consist of three parts:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;dissolving the inner polygon (the &lt;em&gt;center&lt;/em&gt;)&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;dissolving the outer polygon (the &lt;em&gt;outskirts&lt;/em&gt;)&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;joining the &lt;em&gt;center&lt;/em&gt; and &lt;em&gt;outskirts&lt;/em&gt; back to one &lt;code&gt;sf&lt;/code&gt; data frame&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;One important hack that I learned is to extend (buffer) the borders of the city neigbourhoods by half a meter.&lt;/p&gt;
&lt;p&gt;This does not have a visible impact on the outcome (Prague is tens of kilometers long and wide, so half a meter makes no difference either way) but it helps to avoid artifacts (slivers) in place of former inner boundaries. It is a common problem with GEOS and one surprisingly hard to troubleshoot. The &lt;code&gt;st_buffer()&lt;/code&gt; of half a meter dispenses of it elegantly.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;st_union()&lt;/code&gt; function returns just plain geometry, which is in &lt;code&gt;sf&lt;/code&gt; terminology is a &lt;code&gt;sfc&lt;/code&gt; object - a list containing geometry - and requires a call of &lt;code&gt;st_sf()&lt;/code&gt; to become a data frame capable of holding additional data.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;center &amp;lt;- frmPraha[frmPraha$centrum == T, ] %&amp;gt;% # select the central parts
  st_buffer(0.5) %&amp;gt;% # make a buffer of half a meter around all parts (to avoid slivers)
  st_union() %&amp;gt;% # unite to a geometry object
  st_sf() %&amp;gt;% # make the geometry a data frame object
  mutate(centrum = T) # return back the data value 

outskirts &amp;lt;- frmPraha[frmPraha$centrum == F, ] %&amp;gt;% # select the non-central parts
  st_buffer(0.5) %&amp;gt;% # make a buffer of half a meter around all parts (to avoid slivers)
  st_union() %&amp;gt;% # unite to a geometry object
  st_sf() %&amp;gt;% # make the geometry a data frame object
  mutate(centrum = F) # return back the data value 

frmPraha2 &amp;lt;- rbind(center, 
                   outskirts) # merge central and non-central part to a single data frame&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;With the &lt;em&gt;center&lt;/em&gt; and &lt;em&gt;outskirts&lt;/em&gt; polygons bound back to a single &lt;code&gt;sf&lt;/code&gt; data frame there is only one step left: to verify the results by drawing a map of the outcome.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;tm_shape(frmPraha2) + tm_borders(col = &amp;quot;grey40&amp;quot;) + tm_fill(col  = &amp;quot;centrum&amp;quot;) +
  tm_shape(winston) + tm_dots(size = 1/3, col = &amp;quot;red&amp;quot;, shape = 4) + # sir Winston
  tm_shape(bublina) + tm_borders(col = &amp;quot;red&amp;quot;) # the 5 km bubble&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;https://www.jla-data.net/ENG/2018-02-14-dissolving-polygons-in-sf-environment_files/figure-html/final-result-1.png&#34; width=&#34;672&#34; /&gt;&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;str(frmPraha2)&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;## Classes &amp;#39;sf&amp;#39; and &amp;#39;data.frame&amp;#39;:   2 obs. of  2 variables:
##  $ centrum : logi  TRUE FALSE
##  $ geometry:sfc_GEOMETRY of length 2; first list element: List of 1
##   ..$ : num [1:11845, 1:2] -738336 -738357 -738363 -738368 -738378 ...
##   ..- attr(*, &amp;quot;class&amp;quot;)= chr  &amp;quot;XY&amp;quot; &amp;quot;POLYGON&amp;quot; &amp;quot;sfg&amp;quot;
##  - attr(*, &amp;quot;sf_column&amp;quot;)= chr &amp;quot;geometry&amp;quot;
##  - attr(*, &amp;quot;agr&amp;quot;)= Factor w/ 3 levels &amp;quot;constant&amp;quot;,&amp;quot;aggregate&amp;quot;,..: NA
##   ..- attr(*, &amp;quot;names&amp;quot;)= chr &amp;quot;centrum&amp;quot;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Lo and behold - a &lt;code&gt;sf&lt;/code&gt; data frame with just two rows, one for center and one for the outskirts.&lt;/p&gt;
&lt;p&gt;And while it was not my original intention the &lt;em&gt;outskirts&lt;/em&gt; area is a single spatial object consisting of three separate polygons. Which I found rather neat.&lt;/p&gt;
</description>
  </item>
  
<item>
  <title>Parametrized R Markdown Reports</title>
  <link>https://www.jla-data.net/eng/parametrized-r-markdown-reports/</link>
  <pubDate>Wed, 10 Jan 2018 00:00:00 +0000</pubDate>
  
<guid>https://www.jla-data.net/eng/parametrized-r-markdown-reports/</guid>
  <description>


&lt;p&gt;Every business, no matter how big or small, simple or sophisticated, requires regular reports to run. R Studio, especially in its server flavor with option of cron jobs, is eminently capable of producing these. Parametrized reports are thus able to perform the role of a &lt;a href=&#34;https://en.wikipedia.org/wiki/Gateway_drug_theory&#34;&gt;gateway drug&lt;/a&gt; and wean the analytic team off their beloved Excel sheets.&lt;/p&gt;
&lt;p&gt;In fact, if I was looking for a single feature to convince a die hard Excel user to see the light and give up his VLOOKUP, I would stress out the &lt;em&gt;ease&lt;/em&gt; of regular reporting with parametrized reports. It might not be a fancy ML / AI technique that catches the headlines, but it is one of the small things which take the pain out of everyday chores.&lt;/p&gt;
&lt;p&gt;This example will demonstrate creating parametrized reports using the well known and much loved &lt;em&gt;Iris&lt;/em&gt; dataset.&lt;/p&gt;
&lt;p&gt;It will show:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;a &lt;em&gt;R Markdown&lt;/em&gt; template, with a single parameter &lt;code&gt;species&lt;/code&gt; defined&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;using &lt;code&gt;knitr::kable&lt;/code&gt; function and the &lt;code&gt;kableExtra&lt;/code&gt; package to build a simple table with a calculated summary row and some basic formatting&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;a master &lt;em&gt;R&lt;/em&gt; script, calling &lt;code&gt;rmarkdown::render&lt;/code&gt; on the template to build the reports, iterating value of the parameter &lt;code&gt;species&lt;/code&gt; over unique values of species from the Iris dataset&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The R markdown template in its easiest part needs just two parts:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;YAML header&lt;/li&gt;
&lt;li&gt;a single R chunk&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;---
title: &amp;quot;Iris *`r params$species`* are rather cute...&amp;quot; # a report looks better with the title set
params:  # this is the parameter declaration
  species: &amp;quot;setosa&amp;quot; # default value, overrriden by the render function, but helpful for debugging
output:
  pdf_document:
    latex_engine: pdflatex
header-includes:
- \usepackage{booktabs}
- \usepackage{longtable}
- \usepackage{array}
- \usepackage{multirow}
- \usepackage[table]{xcolor}
- \usepackage{wrapfig}
- \usepackage{float}
- \usepackage{colortbl}
- \usepackage{pdflscape}
- \usepackage{tabu}
- \usepackage{threeparttable}
- \usepackage[normalem]{ulem}
---&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The YAML header needs to include declaration of the parameters (indentation is, as is often the case with YAML, crucial). Including a default value is optional, but helpful in debugging.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;header-includes&lt;/code&gt; option loads LaTeX macros necessary for table formatting; this list, &lt;a href=&#34;http://haozhu233.github.io/kableExtra/awesome_table_in_pdf.pdf&#34;&gt;helpfuly provided by&lt;/a&gt; Hao Zhu (the author of &lt;code&gt;kableExtra&lt;/code&gt; package) should keep the dreaded LaTeX error “environment &lt;em&gt;xyz&lt;/em&gt; undefined” at bay.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;library(tidyverse)
library(knitr)
library(kableExtra)

src &amp;lt;- iris %&amp;gt;% # here you would normally load a file or connect to a database...
  filter(Species == params$species) %&amp;gt;%
  mutate(Species = as.character(Species)) %&amp;gt;% # factor would be a problem for summary row
  select(Species, Sepal.Length) %&amp;gt;% # just two columns for the sake of clarity...
  slice(1:5) # first five rows only, so that page space is not an issue

src &amp;lt;- rbind(src, # add summary row 
             c(&amp;quot;Grand total&amp;quot;, sum(src$Sepal.Length)))

kable(src,
      format = &amp;#39;latex&amp;#39;,
      booktabs = T,
      align = c(&amp;#39;l&amp;#39;,&amp;#39;r&amp;#39;)) %&amp;gt;%
      row_spec(nrow(src), bold = T) # make the last (summary) row bold&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The body chunk needs to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;declare your libraries (note that &lt;code&gt;knitr&lt;/code&gt;, where &lt;code&gt;kable&lt;/code&gt; lives, is not a formal part of tidyverse - it is ‘just’ suggested - and needs to be loaded separately)&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;load your data (I have cheated a little, and used a pre-loaded Iris dataset) and&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;peform necessary filtering / aggregating&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Note how &lt;code&gt;params$species&lt;/code&gt; is applied as filter condition, and how the summary row is created by binding a new row to the filtered dataset.&lt;/p&gt;
&lt;p&gt;The master script needs to do two things:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;construct a vector of unique Iris species, each of which will be passed as a parameter the &lt;code&gt;render&lt;/code&gt; function to generate a report&lt;/li&gt;
&lt;li&gt;call the &lt;code&gt;render&lt;/code&gt; function from &lt;code&gt;rmarkdown&lt;/code&gt; package, with a list of parameters as required by the template. In this simple case just a sigle parameter ‘species’.&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;library(rmarkdown)

flowers &amp;lt;- unique(iris$Species) # setosa, versicolor, virginica - you know them all, don&amp;#39;t you?

for (i in seq_along(flowers)) {
  myIris &amp;lt;- flowers[i]  # my species - to be reused as 1) parameter &amp;amp; 2) file name
  render(&amp;quot;report-template.Rmd&amp;quot;, # the template
          params = list(species = myIris), # value of myIris passed to the species parameter
          output_file = paste(myIris, &amp;#39;.pdf&amp;#39;, sep = &amp;#39;&amp;#39;), # name of the output file - species name and pdf extension
          quiet = T,
          encoding = &amp;#39;UTF-8&amp;#39;)
}&lt;/code&gt;&lt;/pre&gt;
When you put it all together and source the master script you should end up with three pdf files like this:
&lt;p align=&#34;center&#34;&gt;
&lt;img src=&#34;https://www.jla-data.net/img/2018-01-10-iris-screenshot.png&#34; /&gt;
&lt;/p&gt;
&lt;p&gt;You can download a working example of both the &lt;a href=&#34;https://www.jla-data.net/sample/par-temp.Rmd&#34;&gt;markdown document&lt;/a&gt; and &lt;a href=&#34;https://www.jla-data.net/sample/par-master.R&#34;&gt;master script&lt;/a&gt; directly from my pages.&lt;/p&gt;
&lt;p&gt;As a next step I recommend learning more about the &lt;a href=&#34;https://cran.r-project.org/web/packages/cronR/cronR.pdf&#34;&gt;cronR&lt;/a&gt; package - when teamed with the parametric report functionality you get a report that makes itself; an business analyst dream!&lt;/p&gt;
</description>
  </item>
  
<item>
  <title>Custom Icons in tmap</title>
  <link>https://www.jla-data.net/eng/custom-icons-in-tmap/</link>
  <pubDate>Sat, 11 Nov 2017 00:00:00 +0000</pubDate>
  
<guid>https://www.jla-data.net/eng/custom-icons-in-tmap/</guid>
  <description>


&lt;p&gt;I am a great fan of &lt;a href=&#34;https://github.com/mtennekes/tmap&#34;&gt;package tmap&lt;/a&gt; for visualizing spatial data in R. One less known, but very interesting and useful, feature of the package is the option to add custom icons on map.&lt;/p&gt;
&lt;p&gt;This has obvious implications for showing points of interest - such as placing a corporate logo to mark branches or other places of physical presence.&lt;/p&gt;
&lt;p&gt;In this example I will be combining the powers of &lt;code&gt;tmap&lt;/code&gt; package and Google, or rather package &lt;code&gt;ggmap&lt;/code&gt; (which uses Google Maps Geocoding API as a backend for its &lt;code&gt;geocode()&lt;/code&gt; function). In a sort of Halloween spirit I will be placing an image of a bat to mark a set of semi-random locations in Prague.&lt;/p&gt;
&lt;p&gt;To make the map prettier and easier to read I am including the shape of river Vltava and a distance marker.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://www.jla-data.net/post/2017-11-11-custom-icons-in-tmap_files/figure-html/haunted-1.png&#34; width=&#34;672&#34; /&gt;&lt;/p&gt;
&lt;p&gt;The custom icon is defined by calling &lt;code&gt;tmap_icons()&lt;/code&gt; with the file name of the bat icon (in this case local, but it could be an url linking to an image on internet as well). It is then passed to the shape argument of the &lt;code&gt;tm_symbols()&lt;/code&gt; call.&lt;/p&gt;
&lt;p&gt;On a side note: I was pleasantly surprised by the robustness of Google geocoding API. It is able to (correctly) geocode not only well defined street names, but also rather broadly defined points of interest.&lt;/p&gt;
&lt;p&gt;The full code to generate the map:&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;library(sf)
library(tidyverse)
library(ggmap)
library(RCzechia)
library(tmap)

cityMap &amp;lt;- obce_polygony[obce_polygony$NAZ_OBEC == &amp;#39;Praha&amp;#39;, ] # Prague city borders

bbox &amp;lt;- st_bbox(cityMap) %&amp;gt;%
  st_as_sfc() # out with the old, in with the sf!
  
vltava &amp;lt;- reky[reky$NAZEV == &amp;#39;Vltava&amp;#39;, ] # The city looks better with its river drawn
vltava &amp;lt;- st_intersection(vltava, bbox) # just the part flowing through the city


mista &amp;lt;- c(&amp;#39;úřad městské části praha 11&amp;#39;, &amp;#39;kramářova vila&amp;#39;, &amp;#39;Babická 2329, Praha 4&amp;#39;) 
# a vector of names of POIs to be vizualized

POI &amp;lt;- geocode(mista, output = &amp;quot;latlon&amp;quot;) %&amp;gt;% # let Google sweat!
 st_as_sf(coords = c(&amp;quot;lon&amp;quot;, &amp;quot;lat&amp;quot;), crs = 4326) # make the points of interest feel spatial!

icon &amp;lt;- tmap_icons(&amp;#39;2017-11-11-netopejr.png&amp;#39;)
# png file of the icon to be drawn; can be local or remote (url)

tm_plot &amp;lt;- tm_shape(cityMap, height = 1.3, relative = T) + tm_borders(&amp;quot;grey30&amp;quot;, lwd = 1.5, lty = &amp;#39;dotdash&amp;#39;) +
  tm_shape(vltava) + tm_lines(col = &amp;#39;steelblue&amp;#39;, lwd = 2.5) +
  tm_shape(POI) + tm_symbols(shape = icon, size = 0.7, border.lwd = NA) +
  tm_style_white(&amp;quot;Prague Haunted Places&amp;quot;, frame = F, fontfamily = &amp;quot;Roboto&amp;quot;, title.size = 2) +
  tm_scale_bar(color.dark = &amp;quot;grey30&amp;quot;)

print(tm_plot)&lt;/code&gt;&lt;/pre&gt;
</description>
  </item>
  
<item>
  <title>Legend in tmap Package</title>
  <link>https://www.jla-data.net/eng/tmap-legend/</link>
  <pubDate>Wed, 20 Sep 2017 00:00:00 +0000</pubDate>
  
<guid>https://www.jla-data.net/eng/tmap-legend/</guid>
  <description>


&lt;p&gt;I am a great fan of the &lt;code&gt;tmap&lt;/code&gt; package by Martijn Tennekes. It is a very versatile package, and my favorite tool for visualization of geospatial data. The package is, by necessity, somewhat complex and some clever and very useful features were not obvious (to me) at the first glance.&lt;/p&gt;
&lt;p&gt;This includes advanced formatting of legend. I would therefore like to share some tips and tricks I wish I had learned the easy way by googling, and not the hard way by trial and error.&lt;/p&gt;
&lt;div id=&#34;hiding-not-applicable-values&#34; class=&#34;section level2&#34;&gt;
&lt;h2&gt;Hiding not applicable values&lt;/h2&gt;
&lt;p&gt;On some occasions it is desirable to hide N/A values. For example when drawing polygons for metro areas and leaving the rural areas blank (but still displayed for context). This is achieved by using &lt;code&gt;showNA = F&lt;/code&gt; parameter of the &lt;code&gt;tm_fill&lt;/code&gt; call.&lt;/p&gt;
&lt;/div&gt;
&lt;div id=&#34;showing-special-format-for-not-applicable-values&#34; class=&#34;section level2&#34;&gt;
&lt;h2&gt;Showing special format for not applicable values&lt;/h2&gt;
&lt;p&gt;On some occasions it is desirable to display the N/A values with a special label. For example when drawing polygons for administrative areas, and explaining in the legend why some are intentionally left blank - I have used this when drawing military training grounds (areas of special administrative status). This is achieved by using &lt;code&gt;textNA = &amp;quot;special&amp;quot;&lt;/code&gt; parameter of the &lt;code&gt;tm_fill&lt;/code&gt; call.&lt;/p&gt;
&lt;/div&gt;
&lt;div id=&#34;advanced-formatting-of-legend-intervals&#34; class=&#34;section level2&#34;&gt;
&lt;h2&gt;Advanced formatting of legend (intervals)&lt;/h2&gt;
&lt;p&gt;On some occasions it is desirable to avoid the default separator “to” in intervals. For example when drawing plots that are labeled in a different language than English. This is achieved by using the &lt;code&gt;legend.format =  list(text.separator=  &amp;quot;-&amp;quot;)&lt;/code&gt; parameter of the &lt;code&gt;tm_style&lt;/code&gt; call. The dash is my favorite text separator by far - it is not language specific.&lt;/p&gt;
&lt;/div&gt;
&lt;div id=&#34;advanced-formatting-of-legend-currency-and-percentages&#34; class=&#34;section level2&#34;&gt;
&lt;h2&gt;Advanced formatting of legend (currency and percentages)&lt;/h2&gt;
&lt;p&gt;On some occasions it is desirable to display the values of legend in special format: as currency, or as percentages.&lt;/p&gt;
&lt;p&gt;This is achieved by using &lt;code&gt;fun&lt;/code&gt; argument of the &lt;code&gt;legend.format&lt;/code&gt; parameter of the &lt;code&gt;tm_fill&lt;/code&gt; call. For example &lt;code&gt;legend.format = list(fun = function(x) paste0(formatC(x, digits = 0, format = &amp;quot;f&amp;quot;), &amp;quot; Kč&amp;quot;)))&lt;/code&gt; will truncate the legend items to zero decimal places and apply “Kč” (i.e. Czech Crowns) as currency symbol.&lt;/p&gt;
&lt;p&gt;Using percentage sign is analogic to currency symbol; the only trick is to remember to multiply the value by 100 at exactly one place (either in raw data, or when displaying legend).&lt;br /&gt;
This call from &lt;code&gt;tm_fill&lt;/code&gt; assumes that data has been multiplied at source &lt;code&gt;legend.format=list(fun=function(x) paste0(formatC(x, digits=0, format=&amp;quot;f&amp;quot;), &amp;quot; %&amp;quot;))&lt;/code&gt;.&lt;/p&gt;
&lt;/div&gt;
</description>
  </item>
  
<item>
  <title>Czech Oil Price</title>
  <link>https://www.jla-data.net/eng/czech-oil-price/</link>
  <pubDate>Fri, 15 Sep 2017 00:00:00 +0000</pubDate>
  
<guid>https://www.jla-data.net/eng/czech-oil-price/</guid>
  <description>


&lt;p&gt;&lt;img src=&#34;https://www.jla-data.net/post/2017-09-15-czech-oil-price_files/figure-html/dataviz-1.png&#34; width=&#34;672&#34; /&gt;&lt;/p&gt;
&lt;p&gt;In the Czech Republic it is common knowledge that the price of oil is the highest on the &lt;a href=&#34;https://en.wikipedia.org/wiki/D1_motorway_(Czech_Republic)&#34;&gt;D1 highway&lt;/a&gt;, connecting Prague to Brno (the #1 and #2 Czech cities).&lt;/p&gt;
&lt;p&gt;But as the saying goes &lt;em&gt;in God we trust, all others bring data&lt;/em&gt;, and so I decided to test the common knowledge against real data. After all the “common knowledge” is commonly known to be fallible.&lt;/p&gt;
&lt;p&gt;It turned out to be a project involving (chiefly) three packages:&lt;br /&gt;
- scraping of internet pages via &lt;code&gt;rvest&lt;/code&gt;&lt;br /&gt;
- data vizualization via &lt;code&gt;tmap&lt;/code&gt;&lt;br /&gt;
- shapefile of Czech Republic via &lt;code&gt;RCzechia&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;I obtained the average price of unleaded gasoline in 653 Czech towns (out of the 6 258 total recognized municipalities) by scraping web pages of &lt;a href=&#34;http://regiony.impuls.cz/benzin.aspx&#34;&gt;Rádio Impulz&lt;/a&gt;. The data is current to 19.01.2018.&lt;/p&gt;
&lt;p&gt;At the end the common knowledge turned to be rather accurate, and the shape of D1 highway connecting Prague and Brno pretty much jumps out of the plot.&lt;/p&gt;
&lt;p&gt;What I did not expect, but what the data shows beyond doubt, is that the price of gasoline on &lt;a href=&#34;https://en.wikipedia.org/wiki/D5_motorway_(Czech_Republic)&#34;&gt;D5 highway&lt;/a&gt;, going from Prague westwards to Pilsen and on to Munich, gives a fair fight to the infamous D1.&lt;/p&gt;
&lt;p&gt;The code to generate the map is following:&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;# Initialization ----
library(rvest)
library(tmap)
library(tmaptools)
library(raster)
library(RCzechia) # set of shapefiles for the Czech Republic - devtools::install_github(&amp;quot;jlacko/RCzechia&amp;quot;)
library(stringr)
library(dplyr)
library(RColorBrewer)

url &amp;lt;- &amp;quot;http://benzin.impuls.cz/benzin.aspx?strana=&amp;quot; # url without page no.
frmBenzin &amp;lt;- data.frame() # empty data frame for data

bbox &amp;lt;- extent(republika) # a little more space around - enough for title and legend
bbox@ymax &amp;lt;- bbox@ymax + 0.35
bbox@ymin &amp;lt;- bbox@ymin - 0.15

# Scraping data ----

for (i in 1:56) { # Scrape data, translate and append to results
  
  impuls &amp;lt;- read_html(paste(url, i, sep = &amp;#39;&amp;#39;), encoding = &amp;quot;windows-1250&amp;quot;)
  asdf &amp;lt;- impuls %&amp;gt;%
    html_table()
  
  frmBenzin &amp;lt;- rbind(frmBenzin, asdf[[1]])
}

# Cleaning data ----

frmBenzin$X1 &amp;lt;- NULL
colnames(frmBenzin) &amp;lt;- c(&amp;quot;nazev&amp;quot;, &amp;quot;obec&amp;quot;, &amp;quot;okres&amp;quot;,&amp;quot;smes&amp;quot;, &amp;quot;datum&amp;quot;, &amp;quot;cena&amp;quot;)
frmBenzin$cena &amp;lt;- gsub(&amp;quot;(*UCP)\\s*Kč&amp;quot;, &amp;quot;&amp;quot;, frmBenzin$cena, perl = T) # regex is tricky - perl is safer
frmBenzin$cena &amp;lt;- as.double(frmBenzin$cena)
frmBenzin$datum &amp;lt;- as.Date(frmBenzin$datum, &amp;quot;%d. %m. %Y&amp;quot;)
frmBenzin$okres &amp;lt;- gsub(&amp;quot;Hlavní město\\s&amp;quot;,&amp;quot;&amp;quot;,frmBenzin$okres)
frmBenzin$obec &amp;lt;- str_split(frmBenzin$obec, &amp;quot;,&amp;quot;, simplify = T)[,1]
frmBenzin$key &amp;lt;- paste(frmBenzin$obec, frmBenzin$okres, sep = &amp;quot;/&amp;quot;)

# Data wrangling ----

frmBenzinKey &amp;lt;- frmBenzin %&amp;gt;%
  select(key, cena, smes) %&amp;gt;%
  filter(smes == &amp;quot;natural95&amp;quot;) %&amp;gt;% # only gasoline - no diesel
  group_by(key) %&amp;gt;%
  summarise(cena = mean(cena)) # average price in town

obce &amp;lt;- obce_body # from package RCzechia
  
obce$key &amp;lt;- paste(obce$Obec, obce$Okres, sep = &amp;quot;/&amp;quot;) # shapefile: preparing a key to bind on
vObce &amp;lt;- c(&amp;quot;Praha&amp;quot;, &amp;quot;Brno&amp;quot;, &amp;quot;Plzeň&amp;quot;, &amp;quot;Ostrava&amp;quot;) # big cities - these will be displayed as a polygon, not a point

obce &amp;lt;- obce %&amp;gt;%
  append_data(frmBenzinKey, key.shp = &amp;quot;key&amp;quot;, key.data = &amp;quot;key&amp;quot;) # binding by key

obce &amp;lt;- subset(obce, !is.na(obce$cena)) # throwing out towns with no known oil price
obce &amp;lt;- subset(obce, !obce$Obec %in% vObce) # throwing out the big cities

wrkObce &amp;lt;- obce_polygony[obce_polygony$Obec %in% vObce, ] 

# Vizualization at last... ----

nadpis &amp;lt;- &amp;quot;Oil price in the Czech Republic&amp;quot; # Chart title
leyenda &amp;lt;- &amp;quot;Natural 95&amp;quot;  # Legend title

tmBenzin &amp;lt;- tm_shape(obce, bbox = bbox) + tm_bubbles(size = 1/15, col = &amp;quot;cena&amp;quot;, alpha = 0.85, border.alpha = 0, showNA = F, pal = &amp;quot;YlOrRd&amp;quot;, title.col = leyenda) +
  tm_shape(republika, bbox = bbox) + tm_borders(&amp;quot;grey30&amp;quot;, lwd = 1) +
  tm_shape(wrkObce) + tm_borders(&amp;quot;grey30&amp;quot;, lwd = 0.5) +
  tm_legend(position = c(&amp;quot;RIGHT&amp;quot;, &amp;quot;top&amp;quot;)) +
  tm_style_white(nadpis, frame = F, fontfamily = &amp;quot;Roboto&amp;quot;, title.size = 2, legend.text.size = 0.6, legend.title.size = 1.2, legend.format = list(text.separator = &amp;quot;-&amp;quot;, fun = function(x) paste0(formatC(x, digits = 0, format = &amp;quot;f&amp;quot;), &amp;quot; Kč&amp;quot;)))

print(tmBenzin)&lt;/code&gt;&lt;/pre&gt;
</description>
  </item>
  
</channel>
  </rss>