input
Class WKTReader

java.lang.Object
  extended by input.WKTReader
Direct Known Subclasses:
WKTMapReader

public class WKTReader
extends java.lang.Object

Class for reading "Well-known text syntax" files. See e.g. Wikipedia for WKT syntax details. For example, Open JUMP GIS program can save compatible data from many other formats.


Field Summary
static java.lang.String LINESTRING
          known WKT type LINESTRING
static java.lang.String MULTILINESTRING
          known WKT type MULTILINESTRING
static java.lang.String POINT
          known WKT type POINT
 
Constructor Summary
WKTReader()
           
 
Method Summary
protected  void init(java.io.Reader input)
          Initialize the reader to use a certain input reader
protected  boolean isDone()
          Returns true if the whole file has been read
protected  boolean isKnownType(java.lang.String type)
          Returns true if type is one of the known WKT types
protected  java.lang.String nextType()
          Returns the next type read from the reader given at init or null if no more types can be read
protected  java.util.List<Coord> parseLineString(java.lang.String line)
          Parses coordinate tuples from "LINESTRING" lines
protected  java.util.List<java.util.List<Coord>> parseMultilinestring()
          Parses a MULTILINESTRING statement that has nested linestrings from the current reader
protected  Coord parsePoint()
          Parses a WKT point data from the intialized reader
 java.util.List<java.util.List<Coord>> readLines(java.io.File file)
          Read line (LINESTRING) data from a file
 java.lang.String readNestedContents()
          Returns nested contents from the reader given at init
 java.lang.String readNestedContents(java.io.Reader r)
          Reads everything from the first opening parenthesis until line that ends to a closing parenthesis and returns the contents in one string
 java.util.List<Coord> readPoints(java.io.File file)
          Read point data from a file
 java.util.List<Coord> readPoints(java.io.Reader r)
          Read point data from a Reader
protected  java.lang.String readWord(java.io.Reader r)
          Reads a "word", ie whitespace delimited string of characters, from the reader
protected  void setDone(boolean done)
          Sets the "is file read" state
protected  char skipAllWhitespace(java.io.Reader r)
          Skips all consecutive whitespace characters from reader
protected  void skipUntil(java.io.Reader r, char until)
          Reads and skips all characters until character "until" is read or end of stream is reached.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LINESTRING

public static final java.lang.String LINESTRING
known WKT type LINESTRING

See Also:
Constant Field Values

MULTILINESTRING

public static final java.lang.String MULTILINESTRING
known WKT type MULTILINESTRING

See Also:
Constant Field Values

POINT

public static final java.lang.String POINT
known WKT type POINT

See Also:
Constant Field Values
Constructor Detail

WKTReader

public WKTReader()
Method Detail

readPoints

public java.util.List<Coord> readPoints(java.io.File file)
                                 throws java.io.IOException
Read point data from a file

Parameters:
file - The file to read points from
Returns:
A list of coordinates read from the file
Throws:
java.io.IOException - if something went wrong while reading

readPoints

public java.util.List<Coord> readPoints(java.io.Reader r)
                                 throws java.io.IOException
Read point data from a Reader

Parameters:
r - The Reader to read points from
Returns:
A list of coordinates that were read
Throws:
java.io.IOException - if something went wrong while reading

readLines

public java.util.List<java.util.List<Coord>> readLines(java.io.File file)
                                                throws java.io.IOException
Read line (LINESTRING) data from a file

Parameters:
file - The file to read data from
Returns:
A list of coordinate lists read from the file
Throws:
java.io.IOException - if something went wrong while reading

init

protected void init(java.io.Reader input)
Initialize the reader to use a certain input reader

Parameters:
input - The input to use

nextType

protected java.lang.String nextType()
                             throws java.io.IOException
Returns the next type read from the reader given at init or null if no more types can be read

Returns:
the next type read from the reader given at init
Throws:
java.io.IOException

isKnownType

protected boolean isKnownType(java.lang.String type)
Returns true if type is one of the known WKT types

Parameters:
type - The type to check
Returns:
true if type is one of the known WKT types

readWord

protected java.lang.String readWord(java.io.Reader r)
                             throws java.io.IOException
Reads a "word", ie whitespace delimited string of characters, from the reader

Parameters:
r - Reader to read the characters from
Returns:
The word that was read (or empty string if nothing was read)
Throws:
java.io.IOException

parseMultilinestring

protected java.util.List<java.util.List<Coord>> parseMultilinestring()
                                                              throws java.io.IOException
Parses a MULTILINESTRING statement that has nested linestrings from the current reader

Returns:
List of parsed Coord lists
Throws:
java.io.IOException

parsePoint

protected Coord parsePoint()
                    throws java.io.IOException
Parses a WKT point data from the intialized reader

Returns:
Point data as a Coordinate
Throws:
java.io.IOException - if couldn't parse coordinate values

skipUntil

protected void skipUntil(java.io.Reader r,
                         char until)
                  throws java.io.IOException
Reads and skips all characters until character "until" is read or end of stream is reached. Also the expected character is discarded.

Parameters:
r - Reader to read characters from
until - What character to expect
Throws:
java.io.IOException

skipAllWhitespace

protected char skipAllWhitespace(java.io.Reader r)
                          throws java.io.IOException
Skips all consecutive whitespace characters from reader

Parameters:
r - Reader where the whitespace is skipped
Returns:
First non-whitespace character read from the reader
Throws:
java.io.IOException

readNestedContents

public java.lang.String readNestedContents(java.io.Reader r)
                                    throws java.io.IOException
Reads everything from the first opening parenthesis until line that ends to a closing parenthesis and returns the contents in one string

Parameters:
r - Reader to read the input from
Returns:
The text between the parentheses
Throws:
java.io.IOException

readNestedContents

public java.lang.String readNestedContents()
                                    throws java.io.IOException
Returns nested contents from the reader given at init

Returns:
nested contents from the reader given at init
Throws:
java.io.IOException
See Also:
readNestedContents(Reader)

parseLineString

protected java.util.List<Coord> parseLineString(java.lang.String line)
Parses coordinate tuples from "LINESTRING" lines

Parameters:
line - String that contains the whole "LINESTRING"'s content
Returns:
List of coordinates parsed from the linestring

isDone

protected boolean isDone()
Returns true if the whole file has been read

Returns:
true if the whole file has been read

setDone

protected void setDone(boolean done)
Sets the "is file read" state

Parameters:
done - If true, reading is done