SlideShare uma empresa Scribd logo
1 de 26
Baixar para ler offline
transforming

publicdata

into

interactive
maps
São Paulo, July/2019
helderdarocha

helder@argonavis.com.br
PresentationdeliveredatTheDeveloper'sConference
2019,inSãoPaulo,Brazil(originallyinPortuguese)
Quem sou eu? Who am I? Кто я?
Helder da Rocha
argonavis.com.br
Tech * Science * Arts
HTML & Web technologies since 1995
Author of books and courses about

Java, XML and Web technologies
helderdarocha.art.br
This is a hands-on tutorial
• You will learn how to create an interactive thematic map using: HTML, CSS, JavaScript,
SVG, D3.js, CSV, GeoJSON (You should know HTML, CSS and some JavaScript)
• Main steps:
1. Get shapefile from naturalearthdata.com
2. Convert to GeoJSON with mapshaper.org and run script to filter data
3. Get data from open data portals: un.data.org and geonames.org
4. Generate strings for SVG paths using D3.js
5. Apply scales, colors, projections and interactive features
• Get code from: https://github.com/argonavisbr/tutorial-geojson
• Playground: JSFiddle (follow links in Readme.md)
• Slides only illustrate the main steps (run the examples and download the code!)
Shapefile: naturalearthdata.com
www.naturalearthdata.com/downloads/110m-cultural-vectors/
Convert to GeoJSON: mapshaper.org
ne_110m_admin_0_countries.json
ne_110m_admin_0_countries.zip
1
23
JSON
Alternatives: GIS ou GDALapps
$ ogr2ogr -f GeoJSON resultado.geojson ne_110m_admin_0_countries.json.shp
gdal.org
qgis.org
GeoJSON
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"id": "FJI",
"properties": {
"name": "Fiji"
},
"geometry": {
"type": "MultiPolygon",
"coordinates": [
[[ [180,-16.067132663642447],
...
[179.4135093629971,-16.379054277547404],
[180,-16.067132663642447] ]],
[[ ... ]], [[ ... ]]
]
}
},{
"type": "Feature",
...
}
},
...
]
}
"id"property
(optional)
"properties"property
(anycontent)
"geometry"property
(containsaGeoJSONtypesuchas:

"Polygon","Point","MultiPolygon")
Remove unnecessary properties
{
"type": "Feature",

"properties": {
"ISO_A3":"...",
"NAME":"...",
"ADMIN":"...",

...,

"MAPCOLOR7":"..."
},
"geometry": {...}
}
{
"type": "Feature",

"id":"...",

"properties": {
"name":"...",
},
"geometry": {...}
}
ForeachFeature:
GitHub:tools/filter-map.js
D3.js
<script src="https://d3js.org/d3.v5.min.js"></script>
<script>
d3.json('../geo/world.geojson')

.then(function(data) {

console.log(data.features);
});
</script>
{
"type": "FeatureCollection",
"features": [ ... ]
}
Step 1: Load GeoJSON
GitHub:tutorial/map-1.html
Step 2: List properties
GitHub:tutorial/map-2.html
const map = {};

d3.json('../geo/world.geojson')

.then(function(data) {

map.features = data.features;

draw();

});



function draw() {

const ol = d3.select("body").append("ol");

ol.selectAll("li")

.data(map.features)

.enter().append("li")

.text(d => d.properties.name +

" ("+ d.id + ")");

}
{ "type": "Feature",

"id":"...",

"properties": {
"name":"...",
},
"geometry": {...} }map.features[n]
Step 3: List object coordinates
GitHub:tutorial/map-3.html
const country =

map.features.filter(k => k.id === "BRA")[0];



const body = d3.select("body");

body.append("h1")

.text(country.properties.name);



body.append("ul").selectAll("li.coord")

.data(country.geometry.coordinates[0])

.enter()

.append("li").attr("class", "coord")

.text(d => "Lon: "+d[0]+", Lat: "+d[1]);
<html lang="en">
<head>
<style>
.poly {
stroke: black;
stroke-width: .05;
fill: yellow;
}
</style>
</head>
<body>
<svg height="500" width="960" viewBox="7 -13 14 28">
<path d="M-10,0 L-3,10 L10,7 L10,-7 L-3,-10 L-10,0" class="poly" />
</svg>
</body>
</html>
Step 4: SVG <path>
GitHub:tutorial/map-6a.html
Step 5: SVG <path> with D3
GitHub:tutorial/map-8.html
<svg height="500" width="960"></svg>


<script>

const svg = d3.select("svg");

const pathData = "M-10,0 L-3,10 L10,7 L10,-7 L-3,-10 Z";



svg.append("path").attr("class", "poly")

.attr("d", pathData);

</script>
Step 6: Generating a <path> with D3
GitHub:tutorial/map-9.html
const geoPath = d3.geoPath();



const map = {};

d3.json('../geo/world.geojson')

.then(function(data) {

map.features = data.features;

draw();

});



function draw() {

const country = map.features.filter(k => k.id === "BRA")[0];

const pathData = geoPath(country);

d3.select("svg").append("path")

.attr("d", pathData);

}
Step 7: Binding data to SVG DOM
GitHub:tutorial/map-10.html
const geoPath = d3.geoPath();

svg.selectAll("path")

.data(map.features)

.enter().append("path")

.attr("d", geoPath)
Eachfeatureboundtoa
<path>object
Step 8: Geographic projections
GitHub:tutorial/map-12.html
const geoPath = d3.geoPath();

const projection = d3.geoMercator(); //d3.geoOrthographic(), d3.geoMollweide()...

geoPath.projection(projection);
d3.geoMercator()
Coordinates for cities: geonames.org
geonameid;asciiname;latitude;longitude;population;timezone

3040051;les Escaldes;42.50729;1.53414;15853;Europe/Andorra

3041563;Andorra la Vella;42.50779;1.52109;20430;Europe/Andorra

290594;Umm al Qaywayn;25.56473;55.55517;44411;Asia/Dubai

291074;Ras al-Khaimah;25.78953;55.9432;115949;Asia/Dubai

291696;Khawr Fakkan;25.33132;56.34199;33575;Asia/Dubai

292223;Dubai;25.0657;55.17128;1137347;Asia/Dubai

292231;Dibba Al-Fujairah;25.59246;56.26176;30000;Asia/Dubai

292239;Dibba Al-Hisn;25.61955;56.27291;26395;Asia/Dubai

292672;Sharjah;25.33737;55.41206;543733;Asia/Dubai

292688;Ar Ruways;24.11028;52.73056;16000;Asia/Dubai

292878;Al Fujayrah;25.11641;56.34141;62415;Asia/Dubai

292913;Al Ain;24.19167;55.76056;408733;Asia/Dubai
GitHub:csv/cities15000.csv
(23505places)
Step 9: Thematic data: cities
GitHub:tutorial/map-15.html
Promise.all([

d3.json('../geo/world.geojson'),

d3.dsv(';', '../csv/cities15000.csv',
function(row) {

return {

name: row.asciiname,

coords: [+row.longitude, +row.latitude]

}

})

]).then(function([shapes, points]) {

map.features = shapes.features;

map.points = points;

draw();

});
svg.selectAll("circle.city")

.data(map.points)

.enter()

.append("circle").attr("class", "city")

.attr("cx", d => projection(d.coords)[0])

.attr("cy", d => projection(d.coords)[1])

.attr("r", d => 1)
Passo 10: Interactivity
GitHub:tutorial/map-19.html
Summary
• D3.js is a powerful library containing a set of tools for data
visualization based on openstandards
• Used by large news portals (NY Times, The Guardian, etc.) in
stunning visualizations and interactive maps. It's also used in
higher-level datavis frameworks, tools and services.
• This tutorial demonstrates how D3 can be used to create
thematicmaps using opendata: an essential skill in data
journalism
Slides, +source-code +demonstrations
github.com/argonavisbr/tutorial-geojson
www.argonavis.com.br/download/
tdc_2019_js.html (pt-BR and en-US)
July/2019
helder da rocha
helder@argonavis.com.br
www.amazon.com/dp/B07PDBBHLLwww.amazon.com/dp/B07RFBV4PC
PresentationdeliveredatTheDeveloper'sConference
2019,inSãoPaulo,Brazil(originallyinPortuguese)

Mais conteúdo relacionado

Mais procurados

Introduction to data visualisations with d3.js — Data Driven Documents
Introduction to data visualisations with d3.js — Data Driven DocumentsIntroduction to data visualisations with d3.js — Data Driven Documents
Introduction to data visualisations with d3.js — Data Driven DocumentsMichał Oniszczuk
 
How to build a html5 websites.v1
How to build a html5 websites.v1How to build a html5 websites.v1
How to build a html5 websites.v1Bitla Software
 
Mongodb Aggregation Pipeline
Mongodb Aggregation PipelineMongodb Aggregation Pipeline
Mongodb Aggregation Pipelinezahid-mian
 
Stylish visualisations with D3.js (OdessaJS)
Stylish visualisations with D3.js (OdessaJS)Stylish visualisations with D3.js (OdessaJS)
Stylish visualisations with D3.js (OdessaJS)Kseniya Redunova
 
Visualization of Big Data in Web Apps
Visualization of Big Data in Web AppsVisualization of Big Data in Web Apps
Visualization of Big Data in Web AppsEPAM
 
Introduction to HTML5 Canvas
Introduction to HTML5 CanvasIntroduction to HTML5 Canvas
Introduction to HTML5 CanvasMindy McAdams
 

Mais procurados (7)

Introduction to data visualisations with d3.js — Data Driven Documents
Introduction to data visualisations with d3.js — Data Driven DocumentsIntroduction to data visualisations with d3.js — Data Driven Documents
Introduction to data visualisations with d3.js — Data Driven Documents
 
How to build a html5 websites.v1
How to build a html5 websites.v1How to build a html5 websites.v1
How to build a html5 websites.v1
 
Pycon2011
Pycon2011Pycon2011
Pycon2011
 
Mongodb Aggregation Pipeline
Mongodb Aggregation PipelineMongodb Aggregation Pipeline
Mongodb Aggregation Pipeline
 
Stylish visualisations with D3.js (OdessaJS)
Stylish visualisations with D3.js (OdessaJS)Stylish visualisations with D3.js (OdessaJS)
Stylish visualisations with D3.js (OdessaJS)
 
Visualization of Big Data in Web Apps
Visualization of Big Data in Web AppsVisualization of Big Data in Web Apps
Visualization of Big Data in Web Apps
 
Introduction to HTML5 Canvas
Introduction to HTML5 CanvasIntroduction to HTML5 Canvas
Introduction to HTML5 Canvas
 

Semelhante a Transforming public data into thematic maps (TDC2019 presentation)

SVCC 2013 D3.js Presentation (10/05/2013)
SVCC 2013 D3.js Presentation (10/05/2013)SVCC 2013 D3.js Presentation (10/05/2013)
SVCC 2013 D3.js Presentation (10/05/2013)Oswald Campesato
 
D3 Mapping Visualization
D3 Mapping VisualizationD3 Mapping Visualization
D3 Mapping VisualizationSudhir Chowbina
 
Visual Exploration of Large Data sets with D3, crossfilter and dc.js
Visual Exploration of Large Data sets with D3, crossfilter and dc.jsVisual Exploration of Large Data sets with D3, crossfilter and dc.js
Visual Exploration of Large Data sets with D3, crossfilter and dc.jsFlorian Georg
 
Mongo db washington dc 2014
Mongo db washington dc 2014Mongo db washington dc 2014
Mongo db washington dc 2014ikanow
 
Create Graph and Grid Using D3 Library
Create Graph and Grid Using D3 LibraryCreate Graph and Grid Using D3 Library
Create Graph and Grid Using D3 LibraryYanliang Bao (Beryl)
 
Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)Remy Sharp
 
Is html5-ready-workshop-110727181512-phpapp02
Is html5-ready-workshop-110727181512-phpapp02Is html5-ready-workshop-110727181512-phpapp02
Is html5-ready-workshop-110727181512-phpapp02PL dream
 
Html5 and web technology update
Html5 and web technology updateHtml5 and web technology update
Html5 and web technology updateDoug Domeny
 
Dynamic Data Visualization With Chartkick
Dynamic Data Visualization With ChartkickDynamic Data Visualization With Chartkick
Dynamic Data Visualization With ChartkickDax Murray
 
Introduction to d3js (and SVG)
Introduction to d3js (and SVG)Introduction to d3js (and SVG)
Introduction to d3js (and SVG)zahid-mian
 
HTML5 after the hype - JFokus2015
HTML5 after the hype - JFokus2015HTML5 after the hype - JFokus2015
HTML5 after the hype - JFokus2015Christian Heilmann
 
PhDigital 2020: Web Development
PhDigital 2020: Web DevelopmentPhDigital 2020: Web Development
PhDigital 2020: Web DevelopmentCindy Royal
 
Building Rich Internet Applications with HTML5 and WebGL
Building Rich Internet Applications with HTML5 and WebGLBuilding Rich Internet Applications with HTML5 and WebGL
Building Rich Internet Applications with HTML5 and WebGLTony Parisi
 
The things browsers can do! SAE Alumni Convention 2014
The things browsers can do! SAE Alumni Convention 2014The things browsers can do! SAE Alumni Convention 2014
The things browsers can do! SAE Alumni Convention 2014Christian Heilmann
 
Implementing Awesome: An HTML5/CSS3 Workshop
Implementing Awesome: An HTML5/CSS3 WorkshopImplementing Awesome: An HTML5/CSS3 Workshop
Implementing Awesome: An HTML5/CSS3 WorkshopShoshi Roberts
 

Semelhante a Transforming public data into thematic maps (TDC2019 presentation) (20)

D3.js and SVG
D3.js and SVGD3.js and SVG
D3.js and SVG
 
Svcc 2013-d3
Svcc 2013-d3Svcc 2013-d3
Svcc 2013-d3
 
SVCC 2013 D3.js Presentation (10/05/2013)
SVCC 2013 D3.js Presentation (10/05/2013)SVCC 2013 D3.js Presentation (10/05/2013)
SVCC 2013 D3.js Presentation (10/05/2013)
 
D3 Mapping Visualization
D3 Mapping VisualizationD3 Mapping Visualization
D3 Mapping Visualization
 
Visual Exploration of Large Data sets with D3, crossfilter and dc.js
Visual Exploration of Large Data sets with D3, crossfilter and dc.jsVisual Exploration of Large Data sets with D3, crossfilter and dc.js
Visual Exploration of Large Data sets with D3, crossfilter and dc.js
 
Mongo db washington dc 2014
Mongo db washington dc 2014Mongo db washington dc 2014
Mongo db washington dc 2014
 
Create Graph and Grid Using D3 Library
Create Graph and Grid Using D3 LibraryCreate Graph and Grid Using D3 Library
Create Graph and Grid Using D3 Library
 
D3
D3D3
D3
 
Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)
 
Is html5-ready-workshop-110727181512-phpapp02
Is html5-ready-workshop-110727181512-phpapp02Is html5-ready-workshop-110727181512-phpapp02
Is html5-ready-workshop-110727181512-phpapp02
 
Html5 and web technology update
Html5 and web technology updateHtml5 and web technology update
Html5 and web technology update
 
Dynamic Data Visualization With Chartkick
Dynamic Data Visualization With ChartkickDynamic Data Visualization With Chartkick
Dynamic Data Visualization With Chartkick
 
Introduction to d3js (and SVG)
Introduction to d3js (and SVG)Introduction to d3js (and SVG)
Introduction to d3js (and SVG)
 
D3 data visualization
D3 data visualizationD3 data visualization
D3 data visualization
 
HTML5 after the hype - JFokus2015
HTML5 after the hype - JFokus2015HTML5 after the hype - JFokus2015
HTML5 after the hype - JFokus2015
 
PhDigital 2020: Web Development
PhDigital 2020: Web DevelopmentPhDigital 2020: Web Development
PhDigital 2020: Web Development
 
Building Rich Internet Applications with HTML5 and WebGL
Building Rich Internet Applications with HTML5 and WebGLBuilding Rich Internet Applications with HTML5 and WebGL
Building Rich Internet Applications with HTML5 and WebGL
 
Html5 - Novas Tags na Prática!
Html5 - Novas Tags na Prática!Html5 - Novas Tags na Prática!
Html5 - Novas Tags na Prática!
 
The things browsers can do! SAE Alumni Convention 2014
The things browsers can do! SAE Alumni Convention 2014The things browsers can do! SAE Alumni Convention 2014
The things browsers can do! SAE Alumni Convention 2014
 
Implementing Awesome: An HTML5/CSS3 Workshop
Implementing Awesome: An HTML5/CSS3 WorkshopImplementing Awesome: An HTML5/CSS3 Workshop
Implementing Awesome: An HTML5/CSS3 Workshop
 

Mais de Helder da Rocha

Como criar um mapa temático interativo com dados abertos e D3.js
Como criar um mapa temático interativo com dados abertos e D3.jsComo criar um mapa temático interativo com dados abertos e D3.js
Como criar um mapa temático interativo com dados abertos e D3.jsHelder da Rocha
 
TDC 2019: transformando 
dados
públicos
em mapas interativos
TDC 2019: transformando 
dados
públicos
em mapas interativosTDC 2019: transformando 
dados
públicos
em mapas interativos
TDC 2019: transformando 
dados
públicos
em mapas interativosHelder da Rocha
 
Padrões essenciais de mensageria para integração de sistemas
Padrões essenciais de mensageria para integração de sistemasPadrões essenciais de mensageria para integração de sistemas
Padrões essenciais de mensageria para integração de sistemasHelder da Rocha
 
Visualização de dados e a Web
Visualização de dados e a WebVisualização de dados e a Web
Visualização de dados e a WebHelder da Rocha
 
Eletrônica Criativa: criando circuitos com materiais alternativos
Eletrônica Criativa: criando circuitos com materiais alternativosEletrônica Criativa: criando circuitos com materiais alternativos
Eletrônica Criativa: criando circuitos com materiais alternativosHelder da Rocha
 
Introdução à Visualização de Dados (2015)
Introdução à Visualização de Dados (2015)Introdução à Visualização de Dados (2015)
Introdução à Visualização de Dados (2015)Helder da Rocha
 
API de segurança do Java EE 8
API de segurança do Java EE 8API de segurança do Java EE 8
API de segurança do Java EE 8Helder da Rocha
 
Curso de Java Persistence API (JPA) (Java EE 7)
Curso de Java Persistence API (JPA) (Java EE 7)Curso de Java Persistence API (JPA) (Java EE 7)
Curso de Java Persistence API (JPA) (Java EE 7)Helder da Rocha
 
Curso de Enterprise JavaBeans (EJB) (JavaEE 7)
Curso de Enterprise JavaBeans (EJB) (JavaEE 7)Curso de Enterprise JavaBeans (EJB) (JavaEE 7)
Curso de Enterprise JavaBeans (EJB) (JavaEE 7)Helder da Rocha
 
Introdução a JPA (2010)
Introdução a JPA (2010)Introdução a JPA (2010)
Introdução a JPA (2010)Helder da Rocha
 
Curso de RESTful WebServices em Java com JAX-RS (Java EE 7)
Curso de RESTful WebServices em Java com JAX-RS (Java EE 7)Curso de RESTful WebServices em Java com JAX-RS (Java EE 7)
Curso de RESTful WebServices em Java com JAX-RS (Java EE 7)Helder da Rocha
 
Minicurso de Segurança em Java EE 7
Minicurso de Segurança em Java EE 7Minicurso de Segurança em Java EE 7
Minicurso de Segurança em Java EE 7Helder da Rocha
 
Curso de WebServlets (Java EE 7)
Curso de WebServlets (Java EE 7)Curso de WebServlets (Java EE 7)
Curso de WebServlets (Java EE 7)Helder da Rocha
 
Atualização Java 8 (2014)
Atualização Java 8 (2014)Atualização Java 8 (2014)
Atualização Java 8 (2014)Helder da Rocha
 
Curso de Java: Introdução a lambda e Streams
Curso de Java: Introdução a lambda e StreamsCurso de Java: Introdução a lambda e Streams
Curso de Java: Introdução a lambda e StreamsHelder da Rocha
 
Threads 07: Sincronizadores
Threads 07: SincronizadoresThreads 07: Sincronizadores
Threads 07: SincronizadoresHelder da Rocha
 
Threads 08: Executores e Futures
Threads 08: Executores e FuturesThreads 08: Executores e Futures
Threads 08: Executores e FuturesHelder da Rocha
 

Mais de Helder da Rocha (20)

Como criar um mapa temático interativo com dados abertos e D3.js
Como criar um mapa temático interativo com dados abertos e D3.jsComo criar um mapa temático interativo com dados abertos e D3.js
Como criar um mapa temático interativo com dados abertos e D3.js
 
TDC 2019: transformando 
dados
públicos
em mapas interativos
TDC 2019: transformando 
dados
públicos
em mapas interativosTDC 2019: transformando 
dados
públicos
em mapas interativos
TDC 2019: transformando 
dados
públicos
em mapas interativos
 
Padrões essenciais de mensageria para integração de sistemas
Padrões essenciais de mensageria para integração de sistemasPadrões essenciais de mensageria para integração de sistemas
Padrões essenciais de mensageria para integração de sistemas
 
Visualização de dados e a Web
Visualização de dados e a WebVisualização de dados e a Web
Visualização de dados e a Web
 
Eletrônica Criativa: criando circuitos com materiais alternativos
Eletrônica Criativa: criando circuitos com materiais alternativosEletrônica Criativa: criando circuitos com materiais alternativos
Eletrônica Criativa: criando circuitos com materiais alternativos
 
Introdução à Visualização de Dados (2015)
Introdução à Visualização de Dados (2015)Introdução à Visualização de Dados (2015)
Introdução à Visualização de Dados (2015)
 
API de segurança do Java EE 8
API de segurança do Java EE 8API de segurança do Java EE 8
API de segurança do Java EE 8
 
Java 9, 10, 11
Java 9, 10, 11Java 9, 10, 11
Java 9, 10, 11
 
Curso de Java Persistence API (JPA) (Java EE 7)
Curso de Java Persistence API (JPA) (Java EE 7)Curso de Java Persistence API (JPA) (Java EE 7)
Curso de Java Persistence API (JPA) (Java EE 7)
 
Curso de Enterprise JavaBeans (EJB) (JavaEE 7)
Curso de Enterprise JavaBeans (EJB) (JavaEE 7)Curso de Enterprise JavaBeans (EJB) (JavaEE 7)
Curso de Enterprise JavaBeans (EJB) (JavaEE 7)
 
Introdução a JPA (2010)
Introdução a JPA (2010)Introdução a JPA (2010)
Introdução a JPA (2010)
 
Curso de RESTful WebServices em Java com JAX-RS (Java EE 7)
Curso de RESTful WebServices em Java com JAX-RS (Java EE 7)Curso de RESTful WebServices em Java com JAX-RS (Java EE 7)
Curso de RESTful WebServices em Java com JAX-RS (Java EE 7)
 
Minicurso de Segurança em Java EE 7
Minicurso de Segurança em Java EE 7Minicurso de Segurança em Java EE 7
Minicurso de Segurança em Java EE 7
 
Curso de WebServlets (Java EE 7)
Curso de WebServlets (Java EE 7)Curso de WebServlets (Java EE 7)
Curso de WebServlets (Java EE 7)
 
Curso de Java: Threads
Curso de Java: ThreadsCurso de Java: Threads
Curso de Java: Threads
 
Atualização Java 8 (2014)
Atualização Java 8 (2014)Atualização Java 8 (2014)
Atualização Java 8 (2014)
 
Curso de Java: Introdução a lambda e Streams
Curso de Java: Introdução a lambda e StreamsCurso de Java: Introdução a lambda e Streams
Curso de Java: Introdução a lambda e Streams
 
Threads 07: Sincronizadores
Threads 07: SincronizadoresThreads 07: Sincronizadores
Threads 07: Sincronizadores
 
Threads 09: Paralelismo
Threads 09: ParalelismoThreads 09: Paralelismo
Threads 09: Paralelismo
 
Threads 08: Executores e Futures
Threads 08: Executores e FuturesThreads 08: Executores e Futures
Threads 08: Executores e Futures
 

Último

Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 

Último (20)

Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 

Transforming public data into thematic maps (TDC2019 presentation)

  • 2. Quem sou eu? Who am I? Кто я? Helder da Rocha argonavis.com.br Tech * Science * Arts HTML & Web technologies since 1995 Author of books and courses about
 Java, XML and Web technologies helderdarocha.art.br
  • 3. This is a hands-on tutorial • You will learn how to create an interactive thematic map using: HTML, CSS, JavaScript, SVG, D3.js, CSV, GeoJSON (You should know HTML, CSS and some JavaScript) • Main steps: 1. Get shapefile from naturalearthdata.com 2. Convert to GeoJSON with mapshaper.org and run script to filter data 3. Get data from open data portals: un.data.org and geonames.org 4. Generate strings for SVG paths using D3.js 5. Apply scales, colors, projections and interactive features • Get code from: https://github.com/argonavisbr/tutorial-geojson • Playground: JSFiddle (follow links in Readme.md) • Slides only illustrate the main steps (run the examples and download the code!)
  • 6. Convert to GeoJSON: mapshaper.org ne_110m_admin_0_countries.json ne_110m_admin_0_countries.zip 1 23 JSON
  • 7. Alternatives: GIS ou GDALapps $ ogr2ogr -f GeoJSON resultado.geojson ne_110m_admin_0_countries.json.shp gdal.org qgis.org
  • 8. GeoJSON { "type": "FeatureCollection", "features": [ { "type": "Feature", "id": "FJI", "properties": { "name": "Fiji" }, "geometry": { "type": "MultiPolygon", "coordinates": [ [[ [180,-16.067132663642447], ... [179.4135093629971,-16.379054277547404], [180,-16.067132663642447] ]], [[ ... ]], [[ ... ]] ] } },{ "type": "Feature", ... } }, ... ] } "id"property (optional) "properties"property (anycontent) "geometry"property (containsaGeoJSONtypesuchas:
 "Polygon","Point","MultiPolygon")
  • 9. Remove unnecessary properties { "type": "Feature",
 "properties": { "ISO_A3":"...", "NAME":"...", "ADMIN":"...",
 ...,
 "MAPCOLOR7":"..." }, "geometry": {...} } { "type": "Feature",
 "id":"...",
 "properties": { "name":"...", }, "geometry": {...} } ForeachFeature: GitHub:tools/filter-map.js
  • 10.
  • 12. Step 1: Load GeoJSON GitHub:tutorial/map-1.html
  • 13.
  • 14.
  • 15. Step 2: List properties GitHub:tutorial/map-2.html const map = {};
 d3.json('../geo/world.geojson')
 .then(function(data) {
 map.features = data.features;
 draw();
 });
 
 function draw() {
 const ol = d3.select("body").append("ol");
 ol.selectAll("li")
 .data(map.features)
 .enter().append("li")
 .text(d => d.properties.name +
 " ("+ d.id + ")");
 } { "type": "Feature",
 "id":"...",
 "properties": { "name":"...", }, "geometry": {...} }map.features[n]
  • 16. Step 3: List object coordinates GitHub:tutorial/map-3.html const country =
 map.features.filter(k => k.id === "BRA")[0];
 
 const body = d3.select("body");
 body.append("h1")
 .text(country.properties.name);
 
 body.append("ul").selectAll("li.coord")
 .data(country.geometry.coordinates[0])
 .enter()
 .append("li").attr("class", "coord")
 .text(d => "Lon: "+d[0]+", Lat: "+d[1]);
  • 17. <html lang="en"> <head> <style> .poly { stroke: black; stroke-width: .05; fill: yellow; } </style> </head> <body> <svg height="500" width="960" viewBox="7 -13 14 28"> <path d="M-10,0 L-3,10 L10,7 L10,-7 L-3,-10 L-10,0" class="poly" /> </svg> </body> </html> Step 4: SVG <path> GitHub:tutorial/map-6a.html
  • 18. Step 5: SVG <path> with D3 GitHub:tutorial/map-8.html <svg height="500" width="960"></svg> 
 <script>
 const svg = d3.select("svg");
 const pathData = "M-10,0 L-3,10 L10,7 L10,-7 L-3,-10 Z";
 
 svg.append("path").attr("class", "poly")
 .attr("d", pathData);
 </script>
  • 19. Step 6: Generating a <path> with D3 GitHub:tutorial/map-9.html const geoPath = d3.geoPath();
 
 const map = {};
 d3.json('../geo/world.geojson')
 .then(function(data) {
 map.features = data.features;
 draw();
 });
 
 function draw() {
 const country = map.features.filter(k => k.id === "BRA")[0];
 const pathData = geoPath(country);
 d3.select("svg").append("path")
 .attr("d", pathData);
 }
  • 20. Step 7: Binding data to SVG DOM GitHub:tutorial/map-10.html const geoPath = d3.geoPath();
 svg.selectAll("path")
 .data(map.features)
 .enter().append("path")
 .attr("d", geoPath) Eachfeatureboundtoa <path>object
  • 21. Step 8: Geographic projections GitHub:tutorial/map-12.html const geoPath = d3.geoPath();
 const projection = d3.geoMercator(); //d3.geoOrthographic(), d3.geoMollweide()...
 geoPath.projection(projection); d3.geoMercator()
  • 22. Coordinates for cities: geonames.org geonameid;asciiname;latitude;longitude;population;timezone
 3040051;les Escaldes;42.50729;1.53414;15853;Europe/Andorra
 3041563;Andorra la Vella;42.50779;1.52109;20430;Europe/Andorra
 290594;Umm al Qaywayn;25.56473;55.55517;44411;Asia/Dubai
 291074;Ras al-Khaimah;25.78953;55.9432;115949;Asia/Dubai
 291696;Khawr Fakkan;25.33132;56.34199;33575;Asia/Dubai
 292223;Dubai;25.0657;55.17128;1137347;Asia/Dubai
 292231;Dibba Al-Fujairah;25.59246;56.26176;30000;Asia/Dubai
 292239;Dibba Al-Hisn;25.61955;56.27291;26395;Asia/Dubai
 292672;Sharjah;25.33737;55.41206;543733;Asia/Dubai
 292688;Ar Ruways;24.11028;52.73056;16000;Asia/Dubai
 292878;Al Fujayrah;25.11641;56.34141;62415;Asia/Dubai
 292913;Al Ain;24.19167;55.76056;408733;Asia/Dubai GitHub:csv/cities15000.csv (23505places)
  • 23. Step 9: Thematic data: cities GitHub:tutorial/map-15.html Promise.all([
 d3.json('../geo/world.geojson'),
 d3.dsv(';', '../csv/cities15000.csv', function(row) {
 return {
 name: row.asciiname,
 coords: [+row.longitude, +row.latitude]
 }
 })
 ]).then(function([shapes, points]) {
 map.features = shapes.features;
 map.points = points;
 draw();
 }); svg.selectAll("circle.city")
 .data(map.points)
 .enter()
 .append("circle").attr("class", "city")
 .attr("cx", d => projection(d.coords)[0])
 .attr("cy", d => projection(d.coords)[1])
 .attr("r", d => 1)
  • 25. Summary • D3.js is a powerful library containing a set of tools for data visualization based on openstandards • Used by large news portals (NY Times, The Guardian, etc.) in stunning visualizations and interactive maps. It's also used in higher-level datavis frameworks, tools and services. • This tutorial demonstrates how D3 can be used to create thematicmaps using opendata: an essential skill in data journalism
  • 26. Slides, +source-code +demonstrations github.com/argonavisbr/tutorial-geojson www.argonavis.com.br/download/ tdc_2019_js.html (pt-BR and en-US) July/2019 helder da rocha helder@argonavis.com.br www.amazon.com/dp/B07PDBBHLLwww.amazon.com/dp/B07RFBV4PC PresentationdeliveredatTheDeveloper'sConference 2019,inSãoPaulo,Brazil(originallyinPortuguese)