Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/370.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Java中将公共类转换为抽象类_Java_Interface_Abstract Class - Fatal编程技术网

在Java中将公共类转换为抽象类

在Java中将公共类转换为抽象类,java,interface,abstract-class,Java,Interface,Abstract Class,我几乎不熟悉Java编程。我想在MATSim中实现以下代码(这是一个用于城市规划目的的模拟程序)。此代码是关于将WGS84(经度和纬度)转换为OSGB36(英国国家电网)的代码 MATSim库有一个接口(如下所示),用于将转换代码放入其中,并将其用于视觉模拟 我已经尝试过很多次处理错误,但都不管用。你能告诉我怎么做吗 package org.matsim.core.utils.geometry; import org.matsim.api.core.v01.Coord; /** * A

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

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);

}
谢谢你,索马耶

好的,错误在这里:

我做了以下工作:

它给了我两个语法错误:

双[]东和北(双lat,双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);
    }
}

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

new double(OSGB36N, OSGB36E)
但是,这是无效的java语法。您应该将其更改为

new double[]{ OSGB36N, OSGB36E }

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

您的公共类在哪里?不清楚您试图做什么,以及“实现以下代码”是什么应该是指,你取得了什么进步,或者出了什么问题。这只是一个接口。你需要一个接口的实现类。不确定MATsim如何工作,但通常应该有一个
提供者
来实现这个接口。这个代码中有什么问题或者出了什么问题?你为什么定义一个方法在另一种方法的中间?谢谢你的建议,Fabian,我可以解决我的问题。我把双数组改成:双LAT1= COORD。GETX();双LAT=数学。TrADADIANS(LAT1);双Lun1= COORD。GETYY();双Lon = Maul.TrurADIANS(LUN1)。;你是最有用的。-索马耶希也请记住你为我的未来详细阐述问题的技巧。谢谢你对我的耐心。索马耶希