/*
 * Licensed Materials - Property of Perforce Software, Inc. 
 * © Copyright Perforce Software, Inc. 2014, 2021 
 * © Copyright IBM Corp. 2009, 2014
 * © Copyright ILOG 1996, 2009
 * All Rights Reserved.
 *
 * Note to U.S. Government Users Restricted Rights:
 * The Software and Documentation were developed at private expense and
 * are "Commercial Items" as that term is defined at 48 CFR 2.101,
 * consisting of "Commercial Computer Software" and
 * "Commercial Computer Software Documentation", as such terms are
 * used in 48 CFR 12.212 or 48 CFR 227.7202-1 through 227.7202-4,
 * as applicable.
 */

import ilog.views.maps.IlvAngularUnit;
import ilog.views.maps.IlvCoordinate;
import ilog.views.maps.IlvLinearUnit;
import ilog.views.maps.IlvUnit;
import ilog.views.maps.projection.IlvHorizontalShiftDatum;
import ilog.views.maps.srs.coordsys.IlvGeographicCoordinateSystem;
import ilog.views.maps.srs.coordsys.IlvMeridian;
import ilog.views.maps.srs.coordtrans.IlvCoordinateTransformation;
import ilog.views.maps.srs.coordtrans.IlvCoordinateTransformationException;

public class Sample3 {

  public void staticDef() {
    IlvLinearUnit unit = IlvLinearUnit.FT;
    double meters = 100D;
    double feet = unit.fromMeters(meters);
    System.out.println("100 m = " + feet + " ft");
    // The following is also valid, as the kernel unit for lengths
    // is the meter.
//    double other_feet = unit.fromKernel(meters);
    System.out.println("100 m = " + feet + " ft");
  }

  public void registeredDef() {
    IlvUnit unit = IlvUnit.GetRegisteredUnit("ft");
    double meters = 100D;
    double feet = unit.fromKernel(meters);
    System.out.println("100 m = " + feet + " ft");
  }

  public void geoGrad() throws IlvCoordinateTransformationException {
    IlvAngularUnit unit = IlvAngularUnit.GRAD;
    IlvGeographicCoordinateSystem gcs = new IlvGeographicCoordinateSystem("My coordsys", IlvHorizontalShiftDatum.WGS84,
        IlvMeridian.GREENWICH, unit, null); // No altitude

    // A transformation from WGS84 geographic coordinate system
    // with degrees as unit to our own coordinate system:
    IlvCoordinateTransformation ct = IlvCoordinateTransformation
        .CreateTransformation(IlvGeographicCoordinateSystem.WGS84, gcs);

    // Example of conversion.
    double lambda = IlvAngularUnit.DEGREE.toRadians(-45D);
    double phi = IlvAngularUnit.DEGREE.toRadians(30D);
    IlvCoordinate coord = new IlvCoordinate(lambda, phi);

    // Convert coordinate, letting the transformation allocate the
    // result.
    IlvCoordinate result = ct.transform(coord, null);

    System.out.println("The expression of point 45W 30N is ");
    System.out.println("x = " + coord.x + " grad");
    System.out.println("y = " + coord.y + " grad");
  }
}