⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 trackpoint301.java

📁 基于Java的地图数据管理软件。使用MySQL数据库管理系统。
💻 JAVA
字号:
package net.aetherial.gis.garmin;

import java.io.*;
import java.util.*;
import net.aetherial.gis.garmin.*;
import net.aetherial.gis.surface.DialogProgress;
import java.awt.Frame;

class TrackPoint301 extends TrackPoint
{
	private Position position;
	private float altitude;
	private float depth;
	private Date time;
	boolean newTrack;
        DialogProgress fp;
	public float getAltitude ()
	{
		return altitude;
	}

	public Date getTime ()
	{
		return time;
	}

	public TrackPoint301 (byte[] contents,DialogProgress fp)
	{
          this.fp = fp;
		ByteArrayInputStream bais = new ByteArrayInputStream (contents);

                byte[] latByte = new byte[4];
                for (int i = 0; i < latByte.length; i++)
                        latByte[i] = (byte) bais.read ();

                byte[] longByte = new byte [4];
                for (int i = 0; i < longByte.length; i++)
                        longByte[i] = (byte) bais.read();

		position = new Position (toLongInt(latByte), toLongInt (longByte));

		byte[] timeBytes = new byte[4];
                for (int i = 0; i < longByte.length; i++)
                        timeBytes[i] = (byte) bais.read();

		GregorianCalendar garminInit = new GregorianCalendar (1989, 11, 31, 8, 0, 0);
		Date dDifference = garminInit.getTime();
                long myByte = (toLongInt (timeBytes));
                if((myByte/1000)>4294924)
                  myByte =0;
		long difference = dDifference.getTime() + (myByte * 1000);
		time = new Date (difference);

		byte[] floByte = new byte[4];
		for (int i = 0; i < floByte.length; i++)
			floByte[i] = (byte) bais.read ();
		altitude = toFloat (floByte);

		for (int i = 0; i < floByte.length; i++)
			floByte[i] = (byte) bais.read ();
		depth = toFloat (floByte);

		if (bais.read () == 0 && bais.read () == 0)
			newTrack = false;

	}

	public void printDetails ()
	{
		Calendar c = new GregorianCalendar ();
//		System.out.println ("This is a debugging tool for dumping track point details.");
//		System.out.println ("Track point Position:           "+position.getDegreeLatitude ()+"."+position.getMinuteLatitude ()+"."+position.getSecondLatitude ()+position.getLatOrientChar ()+", "+position.getDegreeLongitude()+"."+position.getMinuteLongitude ()+"."+position.getSecondLongitude ()+position.getLongOrientChar ());
//		System.out.println ("Track Point Altitude:           "+altitude);
//		System.out.println ("Track Point Depth:              "+depth);
//		c.setTime (time);
//		System.out.println ("Track Point Date:               "+(c.get (Calendar.MONTH)+1)+"-"+c.get (Calendar.DAY_OF_MONTH)+"-"+c.get (Calendar.YEAR)+"  "+c.get (Calendar.HOUR)+":"+c.get (Calendar.MINUTE)+":"+c.get (Calendar.SECOND)+" GMT");
                this.fp.jTextField1.setText("正在读取航迹点:"+position.getDoubleDegreeLatitude()+position.getLatOrientChar ()+", "+position.getDoubleDegreeLongitude()+position.getLongOrientChar ());
                //把值加入到向量static Vector myTest.number 里面
                //myTest.lat.addElement(String.valueOf(position.getDoubleDegreeLatitude()));
                //myTest.lon.addElement(String.valueOf(position.getDoubleDegreeLongitude()));
                //myTest.name.addElement(c.get (Calendar.MONTH)+1+"-"+c.get (Calendar.DAY_OF_MONTH)+" "+c.get (Calendar.HOUR)+":"+c.get (Calendar.MINUTE)+":"+c.get (Calendar.SECOND)+"");
                //
		if (newTrack == true)
			System.out.println ("This is the start of a new track.");
//		System.out.println ("");
	}

	public Position getPosition ()
	{
		return position;
	}

	private long toLong (byte[] bytes)
	{
		long l = (long) ((((long) bytes[7]) * Math.pow (2,56)) + (((long) bytes[6]) * Math.pow (2,48)) + (((long) bytes[5]) * Math.pow(2, 40)) + (((long) bytes[4]) * Math.pow (2,32)) + (((long) bytes[3]) * Math.pow (2,24)) + (((long) bytes[2]) * Math.pow(2,16)) + (((long) bytes[1]) * Math.pow(2,8))) + (long) bytes[0];
		return l;
	}

	private double toDouble (byte[] bytes)
	{
		return Double.longBitsToDouble (toLong (bytes));
	}

	private long toLongInt (byte[] bytes)
	{
		long[] ints = new long[4];

		for (int i = 0; i < ints.length; i++)
		{
			if (bytes[i] < 0)
				ints[i] = (long) (256 + (int) bytes[i]);
			else
				ints[i] = (long) bytes[i];
		}

		for (int i = 0; i < ints.length; i++)
		{
			ints[i] = (ints[i]) * (long) Math.pow (2, (8 * i));
		}

		return ints[3] + ints[2] + ints[1] + ints[0];
	}

	private float toFloat (byte[] bytes)
	{
		int i = (int) toLongInt (bytes);
		float f = Float.intBitsToFloat (i);

		if (f > Math.pow (10, 20))
			return 0;
		else
			return f;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -