Definitely go and check out
http://forum.processing.org/topic/updating-svg-map-example-from-visualizing-data The final code that works is there. The the map counties.svg is placed in the Data folder inside your project folder. The TSV is placed in the same folder.
The below is the code from Ben Fry's book. You'll want to paste this into a new tab in the Processing IDE. (The book is great and other examples from it are here:
http://benfry.com/writing/archives/3) This will allow you to read a TSV. You can use this to parse CSVs as well by changing TAB to ","
- class Table {
- int rowCount;
- String[][] data;
-
-
- Table(String filename) {
- String[] rows = loadStrings(filename);
- data = new String[rows.length][];
-
- for (int i = 0; i < rows.length; i++) {
- if (trim(rows[i]).length() == 0) {
- continue; // skip empty rows
- }
- if (rows[i].startsWith("#")) {
- continue; // skip comment lines
- }
-
- // split the row on the tabs
- String[] pieces = split(rows[i], TAB);
- // copy to the table array
- data[rowCount] = pieces;
- rowCount++;
-
- // this could be done in one fell swoop via:
- //data[rowCount++] = split(rows[i], TAB);
- }
- // resize the 'data' array as necessary
- data = (String[][]) subset(data, 0, rowCount);
- }
-
-
- int getRowCount() {
- return rowCount;
- }
-
-
- // find a row by its name, returns -1 if no row found
- int getRowIndex(String name) {
- for (int i = 0; i < rowCount; i++) {
- if (data[i][0].equals(name)) {
- return i;
- }
- }
- println("No row named '" + name + "' was found");
- return -1;
- }
-
-
- String getRowName(int row) {
- return getString(row, 0);
- }
- String getString(int rowIndex, int column) {
- return data[rowIndex][column];
- }
-
- String getString(String rowName, int column) {
- return getString(getRowIndex(rowName), column);
- }
-
- int getInt(String rowName, int column) {
- return parseInt(getString(rowName, column));
- }
-
- int getInt(int rowIndex, int column) {
- return parseInt(getString(rowIndex, column));
- }
-
- float getFloat(String rowName, int column) {
- return parseFloat(getString(rowName, column));
- }
-
- float getFloat(int rowIndex, int column) {
- return parseFloat(getString(rowIndex, column));
- }
- }
This code colors and draws each county:
- else {
- float value = data.getFloat(row, 1);
- if (value >= 0) {
- float amt = norm(value, 0, dataMax);
- float c = map(amt, 0, 1, 255, 0);
- fill(100, c, 100);
- svg.disableStyle();
- shape(state, 35, 30);
- }
You should look at the Processing reference if you have questions about this.