CoordinateTransformWGS84toRDNew.java

  1. package org.opentrafficsim.core.gis;

  2. import java.awt.geom.Point2D;
  3. import java.io.Serializable;

  4. import nl.javel.gisbeans.io.esri.CoordinateTransform;

  5. /**
  6.  * Convert coordinates from WGS84 to the Dutch RD system. The coordinate transform can be offered to the gisbeans package when
  7.  * parsing GIS coordinates.
  8.  * <p>
  9.  * Copyright (c) 2013-2016 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
  10.  * BSD-style license. See <a href="http://opentrafficsim.org/docs/current/license.html">OpenTrafficSim License</a>.
  11.  * </p>
  12.  * $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $,
  13.  * initial version Oct 29, 2016 <br>
  14.  * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
  15.  * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
  16.  * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
  17.  */
  18. public class CoordinateTransformWGS84toRDNew implements CoordinateTransform, Serializable
  19. {
  20.     /** */
  21.     private static final long serialVersionUID = 20141017L;

  22.     /** the coordinate shift dx w.r.t. the origin if not in Amersfoort. dx will be subtracted from each RD.x coordinate */
  23.     private final double dx;

  24.     /** the coordinate shift dy w.r.t. the origin if not in Amersfoort. dy will be subtracted from each RD.y coordinate */
  25.     private final double dy;

  26.     /**
  27.      * @param dx the coordinate shift dx w.r.t. the origin if not in Amersfoort. dx will be subtracted from each RD.x coordinate
  28.      * @param dy the coordinate shift dy w.r.t. the origin if not in Amersfoort. dy will be subtracted from each RD.y coordinate
  29.      */
  30.     public CoordinateTransformWGS84toRDNew(final double dx, final double dy)
  31.     {
  32.         this.dx = dx;
  33.         this.dy = dy;
  34.     }

  35.     /** {@inheritDoc} */
  36.     @Override
  37.     public final float[] floatTransform(final double x, final double y)
  38.     {
  39.         double[] d = doubleTransform(x, y);
  40.         return new float[] { (float) d[0], (float) d[1] };
  41.     }

  42.     /** {@inheritDoc} */
  43.     @Override
  44.     public final double[] doubleTransform(final double x, final double y)
  45.     {
  46.         try
  47.         {
  48.             Point2D c = TransformWGS84DutchRDNew.fromWGS84(x, y);
  49.             return new double[] { c.getX() - this.dx, c.getY() - this.dy };
  50.         }
  51.         catch (Exception exception)
  52.         {
  53.             System.err.println(exception.getMessage());
  54.             return new double[] { 0, 0 };
  55.         }
  56.     }

  57.     /** {@inheritDoc} */
  58.     @Override
  59.     public final String toString()
  60.     {
  61.         return "CoordinateTransformRD [dx=" + this.dx + ", dy=" + this.dy + "]";
  62.     }
  63. }