NASA World Wind

gov.nasa.worldwind.ogc.kml
Class KMLCoordinateTokenizer

java.lang.Object
  extended by gov.nasa.worldwind.ogc.kml.KMLCoordinateTokenizer

public class KMLCoordinateTokenizer
extends Object

Tokenizer to read coordinate values from KML coordinate string. The components of each coordinate tuple are separated by commas, as defined by the KML spec, coordinate tuples are comma separated, and each tuple is separated from the surrounding tuples by whitespace. For example:

 -18.3,23.5,0 -19.3,23.4,1 -20.0,23.5,2
 

However, some KML files do not follow the spec and embed white space within the coordinate tuples. This tokenizer attempts to be lenient with whitespace handling. If a tuple ends with a comma, the tokenizer considers the next token in the input stream to be part of the same coordinate, not the start of a new coordinate.

For example:

 -18.3,23.56,9     34.9, 56.0, 2     56.9, 19     90.0,23.9,44
 
Will be tokenized to four coordinates: (23.56, -18.3, 9), (56.0, 34.9, 2), (56.9, 19, 0), and (90, 23.9, 44).

The tokenizer also handles coordinate strings with no embedded white space. For example:

 -18.3,23.56,9,34.9,56.0,2
 
Will be tokenized to two coordinates: (23.56, -18.3, 9), (56.0, 34.9, 2)


Field Summary
protected  boolean afterComma
           
protected  char[] buffer
           
protected  int i
           
protected  boolean inWord
           
protected  StringBuilder nextWord
           
protected  List<String> words
           
 
Constructor Summary
KMLCoordinateTokenizer(String s)
          Create a tokenizer to read coordinates from a string.
 
Method Summary
 boolean hasMoreTokens()
          Are there more coordinates to read?
protected  Position makePosition()
           
 Position nextPosition()
          Read the next Position from the coordinate string.
protected  void wordBoundary()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

afterComma

protected boolean afterComma

buffer

protected char[] buffer

i

protected int i

inWord

protected boolean inWord

nextWord

protected StringBuilder nextWord

words

protected List<String> words
Constructor Detail

KMLCoordinateTokenizer

public KMLCoordinateTokenizer(String s)
Create a tokenizer to read coordinates from a string.

Parameters:
s - String to read from.
Method Detail

hasMoreTokens

public boolean hasMoreTokens()
Are there more coordinates to read?

Returns:
True if there are more coordinates to read from the string.

makePosition

protected Position makePosition()

nextPosition

public Position nextPosition()
                      throws NumberFormatException
Read the next Position from the coordinate string.

Returns:
Next Position, or null if an error occurs while parsing the position (number format exception, etc).
Throws:
NumberFormatException - if the coordinates cannot be parsed to a number.

wordBoundary

protected void wordBoundary()

NASA World Wind