11/12/2009, 02:46 PM
|
#21 (permalink) |
|
Member
![]() ![]() Join Date: Nov 2009
Location: UK
Posts: 45
Likes Received: 0
Thanks: 16
Thanked 7 Times in 2 Posts
|
Hi Metaview,
I've tried PMing / posting source code to you, but this forum is preventing me from doing this (because I've only made 5 posts apparently). Could you PM me your email address and I'll send you the source code straight away. |
11/14/2009, 10:08 AM
|
#22 (permalink) |
|
Member
![]() ![]() Join Date: Nov 2009
Location: UK
Posts: 45
Likes Received: 0
Thanks: 16
Thanked 7 Times in 2 Posts
|
Hi MetaView,
I've pasted a small java class below, which I've used to convert GPS track data stored in a Mojo database. It assumes a table with 4 text columns: lat, lon, altitude, time. I used a convention in Mojo code of creating tables with name: Gyyyymmddhhmmss I used an open source SQLite JDBC driver to read the data on the desktop: SQLiteJDBC Please download sqlitejdbc-v056.jar, and copy to same directory as the Java class. After you've compiled with JDK, run as follows: java -cp .;sqlitejdbc-v056.jar MojoTrackConverter --------------------------- MojoTrackConverter.java ------------------------ Code:
import java.sql.*;
import java.io.*;
public class MojoTrackConverter
{
public static void main(String[] args) throws Exception
{
if (args.length < 2)
System.out.println("Usage: MojoTrackConverter DbFile Tblname, or DbFile -l for list of tables");
else
{
if (args[1].equals("-l"))
listTables(args[0]);
else
convert(args[0], args[1]);
}
}
private static void convert(String strDbFile, String strTable) throws Exception
{
FileWriter outFile = null;
PrintWriter out = null;
ResultSet rs = null;
Class.forName("org.sqlite.JDBC");
Connection conn = DriverManager.getConnection("jdbc:sqlite:" + strDbFile);
Statement stat = conn.createStatement();
try
{
outFile = new FileWriter(strTable + ".gpx");
out = new PrintWriter(outFile);
out.println("<?xml version=\"1.0\" standalone=\"yes\"?>");
out.println("<gpx version=\"1.1\" creator=\"MojoTracker\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://www.topografix.com/GPX/1/1\" xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd\">");
out.println("<trk><trkseg>");
}
catch (Exception e)
{
System.out.println("File Error. " + e.getMessage());
return;
}
try
{
rs = stat.executeQuery("select * from " + strTable + ";");
while (rs.next())
{
out.print("<trkpt lat=\"" + rs.getString("lat") + "\" ");
out.print("lon=\"" + rs.getString("lon") + "\">");
out.print("<ele>" + rs.getString("altitude") + "</ele>");
out.println("<time>" + rs.getString("time") + "</time></trkpt>");
}
out.println("</trkseg></trk>");
out.println("</gpx>");
System.out.println("\n--" + strTable + ".GPX created--");
}
catch(SQLException e)
{
System.out.println("Database error occurred. " + e.getMessage());
}
catch(Exception e)
{
System.out.println("Error occurred while converting. " + e.getMessage());
}
finally
{
if (rs != null) rs.close();
conn.close();
out.close();
}
}
private static void listTables(String strDbFile) throws Exception
{
ResultSet rs;
int rscount = 0;
Class.forName("org.sqlite.JDBC");
Connection conn = DriverManager.getConnection("jdbc:sqlite:" + strDbFile);
Statement stat = conn.createStatement();
rs = stat.executeQuery("select tbl_name from sqlite_master where tbl_name like 'G%' order by tbl_name asc;");
while (rs.next())
{
System.out.println(rs.getString("tbl_name"));
rscount++;
}
if (rscount == 0)
{
System.out.println("No tables found - have you supplied a correct Database file?");
}
rs.close();
conn.close();
}
}
|
11/15/2009, 09:29 AM
|
#23 (permalink) |
|
Member
![]() ![]() Join Date: Mar 2006
Location: Berlin, Germany, Europe
Posts: 1,457
Likes Received: 50
Thanks: 85
Thanked 608 Times in 256 Posts
|
Thank you very much. Here is what I have so far: a tracking app without OSM connection
I guess due the end of the week I might have a full functional "Track on OSM".If I understand you correctly you create a new table for each track? Makes it more difficult to list all tracks to the user o nthe device? I use a TrackID at the moment, which is the time-value of themoment starting the app. But I don't have something included yet to show a list of tracks to the user ![]() http://www.metaviewsoft.de/PUM-2009/MapTool.zip
__________________
Paid Apps: UberRadio, Match This! Pro, TravelGuide, Wikay and more. Grab ImageWorker Pro while it's on sale! |
11/15/2009, 11:35 AM
|
#24 (permalink) |
|
Member
![]() ![]() Join Date: Nov 2009
Location: UK
Posts: 45
Likes Received: 0
Thanks: 16
Thanked 7 Times in 2 Posts
|
Great stuff Metaview. Have just installed this, and can see that it's tracking. Agreed, it's probably best to just use one table for all tracks. Using separate tables seemed to keep it a bit tidier.
Can't wait to see it displaying tiles from OSM!! One minor thing though... It doesn't seem to be generating SQLite .db files in the .appstorage folder. Maybe you have to prefix your database name with "ext:"? |
11/15/2009, 12:03 PM
|
#25 (permalink) |
|
Member
![]() ![]() Join Date: Mar 2006
Location: Berlin, Germany, Europe
Posts: 1,457
Likes Received: 50
Thanks: 85
Thanked 608 Times in 256 Posts
|
hit
Will change it.
__________________
Paid Apps: UberRadio, Match This! Pro, TravelGuide, Wikay and more. Grab ImageWorker Pro while it's on sale! |
12/05/2009, 04:04 PM
|
#26 (permalink) |
|
Member
![]() ![]() Join Date: Nov 2009
Location: UK
Posts: 45
Likes Received: 0
Thanks: 16
Thanked 7 Times in 2 Posts
|
Mojo Tracker seems to be available now:
http://www.precentral.net/homebrew-apps/mojotracker Also, there is now an excellent App for displaying maps from OpenStreetMap: http://www.precentral.net/homebrew-apps/minimap |
12/19/2009, 06:07 PM
|
#27 (permalink) |
|
Member
![]() Join Date: Nov 2009
Posts: 3
Likes Received: 0
Thanks: 2
Thanked 0 Times in 0 Posts
|
Hello Wonka,
i am trying to convert the sql-db to a useable format. i downloaded sqlitejdbc-v056.jar, pastet your code in MojoTrackConverter.java (same directory as the jar-file) and entered java -cp .;sqlitejdbc-v056.jar MojoTrackConverter in a dos-box of Windows XP. I get this message: Exception in thread "main" java.lang.NoClassDefFoundError: MojoTrackConverter Caused by: java.lang.ClassNotFoundException: MojoTrackConverter at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClassInternal(Unknown Source) Any idea, what im doing wrong? Maybe i missed the statement "After you've compiled with JDK, run as follows" What do you mean with it? Kind regards, Normen |
12/22/2009, 04:28 AM
|
#28 (permalink) | |
|
Member
![]() ![]() Join Date: Nov 2009
Location: UK
Posts: 45
Likes Received: 0
Thanks: 16
Thanked 7 Times in 2 Posts
|
Quote:
You need to compile that code using the java compiler (javac.exe). This is easily done (javac MojoTrackConverter.java), but first you'll need to download the JDK from java.com. But in this case I'll arrange to send you the compiled module to save you any more hassle. If there's any real demand for this utility then I'll set up a website that will allow the DB files to be uploaded and converted to GPX. |
|
![]() |
|
| Thread Tools | |
| Display Modes | |
|
|



