Package gov.nasa.worldwind.ogc.kml
Class KMLCoordinateTokenizer
- java.lang.Object
-
- gov.nasa.worldwind.ogc.kml.KMLCoordinateTokenizer
-
public class KMLCoordinateTokenizer extends java.lang.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)
-
-
Constructor Summary
Constructors Constructor Description KMLCoordinateTokenizer(java.lang.String s)
Create a tokenizer to read coordinates from a string.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
hasMoreTokens()
Are there more coordinates to read?protected Position
makePosition()
Position
nextPosition()
Read the nextPosition
from the coordinate string.protected void
wordBoundary()
-
-
-
Method Detail
-
hasMoreTokens
public boolean hasMoreTokens()
Are there more coordinates to read?- Returns:
- True if there are more coordinates to read from the string.
-
nextPosition
public Position nextPosition() throws java.lang.NumberFormatException
Read the nextPosition
from the coordinate string.- Returns:
- Next Position, or null if an error occurs while parsing the position (number format exception, etc).
- Throws:
java.lang.NumberFormatException
- if the coordinates cannot be parsed to a number.
-
makePosition
protected Position makePosition()
-
wordBoundary
protected void wordBoundary()
-
-