Tuesday, October 21, 2008

Oracle SDO2FreeEarth Step 2

Next will loop thru the result set and write the data out to a javascipt file using the FreeEarth API. We'll build an array or arrays where a single point is an array of latitude, longitude, and identifier. In this case getString(1) represents the identifier, getString(2) represents latitude, and getString(3) represents the longitude.

String dataLine = "var ptlocations = [";
StringBuffer sb = new StringBuffer();
sb.append(dataLine);
int cnt = 0;

while (rset.next()) {
dataLine = "[\"" + rset.getString(1) + "\"," + rset.getString(2)+ "," + rset.getString(3) + ",\"" + rset.getString(1) + "\"],";
sb.append(dataLine);
cnt++;
}
dataLine = sb.toString();
dataLine = dataLine.substring(0,dataLine.length()-1);
dataLine += "];";

// Create the file to output results
FileUtility fu = new FileUtility("webapps/freeearth_demo/myfreearthpts.js");
fu.openFileWriter();
fu.write(dataLine);
System.out.print(dataLine);
fu.close();
stmt.close();
conn.close();
System.out.println ("\nCount=" + cnt);

1 comment:

GIS Services said...

Thanks for sharing the program.
regards
Cartography