lambert_ruby 1.0.2-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/ext/lambert_ruby/Lambert.java +158 -0
- data/ext/lambert_ruby/LambertPoint.java +52 -0
- data/ext/lambert_ruby/LambertRubyService.java +101 -0
- data/ext/lambert_ruby/LambertZone.java +45 -0
- data/ext/lambert_ruby/extconf.rb +3 -0
- data/ext/lambert_ruby/lambert.c +357 -0
- data/ext/lambert_ruby/lambert.h +126 -0
- data/ext/lambert_ruby/lambert_ruby.c +68 -0
- data/lib/lambert_ruby.jar +0 -0
- data/lib/lambert_ruby.rb +7 -0
- metadata +66 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9fb6c2ea302dfac3ec209ad6a6ccc05a9ff8eb82
|
4
|
+
data.tar.gz: b905b80807d1f4ef9334e8d403446a746eb3dfbd
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c8687464d66c2d32e96e95dc8dbfc7181a7745217a7e976234e1923706885ff9598766c07dbf37fa08cf68c56015d0bb61eddbefdab79f847eabe345437f4d36
|
7
|
+
data.tar.gz: f48c7314cf8acce07fcc9790cac5cdb65eaacec995f9015414af79f80d78e8bdc73fec392da734d101f2e30e5de882c9272b5a9c01e5f6e5cfece6fdfcf9c83d
|
@@ -0,0 +1,158 @@
|
|
1
|
+
package net.yageek.lambert;
|
2
|
+
|
3
|
+
|
4
|
+
import static java.lang.Math.*;
|
5
|
+
import static net.yageek.lambert.LambertZone.*;
|
6
|
+
|
7
|
+
public class Lambert {
|
8
|
+
|
9
|
+
/*
|
10
|
+
* ALGO0002
|
11
|
+
*/
|
12
|
+
private static double latitudeFromLatitudeISO(double latISo, double e, double eps)
|
13
|
+
{
|
14
|
+
|
15
|
+
double phi0 = 2* atan(exp(latISo)) - M_PI_2;
|
16
|
+
double phiI = 2*atan(pow((1+e*sin(phi0))/(1-e*sin(phi0)),e/2.0)*exp(latISo)) - M_PI_2;
|
17
|
+
double delta = abs(phiI - phi0);
|
18
|
+
|
19
|
+
while(delta > eps)
|
20
|
+
{
|
21
|
+
phi0 = phiI;
|
22
|
+
phiI = 2*atan(pow((1+e*sin(phi0))/(1-e*sin(phi0)),e/2.0)*exp(latISo)) - M_PI_2;
|
23
|
+
delta = abs(phiI - phi0);
|
24
|
+
}
|
25
|
+
|
26
|
+
return phiI;
|
27
|
+
|
28
|
+
}
|
29
|
+
|
30
|
+
/*
|
31
|
+
* ALGO0004 - Lambert vers geographiques
|
32
|
+
*/
|
33
|
+
|
34
|
+
private static LambertPoint lambertToGeographic(LambertPoint org, LambertZone zone, double lonMeridian, double e, double eps)
|
35
|
+
{
|
36
|
+
double n = zone.n();
|
37
|
+
double C = zone.c();
|
38
|
+
double xs = zone.xs();
|
39
|
+
double ys = zone.ys();
|
40
|
+
|
41
|
+
double x = org.getX();
|
42
|
+
double y = org.getY();
|
43
|
+
|
44
|
+
|
45
|
+
double lon, gamma, R, latIso;
|
46
|
+
|
47
|
+
R = sqrt((x - xs) * (x - xs) + (y - ys) * (y - ys));
|
48
|
+
|
49
|
+
gamma = atan((x-xs)/(ys-y));
|
50
|
+
|
51
|
+
lon = lonMeridian + gamma/n;
|
52
|
+
|
53
|
+
latIso = -1/n*log(abs(R/C));
|
54
|
+
|
55
|
+
double lat = latitudeFromLatitudeISO(latIso, e, eps);
|
56
|
+
|
57
|
+
LambertPoint dest = new LambertPoint(lon,lat,0);
|
58
|
+
return dest;
|
59
|
+
}
|
60
|
+
|
61
|
+
/*
|
62
|
+
* ALGO0021 - Calcul de la grande Normale
|
63
|
+
*
|
64
|
+
*/
|
65
|
+
|
66
|
+
private static double lambertNormal(double lat, double a, double e)
|
67
|
+
{
|
68
|
+
|
69
|
+
return a/sqrt(1-e*e*sin(lat)*sin(lat));
|
70
|
+
}
|
71
|
+
|
72
|
+
/*
|
73
|
+
* ALGO0009 - Transformations geographiques -> cartésiennes
|
74
|
+
*
|
75
|
+
*/
|
76
|
+
|
77
|
+
private static LambertPoint geographicToCartesian(double lon, double lat, double he, double a, double e)
|
78
|
+
{
|
79
|
+
double N = lambertNormal(lat, a, e);
|
80
|
+
|
81
|
+
LambertPoint pt = new LambertPoint(0,0,0);
|
82
|
+
|
83
|
+
pt.setX((N+he)*cos(lat)*cos(lon));
|
84
|
+
pt.setY((N+he)*cos(lat)*sin(lon));
|
85
|
+
pt.setZ((N*(1-e*e)+he)*sin(lat));
|
86
|
+
|
87
|
+
return pt;
|
88
|
+
|
89
|
+
}
|
90
|
+
|
91
|
+
/*
|
92
|
+
* ALGO0012 - Passage des coordonnées cartésiennes aux coordonnées géographiques
|
93
|
+
*/
|
94
|
+
|
95
|
+
private static LambertPoint cartesianToGeographic(LambertPoint org, double meridien, double a, double e, double eps)
|
96
|
+
{
|
97
|
+
double x = org.getX(), y = org.getY(), z = org.getZ();
|
98
|
+
|
99
|
+
double lon = meridien + atan(y/x);
|
100
|
+
|
101
|
+
double module = sqrt(x*x + y*y);
|
102
|
+
|
103
|
+
double phi0 = atan(z/(module*(1-(a*e*e)/sqrt(x*x+y*y+z*z))));
|
104
|
+
double phiI = atan(z/module/(1-a*e*e*cos(phi0)/(module * sqrt(1-e*e*sin(phi0)*sin(phi0)))));
|
105
|
+
double delta= abs(phiI - phi0);
|
106
|
+
while(delta > eps)
|
107
|
+
{
|
108
|
+
phi0 = phiI;
|
109
|
+
phiI = atan(z/module/(1-a*e*e*cos(phi0)/(module * sqrt(1-e*e*sin(phi0)*sin(phi0)))));
|
110
|
+
delta= abs(phiI - phi0);
|
111
|
+
|
112
|
+
}
|
113
|
+
|
114
|
+
double he = module/cos(phiI) - a/sqrt(1-e*e*sin(phiI)*sin(phiI));
|
115
|
+
|
116
|
+
LambertPoint pt = new LambertPoint(lon,phiI,he);
|
117
|
+
|
118
|
+
return pt;
|
119
|
+
}
|
120
|
+
/*
|
121
|
+
* Convert Lambert -> WGS84
|
122
|
+
* http://geodesie.ign.fr/contenu/fichiers/documentation/pedagogiques/transfo.pdf
|
123
|
+
*
|
124
|
+
*/
|
125
|
+
|
126
|
+
public static LambertPoint convertToWGS84(LambertPoint org, LambertZone zone){
|
127
|
+
|
128
|
+
if(zone == Lambert93)
|
129
|
+
{
|
130
|
+
return lambertToGeographic(org,Lambert93,LON_MERID_IERS,E_WGS84,DEFAULT_EPS);
|
131
|
+
}
|
132
|
+
else {
|
133
|
+
LambertPoint pt1 = lambertToGeographic(org, zone, LON_MERID_PARIS, E_CLARK_IGN, DEFAULT_EPS);
|
134
|
+
|
135
|
+
LambertPoint pt2 = geographicToCartesian(pt1.getX(), pt1.getY(), pt1.getZ(), A_CLARK_IGN, E_CLARK_IGN);
|
136
|
+
|
137
|
+
pt2.translate(-168,-60,320);
|
138
|
+
|
139
|
+
//WGS84 refers to greenwich
|
140
|
+
return cartesianToGeographic(pt2, LON_MERID_GREENWICH, A_WGS84, E_WGS84, DEFAULT_EPS);
|
141
|
+
}
|
142
|
+
}
|
143
|
+
|
144
|
+
public static LambertPoint convertToWGS84(double x, double y, LambertZone zone){
|
145
|
+
|
146
|
+
LambertPoint pt = new LambertPoint(x,y,0);
|
147
|
+
return convertToWGS84(pt, zone);
|
148
|
+
}
|
149
|
+
|
150
|
+
public static LambertPoint convertToWGS84Deg(double x, double y, LambertZone zone){
|
151
|
+
|
152
|
+
LambertPoint pt = new LambertPoint(x,y,0);
|
153
|
+
return convertToWGS84(pt, zone).toDegree();
|
154
|
+
}
|
155
|
+
|
156
|
+
}
|
157
|
+
|
158
|
+
|
@@ -0,0 +1,52 @@
|
|
1
|
+
package net.yageek.lambert;
|
2
|
+
|
3
|
+
public class LambertPoint {
|
4
|
+
|
5
|
+
private double x;
|
6
|
+
private double y;
|
7
|
+
private double z;
|
8
|
+
|
9
|
+
public LambertPoint(double x, double y , double z){
|
10
|
+
this.x = x;
|
11
|
+
this.y = y;
|
12
|
+
this.z = z;
|
13
|
+
}
|
14
|
+
public double getX() {
|
15
|
+
return x;
|
16
|
+
}
|
17
|
+
|
18
|
+
public void setX(double x) {
|
19
|
+
this.x = x;
|
20
|
+
}
|
21
|
+
|
22
|
+
public double getY() {
|
23
|
+
return y;
|
24
|
+
}
|
25
|
+
|
26
|
+
public void setY(double y) {
|
27
|
+
this.y = y;
|
28
|
+
}
|
29
|
+
|
30
|
+
public double getZ() {
|
31
|
+
return z;
|
32
|
+
}
|
33
|
+
|
34
|
+
public void setZ(double z) {
|
35
|
+
this.z = z;
|
36
|
+
}
|
37
|
+
|
38
|
+
public void translate(double x , double y, double z){
|
39
|
+
|
40
|
+
this.x+= x;
|
41
|
+
this.y+= y;
|
42
|
+
this.z+= z;
|
43
|
+
}
|
44
|
+
|
45
|
+
public LambertPoint toDegree(){
|
46
|
+
this.x = this.x * 180/Math.PI;
|
47
|
+
this.y = this.y * 180/Math.PI;
|
48
|
+
this.z = this.z * 180/Math.PI;
|
49
|
+
|
50
|
+
return this;
|
51
|
+
}
|
52
|
+
}
|
@@ -0,0 +1,101 @@
|
|
1
|
+
package com.yageek.lambertruby;
|
2
|
+
|
3
|
+
|
4
|
+
import java.lang.Long;
|
5
|
+
import java.io.IOException;
|
6
|
+
import org.jruby.Ruby;
|
7
|
+
import org.jruby.RubyArray;
|
8
|
+
import org.jruby.RubyClass;
|
9
|
+
import org.jruby.RubyFixnum;
|
10
|
+
import org.jruby.RubyFloat;
|
11
|
+
import org.jruby.RubyModule;
|
12
|
+
import org.jruby.RubyObject;
|
13
|
+
import org.jruby.anno.JRubyMethod;
|
14
|
+
import org.jruby.anno.JRubyClass;
|
15
|
+
import org.jruby.runtime.ObjectAllocator;
|
16
|
+
import org.jruby.runtime.ThreadContext;
|
17
|
+
import org.jruby.runtime.builtin.IRubyObject;
|
18
|
+
import org.jruby.runtime.load.BasicLibraryService;
|
19
|
+
|
20
|
+
public class LambertRubyService implements BasicLibraryService {
|
21
|
+
|
22
|
+
private Ruby runtime;
|
23
|
+
|
24
|
+
public boolean basicLoad(Ruby runtime) throws IOException {
|
25
|
+
this.runtime = runtime;
|
26
|
+
|
27
|
+
RubyModule lambert = runtime.defineModule("Lambert");
|
28
|
+
|
29
|
+
lambert.defineConstant("LambertI", runtime.newFixnum(0));
|
30
|
+
lambert.defineConstant("LambertII", runtime.newFixnum(1));
|
31
|
+
lambert.defineConstant("LambertIII", runtime.newFixnum(2));
|
32
|
+
lambert.defineConstant("LambertIV", runtime.newFixnum(3));
|
33
|
+
lambert.defineConstant("LambertIIExtended", runtime.newFixnum(4));
|
34
|
+
lambert.defineConstant("Lambert93", runtime.newFixnum(5));
|
35
|
+
|
36
|
+
RubyClass lambertPoint = lambert.defineClassUnder("LambertPoint",runtime.getObject(), new ObjectAllocator() {
|
37
|
+
|
38
|
+
public IRubyObject allocate(Ruby runtime, RubyClass rubyClass){
|
39
|
+
|
40
|
+
return new LambertPointRuby(runtime, rubyClass);
|
41
|
+
}
|
42
|
+
|
43
|
+
});
|
44
|
+
|
45
|
+
lambertPoint.defineAnnotatedMethods(LambertPointRuby.class);
|
46
|
+
lambertPoint.addReadAttribute(runtime.getCurrentContext(), "x");
|
47
|
+
lambertPoint.addReadAttribute(runtime.getCurrentContext(), "y");
|
48
|
+
lambertPoint.addReadAttribute(runtime.getCurrentContext(), "z");
|
49
|
+
|
50
|
+
return true;
|
51
|
+
}
|
52
|
+
|
53
|
+
@JRubyClass(name = "Lambert::LambertPoint")
|
54
|
+
public class LambertPointRuby extends RubyObject{
|
55
|
+
|
56
|
+
public LambertPointRuby(final Ruby runtime, RubyClass rubyClass){
|
57
|
+
super(runtime, rubyClass);
|
58
|
+
|
59
|
+
}
|
60
|
+
@JRubyMethod
|
61
|
+
public IRubyObject initialize(ThreadContext context, IRubyObject x, IRubyObject y, IRubyObject z){
|
62
|
+
|
63
|
+
setInstanceVariable("@x", x);
|
64
|
+
setInstanceVariable("@y", y);
|
65
|
+
setInstanceVariable("@z", z);
|
66
|
+
|
67
|
+
return context.nil;
|
68
|
+
}
|
69
|
+
|
70
|
+
@JRubyMethod
|
71
|
+
public void wgs84(ThreadContext context, IRubyObject zone){
|
72
|
+
|
73
|
+
int zoneInt = (int) zone.convertToInteger().getLongValue();
|
74
|
+
|
75
|
+
net.yageek.lambert.LambertZone jZone = net.yageek.lambert.LambertZone.Lambert93;
|
76
|
+
switch(((int) zoneInt)){
|
77
|
+
case 0: jZone = net.yageek.lambert.LambertZone.LambertI; break;
|
78
|
+
case 1: jZone = net.yageek.lambert.LambertZone.LambertII; break;
|
79
|
+
case 2: jZone = net.yageek.lambert.LambertZone.LambertIII; break;
|
80
|
+
case 3: jZone = net.yageek.lambert.LambertZone.LambertIV; break;
|
81
|
+
case 4: jZone = net.yageek.lambert.LambertZone.LambertIIExtended; break;
|
82
|
+
case 5: jZone = net.yageek.lambert.LambertZone.Lambert93; break;
|
83
|
+
default:
|
84
|
+
}
|
85
|
+
|
86
|
+
double x = getInstanceVariable("@x").convertToFloat().getDoubleValue();
|
87
|
+
double y = getInstanceVariable("@y").convertToFloat().getDoubleValue();
|
88
|
+
double z = getInstanceVariable("@z").convertToFloat().getDoubleValue();
|
89
|
+
|
90
|
+
net.yageek.lambert.LambertPoint val = new net.yageek.lambert.LambertPoint(x, y, z);
|
91
|
+
net.yageek.lambert.LambertPoint convertedVal = net.yageek.lambert.Lambert.convertToWGS84(val, jZone);
|
92
|
+
convertedVal.toDegree();
|
93
|
+
|
94
|
+
setInstanceVariable("@x",runtime.newFloat(convertedVal.getX()));
|
95
|
+
setInstanceVariable("@y",runtime.newFloat(convertedVal.getY()));
|
96
|
+
setInstanceVariable("@z",runtime.newFloat(convertedVal.getZ()));
|
97
|
+
|
98
|
+
}
|
99
|
+
|
100
|
+
}
|
101
|
+
}
|
@@ -0,0 +1,45 @@
|
|
1
|
+
|
2
|
+
package net.yageek.lambert;
|
3
|
+
|
4
|
+
public enum LambertZone{
|
5
|
+
|
6
|
+
LambertI(0),LambertII(1), LambertIII(2), LambertIV(3), LambertIIExtended(4),Lambert93(5);
|
7
|
+
private final int lambertZone;
|
8
|
+
|
9
|
+
private final static double[] LAMBERT_N = {0.7604059656, 0.7289686274, 0.6959127966, 0.6712679322, 0.7289686274, 0.7256077650};
|
10
|
+
private final static double[] LAMBERT_C = {11603796.98, 11745793.39, 11947992.52, 12136281.99, 11745793.39, 11754255.426};
|
11
|
+
private final static double[] LAMBERT_XS = {600000.0, 600000.0, 600000.0, 234.358, 600000.0, 700000.0};
|
12
|
+
private final static double[] LAMBERT_YS = {5657616.674, 6199695.768, 6791905.085, 7239161.542, 8199695.768, 12655612.050};
|
13
|
+
|
14
|
+
public final static double M_PI_2 = Math.PI/2.0;
|
15
|
+
public final static double DEFAULT_EPS = 1e-10 ;
|
16
|
+
public final static double E_CLARK_IGN = 0.08248325676 ;
|
17
|
+
public final static double E_WGS84 = 0.08181919106 ;
|
18
|
+
|
19
|
+
public final static double A_CLARK_IGN = 6378249.2 ;
|
20
|
+
public final static double A_WGS84 = 6378137.0 ;
|
21
|
+
public final static double LON_MERID_PARIS = 0 ;
|
22
|
+
public final static double LON_MERID_GREENWICH =0.04079234433 ;
|
23
|
+
public final static double LON_MERID_IERS = 3.0*Math.PI/180.0;
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
private LambertZone(int value){
|
28
|
+
this.lambertZone = value;
|
29
|
+
}
|
30
|
+
|
31
|
+
public double n(){
|
32
|
+
return this.LAMBERT_N[this.lambertZone];
|
33
|
+
}
|
34
|
+
|
35
|
+
public double c(){
|
36
|
+
return this.LAMBERT_C[this.lambertZone];
|
37
|
+
}
|
38
|
+
public double xs(){
|
39
|
+
return this.LAMBERT_XS[this.lambertZone];
|
40
|
+
}
|
41
|
+
public double ys(){
|
42
|
+
return this.LAMBERT_YS[this.lambertZone];
|
43
|
+
}
|
44
|
+
|
45
|
+
}
|
@@ -0,0 +1,357 @@
|
|
1
|
+
/*
|
2
|
+
* Source des algorithmes : http://geodesie.ign.fr/contenu/fichiers/documentation/algorithmes/notice/NTG_71.pdf
|
3
|
+
*
|
4
|
+
*/
|
5
|
+
|
6
|
+
#include "lambert.h"
|
7
|
+
#include <math.h>
|
8
|
+
#include <stdio.h>
|
9
|
+
|
10
|
+
|
11
|
+
static double lambert_n[6] = {0.7604059656, 0.7289686274, 0.6959127966, 0.6712679322, 0.7289686274, 0.7256077650};
|
12
|
+
static double lambert_c[6] = {11603796.98, 11745793.39, 11947992.52, 12136281.99, 11745793.39, 11754255.426};
|
13
|
+
static double lambert_xs[6]= {600000.0, 600000.0, 600000.0, 234.358, 600000.0, 700000.0};
|
14
|
+
static double lambert_ys[6]= {5657616.674, 6199695.768, 6791905.085, 7239161.542, 8199695.768, 12655612.050};
|
15
|
+
|
16
|
+
YGPoint __YGDegreeToRadian(YGPoint pt)
|
17
|
+
{
|
18
|
+
pt.x = pt.x * M_PI / 180.0;
|
19
|
+
pt.y = pt.y * M_PI / 180.0;
|
20
|
+
pt.z = pt.z * M_PI / 180.0;
|
21
|
+
|
22
|
+
pt.unit = RADIAN;
|
23
|
+
|
24
|
+
return pt;
|
25
|
+
}
|
26
|
+
|
27
|
+
YGPoint __YGRadianToDegree(YGPoint pt)
|
28
|
+
{
|
29
|
+
pt.x = pt.x * 180/ M_PI;
|
30
|
+
pt.y = pt.y * 180/ M_PI;
|
31
|
+
pt.z = pt.z * 180/ M_PI;
|
32
|
+
|
33
|
+
pt.unit = DEGREE;
|
34
|
+
|
35
|
+
return pt;
|
36
|
+
}
|
37
|
+
|
38
|
+
YGPoint __YGGradToRadian(YGPoint pt)
|
39
|
+
{
|
40
|
+
pt.x = pt.x * M_PI/200.0;
|
41
|
+
pt.y = pt.y * M_PI/200.0;
|
42
|
+
pt.z = pt.z * M_PI/200.0;
|
43
|
+
|
44
|
+
pt.unit = RADIAN;
|
45
|
+
|
46
|
+
return pt;
|
47
|
+
}
|
48
|
+
YGPoint __YGRadianToGrad(YGPoint pt)
|
49
|
+
{
|
50
|
+
pt.x = pt.x * 200.0/M_PI;
|
51
|
+
pt.y = pt.y * 200.0/M_PI;
|
52
|
+
pt.z = pt.z * 200.0/M_PI;
|
53
|
+
|
54
|
+
pt.unit = GRAD;
|
55
|
+
|
56
|
+
return pt;
|
57
|
+
}
|
58
|
+
|
59
|
+
YGPoint __YGGradToDegree(YGPoint pt)
|
60
|
+
{
|
61
|
+
pt.x = pt.x * 180.0/200.0;
|
62
|
+
pt.y = pt.y * 180.0/200.0;
|
63
|
+
pt.z = pt.z * 180.0/200.0;
|
64
|
+
|
65
|
+
pt.unit = DEGREE;
|
66
|
+
|
67
|
+
return pt;
|
68
|
+
|
69
|
+
}
|
70
|
+
|
71
|
+
YGPoint __YGDegreeToGrad(YGPoint pt)
|
72
|
+
{
|
73
|
+
pt.x = pt.x * 200.0/180.0;
|
74
|
+
pt.y = pt.y * 200.0/180.0;
|
75
|
+
pt.z = pt.z * 200.0/180.0;
|
76
|
+
|
77
|
+
pt.unit = GRAD;
|
78
|
+
|
79
|
+
return pt;
|
80
|
+
}
|
81
|
+
|
82
|
+
|
83
|
+
YGPoint YGPointToDegree(YGPoint pt)
|
84
|
+
{
|
85
|
+
|
86
|
+
switch (pt.unit)
|
87
|
+
{
|
88
|
+
case RADIAN :
|
89
|
+
{
|
90
|
+
pt = __YGRadianToDegree(pt);
|
91
|
+
}
|
92
|
+
break;
|
93
|
+
case GRAD :
|
94
|
+
{
|
95
|
+
pt = __YGGradToDegree(pt);
|
96
|
+
}
|
97
|
+
break;
|
98
|
+
default:
|
99
|
+
break;
|
100
|
+
}
|
101
|
+
|
102
|
+
return pt;
|
103
|
+
|
104
|
+
}
|
105
|
+
|
106
|
+
|
107
|
+
YGPoint YGPointToRadian(YGPoint pt)
|
108
|
+
{
|
109
|
+
switch (pt.unit)
|
110
|
+
{
|
111
|
+
case DEGREE :
|
112
|
+
{
|
113
|
+
pt = __YGDegreeToRadian(pt);
|
114
|
+
}
|
115
|
+
break;
|
116
|
+
case GRAD :
|
117
|
+
{
|
118
|
+
pt = __YGGradToRadian(pt);
|
119
|
+
}
|
120
|
+
break;
|
121
|
+
default:
|
122
|
+
break;
|
123
|
+
}
|
124
|
+
|
125
|
+
return pt;
|
126
|
+
}
|
127
|
+
|
128
|
+
YGPoint YGPointToGrad(YGPoint pt)
|
129
|
+
{
|
130
|
+
switch (pt.unit)
|
131
|
+
{
|
132
|
+
case RADIAN :
|
133
|
+
{
|
134
|
+
pt = __YGRadianToGrad(pt);
|
135
|
+
}
|
136
|
+
break;
|
137
|
+
case DEGREE :
|
138
|
+
{
|
139
|
+
pt = __YGDegreeToGrad(pt);
|
140
|
+
}
|
141
|
+
break;
|
142
|
+
default:
|
143
|
+
break;
|
144
|
+
}
|
145
|
+
|
146
|
+
return pt;
|
147
|
+
}
|
148
|
+
|
149
|
+
YGPoint YGPointToUnit(YGPoint point, CoordUnit unit)
|
150
|
+
{
|
151
|
+
switch (unit) {
|
152
|
+
case DEGREE:
|
153
|
+
return YGPointToDegree(point);
|
154
|
+
break;
|
155
|
+
case GRAD:
|
156
|
+
return YGPointToGrad(point);
|
157
|
+
case RADIAN :
|
158
|
+
return YGPointToDegree(point);
|
159
|
+
break;
|
160
|
+
default:
|
161
|
+
return point;
|
162
|
+
break;
|
163
|
+
}
|
164
|
+
}
|
165
|
+
|
166
|
+
/*****************
|
167
|
+
** IGN algorithms
|
168
|
+
*****************/
|
169
|
+
|
170
|
+
double __YGLatitudeISOFromLatitude(double lat, double e)
|
171
|
+
{
|
172
|
+
return log(tan(M_PI_4+lat/2)*pow((1-e*sin(lat))/(1+e*sin(lat)),e/2));
|
173
|
+
}
|
174
|
+
|
175
|
+
/*
|
176
|
+
* ALGO0002
|
177
|
+
*/
|
178
|
+
|
179
|
+
double __YGLatitudeFromLatitudeISO(double lat_iso, double e,double eps)
|
180
|
+
{
|
181
|
+
|
182
|
+
double phi_0 = 2*atan(exp(lat_iso)) - M_PI_2;
|
183
|
+
double phi_i = 2*atan(pow((1+e*sin(phi_0))/(1-e*sin(phi_0)),e/2.0)*exp(lat_iso)) - M_PI_2;
|
184
|
+
double delta ;
|
185
|
+
while(delta = fabs(phi_i - phi_0),delta > eps)
|
186
|
+
{
|
187
|
+
phi_0 = phi_i;
|
188
|
+
phi_i = 2*atan(pow((1+e*sin(phi_0))/(1-e*sin(phi_0)),e/2.0)*exp(lat_iso)) - M_PI_2;
|
189
|
+
}
|
190
|
+
|
191
|
+
return phi_i;
|
192
|
+
|
193
|
+
}
|
194
|
+
/*
|
195
|
+
* ALGO0004 - Lambert vers geographiques
|
196
|
+
*/
|
197
|
+
|
198
|
+
YGPoint __YGLambertToGeographic(YGPoint org, YGLambertZone zone, double lon_merid, double e, double eps)
|
199
|
+
{
|
200
|
+
double n = lambert_n[zone];
|
201
|
+
double C = lambert_c[zone];
|
202
|
+
double x_s = lambert_xs[zone];
|
203
|
+
double y_s = lambert_ys[zone];
|
204
|
+
|
205
|
+
double x = org.x;
|
206
|
+
double y = org.y;
|
207
|
+
|
208
|
+
double lon, gamma, R, lat_iso;
|
209
|
+
|
210
|
+
R = sqrt((x-x_s)*(x-x_s)+(y-y_s)*(y-y_s));
|
211
|
+
|
212
|
+
gamma = atan((x-x_s)/(y_s-y));
|
213
|
+
|
214
|
+
lon = lon_merid + gamma/n;
|
215
|
+
|
216
|
+
lat_iso = -1/n*log(fabs(R/C));
|
217
|
+
|
218
|
+
double lat = __YGLatitudeFromLatitudeISO(lat_iso,e,eps);
|
219
|
+
|
220
|
+
org.x = lon;
|
221
|
+
org.y = lat;
|
222
|
+
|
223
|
+
return org;
|
224
|
+
}
|
225
|
+
|
226
|
+
|
227
|
+
/*
|
228
|
+
* ALGO0021 - Calcul de la grande Normale
|
229
|
+
*
|
230
|
+
*/
|
231
|
+
|
232
|
+
double __YGLambertNormal(double lat, double a, double e)
|
233
|
+
{
|
234
|
+
|
235
|
+
return a/sqrt(1-e*e*sin(lat)*sin(lat));
|
236
|
+
}
|
237
|
+
|
238
|
+
/**
|
239
|
+
* ALGO0009 - Transformations geographiques -> cartésiennes
|
240
|
+
*
|
241
|
+
*
|
242
|
+
*/
|
243
|
+
|
244
|
+
YGPoint __YGGeographicToCartesian(double lon, double lat, double he, double a, double e)
|
245
|
+
{
|
246
|
+
double N = __YGLambertNormal(lat,a,e);
|
247
|
+
|
248
|
+
YGPoint pt = {0,0,0};
|
249
|
+
pt.x = (N+he)*cos(lat)*cos(lon);
|
250
|
+
|
251
|
+
pt.y = (N+he)*cos(lat)*sin(lon);
|
252
|
+
|
253
|
+
pt.z = (N*(1-e*e)+he)*sin(lat);
|
254
|
+
|
255
|
+
return pt;
|
256
|
+
|
257
|
+
}
|
258
|
+
|
259
|
+
/*
|
260
|
+
* ALGO0012 - Passage des coordonnées cartésiennes aux coordonnées géographiques
|
261
|
+
*/
|
262
|
+
|
263
|
+
YGPoint __YGCartesianToGeographic(YGPoint org, double meridien, double a, double e , double eps)
|
264
|
+
{
|
265
|
+
double x = org.x, y = org.y, z = org.z;
|
266
|
+
|
267
|
+
double lon = meridien + atan(y/x);
|
268
|
+
|
269
|
+
double module = sqrt(x*x + y*y);
|
270
|
+
|
271
|
+
double phi_0 = atan(z/(module*(1-(a*e*e)/sqrt(x*x+y*y+z*z))));
|
272
|
+
double phi_i = atan(z/module/(1-a*e*e*cos(phi_0)/(module * sqrt(1-e*e*sin(phi_0)*sin(phi_0)))));
|
273
|
+
double delta;
|
274
|
+
while(delta = fabs(phi_i - phi_0),delta > eps)
|
275
|
+
{
|
276
|
+
phi_0 = phi_i;
|
277
|
+
phi_i = atan(z/module/(1-a*e*e*cos(phi_0)/(module * sqrt(1-e*e*sin(phi_0)*sin(phi_0)))));
|
278
|
+
|
279
|
+
}
|
280
|
+
|
281
|
+
double he = module/cos(phi_i) - a/sqrt(1-e*e*sin(phi_i)*sin(phi_i));
|
282
|
+
|
283
|
+
YGPoint pt;
|
284
|
+
pt.x = lon;
|
285
|
+
pt.y = phi_i;
|
286
|
+
pt.z = he;
|
287
|
+
pt.unit = RADIAN;
|
288
|
+
|
289
|
+
return pt;
|
290
|
+
}
|
291
|
+
|
292
|
+
/*
|
293
|
+
* Convert Lambert -> WGS84
|
294
|
+
* http://geodesie.ign.fr/contenu/fichiers/documentation/pedagogiques/transfo.pdf
|
295
|
+
*
|
296
|
+
*/
|
297
|
+
|
298
|
+
YGPoint YGPointConvertWGS84(YGPoint point, YGLambertZone zone){
|
299
|
+
|
300
|
+
if(point.unit != METER)
|
301
|
+
{
|
302
|
+
perror("Could not operate on a non METER based point!\n The points returned will be the same!\n");
|
303
|
+
return point;
|
304
|
+
}
|
305
|
+
|
306
|
+
if(LAMBERT_93 == zone)
|
307
|
+
{
|
308
|
+
point = __YGLambertToGeographic(point,zone,LON_MERID_IERS,E_WGS84,DEFAULT_EPS);
|
309
|
+
|
310
|
+
}
|
311
|
+
else
|
312
|
+
{
|
313
|
+
point = __YGLambertToGeographic(point,zone,LON_MERID_PARIS,E_CLARK_IGN,DEFAULT_EPS);
|
314
|
+
point = __YGGeographicToCartesian(point.x,point.y,point.z,A_CLARK_IGN,E_CLARK_IGN);
|
315
|
+
|
316
|
+
point.x-= 168;
|
317
|
+
point.y-= 60;
|
318
|
+
point.z+= 320;
|
319
|
+
|
320
|
+
//WGS84 refers to greenwich
|
321
|
+
point = __YGCartesianToGeographic(point, LON_MERID_GREENWICH, A_WGS84,E_WGS84,DEFAULT_EPS);
|
322
|
+
}
|
323
|
+
|
324
|
+
point.unit = RADIAN;
|
325
|
+
return point;
|
326
|
+
}
|
327
|
+
|
328
|
+
|
329
|
+
|
330
|
+
double __YGLatitudeISO(double lat, double e)
|
331
|
+
{
|
332
|
+
return log(tan(M_PI_4 + lat/2)*pow((1-e*sin(lat))/(1+e*sin(lat)),e/2));
|
333
|
+
}
|
334
|
+
|
335
|
+
YGPoint __YGCoordinatesTransform(double e, double n, double c, double lambda_c, double x_s, double y_s , double lon, double lat)
|
336
|
+
{
|
337
|
+
YGPoint dest = {0,0,0};
|
338
|
+
|
339
|
+
double latiso = __YGLatitudeISO(lat,e);
|
340
|
+
dest.x = x_s + e*exp(-n*latiso)*sin(n*(lon-lambda_c));
|
341
|
+
dest.y = y_s + e*exp(n*latiso)*cos(n*(lon-lambda_c));
|
342
|
+
|
343
|
+
return dest;
|
344
|
+
|
345
|
+
}
|
346
|
+
|
347
|
+
YGPoint __YGSwitchGeodesicSystem(YGPoint u, Vector t, double d, Vector r)
|
348
|
+
{
|
349
|
+
YGPoint v = {0,0,0};
|
350
|
+
|
351
|
+
v.x = t.x + u.x*(1+d) + u.z * r.y - u.y * r.z;
|
352
|
+
v.y = t.y + u.y*(1+d) + u.x * r.z - u.y * r.z;
|
353
|
+
v.z = t.z +u.z*(1+d) + u.y*r.x -u.x*r.y;
|
354
|
+
|
355
|
+
return v;
|
356
|
+
|
357
|
+
}
|
@@ -0,0 +1,126 @@
|
|
1
|
+
#ifndef __LAMBERT_H
|
2
|
+
#define __LAMBERT_H
|
3
|
+
|
4
|
+
|
5
|
+
#define DEFAULT_EPS 1e-10
|
6
|
+
#define E_CLARK_IGN 0.08248325676
|
7
|
+
#define E_WGS84 0.08181919106
|
8
|
+
|
9
|
+
#define A_CLARK_IGN 6378249.2
|
10
|
+
#define A_WGS84 6378137.0
|
11
|
+
|
12
|
+
#define LON_MERID_PARIS 0
|
13
|
+
#define LON_MERID_GREENWICH 0.04079234433
|
14
|
+
#define LON_MERID_IERS (3*M_PI/180)
|
15
|
+
#define AUTOCOMEIQUE_FIRST 44*M_PI/180
|
16
|
+
#define AUTOCOMEIQUE_SECOND 49*M_PI/180
|
17
|
+
#define LAT_ORIG 46.5*M_PI/180
|
18
|
+
#define ct_x0 700000.0
|
19
|
+
#define ct_y0 6600000.0
|
20
|
+
|
21
|
+
|
22
|
+
typedef enum {
|
23
|
+
LAMBERT_I=0,
|
24
|
+
LAMBERT_II=1,
|
25
|
+
LAMBERT_III=2,
|
26
|
+
LAMBERT_IV=3,
|
27
|
+
LAMBERT_II_E=4,
|
28
|
+
LAMBERT_93= 5
|
29
|
+
} YGLambertZone;
|
30
|
+
|
31
|
+
typedef enum {
|
32
|
+
DEGREE,
|
33
|
+
GRAD,
|
34
|
+
RADIAN,
|
35
|
+
METER
|
36
|
+
} CoordUnit;
|
37
|
+
|
38
|
+
typedef struct {
|
39
|
+
double x;
|
40
|
+
double y;
|
41
|
+
double z;
|
42
|
+
CoordUnit unit;
|
43
|
+
} YGPoint;
|
44
|
+
|
45
|
+
typedef struct
|
46
|
+
{
|
47
|
+
double tx;
|
48
|
+
double ty;
|
49
|
+
double tz;
|
50
|
+
} YGTransform;
|
51
|
+
|
52
|
+
typedef YGPoint Vector;
|
53
|
+
|
54
|
+
#define __YGPointWithUnit(_x,_y,_z,_unit) {.x=_x, .y=_y,.z=_z,.unit=_unit};
|
55
|
+
|
56
|
+
#define YGDegreePoint(x,y,z) __YGPointWithUnit(x,y,z,DEGREE)
|
57
|
+
#define YGRadianPoint(x,y,z) __YGPointWithUnit(x,y,z,RADIAN)
|
58
|
+
#define YGGradPoint(x,y,z) __YGPointWithUnit(x,y,z,GRAD)
|
59
|
+
#define YGMeterPoint(x,y,z) __YGPointWithUnit(x,y,z,METER)
|
60
|
+
|
61
|
+
|
62
|
+
YGPoint YGPointToRadian(YGPoint p);
|
63
|
+
YGPoint YGPointToDegree(YGPoint p);
|
64
|
+
YGPoint YGPointToGrad(YGPoint p);
|
65
|
+
YGPoint YGPointToUnit(YGPoint point, CoordUnit unit);
|
66
|
+
|
67
|
+
/*
|
68
|
+
* ALGO0021 - Calcul de la grande Normale
|
69
|
+
*
|
70
|
+
*/
|
71
|
+
double __YGLambertNormal(double lat, double a, double e);
|
72
|
+
|
73
|
+
/*
|
74
|
+
* Convert a YGPoint struct from one lambert zone to WGS84 (Rad)
|
75
|
+
*
|
76
|
+
*/
|
77
|
+
|
78
|
+
|
79
|
+
YGPoint YGPointConvertWGS84(YGPoint point, YGLambertZone zone);
|
80
|
+
|
81
|
+
/*
|
82
|
+
* ALGO0002
|
83
|
+
*/
|
84
|
+
|
85
|
+
double __YGLatitudeFromLatitudeISO(double lat_iso, double e, double eps);
|
86
|
+
|
87
|
+
/*
|
88
|
+
* ALGO0012
|
89
|
+
*/
|
90
|
+
|
91
|
+
YGPoint __YGCartesianToGeographic(YGPoint org, double meridien, double a, double e , double eps);
|
92
|
+
|
93
|
+
/*
|
94
|
+
* ALGO004
|
95
|
+
*/
|
96
|
+
YGPoint __YGLambertToGeographic(YGPoint org, YGLambertZone zone, double lon_merid, double e, double eps);
|
97
|
+
|
98
|
+
/**
|
99
|
+
* ALGO0009 - Transformations geographiques -> cartésiennes
|
100
|
+
*
|
101
|
+
*
|
102
|
+
*/
|
103
|
+
|
104
|
+
YGPoint __YGGeographicToCartesian(double lon, double lat, double he, double a, double e);
|
105
|
+
|
106
|
+
/**
|
107
|
+
* ALGO13 Transformation de Coordonnées à 7 paramètres entre deux systèmes géodésiques
|
108
|
+
*/
|
109
|
+
|
110
|
+
YGPoint __YGSwitchGeodesicSystem(YGPoint u, Vector t, double d, Vector r);
|
111
|
+
|
112
|
+
/**
|
113
|
+
* Algo0001 Calcul de la latitude isomérique
|
114
|
+
*/
|
115
|
+
double __YGLatitudeISO(double lat, double e);
|
116
|
+
|
117
|
+
/**
|
118
|
+
* Algo003
|
119
|
+
*/
|
120
|
+
YGPoint __YGCoordinatesTransform(double e, double n, double c, double lambda_c, double x_s, double y_s , double lon, double lat);
|
121
|
+
|
122
|
+
/**
|
123
|
+
* Algo 01
|
124
|
+
*/
|
125
|
+
double __YGLatitudeISOFromLatitude(double lat, double e);
|
126
|
+
#endif
|
@@ -0,0 +1,68 @@
|
|
1
|
+
#include <ruby.h>
|
2
|
+
#include "lambert.h"
|
3
|
+
|
4
|
+
static VALUE rb_mLambert;
|
5
|
+
static VALUE rb_cPoint;
|
6
|
+
|
7
|
+
static VALUE p_init(int argc, VALUE* argv, VALUE self)
|
8
|
+
{
|
9
|
+
|
10
|
+
VALUE x, y, z;
|
11
|
+
|
12
|
+
rb_scan_args(argc,argv, "21",&x, &y, &z);
|
13
|
+
|
14
|
+
if(NIL_P(z))
|
15
|
+
{
|
16
|
+
z = rb_float_new(0.0);
|
17
|
+
}
|
18
|
+
|
19
|
+
Check_Type(x,T_FLOAT);
|
20
|
+
Check_Type(y,T_FLOAT);
|
21
|
+
Check_Type(z,T_FLOAT);
|
22
|
+
|
23
|
+
rb_iv_set(self, "@x", x);
|
24
|
+
rb_iv_set(self, "@y", y);
|
25
|
+
rb_iv_set(self, "@z", z);
|
26
|
+
|
27
|
+
return self;
|
28
|
+
}
|
29
|
+
|
30
|
+
static VALUE p_convert(VALUE self,VALUE zone){
|
31
|
+
|
32
|
+
double x, y, z;
|
33
|
+
YGLambertZone cZone = NUM2INT(zone);
|
34
|
+
|
35
|
+
x = NUM2DBL(rb_iv_get(self,"@x"));
|
36
|
+
y = NUM2DBL(rb_iv_get(self,"@y"));
|
37
|
+
z = NUM2DBL(rb_iv_get(self,"@z"));
|
38
|
+
|
39
|
+
YGPoint org = YGMeterPoint(x,y,z);
|
40
|
+
org = YGPointConvertWGS84(org,cZone);
|
41
|
+
org = YGPointToDegree(org);
|
42
|
+
|
43
|
+
rb_iv_set(self, "@x", rb_float_new(org.x));
|
44
|
+
rb_iv_set(self, "@y", rb_float_new(org.y));
|
45
|
+
rb_iv_set(self, "@z", rb_float_new(org.z));
|
46
|
+
|
47
|
+
|
48
|
+
return Qnil;
|
49
|
+
}
|
50
|
+
|
51
|
+
void Init_lambert_ruby(void) {
|
52
|
+
|
53
|
+
rb_mLambert = rb_define_module("Lambert");
|
54
|
+
rb_cPoint = rb_define_class_under(rb_mLambert,"LambertPoint",rb_cObject);
|
55
|
+
rb_define_attr(rb_cPoint,"x",1,1);
|
56
|
+
rb_define_attr(rb_cPoint,"y",1,1);
|
57
|
+
rb_define_attr(rb_cPoint,"z",1,1);
|
58
|
+
|
59
|
+
rb_define_method(rb_cPoint,"initialize",p_init,-1);
|
60
|
+
rb_define_method(rb_cPoint,"wgs84",p_convert,1);
|
61
|
+
|
62
|
+
rb_define_const(rb_mLambert,"LambertI",INT2NUM(LAMBERT_I));
|
63
|
+
rb_define_const(rb_mLambert,"LambertII",INT2NUM(LAMBERT_II));
|
64
|
+
rb_define_const(rb_mLambert,"LambertIII",INT2NUM(LAMBERT_III));
|
65
|
+
rb_define_const(rb_mLambert,"LambertIV",INT2NUM(LAMBERT_IV));
|
66
|
+
rb_define_const(rb_mLambert,"LambertIIExtended",INT2NUM(LAMBERT_II_E));
|
67
|
+
rb_define_const(rb_mLambert,"Lambert93",INT2NUM(LAMBERT_93));
|
68
|
+
}
|
Binary file
|
data/lib/lambert_ruby.rb
ADDED
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lambert_ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.2
|
5
|
+
platform: java
|
6
|
+
authors:
|
7
|
+
- Yannick Heinrich
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-01-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - ">="
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: '0'
|
19
|
+
name: rake-compiler
|
20
|
+
prerelease: false
|
21
|
+
type: :development
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: Ruby wrapper for the lambert library
|
28
|
+
email: yannick.heinrich@gmail.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- ext/lambert_ruby/Lambert.java
|
34
|
+
- ext/lambert_ruby/LambertPoint.java
|
35
|
+
- ext/lambert_ruby/LambertRubyService.java
|
36
|
+
- ext/lambert_ruby/LambertZone.java
|
37
|
+
- ext/lambert_ruby/extconf.rb
|
38
|
+
- ext/lambert_ruby/lambert.c
|
39
|
+
- ext/lambert_ruby/lambert.h
|
40
|
+
- ext/lambert_ruby/lambert_ruby.c
|
41
|
+
- lib/lambert_ruby.jar
|
42
|
+
- lib/lambert_ruby.rb
|
43
|
+
homepage: http://rubygems.org/gems/lambert_ruby
|
44
|
+
licenses: []
|
45
|
+
metadata: {}
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options: []
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
requirements: []
|
61
|
+
rubyforge_project:
|
62
|
+
rubygems_version: 2.4.8
|
63
|
+
signing_key:
|
64
|
+
specification_version: 4
|
65
|
+
summary: Ruby wrapper for the lambert library
|
66
|
+
test_files: []
|