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. import nl.tudelft.simulation.dsol.logger.SimLogger;

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

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

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

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

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

  45.     /** {@inheritDoc} */
  46.     @Override
  47.     public final double[] doubleTransform(final double x, final double y)
  48.     {
  49.         try
  50.         {
  51.             Point2D c = TransformWGS84DutchRDNew.fromWGS84(x, y);
  52.             return new double[] {c.getX() - this.dx, c.getY() - this.dy};
  53.         }
  54.         catch (Exception exception)
  55.         {
  56.             SimLogger.always().error(exception);
  57.             return new double[] {0, 0};
  58.         }
  59.     }

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