将公共类转移到Java中的抽象类

时间:2014-08-01 10:24:02

标签: java interface abstract-class

我几乎是Java编程的新手。我想在MATSim中实现以下代码(这是一个用于城市规划目的的模拟程序)。此代码用于将WGS84(经度和纬度)转换为OSGB36(英国国家电网)。

https://gist.github.com/schoenobates/3497544#file-osgb-java

MATSim库有一个接口(如下),用于将转换代码放入其中并用于视觉模拟。

我已经多次尝试过处理错误,但它并没有帮助我。你能否告诉我一些关于如何做到这一点的想法。

package org.matsim.core.utils.geometry;

import org.matsim.api.core.v01.Coord;


/**
 * A simple interface to convert coordinates from one coordinate system to
 * another one.
 *
 * @author mrieser
 */
public interface CoordinateTransformation {

    /**
     * Transforms the given coordinate from one coordinate system to the other.
     *
     * @param coord The coordinate to transform.
     * @return The transformed coordinate.
     */
    public Coord transform(Coord coord);

}

谢谢你,Somayeh

好的,错误在这里:

我做了以下事情:

它给了我两个语法错误:

对于卷曲括号和逗号,

double [] eastANDnorth(double lat,double lon){ ; 和 返回新的双倍(OSGB36N,OSGB36E); 表示双重

package org.matsim.core.utils.geometry.transformations;

import org.matsim.api.core.v01.Coord;
import org.matsim.core.utils.geometry.CoordImpl;
import org.matsim.core.utils.geometry.CoordinateTransformation;


public class WGS84toOSGB36 implements CoordinateTransformation {

    @Override
    public Coord transform(Coord coord) {

        // WGS84 ELLIPSOID
        double WGS84_A = 6378137;
        double WGS84_B = 6356752.314245;
        double WGS84_E2 = ((WGS84_A * WGS84_A) - (WGS84_B * WGS84_B) / (WGS84_A * WGS84_A));

        // NstGrid scale factor on central meridian
        final double F0 = 0.9996012717;

        // Airy 1830 major & minor semi-axes - note .909 not .910

        final double AIRY_A = 6377563.396;
        final double AIRY_B = 6356256.909;

        // NatGrid true origin
        final double LAT0 = Math.toRadians(49); //Phi0
        final double LON0 = Math.toRadians(-2); //Lamda0

        // northing & easting of true origin, metres
        final double N0 = -100000;
        final double E0 = 400000;

        // eccentricity squared 
        final double E2 = ((AIRY_A * AIRY_A) - (AIRY_B * AIRY_B)) / (AIRY_A *AIRY_A);

        final double N = (AIRY_A - AIRY_B) / (AIRY_A + AIRY_B);
        final double N2 = N * N;
        final double N3 = N * N * N;

        final double TX = -446.448;
        final double TY = 125.157;
        final double TZ = -542.060;
        final double RX = Math.toRadians(-0.1502 / 3600);
        final double RY = Math.toRadians(-0.2470 / 3600);
        final double RZ = Math.toRadians(-0.8421 / 3600);
        final double S = 20.4894 / 1e6 + 1;

/*----*/double[] eastANDnorth(double lat, double lon) {/* error in this line */

            // -- 1: convert polar to cartesian coordinates (using ellipse 1)

            // WGS84 ellipsoid
            double sinPhi = Math.sin(lat);
            double cosPhi = Math.cos(lat);
            double sinLambda = Math.sin(lon);
            double cosLambda = Math.cos(lon);
            double H = 24.7; // for the moment

            double nu = WGS84_A / Math.sqrt(1 - WGS84_E2 * sinPhi * sinPhi);

            double x1 = (nu + H) * cosPhi * cosLambda;
            double y1 = (nu + H) * cosPhi * sinLambda;
            double z1 = ((1-WGS84_E2) * nu + H) * sinPhi;

            // -- 2: apply helmert transform using appropriate params
            double x2 = TX + x1 * S - y1 * RZ + z1 * RY;
            double y2 = TY + x1 * RZ + y1 * S - z1 * RX;
            double z2 = TZ - x1 * RY + y1 * RX + z1 * S;

            // -- 3: convert cartesian to polar coordinates (using ellipse 2)
            double precision = 4 / AIRY_A;

            double p = Math.sqrt(x2 * x2 + y2 * y2);
            double phi = Math.atan2(z2, p * (1 - E2)), phiP = 2 * Math.PI;
            while (Math.abs(phi - phiP) > precision) {
                nu = AIRY_A / Math.sqrt(1 - E2 * Math.sin(phi) * Math.sin(phi));
                phiP = phi;
                phi = Math.atan2(z2 + E2 * nu * Math.sin(phi), p);
            }

            double lambda = Math.atan2(y2, x2);

            // -- 4: now we're in OSGB, get the EN coords
            double cosLat = Math.cos(phi), sinLat = Math.sin(phi);
            nu = AIRY_A * F0 / Math.sqrt(1 - E2 * sinLat * sinLat);              
            double rho = AIRY_A * F0 * (1 - E2) / Math.pow(1 - E2 * sinLat * sinLat, 1.5);
            double eta2 = nu / rho - 1;

            double Ma = (1 + N + (5 / 4) * N2 + (5 / 4) * N3) * (phi - LAT0);
            double Mb = (3 * N + 3 * N * N + (21 / 8) * N3) * Math.sin(phi - LAT0) * Math.cos(phi + LAT0);
            double Mc = ((15 / 8) * N2 + (15 / 8) * N3) * Math.sin(2 * (phi - LAT0)) * Math.cos(2 * (phi + LAT0));
            double Md = (35 / 24) * N3 * Math.sin(3 * (phi - LAT0)) * Math.cos(3 * (phi + LAT0));
            double M = AIRY_B * F0 * (Ma - Mb + Mc - Md);              // meridional arc

            double cos3lat = cosLat * cosLat * cosLat;
            double cos5lat = cos3lat * cosLat * cosLat;
            double tan2lat = Math.tan(phi) * Math.tan(phi);
            double tan4lat = tan2lat * tan2lat;

            double I = M + N0;
            double II = (nu / 2) * sinLat * cosLat;
            double III = (nu / 24) * sinLat * cos3lat * (5 - tan2lat + 9 * eta2);
            double IIIA = (nu / 720) * sinLat * cos5lat * (61 - 58 * tan2lat + tan4lat);
            double IV = nu * cosLat;
            double V = (nu / 6) * cos3lat * (nu / rho - tan2lat);
            double VI = (nu / 120) * cos5lat * (5 - 18 * tan2lat + tan4lat + 14 * eta2 - 58 * tan2lat * eta2);

            double dLon = lambda - LON0;
            double dLon2 = dLon * dLon, dLon3 = dLon2 * dLon, dLon4 = dLon3 * dLon, dLon5 = dLon4 * dLon, dLon6 = dLon5 * dLon;

            double OSGB36N = I + II * dLon2 + III * dLon4 + IIIA * dLon6;
            double OSGB36E = E0 + IV * dLon + V * dLon3 + VI * dLon5;

/*--------*/return new double(OSGB36N, OSGB36E);/* error in this line */
        }
            return new CoordImpl(OSGB36N, OSGB36E);
    }
}

1 个答案:

答案 0 :(得分:0)

您正在尝试使用此表达式创建数组:

new double(OSGB36N, OSGB36E)

然而,这是无效的java语法。你应该把它改成

new double[]{ OSGB36N, OSGB36E }

此外,您还试图在另一个方法中声明一个方法,即eastANDnorth内的transform,这在java中无效。