My Blog List

Friday, March 30, 2018

Creating Dot Density Map with Tableau

Mapping population density

I have always been impressed with night satellite photos. Such images were almost precise representation of habitats; where people live (light) and where they don’t (dark).
nightLightsTeaser.jpg

So the question I asked myself is: Can I create something realistic like the picture above using Tableau?

Population density maps have been an interesting topic for many data scientists and enthusiasts for a long time. Software packages like ArcGIS provide custom solutions to mapping population density. However, they often use techniques like heat maps, choropleth map, and similar where specific area would be color based on the population density. Only top professional GIS tools like ArcGIS allow for dot density mapping.

BIH popluation density map 2013.png


I personally did not like these type of maps, since the color scales tend to provide too broad and imprecise imagery of the population density.
In other words, can we create a dot density layer without using professional GIS tools like ArcMAP. It turns out that with some proper data manipulation, a little bit of math and basic Tableau skills we can come pretty close. Here is how to do it.

Challenge


Is it possible to create a dot density map of Bosnia and Herzegovina using Tableau?

Initial steps


For this project we need following software: Excel, MSSQL, and Tableau Desktop.

Data, data and data.

The key to any data science project is good data. Population data for Bosnia and Herzegovina is available from the 1991 and 2013 censuses.

The census provides the following data:
  1. COUNTY_NAM: Name of the municipality
  2. PLACE: ID
  3. NAME: Name of the settlement
  4. TOTAL: Total number of people in that settlement
  5. LATITUDE and LONGITUDE: values for latitude and longitude

In the case of Bosnia and Herzegovina, the census and geocoded data were in two separate data sources, but once they were merged, the final outcome looked as below

Generating lights


The basic idea was to generate points that would simulate lights in a single settlement. When this is done for the entire region, it resembles a night satellite photo. From a single settlement record which has population size of a 100, we would generate a 100 random points around that geographic area.

There is a number of proposed algorithms on how to do this, but I liked this one. Also, there are some other language specific solutions in JAVA and SQL. With the help of my colleague Mladen, we created SQL script files.

So for every settlement record with N inhabitants, the script generated N records, with latitude and longitude in the approximate radius of 8km (5 miles) from the original records.



The picture above shows that we got 327 records for this particular settlement (latitude: 44,0655; longitude: 19,54385). What you see below is the result of the transformation of the original record above.


Loading data into Tabelau



Once this transformation is done, you can remove all extra fields and keep only latitude and longitude. Tableau allows you to import SQL database and work with records as you can see in the picture below.


After you’ve selected the table you want to use, the data from Tableau will display the first 1000 rows to verify and further transform the data.


The next step is to open a new worksheet and connect the selected table.

Tableau will automatically recognize the latitude and longitude fields as geographic points, however, if this doesn't happen during loading, you can manually change it.


Once this is completed, drag and drop longitude into columns and latitude into rows. Then select minimum size of the points that are generated.

Click on Map / Map Layers, and under Background select Dark Style. The final result should look something like this:


Conclusion

This map is more factual, real in terms of population density and clearly shows where people actually live (light) and where they do not live (dark) according to the 1991 Bosnia and Herzegovina Census.

From the basic settlements record, we started with geocoding settlements, generating random points around each settlement in order to mimic population location up to the final representation of the map in Tableau.

In retrospect

In this dot density map I didn’t generate random points for each person, but rather did one for every 100th person. This reduced the number of points that Tableau should visualize. Depending on your time, machine and result you want, you can play with the size of the records.

The second issue is the size of the geographic location where points are distributed. Clearly if a settlement record counts more than 100 000 (in my case one municipality had over 100 000 inhabitants), population density is not the same as for the settlement with 10 000 inhabitants. Default population spread value was around 8 km (5 miles) in radius but one can play and have different sizes depending on the size of the settlement.

The best results would be if we had information not on the settlement level that sometimes can have tens of thousands of inhabitants, but on the local community (part of the municipality; 4th admin level in most countries) level that would provide more granular data set and thus map more accurate. However, in my case I did not have such data.

Additionally, to make density dot map more informative, you can add another layer of inhabitants category (income level, race, education etc).

A challenge for you
I used the 1991 census data, can you create a dot density map for Bosnia and Herzegovina based on the 2013 census? We’d love to hear from you!

Also, use the same technique to map biodiversity of animals and plants.





 

PROBLEM JAVNOG PRIJEVOZA U SARAJEVU

Fuad Ćurčić i Denis Silajdžić
Slika preuzeta od Oleg Vishnepolsky
U prijevodu “Razvijena zemlja nije gdje siromašni imaju auta, nego gdje bogati koriste javni prijevoz.”
Problem javnog transporta u Sarajevu, poslovanja GRASA, broja parking mjesta u gradu su teme koje gotovo svakodnevno okupiraju sarajlije. Svako navodi svoje razloge i mišljenja, od korumpiranog menadžmenta, nesposobne vlade, parking papaka, itd. Prava istina je ...
Krenimo redom po problemima koji su usko povezani.
GRAS je u raspadu jer troškovi firme prevazilaze prihode. Ne ulazeći u rasprave oko efikasnosti upravljanja ovim preduzećem (koje sigurno mora biti bolje), jasno je da broj putnika koji plaćaju kartu nije dovoljan da sistem bude samoodrživ.
Javni transport u gradu koriste sam ljudi koji nemaju auto. Iskreno, ja se lično ne sjećam se kada sam zadnji put koristio javni gradski prijevoz. Danas u tramvajima vidimo samo jalijaše, penzionere i studente. Drugim riječima, javni prijevoz nije cool. Većina će prije uzeti taxi nego tramvaj.
Parking papak je rezultat predbodnog problema. Mahalske ulice trotoari u Starom Gradu su pune parkiranih auta, ljudi koji u stvari ne žele da plate parking.
U Sarajevu nema parkinga. U stvari znači u Sarajevu nema besplatnog parkinga. Svaka objektivna inspekcija parkinga preko puta Vijećnice, na čaršiji ili pored Markala jasno pokazuje da uvijek ima parking mjesta… po 3KM po satu. Realno, u sred Beča ili uz Tkalčićevu ćeš teško ili nikako naći parking, ali papak će radije parkirati uz Sebilj i svratiti brzinski na pitu.
Ljudi hodaju po ulici, a auta stoje po trotoarima. Naredni problem je opet bezbjednost i nesreće koje se dešavaju u gradu. UK važi za razvijenu zemlju koja ima najmanje nesreća u prometu po glavi stanovnika. Ne zbog dobrih vozača, policije i zakona nego što ljudi manje voze a više koriste javni prijevoz.
Smog u zimskom periodu. Svima je jasno da je broj auta jedan od glavnih krivaca za prekomjernu zagađenost koje samo vidimo u zimskom periodu. Više ljudi u tramvaju == > manje auta na cestama == > manja zagađenosti.
To je spisak problema. Kako dalje? Samo krenemo unazad.
Komunalna policija. Od viška GRASovih radnika, koji su tehnološki višak, formirati komunalnu policiju. Redovno pisanje kazni parking papcima će stvoriti tržišni pritisak da se koriste parking mjesta ili javni prijevoz. Ekonomskim riječnikom ovo će stvoriti potražnju za uslugama javnog prijevoza.
Forsirati žutu traku. Redovna policija treba da kažnjava vozila koja voze preko žute trake. Da li se iko sjeća da ona postoji, za šta služi? Ovo će rezultirati da će javni prijevoz ići brže u špici nego privatno auto. Treba li išta dalje objašnjavati?
Čak i taksiste treba pomjeriti sa žute trake, jer su oni više dio problema nego dio rješenja.
Urediti naplatu na stajalištima. Ograditi stajališta tako da imaju elektronske rampe za ulaz i izlaz. Ovo će smanjti potrebu za kondukterima i osigurati da 99% ljudi imaju kartu. Ovo se jednostavni može uraditi na svim stajalištima od Muzeja do Ilidže.
Kada put kroz grad bude spor i skup zbog parkinga ili kazne, većina će se odlučiti za alternativu javnog prijevoza. Tek onda treba...
Javni prijevoz učiniti popularnim. Treba urediti vozila, staviti kamere i besplatni internet. Danas su ovo trivijalni troškovi uključujući i aplikaciju za vrijeme kada stiže naredno vozilo. Političari prije svega trebaju da simbolično počnu da korite javni prijevoz svakodnevno.
Finansijka stabilnost. Kako veći broj ljudi koristi javni prijevoz, ulice će biti prohodnije, manje zagađene, manje nesreća, manje kredita za GRAS, što bi rekli win-win situacija. Zvuči naučna fantastika? Ovo je problem koji ima svaki grad u svijetu i oni hrabni su ga riješili na isti način - od Londona do Bogote sve je isti problem.
Bogota preuzeto sa bloga (znate li gdje je Bogota?)
Ovdje se ne predlaže ništa novo, nego samo se podjećamo kako stvari trebaju da budu.
Da li se slažete?