Mobile app version of vmapp.org
Login or Join
Ravi4787994

: Illustrator data-driven maps I have searched high and low for a way to colorize parts of a map based on a csv or xml file. For instance to illustrate results of a election. Doing it by hand

@Ravi4787994

Posted in: #AdobeIllustrator #DataVisualisation #Xml

I have searched high and low for a way to colorize parts of a map based on a csv or xml file. For instance to illustrate results of a election. Doing it by hand is both tedious

I imagine being able to attach a path to an variable and being able to change the background-image or the swatch based on a numeric value.

Has any one got a idea on how to approach this?

10.04% popularity Vote Up Vote Down


Login to follow query

More posts by @Ravi4787994

4 Comments

Sorted by latest first Latest Oldest Best

 

@Gail6891361

Doing this is pretty simple. All you need is:


A data file in a CSV form with names and values.
Each region shape to be filled annotated by the name.


Then all you do is a loop over each column, although you may want 2 loops if you want to normalize data ranges. Here is the final result of a tutorial that I prepared for students in my university:
#target illustrator


(function () { // protect namespace

var doc = app.activeDocument;
var input = read_data_CSV();

var data = input[0];
var max = input[1];
var min = input[2];

for ( i = 0; i < data.length; i++ ) {
var name = data[i][0];
var value = (data[i][1] - min)/(max-min)*100;

try{
var pathitem = doc.pageItems.getByName(name);

var col = new CMYKColor();
col.black = 0;
col.cyan = 100 - value;
col.magenta = value;
col.yellow = 0;

pathitem.fillColor = col;
if (pathitem.typename === "CompoundPathItem")
pathitem.pathItems[0].fillColor = col;

} catch(err) {
alert(name+ " errors!");
}
}


/**
* Prompt user for a CSV file, two columns
* name and value. The CSV file is assumed
* to be in form:
*
* name;10.5
*
* Where the column separator is ";" and
* the decimal separator is ".".
*
* @returns {array} containing the data, max
* and min.
*/
function read_data_CSV(){
var file = File.openDialog('data', 'center:*.csv');
file.open( 'r' );

var max = Number.MIN_VALUE;
var min = Number.MAX_VALUE;
var data = [];

while( !file.eof ) {
var input = file.readln().split( ';' );
var numeric = parseFloat(input[1]);

if (numeric > max) max = numeric;
if (numeric < min) min = numeric;

data.push([input[0], numeric]);
}

return [data, max, min];
}

})(); //run on load




Image 1: Example map mapped with values form csv file

To test this on some real map data Ive prepared following files:


map.ai, a map containing the map of municipalities in Southern Finland. The map is based on "NLS Yleiskarttarasteri 1:1 000 000, 1.4.2013" you may share or mix this data as long as you attribute the source and list version where it was taken from.
population_31_12_2016_logarithmic.csv, containing the population data for the region in December 31 2016.
percentage_of_unemployment_2015.csv, containing unemployment data in year 2015.


Be sure to have the file to modify active. This is a example only I would need to be much more robust to share it as something else.

10% popularity Vote Up Vote Down


 

@Ogunnowo857

I'm not familiar with Illustrator's scripting / variable abilities, but I did recently learn about the ability to create simple charts in Illustrator. It may be simpler to create the map and color the values manually. Tedious? Yes. But it gets the results you want.

Other alternatives: Tableau as suggested, or the new features in Excel using the Map tool from the Excel store will do the job quickly.

I just started a job using Cognos 10 and I'll be working on maps in the coming weeks, so if you have Cognos Report Studio you could go that route.

10% popularity Vote Up Vote Down


 

@Cofer715

From a purely level-of-effort perspective, consider trying Tableau. I'm pretty sure you can pick it up faster than a script can be written. You can also export your charts/maps to PDF for fine tuning in Illustrator.

Even the free Public version provides some pretty robust mapping functionality. As long as your dataset is named something meaningful, it can recognize geographic territories pretty well out of the box.

Here's a tutorial to give you sense of what's possible: www.interworks.com/blog/ccapitula/2015/02/25/tableau-essentials-formatting-tips-maps
NB: All Tableau Public charts/maps are public by default. Also, I did not create that tutorial.

10% popularity Vote Up Vote Down


 

@Alves566

You may be able to use a self-made, custom script in conjunction with some spreadsheet data to do this. Either you can write yourself, or one will come as an answer in this thread, or you can ask the people on the Adobe Illustrator Scripting forum to write one for you.

When creating the custom script, your basic goal will be to attach the data to the art shape by means of some 'key' such as the path's name in the layers panel, or using the attribute notes or even using the variables feature and attaching a different variable to every path. In the spreadsheet you'll have to include this reference key in one column and the corresponding color data such as a swatch name or color values in another column. Your custom script will need to parse the CSV data and colorize the paths.

If you can provide a link to your files, or use screenshots to explain the structure of your spreadsheet and document, it would be the next step.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme