Class EWKTWriter

java.lang.Object
org.gvsig.fmap.geom.jts.operation.towkt.EWKTWriter

public class EWKTWriter extends Object
Writes the Well-Known Text representation of a Geometry. The Well-Known Text format is defined in the OGC Simple Features Specification for SQL. See WKTReader for a formal specification of the format syntax.

The WKTWriter outputs coordinates rounded to the precision model. Only the maximum number of decimal places necessary to represent the ordinates to the required precision will be output.

The SFS WKT spec does not define a special tag for LinearRings. Under the spec, rings are output as LINESTRINGs. In order to allow precisely specifying constructed geometries, JTS also supports a non-standard LINEARRING tag which is used to output LinearRings.

Version:
1.7
See Also:
  • WKTReader
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new WKTWriter with default settings
    EWKTWriter(int outputDimension)
    Creates a writer that writes Geometrys with the given output dimension (between 2 and 4).
    EWKTWriter(int outputDimension, boolean hashM)
    Creates a writer that writes Geometrys with the given output dimension (between 2 and 4).
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    setFormatted(boolean isFormatted)
    Sets whether the output will be formatted.
    void
    setMaxCoordinatesPerLine(int coordsPerLine)
    Sets the maximum number of coordinates per line written in formatted output.
    void
    setTab(int size)
    Sets the tab size to use for indenting.
    static String
    stringOfChar(char ch, int count)
    Returns a String of repeated characters.
    static String
    toLineString(com.vividsolutions.jts.geom.Coordinate p0, com.vividsolutions.jts.geom.Coordinate p1)
    Generates the WKT for a LINESTRING specified by two Coordinates.
    static String
    toLineString(com.vividsolutions.jts.geom.CoordinateSequence seq)
    Generates the WKT for a LINESTRING specified by a CoordinateSequence.
    static String
    toPoint(com.vividsolutions.jts.geom.Coordinate p0)
    Generates the WKT for a POINT specified by a Coordinate.
    write(com.vividsolutions.jts.geom.Geometry geometry)
    Converts a Geometry to its Well-known Text representation.
    void
    write(com.vividsolutions.jts.geom.Geometry geometry, Writer writer)
    Converts a Geometry to its Well-known Text representation.
    writeFormatted(com.vividsolutions.jts.geom.Geometry geometry)
    Same as write, but with newlines and spaces to make the well-known text more readable.
    void
    writeFormatted(com.vividsolutions.jts.geom.Geometry geometry, Writer writer)
    Same as write, but with newlines and spaces to make the well-known text more readable.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • EWKTWriter

      public EWKTWriter()
      Creates a new WKTWriter with default settings
    • EWKTWriter

      public EWKTWriter(int outputDimension)
      Creates a writer that writes Geometrys with the given output dimension (between 2 and 4). If the specified output dimension is 3 or 4, the Z or M value of coordinates will be written if it is present (i.e. if it is not Double.NaN).
      Parameters:
      outputDimension - the coordinate dimension to output (between 2 and 4)
    • EWKTWriter

      public EWKTWriter(int outputDimension, boolean hashM)
      Creates a writer that writes Geometrys with the given output dimension (between 2 and 4). If the specified output dimension is 3 or 4, the Z or M value of coordinates will be written if it is present (i.e. if it is not Double.NaN).
      Parameters:
      outputDimension - the coordinate dimension to output (between 2 and 4)
  • Method Details

    • toPoint

      public static String toPoint(com.vividsolutions.jts.geom.Coordinate p0)
      Generates the WKT for a POINT specified by a Coordinate.
      Parameters:
      p0 - the point coordinate
      Returns:
      the WKT
    • toLineString

      public static String toLineString(com.vividsolutions.jts.geom.CoordinateSequence seq)
      Generates the WKT for a LINESTRING specified by a CoordinateSequence.
      Parameters:
      seq - the sequence to write
      Returns:
      the WKT string
    • toLineString

      public static String toLineString(com.vividsolutions.jts.geom.Coordinate p0, com.vividsolutions.jts.geom.Coordinate p1)
      Generates the WKT for a LINESTRING specified by two Coordinates.
      Parameters:
      p0 - the first coordinate
      p1 - the second coordinate
      Returns:
      the WKT
    • stringOfChar

      public static String stringOfChar(char ch, int count)
      Returns a String of repeated characters.
      Parameters:
      ch - the character to repeat
      count - the number of times to repeat the character
      Returns:
      a String of characters
    • setFormatted

      public void setFormatted(boolean isFormatted)
      Sets whether the output will be formatted.
      Parameters:
      isFormatted - true if the output is to be formatted
    • setMaxCoordinatesPerLine

      public void setMaxCoordinatesPerLine(int coordsPerLine)
      Sets the maximum number of coordinates per line written in formatted output. If the provided coordinate number is invalid input: '<'= 0, coordinates will be written all on one line.
      Parameters:
      coordsPerLine - the number of coordinates per line to output.
    • setTab

      public void setTab(int size)
      Sets the tab size to use for indenting.
      Parameters:
      size - the number of spaces to use as the tab string
      Throws:
      IllegalArgumentException - if the size is non-positive
    • write

      public String write(com.vividsolutions.jts.geom.Geometry geometry)
      Converts a Geometry to its Well-known Text representation.
      Parameters:
      geometry - a Geometry to process
      Returns:
      a string (see the OpenGIS Simple Features Specification)
    • write

      public void write(com.vividsolutions.jts.geom.Geometry geometry, Writer writer) throws IOException
      Converts a Geometry to its Well-known Text representation.
      Parameters:
      geometry - a Geometry to process
      Throws:
      IOException
    • writeFormatted

      public String writeFormatted(com.vividsolutions.jts.geom.Geometry geometry)
      Same as write, but with newlines and spaces to make the well-known text more readable.
      Parameters:
      geometry - a Geometry to process
      Returns:
      a string (see the OpenGIS Simple Features Specification), with newlines and spaces
    • writeFormatted

      public void writeFormatted(com.vividsolutions.jts.geom.Geometry geometry, Writer writer) throws IOException
      Same as write, but with newlines and spaces to make the well-known text more readable.
      Parameters:
      geometry - a Geometry to process
      Throws:
      IOException