public class KMLCoordinateTokenizer
extends java.lang.Object
-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,44Will 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,2Will be tokenized to two coordinates: (23.56, -18.3, 9), (56.0, 34.9, 2)
Modifier and Type | Field and Description |
---|---|
protected boolean |
afterComma |
protected char[] |
buffer |
protected int |
i |
protected boolean |
inWord |
protected java.lang.StringBuilder |
nextWord |
protected java.util.List<java.lang.String> |
words |
Constructor and Description |
---|
KMLCoordinateTokenizer(java.lang.String s)
Create a tokenizer to read coordinates from a string.
|
Modifier and Type | Method and Description |
---|---|
boolean |
hasMoreTokens()
Are there more coordinates to read?
|
protected Position |
makePosition() |
Position |
nextPosition()
Read the next
Position from the coordinate string. |
protected void |
wordBoundary() |
protected boolean afterComma
protected char[] buffer
protected int i
protected boolean inWord
protected java.lang.StringBuilder nextWord
protected java.util.List<java.lang.String> words
public KMLCoordinateTokenizer(java.lang.String s)
s
- String to read from.public boolean hasMoreTokens()
protected Position makePosition()
public Position nextPosition() throws java.lang.NumberFormatException
Position
from the coordinate string.java.lang.NumberFormatException
- if the coordinates cannot be parsed to a number.protected void wordBoundary()