Class SVGWriter


  • public class SVGWriter
    extends java.lang.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
      SVGWriter()
      Creates a new SVGWriter with default settings
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private void appendCoordinate​(Coordinate coordinate, java.io.Writer writer)
      Converts a Coordinate to <Point> format, then appends it to the writer.
      private void appendCoordinate​(CoordinateSequence seq, int i, java.io.Writer writer)
      Appends the i'th coordinate from the sequence to the writer
      private void appendGeometryCollectionTaggedText​(GeometryCollection geometryCollection, int level, java.io.Writer writer)
      Converts a GeometryCollection to <GeometryCollection Tagged Text> format, then appends it to the writer.
      private void appendGeometryCollectionText​(GeometryCollection geometryCollection, int level, java.io.Writer writer)
      Converts a GeometryCollection to <GeometryCollectionText> format, then appends it to the writer.
      private void appendGeometryTaggedText​(Geometry geometry, int level, java.io.Writer writer)
      Converts a Geometry to <Geometry Tagged Text> format, then appends it to the writer.
      private void appendLinearRingTaggedText​(LinearRing linearRing, int level, java.io.Writer writer)
      Converts a LinearRing to <LinearRing Tagged Text> format, then appends it to the writer.
      private void appendLineString​(LineString lineString, int level, boolean doIndent, java.io.Writer writer)
      Converts a LineString to <LineString Text> format, then appends it to the writer.
      private void appendLineStringTaggedText​(LineString lineString, int level, java.io.Writer writer)
      Converts a LineString to <LineString Tagged Text> format, then appends it to the writer.
      private void appendMultiLineStringTaggedText​(MultiLineString multiLineString, int level, java.io.Writer writer)
      Converts a MultiLineString to <MultiLineString Tagged Text> format, then appends it to the writer.
      private void appendMultiLineStringText​(MultiLineString multiLineString, int level, boolean indentFirst, java.io.Writer writer)
      Converts a MultiLineString to <MultiLineString Text> format, then appends it to the writer.
      private void appendMultiPointTaggedText​(MultiPoint multipoint, int level, java.io.Writer writer)
      Converts a MultiPoint to <MultiPoint Tagged Text> format, then appends it to the writer.
      private void appendMultiPointText​(MultiPoint multiPoint, int level, java.io.Writer writer)
      Converts a MultiPoint to <MultiPoint Text> format, then appends it to the writer.
      private void appendMultiPolygonTaggedText​(MultiPolygon multiPolygon, int level, java.io.Writer writer)
      Converts a MultiPolygon to <MultiPolygon Tagged Text> format, then appends it to the writer.
      private void appendMultiPolygonText​(MultiPolygon multiPolygon, int level, java.io.Writer writer)
      Converts a MultiPolygon to <MultiPolygon Text> format, then appends it to the writer.
      private void appendPathEnd​(java.io.Writer writer)  
      private void appendPathStart​(boolean useFillRule, java.io.Writer writer)  
      private void appendPoint​(Coordinate coordinate, int level, java.io.Writer writer, PrecisionModel precisionModel)
      Converts a Coordinate to <Point Text> format, then appends it to the writer.
      private void appendPointTaggedText​(Coordinate coordinate, int level, java.io.Writer writer, PrecisionModel precisionModel)
      Converts a Coordinate to <Point Tagged Text> format, then appends it to the writer.
      private void appendPolygon​(Polygon polygon, int level, java.io.Writer writer)
      Converts a Polygon to <Polygon Tagged Text> format, then appends it to the writer.
      private void appendPolygonPath​(Polygon polygon, int level, boolean indentFirst, java.io.Writer writer)  
      private void appendPolygonPolygon​(Polygon polygon, int level, boolean indentFirst, java.io.Writer writer)
      Converts a Polygon to <Polygon Text> format, then appends it to the writer.
      private void appendSequencePath​(CoordinateSequence seq, int level, boolean doIndent, java.io.Writer writer)
      Converts a LineString to <LineString Text> format, then appends it to the writer.
      private void appendSequencePoints​(CoordinateSequence seq, int level, boolean doIndent, java.io.Writer writer)  
      private static java.text.DecimalFormat createFormatter​(PrecisionModel precisionModel)
      Creates the DecimalFormat used to write doubles with a sufficient number of decimal places.
      private void indent​(int level, java.io.Writer writer)  
      private void indentCoords​(int coordIndex, int level, java.io.Writer writer)  
      static java.lang.String stringOfChar​(char ch, int count)
      Returns a String of repeated characters.
      java.lang.String write​(Geometry geometry)
      Converts a Geometry to its Well-known Text representation.
      void write​(Geometry geometry, java.io.Writer writer)
      Converts a Geometry to its Well-known Text representation.
      java.lang.String writeFormatted​(Geometry geometry)
      Same as write, but with newlines and spaces to make the well-known text more readable.
      private void writeFormatted​(Geometry geometry, boolean useFormatting, java.io.Writer writer)
      Converts a Geometry to its Well-known Text representation.
      void writeFormatted​(Geometry geometry, java.io.Writer writer)
      Same as write, but with newlines and spaces to make the well-known text more readable.
      private java.lang.String writeNumber​(double d)
      Converts a double to a String, not in scientific notation.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • outputDimension

        private int outputDimension
      • formatter

        private java.text.DecimalFormat formatter
      • isFormatted

        private boolean isFormatted
      • useFormatting

        private boolean useFormatting
      • level

        private int level
      • coordsPerLine

        private int coordsPerLine
      • indentTabStr

        private java.lang.String indentTabStr
    • Constructor Detail

      • SVGWriter

        public SVGWriter()
        Creates a new SVGWriter with default settings
    • Method Detail

      • createFormatter

        private static java.text.DecimalFormat createFormatter​(PrecisionModel precisionModel)
        Creates the DecimalFormat used to write doubles with a sufficient number of decimal places.
        Parameters:
        precisionModel - the PrecisionModel used to determine the number of decimal places to write.
        Returns:
        a DecimalFormat that write double s without scientific notation.
      • stringOfChar

        public static java.lang.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
      • write

        public java.lang.String write​(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​(Geometry geometry,
                          java.io.Writer writer)
                   throws java.io.IOException
        Converts a Geometry to its Well-known Text representation.
        Parameters:
        geometry - a Geometry to process
        Throws:
        java.io.IOException
      • writeFormatted

        public java.lang.String writeFormatted​(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​(Geometry geometry,
                                   java.io.Writer writer)
                            throws java.io.IOException
        Same as write, but with newlines and spaces to make the well-known text more readable.
        Parameters:
        geometry - a Geometry to process
        Throws:
        java.io.IOException
      • writeFormatted

        private void writeFormatted​(Geometry geometry,
                                    boolean useFormatting,
                                    java.io.Writer writer)
                             throws java.io.IOException
        Converts a Geometry to its Well-known Text representation.
        Parameters:
        geometry - a Geometry to process
        Throws:
        java.io.IOException
      • appendGeometryTaggedText

        private void appendGeometryTaggedText​(Geometry geometry,
                                              int level,
                                              java.io.Writer writer)
                                       throws java.io.IOException
        Converts a Geometry to <Geometry Tagged Text> format, then appends it to the writer.
        Parameters:
        geometry - the Geometry to process
        writer - the output writer to append to
        Throws:
        java.io.IOException
      • appendPointTaggedText

        private void appendPointTaggedText​(Coordinate coordinate,
                                           int level,
                                           java.io.Writer writer,
                                           PrecisionModel precisionModel)
                                    throws java.io.IOException
        Converts a Coordinate to <Point Tagged Text> format, then appends it to the writer.
        Parameters:
        coordinate - the Coordinate to process
        writer - the output writer to append to
        precisionModel - the PrecisionModel to use to convert from a precise coordinate to an external coordinate
        Throws:
        java.io.IOException
      • appendLineStringTaggedText

        private void appendLineStringTaggedText​(LineString lineString,
                                                int level,
                                                java.io.Writer writer)
                                         throws java.io.IOException
        Converts a LineString to <LineString Tagged Text> format, then appends it to the writer.
        Parameters:
        lineString - the LineString to process
        writer - the output writer to append to
        Throws:
        java.io.IOException
      • appendLinearRingTaggedText

        private void appendLinearRingTaggedText​(LinearRing linearRing,
                                                int level,
                                                java.io.Writer writer)
                                         throws java.io.IOException
        Converts a LinearRing to <LinearRing Tagged Text> format, then appends it to the writer.
        Parameters:
        linearRing - the LinearRing to process
        writer - the output writer to append to
        Throws:
        java.io.IOException
      • appendPolygon

        private void appendPolygon​(Polygon polygon,
                                   int level,
                                   java.io.Writer writer)
                            throws java.io.IOException
        Converts a Polygon to <Polygon Tagged Text> format, then appends it to the writer.
        Parameters:
        polygon - the Polygon to process
        writer - the output writer to append to
        Throws:
        java.io.IOException
      • appendMultiPointTaggedText

        private void appendMultiPointTaggedText​(MultiPoint multipoint,
                                                int level,
                                                java.io.Writer writer)
                                         throws java.io.IOException
        Converts a MultiPoint to <MultiPoint Tagged Text> format, then appends it to the writer.
        Parameters:
        multipoint - the MultiPoint to process
        writer - the output writer to append to
        Throws:
        java.io.IOException
      • appendMultiLineStringTaggedText

        private void appendMultiLineStringTaggedText​(MultiLineString multiLineString,
                                                     int level,
                                                     java.io.Writer writer)
                                              throws java.io.IOException
        Converts a MultiLineString to <MultiLineString Tagged Text> format, then appends it to the writer.
        Parameters:
        multiLineString - the MultiLineString to process
        writer - the output writer to append to
        Throws:
        java.io.IOException
      • appendMultiPolygonTaggedText

        private void appendMultiPolygonTaggedText​(MultiPolygon multiPolygon,
                                                  int level,
                                                  java.io.Writer writer)
                                           throws java.io.IOException
        Converts a MultiPolygon to <MultiPolygon Tagged Text> format, then appends it to the writer.
        Parameters:
        multiPolygon - the MultiPolygon to process
        writer - the output writer to append to
        Throws:
        java.io.IOException
      • appendGeometryCollectionTaggedText

        private void appendGeometryCollectionTaggedText​(GeometryCollection geometryCollection,
                                                        int level,
                                                        java.io.Writer writer)
                                                 throws java.io.IOException
        Converts a GeometryCollection to <GeometryCollection Tagged Text> format, then appends it to the writer.
        Parameters:
        geometryCollection - the GeometryCollection to process
        writer - the output writer to append to
        Throws:
        java.io.IOException
      • appendPoint

        private void appendPoint​(Coordinate coordinate,
                                 int level,
                                 java.io.Writer writer,
                                 PrecisionModel precisionModel)
                          throws java.io.IOException
        Converts a Coordinate to <Point Text> format, then appends it to the writer.
        Parameters:
        coordinate - the Coordinate to process
        writer - the output writer to append to
        precisionModel - the PrecisionModel to use to convert from a precise coordinate to an external coordinate
        Throws:
        java.io.IOException
      • appendCoordinate

        private void appendCoordinate​(CoordinateSequence seq,
                                      int i,
                                      java.io.Writer writer)
                               throws java.io.IOException
        Appends the i'th coordinate from the sequence to the writer
        Parameters:
        seq - the CoordinateSequence to process
        i - the index of the coordinate to write
        writer - the output writer to append to
        Throws:
        java.io.IOException
      • appendCoordinate

        private void appendCoordinate​(Coordinate coordinate,
                                      java.io.Writer writer)
                               throws java.io.IOException
        Converts a Coordinate to <Point> format, then appends it to the writer.
        Parameters:
        coordinate - the Coordinate to process
        writer - the output writer to append to
        Throws:
        java.io.IOException
      • writeNumber

        private java.lang.String writeNumber​(double d)
        Converts a double to a String, not in scientific notation.
        Parameters:
        d - the double to convert
        Returns:
        the double as a String, not in scientific notation
      • appendSequencePath

        private void appendSequencePath​(CoordinateSequence seq,
                                        int level,
                                        boolean doIndent,
                                        java.io.Writer writer)
                                 throws java.io.IOException
        Converts a LineString to <LineString Text> format, then appends it to the writer.
        Parameters:
        lineString - the LineString to process
        writer - the output writer to append to
        Throws:
        java.io.IOException
      • appendSequencePoints

        private void appendSequencePoints​(CoordinateSequence seq,
                                          int level,
                                          boolean doIndent,
                                          java.io.Writer writer)
                                   throws java.io.IOException
        Throws:
        java.io.IOException
      • appendLineString

        private void appendLineString​(LineString lineString,
                                      int level,
                                      boolean doIndent,
                                      java.io.Writer writer)
                               throws java.io.IOException
        Converts a LineString to <LineString Text> format, then appends it to the writer.
        Parameters:
        lineString - the LineString to process
        writer - the output writer to append to
        Throws:
        java.io.IOException
      • appendPolygonPolygon

        private void appendPolygonPolygon​(Polygon polygon,
                                          int level,
                                          boolean indentFirst,
                                          java.io.Writer writer)
                                   throws java.io.IOException
        Converts a Polygon to <Polygon Text> format, then appends it to the writer.
        Parameters:
        polygon - the Polygon to process
        writer - the output writer to append to
        Throws:
        java.io.IOException
      • appendPolygonPath

        private void appendPolygonPath​(Polygon polygon,
                                       int level,
                                       boolean indentFirst,
                                       java.io.Writer writer)
                                throws java.io.IOException
        Throws:
        java.io.IOException
      • appendPathStart

        private void appendPathStart​(boolean useFillRule,
                                     java.io.Writer writer)
                              throws java.io.IOException
        Throws:
        java.io.IOException
      • appendPathEnd

        private void appendPathEnd​(java.io.Writer writer)
                            throws java.io.IOException
        Throws:
        java.io.IOException
      • appendMultiPointText

        private void appendMultiPointText​(MultiPoint multiPoint,
                                          int level,
                                          java.io.Writer writer)
                                   throws java.io.IOException
        Converts a MultiPoint to <MultiPoint Text> format, then appends it to the writer.
        Parameters:
        multiPoint - the MultiPoint to process
        writer - the output writer to append to
        Throws:
        java.io.IOException
      • appendMultiLineStringText

        private void appendMultiLineStringText​(MultiLineString multiLineString,
                                               int level,
                                               boolean indentFirst,
                                               java.io.Writer writer)
                                        throws java.io.IOException
        Converts a MultiLineString to <MultiLineString Text> format, then appends it to the writer.
        Parameters:
        multiLineString - the MultiLineString to process
        writer - the output writer to append to
        Throws:
        java.io.IOException
      • appendMultiPolygonText

        private void appendMultiPolygonText​(MultiPolygon multiPolygon,
                                            int level,
                                            java.io.Writer writer)
                                     throws java.io.IOException
        Converts a MultiPolygon to <MultiPolygon Text> format, then appends it to the writer.
        Parameters:
        multiPolygon - the MultiPolygon to process
        writer - the output writer to append to
        Throws:
        java.io.IOException
      • appendGeometryCollectionText

        private void appendGeometryCollectionText​(GeometryCollection geometryCollection,
                                                  int level,
                                                  java.io.Writer writer)
                                           throws java.io.IOException
        Converts a GeometryCollection to <GeometryCollectionText> format, then appends it to the writer.
        Parameters:
        geometryCollection - the GeometryCollection to process
        writer - the output writer to append to
        Throws:
        java.io.IOException
      • indentCoords

        private void indentCoords​(int coordIndex,
                                  int level,
                                  java.io.Writer writer)
                           throws java.io.IOException
        Throws:
        java.io.IOException
      • indent

        private void indent​(int level,
                            java.io.Writer writer)
                     throws java.io.IOException
        Throws:
        java.io.IOException