saveTable function seems to save 2 copies of the rows that are added to the table?
in
Programming Questions
•
7 months ago
When I populate a Table object with one set of data I end up with a file that has a header and data then the header again and the data rows again. So when I then try to load the table file with loadTable I have problems.
Table t = createTable();
t.addColumn("id");
t.addColumn("imgFilename");
t.addColumn("x");
t.addColumn("y");
t.addColumn("z");
for ( int i=0; i<maxImg; i++ ) {
TableRow tr = t.addRow();
tr.setInt("id", t.getRowCount()-1);
tr.setString("imgFilename",img[i].imgFilename);
tr.setFloat("x",img[i].x);
tr.setFloat("y",img[i].y);
tr.setFloat("z",img[i].z);
}
String fnBase = "worldImagesState";
String fn = fnBase + ".csv";
File f = new File(dataPath(fn));
int fnSuffix = 1;
while ( f.exists() ) {
fn = fnBase + fnSuffix + ".csv";
f = new File(dataPath(fn));
fnSuffix += 1;
}
saveTable( t, "data/"+fn, "csv" );
And the file looks like:
id,imgFilename,x,y,z
0,screen-1980.tif,-4126.241,-2663.392,-2464.8552
1,screen-0804.tif,-3227.971,255.46973,-1855.0681
2,screen-0238.tif,-2085.183,-1370.5723,-4370.528
3,screen-6868.tif,260.92798,4980.0,-1661.2876
id,imgFilename,x,y,z
0,screen-1980.tif,-4126.241,-2663.392,-2464.8552
1,screen-0804.tif,-3227.971,255.46973,-1855.0681
2,screen-0238.tif,-2085.183,-1370.5723,-4370.528
3,screen-6868.tif,260.92798,4980.0,-1661.2876
1