We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › load textfile data as coordinates
Page Index Toggle Pages: 1
load textfile data as coordinates (Read 762 times)
load textfile data as coordinates
Nov 1st, 2005, 2:27pm
 
Hallo,
i'm kind of a newbie to processing, so please excuse me, if my problem is a little too under-your-average problem. ;)
i am trying to program a tool that displays the broadening of a disease on a map. therefor i got a textfile that has

-the index number of the city
-its latitude/longitude
-the index numbers of the cities the city is connected to

so, how am i getting these numbers as variables into my program? with "loadStrings"?
well, but how can i use the data for displaying a rectangle at the coordinates? and what structure should the textfile have?
Re: load textfile data as coordinates
Reply #1 - Nov 10th, 2005, 6:39am
 
I'm having a similar problem.  I essentially want to take the string:
"2 55 0 34 75 0 0 0 328 0 15 0 101 0 1" and extract each number in order to create a bar graph, but I need to get those values as type int first.
Re: load textfile data as coordinates
Reply #2 - Nov 10th, 2005, 7:06am
 
MK-Ultra wrote on Nov 1st, 2005, 2:27pm:
-the index number of the city
-its latitude/longitude
-the index numbers of the cities the city is connected to

so, how am i getting these numbers as variables into my program with "loadStrings"
well, but how can i use the data for displaying a rectangle at the coordinates and what structure should the textfile have

save the file as tab-delimited text, then use something like this (not tested):

Code:
String lines[] = loadStrings("stuff.txt");
int count = 0;
int index[] = new int[lines.length];
float lat[] = new float[lines.length];
float lon[] = new float[lines.length];
int connected[][] = new String[lines.length][];

for (int i = 0; i < lines.length; i++) {
String pieces[] = split(lines[i], '\t');
index[count] = toInt(pieces[0]);
lat[count] = toFloat(pieces[1]);
lon[count] = toFloat(pieces[2]);

// assuming that this column is separated by commas
// and maybe additional space
connected[count] = toInt(split(pieces[3]), ",");

count++;
}
Re: load textfile data as coordinates
Reply #3 - Nov 10th, 2005, 7:08am
 
markr wrote on Nov 10th, 2005, 6:39am:
I'm having a similar problem.  I essentially want to take the string:
"2 55 0 34 75 0 0 0 328 0 15 0 101 0 1" and extract each number in order to create a bar graph, but I need to get those values as type int first.


if it's a single line, do like so:

Code:
String lines[] = loadStrings("data.txt");
int nums[] = toInt(split(lines[0]));

then nums.length will have the count of the numbers in there.
Page Index Toggle Pages: 1