📄 waypoint103.java
字号:
package net.aetherial.gis.garmin;
import java.io.*;
import java.util.*;
import net.aetherial.gis.garmin.*;
class Waypoint103 extends Waypoint
{
private MapSymbol symbol;
private Position position;
private String identifier;
private String comment;
private byte dspl;
public Waypoint103 (byte[] contents)
{
ByteArrayInputStream bais = new ByteArrayInputStream (contents);
try
{
byte[] ident = new byte[6];
for (int i = 0; i < 6; i++)
{
ident[i] = (byte) bais.read ();
}
identifier = new String (ident, 0, ident.length, "US-ASCII");
}
catch (UnsupportedEncodingException e)
{
identifier = new String ("");
}
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));
bais.read();
bais.read();
bais.read();
bais.read();
try
{
byte[] coBytes = new byte[40];
for (int i = 0; i < 40; i++)
{
coBytes[i] = (byte) bais.read ();
}
comment = new String (coBytes, 0, coBytes.length, "US-ASCII");
}
catch (UnsupportedEncodingException e)
{
comment = new String ("");
}
byte symbolByte[] = new byte[2];
symbolByte[0] = (byte) 0;
symbolByte[1] = (byte) bais.read ();
symbol = new MapSymbol (symbolByte);
dspl = (byte) bais.read ();
try
{
bais.close ();
}
catch (IOException e)
{
}
GarminGMLDoc.getDocument ();
GarminGMLDoc.addWaypoint (this);
}
public void printDetails ()
{
// System.out.println ("This is a debugging tool for dumping waypoint details.");
// System.out.println ("Waypoint Symbol: "+symbol.getMapSymbol ());
// System.out.println ("Waypoint Position: "+position.getDoubleDegreeLatitude()+position.getLatOrientChar ()+", "+position.getDoubleDegreeLongitude()+position.getLongOrientChar ());
// System.out.println ("Waypoint Identifier: "+identifier);
// System.out.println ("Other options will be implemented soon.");
// System.out.println ("");
}
public String getCSVRepresentation ()
{
String csv = new String ();
csv = csv + identifier + "," + position.getFloatDegreeLatitude () + "," + position.getFloatDegreeLongitude ();
return csv;
}
public String getIdentifier ()
{
return identifier;
}
public MapSymbol getSymbol ()
{
return symbol;
}
public String getComment ()
{
return comment;
}
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 + -