/* * GeoTools - The Open Source Java GIS Toolkit * http://geotools.org * * (C) 2004-2008, Open Source Geospatial Foundation (OSGeo) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * version 2.1 of the License. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. */ package org.geotools.referencing; import java.io.FileReader; import java.io.IOException; import java.io.LineNumberReader; import java.text.DecimalFormat; import java.text.NumberFormat; import java.text.ParsePosition; import java.text.ParseException; import java.util.Arrays; import java.util.Locale; import java.util.StringTokenizer; import org.opengis.referencing.FactoryException; import org.opengis.referencing.crs.CoordinateReferenceSystem; import org.opengis.referencing.operation.CoordinateOperationFactory; import org.opengis.referencing.operation.MathTransform; import org.opengis.referencing.operation.NoninvertibleTransformException; import org.opengis.referencing.operation.TransformException; import org.opengis.geometry.DirectPosition; import org.opengis.geometry.MismatchedDimensionException; import org.geotools.geometry.GeneralDirectPosition; import org.geotools.io.TableWriter; import org.geotools.measure.Measure; import org.geotools.referencing.crs.AbstractCRS; import org.geotools.referencing.wkt.AbstractConsole; import org.geotools.referencing.wkt.Parser; import org.geotools.referencing.wkt.Preprocessor; import org.geotools.resources.Arguments; import org.geotools.resources.i18n.Errors; import org.geotools.resources.i18n.ErrorKeys; import org.geotools.resources.i18n.Vocabulary; import org.geotools.resources.i18n.VocabularyKeys; /** * A console for executing CRS operations from the command line. * Instructions are read from the {@linkplain System#in standard input stream} * and results are sent to the {@linkplain System#out standard output stream}. * Instructions include: * *
{@code SET} name {@code =} wkt | * Set the specified name as a shortcut for the specified Well Know * Text (wkt). This WKT can contains other shortcuts defined previously. |
{@code transform = } wkt | * Set explicitly a {@linkplain MathTransform math transform} to use for * coordinate transformations. This instruction is a more direct alternative to the usage of * {@code source crs} and {@code target crs} instruction. |
{@code source crs = } wkt | * Set the source {@linkplain CoordinateReferenceSystem coordinate reference * system} to the specified object. This object can be specified as a Well Know Text * (wkt) or as a shortcut previously set. |
{@code target crs = } wkt | * Set the target {@linkplain CoordinateReferenceSystem coordinate reference * system} to the specified object. This object can be specified as a Well Know Text * (wkt) or as a shortcut previously set. Once both source and target * CRS are specified a {@linkplain MathTransform math transform} from source to * target CRS is automatically infered. |
{@code source pt = } coord | * Transforms the specified coordinates from source CRS to target CRS * and prints the result. |
{@code target pt = } coord | * Inverse transforms the specified coordinates from target CRS to source CRS * and prints the result. |
{@code test tolerance = } vector | * Set the maximum difference between the transformed source point and the * target point. Once this value is set, every occurence of the {@code target pt} instruction * will trig this comparaison. If a greater difference is found, an exception is thrown or a * message is printed to the error stream. |
{@code print set} | * Prints the set of shortcuts defined in previous calls to {@code SET} instruction. |
{@code print crs} | * Prints the source and target {@linkplain CoordinateReferenceSystem coordinate reference system} * {@linkplain MathTransform math transform} and its inverse as Well Know Text (wkt). |
{@code print pts} | * Prints the source and target points, their transformed points, and the distance between * them. |
{@code exit} | * Quit the console. |
*
-load <filename> |
* Load a definition file before to run instructions from * the standard input stream. |
-encoding <code> |
* Set the character encoding. |
-locale <language> |
* Set the language for the output (e.g. "fr" for French). |
* (46.69439222, 13.91405611, 41.21) ** * @param text The vector to parse. * @return The vector as floating point numbers. * @throws ParseException if a number can't be parsed. */ private double[] parseVector(String text) throws ParseException { text = removeDelimitors(text, '(', ')'); final StringTokenizer st = new StringTokenizer(text, numberSeparator); final double[] values = new double[st.countTokens()]; for (int i=0; i