org.kaboum.util
Class KaboumWKTReader

java.lang.Object
  extended by org.kaboum.util.KaboumWKTReader

public class KaboumWKTReader
extends java.lang.Object

Converts a Well-known Text string to a Geometry. The Well-known Text format is defined in the OpenGIS Simple Features Specification for SQL .

The WKTReader assume that the input numbers are in external representation. It will convert the input numbers to the internal representation


Constructor Summary
KaboumWKTReader(KaboumPrecisionModel precisionModel)
          Default constructor
 
Method Summary
protected  KaboumCoordinate[] getCoordinates(java.io.StreamTokenizer tokenizer)
          Returns the next array of Coordinates in the stream.
protected  java.lang.String getNextCloser(java.io.StreamTokenizer tokenizer)
          Returns the next ")" in the stream.
protected  java.lang.String getNextCloserOrComma(java.io.StreamTokenizer tokenizer)
          Returns the next ")" or "," in the stream.
protected  java.lang.String getNextEmptyOrOpener(java.io.StreamTokenizer tokenizer)
          Returns the next "EMPTY" or "(" in the stream as uppercase text.
protected  double getNextNumber(java.io.StreamTokenizer tokenizer)
          Returns the next number in the stream.
protected  java.lang.String getNextWord(java.io.StreamTokenizer tokenizer)
          Returns the next word in the stream as uppercase text.
 KaboumGeometry read(java.lang.String wellKnownText)
          Converts a Well-known Text representation to a Geometry.
protected  KaboumGeometryCollection readGeometryCollectionText(java.io.StreamTokenizer tokenizer)
          Creates a GeometryCollection using the next token in the stream.
protected  KaboumGeometry readGeometryTaggedText(java.io.StreamTokenizer tokenizer)
          Creates a Geometry using the next token in the stream.
protected  KaboumLinearRing readLinearRingText(java.io.StreamTokenizer tokenizer)
          Creates a LinearRing using the next token in the stream.
protected  KaboumLineString readLineStringText(java.io.StreamTokenizer tokenizer)
          Creates a LineString using the next token in the stream.
protected  KaboumMultiLineString readMultiLineStringText(java.io.StreamTokenizer tokenizer)
          Creates a MultiLineString using the next token in the stream.
protected  KaboumMultiPoint readMultiPointText(java.io.StreamTokenizer tokenizer)
          Creates a MultiPoint using the next token in the stream.
protected  KaboumMultiPolygon readMultiPolygonText(java.io.StreamTokenizer tokenizer)
          Creates a MultiPolygon using the next token in the stream.
protected  KaboumPoint readPointText(java.io.StreamTokenizer tokenizer)
          Creates a Point using the next token in the stream.
protected  KaboumPolygon readPolygonText(java.io.StreamTokenizer tokenizer)
          Creates a Polygon using the next token in the stream.
protected  KaboumPoint[] toPoints(KaboumCoordinate[] coordinates)
          Creates an array of Points having the given Coordinate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

KaboumWKTReader

public KaboumWKTReader(KaboumPrecisionModel precisionModel)
Default constructor

Method Detail

read

public KaboumGeometry read(java.lang.String wellKnownText)
                    throws java.lang.Exception
Converts a Well-known Text representation to a Geometry.

Parameters:
wellKnownText - a WKT string
Throws:
java.lang.Exception - if a parsing problem occurs

getCoordinates

protected KaboumCoordinate[] getCoordinates(java.io.StreamTokenizer tokenizer)
                                     throws java.lang.Exception
Returns the next array of Coordinates in the stream.

Parameters:
tokenizer - tokenizer over a stream of text in Well-known Text format. The next element returned by the stream should be "(" (the beginning of "(x1 y1, x2 y2, ..., xn yn)") or "EMPTY".
Throws:
java.lang.Exception - if an unexpected token was encountered

getNextNumber

protected double getNextNumber(java.io.StreamTokenizer tokenizer)
                        throws java.lang.Exception
Returns the next number in the stream.

Parameters:
tokenizer - tokenizer over a stream of text in Well-known Text format. The next token must be a number.
Throws:
java.lang.Exception - if an I/O error occurs

getNextEmptyOrOpener

protected java.lang.String getNextEmptyOrOpener(java.io.StreamTokenizer tokenizer)
                                         throws java.lang.Exception
Returns the next "EMPTY" or "(" in the stream as uppercase text.

Parameters:
tokenizer - tokenizer over a stream of text in Well-known Text format. The next token must be "EMPTY" or "(".
Throws:
java.lang.Exception - if an I/O error occurs

getNextCloserOrComma

protected java.lang.String getNextCloserOrComma(java.io.StreamTokenizer tokenizer)
                                         throws java.lang.Exception
Returns the next ")" or "," in the stream.

Parameters:
tokenizer - tokenizer over a stream of text in Well-known Text format. The next token must be ")" or ",".
Throws:
java.io.IOException - if an I/O error occurs
java.lang.Exception

getNextCloser

protected java.lang.String getNextCloser(java.io.StreamTokenizer tokenizer)
                                  throws java.lang.Exception
Returns the next ")" in the stream.

Parameters:
tokenizer - tokenizer over a stream of text in Well-known Text format. The next token must be ")".
Throws:
ParseException - if the next token is not ")"
java.lang.Exception

getNextWord

protected java.lang.String getNextWord(java.io.StreamTokenizer tokenizer)
                                throws java.lang.Exception
Returns the next word in the stream as uppercase text.

Parameters:
tokenizer - tokenizer over a stream of text in Well-known Text format. The next token must be a word.
Throws:
ParseException - if the next token is not a word
java.lang.Exception

readGeometryTaggedText

protected KaboumGeometry readGeometryTaggedText(java.io.StreamTokenizer tokenizer)
                                         throws java.lang.Exception
Creates a Geometry using the next token in the stream.

Parameters:
tokenizer - tokenizer over a stream of text in Well-known Text format. The next tokens must form a <Geometry Tagged Text>.
Throws:
java.lang.Exception - if the coordinates used to create a Polygon shell and holes do not form closed linestrings, or if an unexpected token was encountered

readPointText

protected KaboumPoint readPointText(java.io.StreamTokenizer tokenizer)
                             throws java.lang.Exception
Creates a Point using the next token in the stream.

Parameters:
tokenizer - tokenizer over a stream of text in Well-known Text format. The next tokens must form a <Point Text>.
Throws:
java.lang.Exception - if an I/O error occurs

readLineStringText

protected KaboumLineString readLineStringText(java.io.StreamTokenizer tokenizer)
                                       throws java.lang.Exception
Creates a LineString using the next token in the stream.

Parameters:
tokenizer - tokenizer over a stream of text in Well-known Text format. The next tokens must form a <LineString Text>.
Throws:
java.lang.Exception - if error occurs

readLinearRingText

protected KaboumLinearRing readLinearRingText(java.io.StreamTokenizer tokenizer)
                                       throws java.lang.Exception
Creates a LinearRing using the next token in the stream.

Parameters:
tokenizer - tokenizer over a stream of text in Well-known Text format. The next tokens must form a <LineString Text>.
Throws:
java.lang.Exception - if the coordinates used to create the LinearRing do not form a closed linestring, or if an unexpected token was encountered

readMultiPointText

protected KaboumMultiPoint readMultiPointText(java.io.StreamTokenizer tokenizer)
                                       throws java.lang.Exception
Creates a MultiPoint using the next token in the stream.

Parameters:
tokenizer - tokenizer over a stream of text in Well-known Text format. The next tokens must form a <MultiPoint Text>.
Throws:
ParseException - if an unexpected token was encountered
java.lang.Exception

toPoints

protected KaboumPoint[] toPoints(KaboumCoordinate[] coordinates)
Creates an array of Points having the given Coordinate

Parameters:
coordinates - the Coordinates with which to create the Points

readPolygonText

protected KaboumPolygon readPolygonText(java.io.StreamTokenizer tokenizer)
                                 throws java.lang.Exception
Creates a Polygon using the next token in the stream.

Parameters:
tokenizer - tokenizer over a stream of text in Well-known Text format. The next tokens must form a <Polygon Text>.
Throws:
java.lang.Exception - if an error occurs

readMultiLineStringText

protected KaboumMultiLineString readMultiLineStringText(java.io.StreamTokenizer tokenizer)
                                                 throws java.lang.Exception
Creates a MultiLineString using the next token in the stream.

Parameters:
tokenizer - tokenizer over a stream of text in Well-known Text format. The next tokens must form a <MultiLineString Text>.
Throws:
java.lang.Exception - if an unexpected token was encountered

readMultiPolygonText

protected KaboumMultiPolygon readMultiPolygonText(java.io.StreamTokenizer tokenizer)
                                           throws java.lang.Exception
Creates a MultiPolygon using the next token in the stream.

Parameters:
tokenizer - tokenizer over a stream of text in Well-known Text format. The next tokens must form a <MultiPolygon Text>.
Throws:
java.lang.Exception - if an unexpected token was encountered

readGeometryCollectionText

protected KaboumGeometryCollection readGeometryCollectionText(java.io.StreamTokenizer tokenizer)
                                                       throws java.lang.Exception
Creates a GeometryCollection using the next token in the stream.

Parameters:
tokenizer - tokenizer over a stream of text in Well-known Text format. The next tokens must form a <GeometryCollection Text>.
Throws:
ParseException - if the coordinates used to create a Polygon shell and holes do not form closed linestrings, or if an unexpected token was encountered
java.lang.Exception


Copyright © 2005 Kaboum team. All Rights Reserved.