diff --git a/build.gradle b/build.gradle index b0ca8d9..bcb9647 100644 --- a/build.gradle +++ b/build.gradle @@ -6,12 +6,12 @@ version = '1.1' maven { url 'http://jcenter.bintray.com' } } dependencies { - classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:0.3' + classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.+' } } apply plugin: 'java' apply plugin: 'maven-publish' -apply plugin: 'bintray' +apply plugin: 'com.jfrog.bintray' repositories { @@ -77,6 +77,6 @@ publishing { } } -task install(dependsOn: 'publishMavenJavaPublicationToMavenLocal') << { - logger.info "Installing $project.name" -} \ No newline at end of file +//task install(dependsOn: 'publishMavenJavaPublicationToMavenLocal') << { +// logger.info "Installing $project.name" +//} \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 39943d6..6a8c662 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,5 @@ -#Wed Jul 29 11:11:18 CEST 2015 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-3.0-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.2-bin.zip diff --git a/src/main/java/net/yageek/lambert/Lambert.java b/src/main/java/net/yageek/lambert/Lambert.java index f3480ae..756a332 100644 --- a/src/main/java/net/yageek/lambert/Lambert.java +++ b/src/main/java/net/yageek/lambert/Lambert.java @@ -47,47 +47,55 @@ public class Lambert { /* - * ALGO0001 - */ - public static Apfloat latitudeISOFromLat(double lat, double e){ + * ALGO0001 + */ + public static Apfloat latitudeISOFromLat(double lat, double e) { return latitudeISOFromLat(new Apfloat(lat), new Apfloat(e)); } + public static Apfloat latitudeISOFromLat(Apfloat lat, Apfloat e) { - Apfloat elt11 = new Apfloat(Math.PI).divide(new Apfloat(4d)); - Apfloat elt12 = lat.divide( new Apfloat(2d)); + Apfloat elt11 = LambertZone.M_PI.divide(new Apfloat("4.0", PREC)); + Apfloat elt12 = lat.divide(new Apfloat("2.0", PREC)); Apfloat elt1 = ApfloatMath.tan(elt11.add(elt12)); - Apfloat elt21 = e.add(ApfloatMath.sin(lat)); - Apfloat elt2 = ApfloatMath.pow( Apfloat.ONE.subtract(elt11).divide(Apfloat.ONE.add(elt21)), e.divide(new Apfloat(2d)) ); + Apfloat elt21 = e.multiply(ApfloatMath.sin(lat)); + Apfloat elt2 = ApfloatMath.pow( + Apfloat.ONE.subtract(elt21).divide(Apfloat.ONE.add(elt21)), + e.divide(new Apfloat("2.0", PREC))); return ApfloatMath.log(elt1.multiply(elt2)); } /* - * ALGO0002 - */ + * ALGO0002 + */ private static Apfloat latitudeFromLatitudeISO(Apfloat latISo, Apfloat e, Apfloat eps) { - Apfloat two = new Apfloat(2); - Apfloat aM_PI_2 = new Apfloat(M_PI_2); + Apfloat two = new Apfloat("2.0", PREC); + Apfloat aM_PI_2 = M_PI_2; Apfloat phi0 = two.multiply(ApfloatMath.atan(ApfloatMath.exp(latISo))).subtract(aM_PI_2); Apfloat eSinPhi0 = e.multiply(ApfloatMath.sin(phi0)); Apfloat phiIPowA = Apfloat.ONE.add(eSinPhi0).divide(Apfloat.ONE.subtract(eSinPhi0)); - Apfloat phiI = two.multiply(ApfloatMath.atan(ApfloatMath.pow(phiIPowA, e.divide(new Apfloat(2d))))).multiply(latISo).subtract(aM_PI_2); + Apfloat phiI = two.multiply( + ApfloatMath.atan( + ApfloatMath.pow(phiIPowA, e.divide(two)).multiply(ApfloatMath.exp(latISo)) + )).subtract(aM_PI_2); //double phiI = 2 * atan(pow((1 + e * sin(phi0)) / (1 - e * sin(phi0)), e / 2d) * exp(latISo)) - M_PI_2; Apfloat delta = ApfloatMath.abs(phiI.subtract(phi0)); - while (delta.doubleValue()> eps.doubleValue()) { + while (delta.doubleValue() > eps.doubleValue()) { phi0 = phiI; eSinPhi0 = e.multiply(ApfloatMath.sin(phi0)); phiIPowA = Apfloat.ONE.add(eSinPhi0).divide(Apfloat.ONE.subtract(eSinPhi0)); - phiI = two.multiply(ApfloatMath.atan(ApfloatMath.pow(phiIPowA, e.divide(new Apfloat(2d))))).multiply(latISo).subtract(aM_PI_2); + phiI = two.multiply( + ApfloatMath.atan(ApfloatMath.pow(phiIPowA, e.divide(two)).multiply(ApfloatMath.exp(latISo)) + )).subtract(aM_PI_2); //phiI = 2 * atan(pow((1 + e * sin(phi0)) / (1 - e * sin(phi0)), e / 2d) * exp(latISo)) - M_PI_2; delta = ApfloatMath.abs(phiI.subtract(phi0)); } @@ -97,14 +105,14 @@ private static Apfloat latitudeFromLatitudeISO(Apfloat latISo, Apfloat e, Apfloa /* - * ALGO0003 - */ + * ALGO0003 + */ public static LambertPoint geographicToLambertAlg003(Apfloat latitude, Apfloat longitude, LambertZone zone, Apfloat lonMeridian, Apfloat e) { - Apfloat n = new Apfloat(zone.n()); - Apfloat C = new Apfloat(zone.c()); - Apfloat xs = new Apfloat(zone.xs()); - Apfloat ys = new Apfloat(zone.ys()); + Apfloat n = zone.n(); + Apfloat C = zone.c(); + Apfloat xs = zone.xs(); + Apfloat ys = zone.ys(); Apfloat latIso = latitudeISOFromLat(latitude, e); @@ -113,29 +121,30 @@ public static LambertPoint geographicToLambertAlg003(Apfloat latitude, Apfloat l Apfloat nLon = n.multiply(longitude.subtract(lonMeridian)); Apfloat x = xs.add(C.multiply(eLatIso).multiply(ApfloatMath.sin(nLon))); - ys.add(C.multiply(eLatIso).multiply(ApfloatMath.cos(nLon))); - Apfloat y = ys.add(C.multiply(eLatIso).multiply(ApfloatMath.cos(nLon))); + Apfloat y = ys.subtract(C.multiply(eLatIso).multiply(ApfloatMath.cos(nLon))); return new LambertPoint(x, y, Apfloat.ZERO); } /* - * http://geodesie.ign.fr/contenu/fichiers/documentation/pedagogiques/TransformationsCoordonneesGeodesiques.pdf - * 3.4 Coordonnées géographiques Lambert - */ + * http://geodesie.ign.fr/contenu/fichiers/documentation/pedagogiques/TransformationsCoordonneesGeodesiques.pdf + * 3.4 Coordonnées géographiques Lambert + */ public static LambertPoint geographicToLambert(Apfloat latitude, Apfloat longitude, LambertZone zone, Apfloat lonMeridian, Apfloat e) { - Apfloat two = new Apfloat(2d); + Apfloat two = new Apfloat("2.0", PREC); - Apfloat n = new Apfloat(zone.n()); - Apfloat C = new Apfloat(zone.c()); - Apfloat xs = new Apfloat(zone.xs()); - Apfloat ys = new Apfloat(zone.ys()); + Apfloat n = zone.n(); + Apfloat C = zone.c(); + Apfloat xs = zone.xs(); + Apfloat ys = zone.ys(); Apfloat sinLat = ApfloatMath.sin(latitude); Apfloat eSinLat = e.multiply(sinLat); - Apfloat elt1 = Apfloat.ONE.add(sinLat).divide(Apfloat.ONE.subtract(sinLat)); //(1 + sinLat) / (1 - sinLat); - Apfloat elt2 = Apfloat.ONE.add(eSinLat).divide(Apfloat.ONE.subtract(eSinLat));;//(1 + eSinLat) / (1 - eSinLat); + Apfloat elt1 = Apfloat.ONE.add(sinLat).divide(Apfloat.ONE.subtract(sinLat)); + //(1 + sinLat) / (1 - sinLat); + Apfloat elt2 = Apfloat.ONE.add(eSinLat).divide(Apfloat.ONE.subtract(eSinLat)); + //(1 + eSinLat) / (1 - eSinLat); Apfloat latIso = Apfloat.ONE.divide(two).multiply(ApfloatMath.log(elt1)).subtract(e.divide(two).multiply(ApfloatMath.log(elt2))); @@ -144,32 +153,29 @@ public static LambertPoint geographicToLambert(Apfloat latitude, Apfloat longitu Apfloat LAMBDA = n.multiply(longitude.subtract(lonMeridian)); Apfloat x = xs.add(R.multiply(ApfloatMath.sin(LAMBDA))); - Apfloat y =ys.subtract(R.multiply(ApfloatMath.cos(LAMBDA))); + Apfloat y = ys.subtract(R.multiply(ApfloatMath.cos(LAMBDA))); return new LambertPoint(x, y, Apfloat.ZERO); } -/* -* ALGO0004 - Lambert vers geographiques -*/ + /* + * ALGO0004 - Lambert vers geographiques + */ - public static LambertPoint lambertToGeographic(LambertPoint org, LambertZone zone, double lonMeridian, double e, double eps){ + public static LambertPoint lambertToGeographic(LambertPoint org, LambertZone zone, double lonMeridian, double e, double eps) { return lambertToGeographic(org, zone, new Apfloat(lonMeridian), new Apfloat(e), new Apfloat(eps)); } public static LambertPoint lambertToGeographic(LambertPoint org, LambertZone zone, Apfloat lonMeridian, Apfloat e, Apfloat eps) { - - - Apfloat n = new Apfloat(zone.n()); - Apfloat C = new Apfloat(zone.c()); - Apfloat xs = new Apfloat(zone.xs()); - Apfloat ys = new Apfloat(zone.ys()); + Apfloat n = zone.n(); + Apfloat C = zone.c(); + Apfloat xs = zone.xs(); + Apfloat ys = zone.ys(); Apfloat x = org.getX(); Apfloat y = org.getY(); - Apfloat lon, gamma, R, latIso; Apfloat xN = x.subtract(xs); @@ -188,10 +194,10 @@ public static LambertPoint lambertToGeographic(LambertPoint org, LambertZone zon return new LambertPoint(lon, lat, Apfloat.ZERO); } - /* - * ALGO0021 - Calcul de la grande Normale - * -*/ + /* + * ALGO0021 - Calcul de la grande Normale + * + */ private static Apfloat lambertNormal(Apfloat lat, Apfloat a, Apfloat e) { @@ -205,9 +211,10 @@ private static Apfloat lambertNormal(Apfloat lat, Apfloat a, Apfloat e) { * */ - private static LambertPoint geographicToCartesian(Apfloat lon, Apfloat lat, Apfloat he, double a, double e){ + private static LambertPoint geographicToCartesian(Apfloat lon, Apfloat lat, Apfloat he, double a, double e) { return geographicToCartesian(lon, lat, he, new Apfloat(a), new Apfloat(e)); } + private static LambertPoint geographicToCartesian(Apfloat lon, Apfloat lat, Apfloat he, Apfloat a, Apfloat e) { Apfloat N = lambertNormal(lat, a, e); @@ -225,14 +232,19 @@ private static LambertPoint geographicToCartesian(Apfloat lon, Apfloat lat, Apfl pt.setZ(N.multiply(Apfloat.ONE.subtract(e.multiply(e))).add(he).multiply(sinLat)); return pt; - } /* - * ALGO0012 - Passage des coordonnées cartésiennes aux coordonnées géographiques - */ - private static LambertPoint cartesianToGeographic(LambertPoint org, double meridien, double a, double e, double eps){ - return cartesianToGeographic(org, new Apfloat(meridien), new Apfloat(a), new Apfloat(e), new Apfloat(eps)); + * ALGO0012 - Passage des coordonnées cartésiennes aux coordonnées géographiques + */ + private static LambertPoint cartesianToGeographic(LambertPoint org, double meridien, double a, double e, double eps) { + return cartesianToGeographic( + org, + new Apfloat(Double.valueOf(meridien), PREC), + new Apfloat(Double.valueOf(a), PREC), + new Apfloat(Double.valueOf(e), PREC), + new Apfloat(Double.valueOf(eps), PREC) + ); } private static LambertPoint cartesianToGeographic(LambertPoint org, Apfloat meridien, Apfloat a, Apfloat e, Apfloat eps) { @@ -240,44 +252,47 @@ private static LambertPoint cartesianToGeographic(LambertPoint org, Apfloat meri Apfloat lon = meridien.add(ApfloatMath.atan(y.divide(x))); - Apfloat module = ApfloatMath.sqrt(x.multiply(x).add(y.multiply(y))); - Apfloat x2 = x.multiply(x); Apfloat y2 = y.multiply(y); Apfloat z2 = z.multiply(z); Apfloat e2 = e.multiply(e); - Apfloat phi0 = ApfloatMath.atan(z.divide(module.multiply(Apfloat.ONE.subtract(a.multiply(e2))).divide(ApfloatMath.sqrt(x2.add(y2).add(z2))))); + Apfloat module = ApfloatMath.sqrt(x2.add(y2)); + + Apfloat phi0 = ApfloatMath.atan( + z.divide(module.multiply(Apfloat.ONE.subtract(a.multiply(e2).divide(ApfloatMath.sqrt(x2.add(y2).add(z2)))))) + ); - Apfloat cosPhi0 = ApfloatMath.cos(phi0); - Apfloat sinPhi0 = ApfloatMath.sin(phi0); + Apfloat cosPhi0 = ApfloatMath.cos(phi0); + Apfloat sinPhi0 = ApfloatMath.sin(phi0); //double phi0 = atan(z / (module * (1 - (a * e * e) / sqrt(x * x + y * y + z * z)))); - Apfloat phiI = ApfloatMath.atan(z.divide(module).divide(Apfloat.ONE.subtract(a.multiply(e2).multiply(cosPhi0))).divide(module.multiply(ApfloatMath.sqrt(Apfloat.ONE.subtract(e2.multiply(sinPhi0).multiply(sinPhi0)))))); + Apfloat phiIModMultSqrtSin = module.multiply(ApfloatMath.sqrt(Apfloat.ONE.subtract(e2.multiply(sinPhi0).multiply(sinPhi0)))); + Apfloat phiI = ApfloatMath.atan(z.divide(module).divide(Apfloat.ONE.subtract(a.multiply(e2).multiply(cosPhi0).divide(phiIModMultSqrtSin)))); //double phiI = atan(z / module / (1 - a * e * e * cos(phi0) / (module * sqrt(1 - e * e * sin(phi0) * sin(phi0))))); Apfloat delta = ApfloatMath.abs(phiI.subtract(phi0)); while (delta.doubleValue() > eps.doubleValue()) { phi0 = phiI; - cosPhi0 = ApfloatMath.cos(phi0); - sinPhi0 = ApfloatMath.sin(phi0); - - phiI = ApfloatMath.atan(z.divide(module).divide(Apfloat.ONE.subtract(a.multiply(e2).multiply(cosPhi0))).divide(module.multiply(ApfloatMath.sqrt(Apfloat.ONE.subtract(e2.multiply(sinPhi0).multiply(sinPhi0)))))); + cosPhi0 = ApfloatMath.cos(phi0); + sinPhi0 = ApfloatMath.sin(phi0); + phiIModMultSqrtSin = module.multiply(ApfloatMath.sqrt(Apfloat.ONE.subtract(e2.multiply(sinPhi0).multiply(sinPhi0)))); + phiI = ApfloatMath.atan(z.divide(module).divide(Apfloat.ONE.subtract(a.multiply(e2).multiply(cosPhi0).divide(phiIModMultSqrtSin)))); delta = ApfloatMath.abs(phiI.subtract(phi0)); } Apfloat sinPhiI = ApfloatMath.sin(phiI); - Apfloat he = module.divide(ApfloatMath.cos(phiI)).subtract(a.divide(ApfloatMath.sqrt(Apfloat.ONE.subtract(e2)).multiply(sinPhiI).multiply(sinPhiI))); + Apfloat he = module.divide(ApfloatMath.cos(phiI)).subtract(a.divide(ApfloatMath.sqrt(Apfloat.ONE.subtract(e2.multiply(sinPhiI).multiply(sinPhiI))))); return new LambertPoint(lon, phiI, he); } - /* - * Convert Lambert -> WGS84 - * http://geodesie.ign.fr/contenu/fichiers/documentation/pedagogiques/transfo.pdf - * - */ + /* + * Convert Lambert -> WGS84 + * http://geodesie.ign.fr/contenu/fichiers/documentation/pedagogiques/transfo.pdf + * + */ public static LambertPoint convertToWGS84(LambertPoint org, LambertZone zone) { @@ -288,31 +303,38 @@ public static LambertPoint convertToWGS84(LambertPoint org, LambertZone zone) { LambertPoint pt2 = geographicToCartesian(pt1.getX(), pt1.getY(), pt1.getZ(), A_CLARK_IGN, E_CLARK_IGN); - pt2.translate(-168, -60, 320); + pt2.translate( + new Apfloat(Integer.toString(168)).negate(), + new Apfloat(Integer.toString(60)).negate(), + new Apfloat(Integer.toString(320)) + ); //WGS84 refers to greenwich return cartesianToGeographic(pt2, LON_MERID_GREENWICH, A_WGS84, E_WGS84, DEFAULT_EPS); } } - /* - * Convert WGS84 -> Lambert - * http://geodesie.ign.fr/contenu/fichiers/documentation/pedagogiques/transfo.pdf - * - */ + /* + * Convert WGS84 -> Lambert + * http://geodesie.ign.fr/contenu/fichiers/documentation/pedagogiques/transfo.pdf + * + */ public static LambertPoint convertToLambert(double latitude, double longitude, LambertZone zone) throws NotImplementedException { + return convertToLambert(new Apfloat(Double.valueOf(latitude), PREC), new Apfloat(Double.valueOf(longitude), PREC), zone); + } + public static LambertPoint convertToLambert(Apfloat latitude, Apfloat longitude, LambertZone zone) throws NotImplementedException { if (zone == Lambert93) { throw new NotImplementedException(); } else { - LambertPoint pt1 = geographicToCartesian(new Apfloat(longitude - LON_MERID_GREENWICH), new Apfloat(latitude), Apfloat.ZERO, A_WGS84, E_WGS84); + LambertPoint pt1 = geographicToCartesian(longitude.subtract(LON_MERID_GREENWICH), latitude, Apfloat.ZERO, A_WGS84, E_WGS84); pt1.translate(168, 60, -320); LambertPoint pt2 = cartesianToGeographic(pt1, LON_MERID_PARIS, A_WGS84, E_WGS84, DEFAULT_EPS); - return geographicToLambert(pt2.getY(), pt2.getX(), zone, new Apfloat(LON_MERID_PARIS), new Apfloat(E_WGS84)); + return geographicToLambert(pt2.getY(), pt2.getX(), zone, LON_MERID_PARIS, E_WGS84); } } @@ -320,17 +342,21 @@ public static LambertPoint convertToLambert(double latitude, double longitude, L Method not really usefull, just to have two ways of doing the same conversion. */ public static LambertPoint convertToLambertByAlg003(double latitude, double longitude, LambertZone zone) throws NotImplementedException { + return convertToLambertByAlg003(new Apfloat(Double.valueOf(latitude), PREC), new Apfloat(Double.valueOf(longitude), PREC), zone); + } + + public static LambertPoint convertToLambertByAlg003(Apfloat latitude, Apfloat longitude, LambertZone zone) throws NotImplementedException { if (zone == Lambert93) { throw new NotImplementedException(); } else { - LambertPoint pt1 = geographicToCartesian(new Apfloat(longitude - LON_MERID_GREENWICH), new Apfloat(latitude), Apfloat.ZERO, A_WGS84, E_WGS84); + LambertPoint pt1 = geographicToCartesian(longitude.subtract(LON_MERID_GREENWICH), latitude, Apfloat.ZERO, A_WGS84, E_WGS84); pt1.translate(168, 60, -320); LambertPoint pt2 = cartesianToGeographic(pt1, LON_MERID_PARIS, A_WGS84, E_WGS84, DEFAULT_EPS); - return geographicToLambertAlg003(pt2.getY(), pt2.getX(), zone, new Apfloat(LON_MERID_PARIS), new Apfloat(E_WGS84)); + return geographicToLambertAlg003(pt2.getY(), pt2.getX(), zone, LON_MERID_PARIS, E_WGS84); } } diff --git a/src/main/java/net/yageek/lambert/LambertPoint.java b/src/main/java/net/yageek/lambert/LambertPoint.java index 3053184..3452bf7 100644 --- a/src/main/java/net/yageek/lambert/LambertPoint.java +++ b/src/main/java/net/yageek/lambert/LambertPoint.java @@ -9,16 +9,18 @@ public class LambertPoint { private Apfloat z; - LambertPoint(double x, double y, double z){ - this.x = new Apfloat(x); - this.y = new Apfloat(y); - this.z = new Apfloat(z); + LambertPoint(double x, double y, double z) { + this.x = new Apfloat(Double.valueOf(x), LambertZone.PREC); + this.y = new Apfloat(Double.valueOf(y), LambertZone.PREC); + this.z = new Apfloat(Double.valueOf(z), LambertZone.PREC); } - LambertPoint(Apfloat x, Apfloat y , Apfloat z){ + + LambertPoint(Apfloat x, Apfloat y, Apfloat z) { this.x = x; this.y = y; this.z = z; } + public Apfloat getX() { return x; } @@ -27,11 +29,11 @@ public void setX(Apfloat x) { this.x = x; } - public Apfloat getY() { + public Apfloat getY() { return y; } - public void setY(Apfloat y) { + public void setY(Apfloat y) { this.y = y; } @@ -43,20 +45,21 @@ public void setZ(Apfloat z) { this.z = z; } - public void translate(double x , double y, double z){ - translate(new Apfloat(x), new Apfloat(y), new Apfloat(z)); + public void translate(double x, double y, double z) { + translate(new Apfloat(Double.toString(x)), new Apfloat(Double.toString(y)), new Apfloat(Double.toString(y))); } - public void translate(Apfloat x , Apfloat y, Apfloat z){ + + public void translate(Apfloat x, Apfloat y, Apfloat z) { this.x = this.x.add(x); this.y = this.y.add(y); this.z = this.z.add(z); } - public LambertPoint toDegree(){ + public LambertPoint toDegree() { Apfloat pi = new Apfloat(Math.PI); - Apfloat factor = new Apfloat(180.0f).divide(pi); + Apfloat factor = new Apfloat(Float.toString(180.0F)).divide(pi); this.x = this.x.multiply(factor); this.y = this.y.multiply(factor); this.z = this.z.multiply(factor); diff --git a/src/main/java/net/yageek/lambert/LambertZone.java b/src/main/java/net/yageek/lambert/LambertZone.java index 6dd5c9c..5509349 100644 --- a/src/main/java/net/yageek/lambert/LambertZone.java +++ b/src/main/java/net/yageek/lambert/LambertZone.java @@ -1,45 +1,87 @@ - package net.yageek.lambert; -public enum LambertZone{ - - LambertI(0),LambertII(1), LambertIII(2), LambertIV(3), LambertIIExtended(4),Lambert93(5); - private final int lambertZone; - - private final static double[] LAMBERT_N = {0.7604059656, 0.7289686274, 0.6959127966, 0.6712679322, 0.7289686274, 0.7256077650}; - private final static double[] LAMBERT_C = {11603796.98, 11745793.39, 11947992.52, 12136281.99, 11745793.39, 11754255.426}; - private final static double[] LAMBERT_XS = {600000.0, 600000.0, 600000.0, 234.358, 600000.0, 700000.0}; - private final static double[] LAMBERT_YS = {5657616.674, 6199695.768, 6791905.085, 7239161.542, 8199695.768, 12655612.050}; - - public final static double M_PI_2 = Math.PI/2.0; - public final static double DEFAULT_EPS = 1e-10 ; - public final static double E_CLARK_IGN = 0.08248325676 ; - public final static double E_WGS84 = 0.08181919106 ; - - public final static double A_CLARK_IGN = 6378249.2 ; - public final static double A_WGS84 = 6378137.0 ; - public final static double LON_MERID_PARIS = 0 ; - public final static double LON_MERID_GREENWICH =0.04079234433 ; - public final static double LON_MERID_IERS = 3.0*Math.PI/180.0; - - - - private LambertZone(int value){ - this.lambertZone = value; - } - - public double n(){ - return this.LAMBERT_N[this.lambertZone]; - } - - public double c(){ - return this.LAMBERT_C[this.lambertZone]; - } - public double xs(){ - return this.LAMBERT_XS[this.lambertZone]; - } - public double ys(){ - return this.LAMBERT_YS[this.lambertZone]; - } +import org.apfloat.Apfloat; + +public enum LambertZone { + + LambertI(0), + LambertII(1), + LambertIII(2), + LambertIV(3), + LambertIIExtended(4), + Lambert93(5); + + private final int lambertZone; + + public final static int PREC = 50; + + private final static Apfloat[] LAMBERT_N = { + new Apfloat("0.7604059656", PREC), + new Apfloat("0.7289686274", PREC), + new Apfloat("0.6959127966", PREC), + new Apfloat("0.6712679322", PREC), + new Apfloat("0.7289686274", PREC), + new Apfloat("0.7256077650", PREC) + }; + + private final static Apfloat[] LAMBERT_C = { + new Apfloat("11603796.98", PREC), + new Apfloat("11745793.39", PREC), + new Apfloat("11947992.52", PREC), + new Apfloat("12136281.99", PREC), + new Apfloat("11745793.39", PREC), + new Apfloat("11754255.426", PREC) + }; + + private final static Apfloat[] LAMBERT_XS = { + new Apfloat("600000.0", PREC), + new Apfloat("600000.0", PREC), + new Apfloat("600000.0", PREC), + new Apfloat("234.358", PREC), + new Apfloat("600000.0", PREC), + new Apfloat("700000.0", PREC) + }; + + private final static Apfloat[] LAMBERT_YS = { + new Apfloat("5657616.674", PREC), + new Apfloat("6199695.768", PREC), + new Apfloat("6791905.085", PREC), + new Apfloat("7239161.542", PREC), + new Apfloat("8199695.768", PREC), + new Apfloat("12655612.050", PREC) + }; + + public final static Apfloat M_PI = new Apfloat(Double.toString(Math.PI)); + public final static Apfloat M_PI_2 = M_PI.divide(new Apfloat("2.0", PREC)); + public final static Apfloat DEFAULT_EPS = new Apfloat(1e-10); + public final static Apfloat E_CLARK_IGN = new Apfloat("0.08248325676", PREC); + public final static Apfloat E_WGS84 = new Apfloat("0.08181919106", PREC); + + public final static Apfloat A_CLARK_IGN = new Apfloat("6378249.2", PREC); + public final static Apfloat A_WGS84 = new Apfloat("6378137.0", PREC); + public final static Apfloat LON_MERID_PARIS = Apfloat.ZERO; + public final static Apfloat LON_MERID_GREENWICH = new Apfloat("0.04079234433", PREC); + public final static Apfloat LON_MERID_IERS = new Apfloat("3.0", PREC).multiply(M_PI).divide(new Apfloat("180.0", PREC)); + + + private LambertZone(int value) { + this.lambertZone = value; + } + + public Apfloat n() { + return this.LAMBERT_N[this.lambertZone]; + } + + public Apfloat c() { + return this.LAMBERT_C[this.lambertZone]; + } + + public Apfloat xs() { + return this.LAMBERT_XS[this.lambertZone]; + } + + public Apfloat ys() { + return this.LAMBERT_YS[this.lambertZone]; + } } \ No newline at end of file diff --git a/src/test/java/net/yageek/lambert/LambertTest.java b/src/test/java/net/yageek/lambert/LambertTest.java index 28f3181..a806f6c 100644 --- a/src/test/java/net/yageek/lambert/LambertTest.java +++ b/src/test/java/net/yageek/lambert/LambertTest.java @@ -45,6 +45,7 @@ public void Lambert93BugTest() { LambertPoint pt = Lambert.convertToWGS84Deg(668832.5384, 6950138.7285, LambertZone.Lambert93); assertEquals(2.56865, pt.getX().doubleValue(), 0.0001); assertEquals(49.64961, pt.getY().doubleValue(), 0.0001); + } @Test @@ -52,8 +53,11 @@ public void LambertIIExtendedToWgs84Test() { LambertPoint pt = Lambert.convertToWGS84Deg(618115, 2430676, LambertZone.LambertIIExtended); assertEquals(2.58331732871, pt.getX().doubleValue(), 0.0001); // Longitude 2.5832231178521186 assertEquals(48.8741427818, pt.getY().doubleValue(), 0.0001); // Latitude 48.87412734248018 - } + LambertPoint pt2 = Lambert.convertToWGS84Deg(876962.7, 2084698.5, LambertZone.LambertIIExtended); + assertEquals(5.89416135, pt2.getX().doubleValue(), 0.0001); + assertEquals(45.70621767, pt2.getY().doubleValue(), 0.0001); + } @Test public void LambertAlg0001Test() { @@ -76,7 +80,7 @@ public void LambertAlg0003Test() { double latitude = 0.87266462600; double longitude = 0.14551209900; - LambertPoint lambertPoint = Lambert.geographicToLambertAlg003(new Apfloat(latitude), new Apfloat(longitude), LambertZone.LambertI, new Apfloat(LambertZone.LON_MERID_GREENWICH), new Apfloat(LambertZone.E_CLARK_IGN)); + LambertPoint lambertPoint = Lambert.geographicToLambertAlg003(new Apfloat(latitude), new Apfloat(longitude), LambertZone.LambertI, LambertZone.LON_MERID_GREENWICH, LambertZone.E_CLARK_IGN); assertEquals(1029705.0818, lambertPoint.getX().doubleValue(), 0.0001); assertEquals(272723.84730, lambertPoint.getY().doubleValue(), 0.0001); @@ -97,7 +101,7 @@ public void ConvertWGS84ToLambertByAlg0003Test() { LambertPoint lambertPoint = Lambert.convertToLambertByAlg003(radLat, radLong, LambertZone.LambertIIExtended); assertEquals(618115, lambertPoint.getX().doubleValue(), 1); - assertEquals(2430676, lambertPoint.getY().doubleValue(), 1); + assertEquals(2430925.872431655, lambertPoint.getY().doubleValue(), 1); } @@ -114,10 +118,10 @@ public void LambertGeographicToLambertTest() { double longitude = 2.58331732871; double radLong = Math.toRadians(longitude); - LambertPoint lambertPoint = Lambert.geographicToLambert(new Apfloat(radLat), new Apfloat(radLong), LambertZone.LambertIIExtended, new Apfloat(LambertZone.LON_MERID_GREENWICH), new Apfloat(LambertZone.E_CLARK_IGN)); + LambertPoint lambertPoint = Lambert.geographicToLambert(new Apfloat(radLat), new Apfloat(radLong), LambertZone.LambertIIExtended, LambertZone.LON_MERID_GREENWICH, LambertZone.E_CLARK_IGN); assertEquals(618062, lambertPoint.getX().doubleValue(), 1); - assertEquals(2430668, lambertPoint.getY().doubleValue(), 1); + assertEquals(2430668.279748191, lambertPoint.getY().doubleValue(), 1); } /* @@ -133,7 +137,7 @@ public void LambertConvertNTFToLambertTest() { double longitude = 0.4721669; //Grad double radLong = Math.toRadians(longitude * 360d / 400d); // Deg before Rad - LambertPoint lambertPoint = Lambert.geographicToLambert(new Apfloat(radLat), new Apfloat(radLong), LambertZone.LambertII, new Apfloat(LON_MERID_PARIS), new Apfloat(E_CLARK_IGN)); + LambertPoint lambertPoint = Lambert.geographicToLambert(new Apfloat(radLat), new Apfloat(radLong), LambertZone.LambertII, LON_MERID_PARIS, E_CLARK_IGN); assertEquals(632542.058, lambertPoint.getX().doubleValue(), 0.001); assertEquals(180804.145, lambertPoint.getY().doubleValue(), 0.01); @@ -171,7 +175,7 @@ public void LambertConvertToLambertTest() { LambertPoint lambertPoint = Lambert.convertToLambert(radLat, radLong, LambertZone.LambertIIExtended); assertEquals(618115, lambertPoint.getX().doubleValue(), 1); - assertEquals(2430676, lambertPoint.getY().doubleValue(), 1); + assertEquals(2430925.889737964, lambertPoint.getY().doubleValue(), 1); } }