Git Product home page Git Product logo

sparkline_map's Introduction

COVID-19 Sparkline Map

Steps

Download QGIS

I used version 3.12

Open project sparkline_map.qgz

You'll have this :

That's it ! Now, play with styling, parameters

Data

Expression

We use this expression for the line geometry :

with_variable(
'height',
-- Height factor for each segment. Total height will be nb cases * @height
100,
with_variable(
-- Width of the line, starting from centroid
'width',
200000,
with_variable(
'nb_cases',
array_sort(
	relation_aggregate( 
		-- Relation name 
		'covid_data_dep_french_dep_INSEE_DEP',
		-- Compile in an array
		'array_agg', 
		-- Calculate number of cases
		to_int("dc")+to_int("hosp")+to_int("rea")+to_int("rad")
	)
 ),
 -- Create geometry
geom_from_wkt(
	-- Create WKT String
	'LINESTRING ('  || 
	-- First node is the centroid
	x(centroid($geometry))||' '||y(centroid($geometry)) ||','||
	-- Paste the node coordinates
	array_to_string(
		-- Iterate over indexes
		array_foreach(
			-- Generate a series over the indexes / nodes
			generate_series(1, array_length(@nb_cases)), 
			-- X Coordinate of the node
			to_string(x(centroid($geometry)) + (@element/array_length(@nb_cases)*@width)) ||' '||
			-- Y coordinate of the node
			to_string(y(centroid($geometry)) + @nb_cases[@element]*@height)
		),
	',') || ')'
)
)))

Also, the labels are positioned using the same kind of expression.

Links

See my blog post for an explanation of the expression code

Map image licence

CC BY SA NC

sparkline_map's People

Contributors

datagistips avatar mrajerisoncerema avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.