|
|
TrekBuddy www.trekbuddy.net Outdoor companion.
|
- bluetooth / serial / internal GPS, simulator
- offline raster maps (common grids and projections)
- smart GPX / raw NMEA logs
- waypoints and simple navigation
- ... and more
|
- MIDP and Symbian phones
- Blackberry
- Android
- Windows Mobile 5.x/6.x
- Windows Phone coming
|
|
Visit our wiki to see all features, guides and howtos.
Project tracker.
|
|
|
|
|
|
|
| View previous topic :: View next topic |
| Author |
Message |
blaufish
Joined: 28 Jul 2008 Posts: 1
|
Posted: Mon Jul 28, 2008 7:25 pm Post subject: Geotagging Trekbuddy wgps*.gpx parser which run exiftool.exe |
|
|
Hi guys...
http://blaufish.blogg.se/2008/july/trekbuddy-wgps-snapshot-parser-beta-release.html
Basically I wanted to get rid of having to fiddle around with clock synchronization, after noticing that some of my geotaggings got wrong (probably because the cell phone's clock wasn't spot on). So I decided "it's my way or the highway" and wrote a small tool which simply smashes the information in the wgps*.gpx file into the pictures, using exiftool.exe.
It's very very very beta (a late evening + an early morning crunch) and primarily written for my own use, but I figured some of you might also find it useful.
| Code: |
/*
* Blaufish's Trekbuddy WGPS-*.GPX Geotagging Snapshot Parser
* http://blaufish.blogg.se/
*
* Some rights reserved;
* http://creativecommons.org/licenses/by-nc-sa/3.0/
*
*/
import java.io.*;
import org.xml.sax.helpers.*;
import org.xml.sax.*;
public class TBuddy extends DefaultHandler {
String lat;
String lon;
String ele;
String time;
String link;
String chars;
@Override public void startElement(String uri, String localName, String qName, Attributes attributes) {
if (localName.equals("wpt")) {
lat = attributes.getValue("lat");
lon = attributes.getValue("lon");
ele = null;
time = null;
link = null;
chars = null;
}
else if (localName.equals("link")) {
link = attributes.getValue("href");
}
}
@Override public void endElement(String uri, String localName, String name) {
if (localName.equals("ele")) {
ele = chars;
}
else if (localName.equals("time")) {
time = chars;
}
else if (localName.equals("wpt")) {
runExifTool();
}
}
@Override public void characters(char[] ch, int start, int length) {
chars = new String(ch,start,length);
}
public void runExifTool() {
if ("".equals(lat) || "".equals(lon) || "".equals(link) ) return ;
StringBuilder command = new StringBuilder("exiftool");
if (lat.charAt(0)=='-')
command.append(" -GPSLatitudeRef=S -GPSLatitude=").append(lat.substring(1));
else
command.append(" -GPSLatitudeRef=N -GPSLatitude=").append(lat);
if (lon.charAt(0)=='-')
command.append(" -GPSLongitudeRef=W -GPSLongitude=").append(lon.substring(1));
else
command.append(" -GPSLongitudeRef=E -GPSLongitude=").append(lon);
if (ele != null) {
if (ele.charAt(0)=='-')
command.append(" -GPSAltitudeRef=1 -GPSAltitude=").append(ele.substring(1));
else
command.append(" -GPSAltitudeRef=0 -GPSAltitude=").append(ele);
}
if (time != null) {
String gpsdatestamp = time.substring(0,10).replace('-', ':');
String gpstimestamp = time.substring(11,19);
command.append(" -GPSDateStamp=").append(gpsdatestamp).append(" -GPSTimeStamp=").append(gpstimestamp);
}
command.append(" ").append(link);
System.out.println(command);
try {
Process p = Runtime.getRuntime().exec(command.toString());
p.waitFor();
int exitValue = p.exitValue();
if ( exitValue != 0) {
InputStream[] isa = { p.getErrorStream(), p.getInputStream() };
for( InputStream is : isa ) {
BufferedReader br = new BufferedReader( new InputStreamReader( is ));
for( String line ; ( line = br.readLine() ) != null ; System.out.println("EXIFTOOL: "+line) );
}
throw new RuntimeException("Error: exiftool returned error ("+exitValue+").");
}
}
catch( Exception e ) { throw new RuntimeException(e); }
}
public TBuddy() { }
public TBuddy( String gpxFileName ) {
try {
XMLReader xr = XMLReaderFactory.createXMLReader();
xr.setContentHandler( this );
FileReader r = new FileReader(gpxFileName);
xr.parse(new InputSource(r));
}
catch( Exception e ) { throw new RuntimeException(e); }
}
public static void main(String[] args) throws Exception {
if ( args.length == 0 ) {
System.out.println("Blaufish's Trekbuddy WGPS-*.GPX Geotagging Snapshot Parser "
+ "http://blaufish.blogg.se "
+ "Parses a WGPS-xxxxx.GPX file created by Trekbuddy -> Waypoint -> Record Current -> Take Snapshot, "
+ "and executes the appropriate exiftool command e.g. "
+ "exiftool -GPSLatitudeRef=N -GPSLatitude=57.622655333 -GPSLongitudeRef=E "
+ " -GPSLongitude=11.756720333 -GPSAltitudeRef=1 -GPSAltitude=19.6 "
+ " -GPSDateStamp=2008:07:19 -GPSTimeStamp=08:55:00 "
+ " images-2008-07-19-10-55-20/pic-1.jpg "
+ "Some rights reserved; "
+ "http://creativecommons.org/licenses/by-nc-sa/3.0/ "
+ "Usage: java TBuddy [wgps*.gpx files...] "
+ "Example: java TBuddy wgps-2008-07-19-10-55-20.gpx" );
return ;
}
for( String wgpsGpxFileName : args ) new TBuddy( wgpsGpxFileName );
}
}
|
_________________ http://blaufish.blogg.se/ |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|