org.geotoolkit.io.wkt
Class PrjFiles

Object
  extended by Static
      extended by PrjFiles

public final class PrjFiles
extends Static

Parses and formats PRJ files. Those files usually have the ".prj" suffix and contain the definition of exactly one Coordinate Reference System (CRS) in Well Known Text (WKT) format. This class allows the definition to span many lines, but the common practice is to provide the full WKT string on a single line.

If the definition is not a valid WKT string (during reads), or if a CRS can not be formatted as a WKT (during writes), then the methods in this class throw a ContentFormatException. This is a subclass of IOException and consequently does not require a try … catch block different than the one for normal I/O operations.

Every files are expected to use the ISO-8859-1 (a.k.a. ISO-LATIN-1) encoding.

Since:
3.05
Version:
3.07
Author:
Martin Desruisseaux (Geomatys)
Module:
referencing/geotk-referencing (download)    View source code for this class

Method Summary
static CoordinateReferenceSystem read(BufferedReader in, boolean close)
          Parses a PRJ file from a reader and returns its content as a coordinate reference system.
static CoordinateReferenceSystem read(File file)
          Parses a PRJ file and returns its content as a coordinate reference system.
static CoordinateReferenceSystem read(InputStream in, boolean close)
          Parses a PRJ file from a stream and returns its content as a coordinate reference system.
static CoordinateReferenceSystem read(ReadableByteChannel in, boolean close)
          Parses a PRJ file from a channel and returns its content as a coordinate reference system.
static CoordinateReferenceSystem read(URL file)
          Parses a PRJ file from a URL and returns its content as a coordinate reference system.
static void write(CoordinateReferenceSystem crs, File file)
          Formats a coordinate reference system as a PRJ file.
static void write(CoordinateReferenceSystem crs, OutputStream out)
          Formats a coordinate reference system as a PRJ file in the given stream.
static void write(CoordinateReferenceSystem crs, WritableByteChannel out)
          Formats a coordinate reference system as a PRJ file in the given channel.
static void write(CoordinateReferenceSystem crs, Writer out)
          Formats a coordinate reference system as a PRJ file in the given writer.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

read

public static CoordinateReferenceSystem read(File file)
                                      throws ContentFormatException,
                                             IOException
Parses a PRJ file and returns its content as a coordinate reference system.

Parameters:
file - The file to parse. It usually has the ".prj" suffix,
Returns:
The PRJ file content as a coordinate reference system.
Throws:
ContentFormatException - If the content of the PRJ file is an invalid WKT.
IOException - If the parsing failed for an other raison.

read

public static CoordinateReferenceSystem read(URL file)
                                      throws ContentFormatException,
                                             IOException
Parses a PRJ file from a URL and returns its content as a coordinate reference system.

Parameters:
file - The file to parse. It usually has the ".prj" suffix,
Returns:
The PRJ file content as a coordinate reference system.
Throws:
ContentFormatException - If the content of the PRJ file is an invalid WKT.
IOException - If the parsing failed for an other raison.

read

public static CoordinateReferenceSystem read(ReadableByteChannel in,
                                             boolean close)
                                      throws ContentFormatException,
                                             IOException
Parses a PRJ file from a channel and returns its content as a coordinate reference system. The given channel is not closed by this method, unless the close argument is set to true. The later case allows this method to close the channel sooner than what could be achieved if the channel was closed by the caller: before the WKT parsing begin.

Parameters:
in - The channel to read.
close - Whatever this method should close the channel.
Returns:
The PRJ file content as a coordinate reference system.
Throws:
ContentFormatException - If the content of the PRJ file is an invalid WKT.
IOException - If the parsing failed for an other raison.
Since:
3.07

read

public static CoordinateReferenceSystem read(InputStream in,
                                             boolean close)
                                      throws ContentFormatException,
                                             IOException
Parses a PRJ file from a stream and returns its content as a coordinate reference system. The given stream is not closed by this method, unless the close argument is set to true. The later case allows this method to close the stream sooner than what could be achieved if the stream was closed by the caller: before the WKT parsing begin.

Parameters:
in - The stream to read.
close - Whatever this method should close the stream.
Returns:
The PRJ file content as a coordinate reference system.
Throws:
ContentFormatException - If the content of the PRJ file is an invalid WKT.
IOException - If the parsing failed for an other raison.

read

public static CoordinateReferenceSystem read(BufferedReader in,
                                             boolean close)
                                      throws ContentFormatException,
                                             IOException
Parses a PRJ file from a reader and returns its content as a coordinate reference system. The given reader is not closed by this method, unless the close argument is set to true. The later case allows this method to close the reader sooner than what could be achieved if the reader was closed by the caller: before the WKT parsing begin.

Parameters:
in - The reader.
close - Whatever this method should close the reader.
Returns:
The PRJ file content as a coordinate reference system.
Throws:
ContentFormatException - If the content of the PRJ file is an invalid WKT.
IOException - If the parsing failed for an other raison.

write

public static void write(CoordinateReferenceSystem crs,
                         File file)
                  throws ContentFormatException,
                         IOException
Formats a coordinate reference system as a PRJ file. The file is created only if the given CRS is formattable.

Parameters:
crs - The PRJ file content as a coordinate reference system.
file - The file to create. It usually has the ".prj" suffix,
Throws:
ContentFormatException - if the given CRS is not formattable as a WKT.
IOException - If an other error occurred while writing the file.

write

public static void write(CoordinateReferenceSystem crs,
                         WritableByteChannel out)
                  throws ContentFormatException,
                         IOException
Formats a coordinate reference system as a PRJ file in the given channel. The channel is not closed by this method. It is caller responsibility to close it.

Parameters:
crs - The PRJ file content as a coordinate reference system.
out - The channel where to write.
Throws:
ContentFormatException - if the given CRS is not formattable as a WKT.
IOException - If an other error occurred while writing the file.
Since:
3.07

write

public static void write(CoordinateReferenceSystem crs,
                         OutputStream out)
                  throws ContentFormatException,
                         IOException
Formats a coordinate reference system as a PRJ file in the given stream. The stream is not closed by this method. It is caller responsibility to close it.

Parameters:
crs - The PRJ file content as a coordinate reference system.
out - The stream where to write.
Throws:
ContentFormatException - if the given CRS is not formattable as a WKT.
IOException - If an other error occurred while writing the file.

write

public static void write(CoordinateReferenceSystem crs,
                         Writer out)
                  throws ContentFormatException,
                         IOException
Formats a coordinate reference system as a PRJ file in the given writer. The writer is not closed by this method. It is caller responsibility to close it.

Parameters:
crs - The PRJ file content as a coordinate reference system.
out - The writer.
Throws:
ContentFormatException - if the given CRS is not formattable as a WKT.
IOException - If an other error occurred while writing the file.


Copyright © 2009-2011 Geotoolkit.org. All Rights Reserved.