if( line.matches(patternGPRMC))
{
try {
TAMTPoint p = new TAMTPoint();
p.setId(UUID.randomUUID().toString());
/*
* Extract the data from the GPRMC sentence (ie,
* line)
*/
String[] data = pattern.split(line);
// timestamp from hhmmss, ddmmyy
String timestamp = parseDate(data[1], data[9]);
p.setTimestamp(timestamp);
// latitude (ddmm.ss), latitude hemisphere (N or S)
double latitude = parseCoordRegex(data[3], data[4], coordRegex);
p.setLatitude(latitude);
// longitude (ddmm.ss), longitude hemisphere (E or
// W)
double longitude = parseCoordRegex(data[5], data[6], coordRegex);
p.setLongitude(longitude);
// bearing
double bearing = Double.parseDouble(data[8]);
p.setBearing(bearing);
// speed (in knots)
double speed = Double.parseDouble(data[7]);
// convert to meters per second
// 1 knot = 0.514444444 meters per second
speed = (speed * 0.5144);
p.setSpeed(speed);
// if we have not failed up to this point
// (as indicated by fetching the timestamp -- kind
// of a hack)
// then we can append the point to the COPY file
if (p.getTimestamp() != null) {
// append to a file in /tmp/
StringBuffer sb = new StringBuffer();
// id, gpsLogId, gpsTraceId, lat, lng, bearing, speed,
// altitude, created, geometry (POINT)
sb.append(nextSequence);
sb.append(DELIMITER);
sb.append(p.getId());
sb.append(DELIMITER);
sb.append(traceId); // the parent id of the
// GPSTrace containing the
// zip from which this point
// came
sb.append(DELIMITER);
sb.append(p.getLatitude());
sb.append(DELIMITER);
sb.append(p.getLongitude());
sb.append(DELIMITER);
sb.append(p.getBearing());
sb.append(DELIMITER);
sb.append(p.getSpeed());
sb.append(DELIMITER);
sb.append(p.getAltitude());
sb.append(DELIMITER);
sb.append(p.getTimestamp());
sb.append(DELIMITER);
sb.append("\\N"); // null for geometry;
sb.append(DELIMITER);
sb.append("\\N"); // null for tag_id;
sb.append(DELIMITER);