lambert_ruby 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- NzM5YmI2MWY2OWFhZTVlZmE4ODQ1NGU5YWYzZmU3NGYwNjljYzY3ZQ==
5
- data.tar.gz: !binary |-
6
- YWM1NWNiNTBlOWIyMGMzZDFjNGYyZmIyZGVjZTEwMjZmYmE1NDk3MA==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- YmI2ZmIwNDkxMjk2YjMwYTQzY2I3OTY0MTE0MmI1NWNjNjVhMjg3M2QyYmVh
10
- MmY5ODVkNjQ0M2IwMzE0ZmQzYjcxZDJhNjU2ZDQzNGI3NTA5YTNiODE1MTc4
11
- YzA5YzQ3MGY5YTI0ZGViZWEzNjBiZTg1YmNkNDU3OGVhYWQxOWE=
12
- data.tar.gz: !binary |-
13
- NTUzODYwZmQyYzQ2YTMwY2I4MDE2ZjRjOThlOTVhN2YxYzQwYWQyMDUwZjIw
14
- YmU5MzRkN2EzNWU1N2VkNzBhMjU3ZGY0ZTE4MmY4M2IxM2IyOGFhY2ZjMDJi
15
- ODVjMTg4NjM4Zjk3YWUyOWYwOTgxOTJlOTgwZWNhNzYzMzM0MWE=
2
+ SHA1:
3
+ metadata.gz: f6d21e2b9e2e9f9adc7d68c49b8b7815d5e79d46
4
+ data.tar.gz: ead3cb60d5d7fe04da12c7365e00af6340a27bba
5
+ SHA512:
6
+ metadata.gz: a885864daeb46f4bc2dbb4e28cef5619f64694724e59f81fcf489c251de4bb67a450bc057f87ad8ce3d31c919075a592b392a392e401db3c0aaa5282b3ce3d50
7
+ data.tar.gz: 93b944cb36c7078d73438e8edb4578680cde8b159c8fe475834e9ab950a7ede8d993462d92581e1f5e6ed11b627fede29e4e24b0b462cbe8d6e28369512855dd
@@ -17,8 +17,31 @@ static double lambert_c[6] = {11603796.98, 11745793.39, 11947992.52, 12136281.99
17
17
  static double lambert_xs[6]= {600000.0, 600000.0, 600000.0, 234.358, 600000.0, 700000.0};
18
18
  static double lambert_ys[6]= {5657616.674, 6199695.768, 6791905.085, 7239161.542, 8199695.768, 12655612.050};
19
19
 
20
+ YGPoint pointToDegree(YGPoint p)
21
+ {
22
+
23
+ p.x = p.x * 180/M_PI;
24
+ p.y = p.y * 180/M_PI;
25
+ p.z = p.z * 180/M_PI;
26
+
27
+ return p;
28
+ }
20
29
 
21
- /*
30
+ YGPoint pointToRadian(YGPoint p)
31
+ {
32
+ p.x = p.x * M_PI/180;
33
+ p.y = p.y * M_PI/180;
34
+ p.z = p.z * M_PI/180;
35
+
36
+ return p;
37
+ }
38
+
39
+ double latitude_iso_from_lat(double lat, double e)
40
+ {
41
+ return log(tan(M_PI_4+lat/2)*pow((1-e*sin(lat))/(1+e*sin(lat)),e/2));
42
+ }
43
+
44
+ /*
22
45
  * ALGO0002
23
46
  */
24
47
 
@@ -41,7 +64,7 @@ double lat_from_lat_iso(double lat_iso, double e,double eps)
41
64
  * ALGO0004 - Lambert vers geographiques
42
65
  */
43
66
 
44
- void lambert_to_geographic(const YGLambertPoint * org,YGLambertPoint *dest, LambertZone zone, double lon_merid, double e, double eps)
67
+ void lambert_to_geographic(const YGPoint * org,YGPoint *dest, YGLambertZone zone, double lon_merid, double e, double eps)
45
68
  {
46
69
  double n = lambert_n[zone];
47
70
  double C = lambert_c[zone];
@@ -85,11 +108,11 @@ double lambert_normal(double lat, double a, double e)
85
108
  *
86
109
  */
87
110
 
88
- YGLambertPoint geographic_to_cartesian(double lon, double lat, double he, double a, double e)
111
+ YGPoint geographic_to_cartesian(double lon, double lat, double he, double a, double e)
89
112
  {
90
113
  double N = lambert_normal(lat,a,e);
91
114
 
92
- YGLambertPoint pt = {0,0,0};
115
+ YGPoint pt = {0,0,0};
93
116
  pt.x = (N+he)*cos(lat)*cos(lon);
94
117
 
95
118
  pt.y = (N+he)*cos(lat)*sin(lon);
@@ -104,7 +127,7 @@ double lambert_normal(double lat, double a, double e)
104
127
  * ALGO0012 - Passage des coordonnées cartésiennes aux coordonnées géographiques
105
128
  */
106
129
 
107
- YGLambertPoint cartesian_to_geographic(YGLambertPoint org, double meridien, double a, double e , double eps)
130
+ YGPoint cartesian_to_geographic(YGPoint org, double meridien, double a, double e , double eps)
108
131
  {
109
132
  double x = org.x, y = org.y, z = org.z;
110
133
 
@@ -124,7 +147,7 @@ double lambert_normal(double lat, double a, double e)
124
147
 
125
148
  double he = module/cos(phi_i) - a/sqrt(1-e*e*sin(phi_i)*sin(phi_i));
126
149
 
127
- YGLambertPoint pt;
150
+ YGPoint pt;
128
151
  pt.x = lon;
129
152
  pt.y = phi_i;
130
153
  pt.z = he;
@@ -132,40 +155,71 @@ double lambert_normal(double lat, double a, double e)
132
155
  return pt;
133
156
  }
134
157
 
135
-
136
-
137
158
  /*
138
159
  * Convert Lambert -> WGS84
139
160
  * http://geodesie.ign.fr/contenu/fichiers/documentation/pedagogiques/transfo.pdf
140
161
  *
141
162
  */
142
163
 
143
- void lambert_to_wgs84(const YGLambertPoint * org, YGLambertPoint *dest,LambertZone zone){
164
+ void lambert_to_wgs84(const YGPoint * org, YGPoint *dest,YGLambertZone zone){
165
+
166
+
167
+
168
+ if(LAMBERT_93 == zone)
169
+ {
170
+ lambert_to_geographic(org,dest,zone,LON_MERID_IERS,E_WGS84,DEFAULT_EPS);
171
+ }
172
+ else
173
+ {
174
+ lambert_to_geographic(org,dest,zone,LON_MERID_PARIS,E_CLARK_IGN,DEFAULT_EPS);
175
+ YGPoint temp = geographic_to_cartesian(dest->x,dest->y,dest->z,A_CLARK_IGN,E_CLARK_IGN);
176
+
177
+ temp.x= temp.x - 168;
178
+ temp.y= temp.y - 60;
179
+ temp.z= temp.z + 320;
180
+
181
+ //WGS84 refers to greenwich
182
+ temp = cartesian_to_geographic(temp, LON_MERID_IERS, A_WGS84,E_WGS84,DEFAULT_EPS);
183
+
184
+ dest->x = temp.x;
185
+ dest->y = temp.y;
186
+ }
187
+ }
188
+
144
189
 
145
- lambert_to_geographic(org,dest,zone,LON_MERID_PARIS,E_CLARK_IGN,DEFAULT_EPS);
190
+ void lambert_to_wgs84_deg(const YGPoint * org, YGPoint *dest, YGLambertZone zone)
191
+ {
192
+ YGPoint temp = {0,0,0};
193
+
194
+ lambert_to_wgs84(org,&temp,zone);
195
+ *dest = pointToDegree(temp);
196
+ }
146
197
 
147
- YGLambertPoint temp = geographic_to_cartesian(dest->x,dest->y,dest->z,A_CLARK_IGN,E_CLARK_IGN);
198
+ double lat_iso(double lat, double e)
199
+ {
200
+ return log(tan(M_PI_4 + lat/2)*pow((1-e*sin(lat))/(1+e*sin(lat)),e/2));
201
+ }
148
202
 
149
- temp.x= temp.x - 168;
150
- temp.y= temp.y - 60;
151
- temp.z= temp.z + 320;
203
+ YGPoint coord_transform(double e, double n, double c, double lambda_c, double x_s, double y_s , double lon, double lat)
204
+ {
205
+ YGPoint dest = {0,0,0};
152
206
 
153
- //WGS84 refers to greenwich
154
- temp = cartesian_to_geographic(temp, LON_MERID_GREENWICH, A_WGS84,E_WGS84,DEFAULT_EPS);
207
+ double latiso = lat_iso(lat,e);
208
+ dest.x = x_s + e*exp(-n*latiso)*sin(n*(lon-lambda_c));
209
+ dest.y = y_s + e*exp(n*latiso)*cos(n*(lon-lambda_c));
155
210
 
156
- dest->x = temp.x;
157
- dest->y = temp.y;
211
+ return dest;
158
212
 
159
213
  }
160
214
 
161
-
162
- void lambert_to_wgs84_deg(const YGLambertPoint * org, YGLambertPoint *dest, LambertZone zone)
215
+ YGPoint switch_geodesic_system(YGPoint u, Vector t, double d, Vector r)
163
216
  {
164
- YGLambertPoint temp = {0,0,0};
165
-
166
- lambert_to_wgs84(org,&temp,zone);
217
+ YGPoint v = {0,0,0};
167
218
 
168
- dest->x = temp.x * 180/M_PI;
169
- dest->y = temp.y * 180/M_PI;
170
- dest->z = temp.z * 180/M_PI;
171
- }
219
+ v.x = t.x + u.x*(1+d) + u.z * r.y - u.y * r.z;
220
+ v.y = t.y + u.y*(1+d) + u.x * r.z - u.y * r.z;
221
+ v.z = t.z +u.z*(1+d) + u.y*r.x -u.x*r.y;
222
+
223
+ return v;
224
+
225
+ }
@@ -1,3 +1,7 @@
1
+ #ifndef __LAMBERT_H
2
+ #define __LAMBERT_H
3
+
4
+
1
5
  #define DEFAULT_EPS 1e-10
2
6
  #define E_CLARK_IGN 0.08248325676
3
7
  #define E_WGS84 0.08181919106
@@ -7,9 +11,15 @@
7
11
 
8
12
  #define LON_MERID_PARIS 0
9
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
10
20
 
11
- #define DISPLAY_YGLambertPoint(YGLambertPoint) printf(#YGLambertPoint" X:%f | Y:%f | Z:%f\n",YGLambertPoint.x,YGLambertPoint.y,YGLambertPoint.z);
12
- #define DISPLAY_YGLambertPoint_REF(YGLambertPoint) printf(#YGLambertPoint" X:%f | Y:%f | Z:%f\n",YGLambertPoint->x,YGLambertPoint->y,YGLambertPoint->z);
21
+ #define DISPLAY_YGPoint(YGPoint) printf(#YGPoint" X:%f | Y:%f | Z:%f\n",YGPoint.x,YGPoint.y,YGPoint.z);
22
+ #define DISPLAY_YGPoint_REF(YGPoint) printf(#YGPoint" X:%f | Y:%f | Z:%f\n",YGPoint->x,YGPoint->y,YGPoint->z);
13
23
 
14
24
  typedef enum {
15
25
  LAMBERT_I=0,
@@ -18,14 +28,32 @@ typedef enum {
18
28
  LAMBERT_IV=3,
19
29
  LAMBERT_II_E=4,
20
30
  LAMBERT_93= 5
21
- } LambertZone;
31
+ } YGLambertZone;
32
+
33
+ typedef enum {
34
+ DEGREE,
35
+ GRAD,
36
+ RADIAN
37
+ } CoordUnit;
22
38
 
23
39
  typedef struct {
24
40
  double x;
25
41
  double y;
26
42
  double z;
27
- } YGLambertPoint;
43
+ CoordUnit unit;
44
+ } YGPoint;
28
45
 
46
+ typedef struct
47
+ {
48
+ double tx;
49
+ double ty;
50
+ double tz;
51
+ } YGTransform;
52
+
53
+ typedef YGPoint Vector;
54
+
55
+ YGPoint pointToRadian(YGPoint p);
56
+ YGPoint pointToDegree(YGPoint p);
29
57
 
30
58
  /*
31
59
  * ALGO0021 - Calcul de la grande Normale
@@ -34,16 +62,16 @@ typedef struct {
34
62
  double lambert_normal(double lat, double a, double e);
35
63
 
36
64
  /*
37
- * Convert a YGLambertPoint struct from one lambert zone to WGS84 (Rad)
65
+ * Convert a YGPoint struct from one lambert zone to WGS84 (Rad)
38
66
  *
39
67
  */
40
- void lambert_to_wgs84(const YGLambertPoint * org, YGLambertPoint *dest, LambertZone zone);
68
+ void lambert_to_wgs84(const YGPoint * org, YGPoint *dest, YGLambertZone zone);
41
69
 
42
70
  /*
43
- * Convert a YGLambertPoint struct from one lambert zone to WGS84 (Deg)
71
+ * Convert a YGPoint struct from one lambert zone to WGS84 (Deg)
44
72
  *
45
73
  */
46
- void lambert_to_wgs84_deg(const YGLambertPoint * org, YGLambertPoint *dest, LambertZone zone);
74
+ void lambert_to_wgs84_deg(const YGPoint * org, YGPoint *dest, YGLambertZone zone);
47
75
 
48
76
  /*
49
77
  * ALGO0002
@@ -55,12 +83,12 @@ double lat_from_lat_iso(double lat_iso, double e, double eps);
55
83
  * ALGO0012
56
84
  */
57
85
 
58
- YGLambertPoint cartesian_to_geographic(YGLambertPoint org, double meridien, double a, double e , double eps);
86
+ YGPoint cartesian_to_geographic(YGPoint org, double meridien, double a, double e , double eps);
59
87
 
60
88
  /*
61
89
  * ALGO004
62
90
  */
63
- void lambert_to_geographic(const YGLambertPoint * org,YGLambertPoint *dest, LambertZone zone, double lon_merid, double e, double eps);
91
+ void lambert_to_geographic(const YGPoint * org,YGPoint *dest, YGLambertZone zone, double lon_merid, double e, double eps);
64
92
 
65
93
  /**
66
94
  * ALGO0009 - Transformations geographiques -> cartésiennes
@@ -68,4 +96,26 @@ void lambert_to_geographic(const YGLambertPoint * org,YGLambertPoint *dest, Lamb
68
96
  *
69
97
  */
70
98
 
71
- YGLambertPoint geographic_to_cartesian(double lon, double lat, double he, double a, double e);
99
+ YGPoint geographic_to_cartesian(double lon, double lat, double he, double a, double e);
100
+
101
+ /**
102
+ * ALGO13 Transformation de Coordonnées à 7 paramètres entre deux systèmes géodésiques
103
+ */
104
+
105
+ YGPoint switch_geodesic_system(YGPoint u, Vector t, double d, Vector r);
106
+
107
+ /**
108
+ * Algo0001 Calcul de la latitude isomérique
109
+ */
110
+ double lat_iso(double lat, double e);
111
+
112
+ /**
113
+ * Algo003
114
+ */
115
+ YGPoint coord_transform(double e, double n, double c, double lambda_c, double x_s, double y_s , double lon, double lat);
116
+
117
+ /**
118
+ * Algo 01
119
+ */
120
+ double latitude_iso_from_lat(double lat, double e);
121
+ #endif
@@ -17,8 +17,31 @@ static double lambert_c[6] = {11603796.98, 11745793.39, 11947992.52, 12136281.99
17
17
  static double lambert_xs[6]= {600000.0, 600000.0, 600000.0, 234.358, 600000.0, 700000.0};
18
18
  static double lambert_ys[6]= {5657616.674, 6199695.768, 6791905.085, 7239161.542, 8199695.768, 12655612.050};
19
19
 
20
+ YGPoint pointToDegree(YGPoint p)
21
+ {
22
+
23
+ p.x = p.x * 180/M_PI;
24
+ p.y = p.y * 180/M_PI;
25
+ p.z = p.z * 180/M_PI;
26
+
27
+ return p;
28
+ }
20
29
 
21
- /*
30
+ YGPoint pointToRadian(YGPoint p)
31
+ {
32
+ p.x = p.x * M_PI/180;
33
+ p.y = p.y * M_PI/180;
34
+ p.z = p.z * M_PI/180;
35
+
36
+ return p;
37
+ }
38
+
39
+ double latitude_iso_from_lat(double lat, double e)
40
+ {
41
+ return log(tan(M_PI_4+lat/2)*pow((1-e*sin(lat))/(1+e*sin(lat)),e/2));
42
+ }
43
+
44
+ /*
22
45
  * ALGO0002
23
46
  */
24
47
 
@@ -41,7 +64,7 @@ double lat_from_lat_iso(double lat_iso, double e,double eps)
41
64
  * ALGO0004 - Lambert vers geographiques
42
65
  */
43
66
 
44
- void lambert_to_geographic(const YGLambertPoint * org,YGLambertPoint *dest, LambertZone zone, double lon_merid, double e, double eps)
67
+ void lambert_to_geographic(const YGPoint * org,YGPoint *dest, YGLambertZone zone, double lon_merid, double e, double eps)
45
68
  {
46
69
  double n = lambert_n[zone];
47
70
  double C = lambert_c[zone];
@@ -85,11 +108,11 @@ double lambert_normal(double lat, double a, double e)
85
108
  *
86
109
  */
87
110
 
88
- YGLambertPoint geographic_to_cartesian(double lon, double lat, double he, double a, double e)
111
+ YGPoint geographic_to_cartesian(double lon, double lat, double he, double a, double e)
89
112
  {
90
113
  double N = lambert_normal(lat,a,e);
91
114
 
92
- YGLambertPoint pt = {0,0,0};
115
+ YGPoint pt = {0,0,0};
93
116
  pt.x = (N+he)*cos(lat)*cos(lon);
94
117
 
95
118
  pt.y = (N+he)*cos(lat)*sin(lon);
@@ -104,7 +127,7 @@ double lambert_normal(double lat, double a, double e)
104
127
  * ALGO0012 - Passage des coordonnées cartésiennes aux coordonnées géographiques
105
128
  */
106
129
 
107
- YGLambertPoint cartesian_to_geographic(YGLambertPoint org, double meridien, double a, double e , double eps)
130
+ YGPoint cartesian_to_geographic(YGPoint org, double meridien, double a, double e , double eps)
108
131
  {
109
132
  double x = org.x, y = org.y, z = org.z;
110
133
 
@@ -124,7 +147,7 @@ double lambert_normal(double lat, double a, double e)
124
147
 
125
148
  double he = module/cos(phi_i) - a/sqrt(1-e*e*sin(phi_i)*sin(phi_i));
126
149
 
127
- YGLambertPoint pt;
150
+ YGPoint pt;
128
151
  pt.x = lon;
129
152
  pt.y = phi_i;
130
153
  pt.z = he;
@@ -132,40 +155,71 @@ double lambert_normal(double lat, double a, double e)
132
155
  return pt;
133
156
  }
134
157
 
135
-
136
-
137
158
  /*
138
159
  * Convert Lambert -> WGS84
139
160
  * http://geodesie.ign.fr/contenu/fichiers/documentation/pedagogiques/transfo.pdf
140
161
  *
141
162
  */
142
163
 
143
- void lambert_to_wgs84(const YGLambertPoint * org, YGLambertPoint *dest,LambertZone zone){
164
+ void lambert_to_wgs84(const YGPoint * org, YGPoint *dest,YGLambertZone zone){
165
+
166
+
167
+
168
+ if(LAMBERT_93 == zone)
169
+ {
170
+ lambert_to_geographic(org,dest,zone,LON_MERID_IERS,E_WGS84,DEFAULT_EPS);
171
+ }
172
+ else
173
+ {
174
+ lambert_to_geographic(org,dest,zone,LON_MERID_PARIS,E_CLARK_IGN,DEFAULT_EPS);
175
+ YGPoint temp = geographic_to_cartesian(dest->x,dest->y,dest->z,A_CLARK_IGN,E_CLARK_IGN);
176
+
177
+ temp.x= temp.x - 168;
178
+ temp.y= temp.y - 60;
179
+ temp.z= temp.z + 320;
180
+
181
+ //WGS84 refers to greenwich
182
+ temp = cartesian_to_geographic(temp, LON_MERID_IERS, A_WGS84,E_WGS84,DEFAULT_EPS);
183
+
184
+ dest->x = temp.x;
185
+ dest->y = temp.y;
186
+ }
187
+ }
188
+
144
189
 
145
- lambert_to_geographic(org,dest,zone,LON_MERID_PARIS,E_CLARK_IGN,DEFAULT_EPS);
190
+ void lambert_to_wgs84_deg(const YGPoint * org, YGPoint *dest, YGLambertZone zone)
191
+ {
192
+ YGPoint temp = {0,0,0};
193
+
194
+ lambert_to_wgs84(org,&temp,zone);
195
+ *dest = pointToDegree(temp);
196
+ }
146
197
 
147
- YGLambertPoint temp = geographic_to_cartesian(dest->x,dest->y,dest->z,A_CLARK_IGN,E_CLARK_IGN);
198
+ double lat_iso(double lat, double e)
199
+ {
200
+ return log(tan(M_PI_4 + lat/2)*pow((1-e*sin(lat))/(1+e*sin(lat)),e/2));
201
+ }
148
202
 
149
- temp.x= temp.x - 168;
150
- temp.y= temp.y - 60;
151
- temp.z= temp.z + 320;
203
+ YGPoint coord_transform(double e, double n, double c, double lambda_c, double x_s, double y_s , double lon, double lat)
204
+ {
205
+ YGPoint dest = {0,0,0};
152
206
 
153
- //WGS84 refers to greenwich
154
- temp = cartesian_to_geographic(temp, LON_MERID_GREENWICH, A_WGS84,E_WGS84,DEFAULT_EPS);
207
+ double latiso = lat_iso(lat,e);
208
+ dest.x = x_s + e*exp(-n*latiso)*sin(n*(lon-lambda_c));
209
+ dest.y = y_s + e*exp(n*latiso)*cos(n*(lon-lambda_c));
155
210
 
156
- dest->x = temp.x;
157
- dest->y = temp.y;
211
+ return dest;
158
212
 
159
213
  }
160
214
 
161
-
162
- void lambert_to_wgs84_deg(const YGLambertPoint * org, YGLambertPoint *dest, LambertZone zone)
215
+ YGPoint switch_geodesic_system(YGPoint u, Vector t, double d, Vector r)
163
216
  {
164
- YGLambertPoint temp = {0,0,0};
165
-
166
- lambert_to_wgs84(org,&temp,zone);
217
+ YGPoint v = {0,0,0};
167
218
 
168
- dest->x = temp.x * 180/M_PI;
169
- dest->y = temp.y * 180/M_PI;
170
- dest->z = temp.z * 180/M_PI;
171
- }
219
+ v.x = t.x + u.x*(1+d) + u.z * r.y - u.y * r.z;
220
+ v.y = t.y + u.y*(1+d) + u.x * r.z - u.y * r.z;
221
+ v.z = t.z +u.z*(1+d) + u.y*r.x -u.x*r.y;
222
+
223
+ return v;
224
+
225
+ }
@@ -1,3 +1,7 @@
1
+ #ifndef __LAMBERT_H
2
+ #define __LAMBERT_H
3
+
4
+
1
5
  #define DEFAULT_EPS 1e-10
2
6
  #define E_CLARK_IGN 0.08248325676
3
7
  #define E_WGS84 0.08181919106
@@ -7,9 +11,15 @@
7
11
 
8
12
  #define LON_MERID_PARIS 0
9
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
10
20
 
11
- #define DISPLAY_YGLambertPoint(YGLambertPoint) printf(#YGLambertPoint" X:%f | Y:%f | Z:%f\n",YGLambertPoint.x,YGLambertPoint.y,YGLambertPoint.z);
12
- #define DISPLAY_YGLambertPoint_REF(YGLambertPoint) printf(#YGLambertPoint" X:%f | Y:%f | Z:%f\n",YGLambertPoint->x,YGLambertPoint->y,YGLambertPoint->z);
21
+ #define DISPLAY_YGPoint(YGPoint) printf(#YGPoint" X:%f | Y:%f | Z:%f\n",YGPoint.x,YGPoint.y,YGPoint.z);
22
+ #define DISPLAY_YGPoint_REF(YGPoint) printf(#YGPoint" X:%f | Y:%f | Z:%f\n",YGPoint->x,YGPoint->y,YGPoint->z);
13
23
 
14
24
  typedef enum {
15
25
  LAMBERT_I=0,
@@ -18,14 +28,32 @@ typedef enum {
18
28
  LAMBERT_IV=3,
19
29
  LAMBERT_II_E=4,
20
30
  LAMBERT_93= 5
21
- } LambertZone;
31
+ } YGLambertZone;
32
+
33
+ typedef enum {
34
+ DEGREE,
35
+ GRAD,
36
+ RADIAN
37
+ } CoordUnit;
22
38
 
23
39
  typedef struct {
24
40
  double x;
25
41
  double y;
26
42
  double z;
27
- } YGLambertPoint;
43
+ CoordUnit unit;
44
+ } YGPoint;
28
45
 
46
+ typedef struct
47
+ {
48
+ double tx;
49
+ double ty;
50
+ double tz;
51
+ } YGTransform;
52
+
53
+ typedef YGPoint Vector;
54
+
55
+ YGPoint pointToRadian(YGPoint p);
56
+ YGPoint pointToDegree(YGPoint p);
29
57
 
30
58
  /*
31
59
  * ALGO0021 - Calcul de la grande Normale
@@ -34,16 +62,16 @@ typedef struct {
34
62
  double lambert_normal(double lat, double a, double e);
35
63
 
36
64
  /*
37
- * Convert a YGLambertPoint struct from one lambert zone to WGS84 (Rad)
65
+ * Convert a YGPoint struct from one lambert zone to WGS84 (Rad)
38
66
  *
39
67
  */
40
- void lambert_to_wgs84(const YGLambertPoint * org, YGLambertPoint *dest, LambertZone zone);
68
+ void lambert_to_wgs84(const YGPoint * org, YGPoint *dest, YGLambertZone zone);
41
69
 
42
70
  /*
43
- * Convert a YGLambertPoint struct from one lambert zone to WGS84 (Deg)
71
+ * Convert a YGPoint struct from one lambert zone to WGS84 (Deg)
44
72
  *
45
73
  */
46
- void lambert_to_wgs84_deg(const YGLambertPoint * org, YGLambertPoint *dest, LambertZone zone);
74
+ void lambert_to_wgs84_deg(const YGPoint * org, YGPoint *dest, YGLambertZone zone);
47
75
 
48
76
  /*
49
77
  * ALGO0002
@@ -55,12 +83,12 @@ double lat_from_lat_iso(double lat_iso, double e, double eps);
55
83
  * ALGO0012
56
84
  */
57
85
 
58
- YGLambertPoint cartesian_to_geographic(YGLambertPoint org, double meridien, double a, double e , double eps);
86
+ YGPoint cartesian_to_geographic(YGPoint org, double meridien, double a, double e , double eps);
59
87
 
60
88
  /*
61
89
  * ALGO004
62
90
  */
63
- void lambert_to_geographic(const YGLambertPoint * org,YGLambertPoint *dest, LambertZone zone, double lon_merid, double e, double eps);
91
+ void lambert_to_geographic(const YGPoint * org,YGPoint *dest, YGLambertZone zone, double lon_merid, double e, double eps);
64
92
 
65
93
  /**
66
94
  * ALGO0009 - Transformations geographiques -> cartésiennes
@@ -68,4 +96,26 @@ void lambert_to_geographic(const YGLambertPoint * org,YGLambertPoint *dest, Lamb
68
96
  *
69
97
  */
70
98
 
71
- YGLambertPoint geographic_to_cartesian(double lon, double lat, double he, double a, double e);
99
+ YGPoint geographic_to_cartesian(double lon, double lat, double he, double a, double e);
100
+
101
+ /**
102
+ * ALGO13 Transformation de Coordonnées à 7 paramètres entre deux systèmes géodésiques
103
+ */
104
+
105
+ YGPoint switch_geodesic_system(YGPoint u, Vector t, double d, Vector r);
106
+
107
+ /**
108
+ * Algo0001 Calcul de la latitude isomérique
109
+ */
110
+ double lat_iso(double lat, double e);
111
+
112
+ /**
113
+ * Algo003
114
+ */
115
+ YGPoint coord_transform(double e, double n, double c, double lambda_c, double x_s, double y_s , double lon, double lat);
116
+
117
+ /**
118
+ * Algo 01
119
+ */
120
+ double latitude_iso_from_lat(double lat, double e);
121
+ #endif
@@ -0,0 +1,206 @@
1
+
2
+ #include "rgf93.h"
3
+ #include "config.h"
4
+
5
+ #include<stdio.h>
6
+ #include<stdlib.h>
7
+ #include<limits.h>
8
+ #include <string.h>
9
+ #include <math.h>
10
+
11
+ #define MAX_LINE_BUFFER 1024
12
+ #define MAX_PATH_SIZE 1024
13
+ #define DELTA_REALLOCATION 10
14
+
15
+
16
+ typedef struct {
17
+
18
+ double lon;
19
+ double lat;
20
+ double tx;
21
+ double ty;
22
+ double tz;
23
+ double precision;
24
+ } NTV2Reg;
25
+
26
+ static char currentNTVPath[OPEN_MAX];
27
+ static FILE * gridFD = NULL;
28
+ static char grd3dparams[4][MAX_LINE_BUFFER] = {{0}};
29
+
30
+ static NTV2Reg *regcache = NULL;
31
+ static int lastRegPos = 0;
32
+ static int regcacheSize = 0;
33
+
34
+ static int lastReadedLine;
35
+
36
+
37
+ NTV2Reg regFromLine(const char * line)
38
+ {
39
+ char *sep = " ";
40
+ char *buffer = malloc(strlen(line)* sizeof(char));
41
+ strcpy(buffer, line);
42
+
43
+ NTV2Reg reg = {0};
44
+
45
+ strtok(buffer, sep);
46
+
47
+ reg.lon = strtod(strtok(NULL, sep), NULL);
48
+ reg.lat = strtod(strtok(NULL, sep), NULL);
49
+ reg.tx = strtod(strtok(NULL, sep), NULL);
50
+ reg.ty = strtod(strtok(NULL, sep), NULL);
51
+ reg.tz = strtod(strtok(NULL, sep), NULL);
52
+ reg.precision = strtod(strtok(NULL, sep), NULL);
53
+
54
+ return reg;
55
+ }
56
+
57
+ void addRegToCache(NTV2Reg reg)
58
+ {
59
+ if(!regcache)
60
+ {
61
+ regcache = malloc(DELTA_REALLOCATION*sizeof(NTV2Reg));
62
+ regcacheSize = DELTA_REALLOCATION;
63
+ lastRegPos = 0;
64
+ }
65
+
66
+ if(lastRegPos > regcacheSize-1)
67
+ {
68
+
69
+ NTV2Reg * newLoc =realloc(regcache, (regcacheSize+DELTA_REALLOCATION)*sizeof(NTV2Reg));
70
+
71
+ regcache = newLoc;
72
+ regcacheSize+=DELTA_REALLOCATION;
73
+
74
+ }
75
+
76
+ regcache[lastRegPos] = reg;
77
+ lastRegPos++;
78
+ }
79
+
80
+
81
+ int loadGrid()
82
+ {
83
+ snprintf(currentNTVPath,50,"%s/%s",resource_file_path,"gr3df97a.txt");
84
+ lastReadedLine = 0;
85
+
86
+ gridFD = fopen(currentNTVPath,"r");
87
+
88
+ if(!gridFD)
89
+ {
90
+ printf("Could not open grid file at path :%s\n", currentNTVPath);
91
+ return -1;
92
+ }
93
+
94
+ char line[MAX_LINE_BUFFER];
95
+ while(lastReadedLine < 4)
96
+ {
97
+ fgets(line, MAX_LINE_BUFFER, gridFD);
98
+ ++lastReadedLine;
99
+ }
100
+ char line_buffer[MAX_LINE_BUFFER] = {0};
101
+
102
+ while(NULL != fgets(line_buffer, MAX_LINE_BUFFER, gridFD))
103
+ {
104
+ NTV2Reg reg = regFromLine(line_buffer);
105
+ addRegToCache(reg);
106
+ }
107
+
108
+ return 0;
109
+ }
110
+
111
+
112
+ void printParameters()
113
+ {
114
+ printf("===== Parameters =====\n");
115
+ printf("%s\n", grd3dparams[0]);
116
+ printf("%s\n", grd3dparams[1]);
117
+ printf("%s\n", grd3dparams[2]);
118
+ printf("%s\n", grd3dparams[3]);
119
+
120
+ }
121
+
122
+ void printReg(NTV2Reg reg)
123
+ {
124
+ printf("LON:%f - LAT:%f - TX:%f - TY:%f - TZ:%f - PRE:%f\n",reg.lon,reg.lat,reg.tx,reg.ty,reg.tz,reg.precision);
125
+ }
126
+ void unloadGrid()
127
+ {
128
+ fclose(gridFD);
129
+ free(regcache);
130
+ }
131
+
132
+ void regToBuff(double *buf,NTV2Reg reg)
133
+ {
134
+ buf[0] = reg.tx;
135
+ buf[1] = reg.ty;
136
+ buf[2] = reg.tz;
137
+ }
138
+
139
+ void ntvreg_around_point(const YGPoint pt, NTV2Reg *t1, NTV2Reg *t2, NTV2Reg * t3, NTV2Reg * t4)
140
+ {
141
+
142
+ NTV2Reg *a = regcache,*b = regcache+1;
143
+
144
+ while(!(pt.x >= a->lon && pt.x <= b->lon))
145
+ {
146
+ ++a;
147
+ ++b;
148
+ }
149
+
150
+ NTV2Reg *searchReg = a;
151
+
152
+ while (searchReg->lat > pt.y)
153
+ {
154
+ searchReg--;
155
+ }
156
+
157
+ *t1 = *searchReg;
158
+ *t2 = *(++searchReg);
159
+
160
+ searchReg = b;
161
+
162
+ while (searchReg->lat < pt.y)
163
+ {
164
+ searchReg++;
165
+ }
166
+
167
+ *t4 = *(searchReg);
168
+ *t3 = *(--searchReg);
169
+
170
+ }
171
+ YGTransform ntf_to_rgf93(YGPoint pt)
172
+ {
173
+ if(!gridFD)
174
+ loadGrid();
175
+
176
+ NTV2Reg t1,t2,t3,t4;
177
+
178
+
179
+ ntvreg_around_point(pt, &t1, &t2, &t3, &t4);
180
+
181
+ double x = (pt.x - t1.lon)/(t3.lon - t1.lon);
182
+ double y = (pt.y - t1.lat)/(t2.lat - t1.lat);
183
+
184
+
185
+ double d[3], t1Buf[3], t2Buf[3], t3Buf[3], t4Buf[3];
186
+
187
+ regToBuff(t1Buf,t1);
188
+ regToBuff(t2Buf,t2);
189
+ regToBuff(t3Buf,t3);
190
+ regToBuff(t4Buf,t4);
191
+
192
+ for(int i = 0; i< 3; ++i)
193
+ {
194
+ d[i] = (1-x)*(1-y)*t1Buf[i] + (1-x)*y*t2Buf[i] + (1-y)*x*t3Buf[i] + x*y*t4Buf[i];
195
+ }
196
+
197
+ YGTransform tm ={d[0],d[1],d[2]};
198
+ return tm;
199
+ }
200
+
201
+ YGTransform rgf93_to_ntf(YGPoint pt)
202
+ {
203
+ YGTransform tm = ntf_to_rgf93(pt);
204
+ YGTransform val = {-1*tm.tx,-1*tm.ty,-1*tm.tz};
205
+ return val;
206
+ }
@@ -0,0 +1,7 @@
1
+ #ifndef __NTV2_H
2
+ #define __NTV2_H
3
+ #include "lambert.h"
4
+
5
+ YGTransform ntf_to_rgf93(YGPoint pt);
6
+ YGTransform rgf93_to_ntf(YGPoint pt);
7
+ #endif
@@ -4,6 +4,7 @@
4
4
  #include <math.h>
5
5
  #include <stdlib.h>
6
6
  #include "../src/lambert.h"
7
+ #include "../src/rgf93.h"
7
8
 
8
9
  #define DISPLAY_POINT(point) printf(#point" X:%f | Y:%f | Z:%f\n",point.x,point.y,point.z);
9
10
 
@@ -30,9 +31,9 @@ double rounded_down(double val,int n){
30
31
 
31
32
  void test_lambert_deg(void)
32
33
  {
33
- YGLambertPoint org = {999534.581,112186.569,0};
34
- YGLambertPoint dest = {0,0,0};
35
- LambertZone zone = LAMBERT_I;
34
+ YGPoint org = {994300.623,113409.981,0};
35
+ YGPoint dest = {0,0,0};
36
+ YGLambertZone zone = LAMBERT_I;
36
37
 
37
38
  lambert_to_wgs84_deg(&org, &dest, zone);
38
39
  printf("(Deg)Lon:%.11f - Lat:%.11f - H:%.11f\n",dest.x,dest.y,dest.z);
@@ -41,12 +42,11 @@ void test_lambert_deg(void)
41
42
  void test_lambert(void)
42
43
  {
43
44
 
44
- YGLambertPoint org = {999534.581,112186.569,0};
45
- YGLambertPoint dest = {0,0,0};
46
- LambertZone zone = LAMBERT_I;
45
+ YGPoint org = {999534.581,112186.569,0};
46
+ YGPoint dest = {0,0,0};
47
+ YGLambertZone zone = LAMBERT_I;
47
48
 
48
49
  lambert_to_wgs84(&org, &dest, zone);
49
-
50
50
  }
51
51
 
52
52
  void test_algo009(void)
@@ -61,7 +61,7 @@ void test_algo009(void)
61
61
  unsigned int i;
62
62
  for (i =0; i < 3;++i)
63
63
  {
64
- YGLambertPoint pt = geographic_to_cartesian(lon[i],lat[i],he[i],a[i],e[i]);
64
+ YGPoint pt = geographic_to_cartesian(lon[i],lat[i],he[i],a[i],e[i]);
65
65
  DISPLAY_POINT(pt);
66
66
  }
67
67
 
@@ -122,8 +122,8 @@ void test_algo0012(void)
122
122
  double ign_eps = 1e-11;
123
123
  for(i=0; i < 3;++i)
124
124
  {
125
- YGLambertPoint sample = {x[i],y[i],z[i]};
126
- YGLambertPoint val ;
125
+ YGPoint sample = {x[i],y[i],z[i]};
126
+ YGPoint val ;
127
127
  val = cartesian_to_geographic(sample,LON_MERID_PARIS,a[i],e[i],eps[i]);
128
128
 
129
129
  // printf("X Computed:%.11f - Expected:%.11f\n",val.x,lon[i]);
@@ -139,9 +139,9 @@ void test_algo0012(void)
139
139
  void test_algo004(void)
140
140
  {
141
141
 
142
- YGLambertPoint org = {1029705.083,272723.849,0};
143
- YGLambertPoint dest = {0,0,0};
144
- YGLambertPoint expected = {0.145512099,0.872664626};
142
+ YGPoint org = {1029705.083,272723.849,0};
143
+ YGPoint dest = {0,0,0};
144
+ YGPoint expected = {0.145512099,0.872664626};
145
145
 
146
146
 
147
147
  lambert_to_geographic(&org,&dest, LAMBERT_I, LON_MERID_GREENWICH,E_CLARK_IGN,1e-9);
@@ -150,6 +150,35 @@ void test_algo004(void)
150
150
  CU_ASSERT(fabs(dest.y - expected.y) <= 1e-9);
151
151
  }
152
152
 
153
+
154
+ void testBug2(void)
155
+ {
156
+ YGPoint org = {668832.5384,6950138.7285,0};
157
+ YGPoint dest = {0,0,0};
158
+ YGLambertZone zone= LAMBERT_93;
159
+
160
+ lambert_to_wgs84_deg(&org,&dest,zone);
161
+ printf("Lat:%.9f - Lon:%.9f",dest.y,dest.x);
162
+
163
+ }
164
+ void testOpenGrid(void)
165
+ {
166
+ YGPoint org = {.x=2.424971108, .y=48.844445839,.z=0,.unit=DEGREE};
167
+
168
+ YGTransform tr = rgf93_to_ntf(org);
169
+
170
+ YGPoint t = {tr.tx,tr.ty,tr.tz};
171
+ YGPoint null= {0,0,0};
172
+
173
+ org = pointToRadian(org);
174
+ org = geographic_to_cartesian(org.x,org.y,org.z,A_WGS84,E_WGS84);
175
+
176
+ org = switch_geodesic_system(org, t, 0, null);
177
+ org = cartesian_to_geographic(org, LON_MERID_PARIS, A_CLARK_IGN, E_CLARK_IGN, DEFAULT_EPS);
178
+
179
+ org = pointToDegree(org);
180
+ }
181
+
153
182
  int main(int argc, char **argv){
154
183
 
155
184
  CU_pSuite pSuite = NULL;
@@ -171,7 +200,9 @@ int main(int argc, char **argv){
171
200
  NULL == CU_add_test(pSuite,"Test Algo004",test_algo004) ||
172
201
  NULL == CU_add_test(pSuite,"Test algo0021",test_algo0021) ||
173
202
  NULL == CU_add_test(pSuite,"test_algo009",test_algo009) ||
174
- NULL == CU_add_test(pSuite,"test_algo009",test_lambert_deg) ||
203
+ NULL == CU_add_test(pSuite,"test_lambert_deg",test_lambert_deg) ||
204
+ NULL == CU_add_test(pSuite,"testBug2",testBug2) ||
205
+ NULL == CU_add_test(pSuite,"testNTFRGF93",testOpenGrid) ||
175
206
  NULL == CU_add_test(pSuite, "Test lambert", test_lambert)
176
207
  )
177
208
  {
@@ -30,14 +30,14 @@ static VALUE p_init(int argc, VALUE* argv, VALUE self)
30
30
  static VALUE p_convert(VALUE self,VALUE zone){
31
31
 
32
32
  double x, y, z;
33
- LambertZone cZone = NUM2INT(zone);
33
+ YGLambertZone cZone = NUM2INT(zone);
34
34
 
35
35
  x = NUM2DBL(rb_iv_get(self,"@x"));
36
36
  y = NUM2DBL(rb_iv_get(self,"@y"));
37
37
  z = NUM2DBL(rb_iv_get(self,"@z"));
38
38
 
39
- YGLambertPoint org = {x,y,z};
40
- YGLambertPoint dest = {0,0,0};
39
+ YGPoint org = {x,y,z};
40
+ YGPoint dest = {0,0,0};
41
41
 
42
42
  lambert_to_wgs84_deg(&org,&dest,cZone);
43
43
 
@@ -66,4 +66,4 @@ void Init_lambert_ruby(void) {
66
66
  rb_define_const(rb_mLambert,"LambertIV",INT2NUM(LAMBERT_IV));
67
67
  rb_define_const(rb_mLambert,"LambertIIExtended",INT2NUM(LAMBERT_II_E));
68
68
  rb_define_const(rb_mLambert,"Lambert93",INT2NUM(LAMBERT_93));
69
- }
69
+ }
metadata CHANGED
@@ -1,17 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lambert_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yannick Heinrich
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-24 00:00:00.000000000 Z
11
+ date: 2013-10-14 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: Ruby wrapper for the lambert library that converts Lambert coordinates
14
- to WGS84. It wraps the original C files with a basic Ruby interface.
13
+ description: Ruby wrapper for the lambert library
15
14
  email: yannick.heinrich@gmail.com
16
15
  executables: []
17
16
  extensions:
@@ -20,15 +19,16 @@ extra_rdoc_files: []
20
19
  files:
21
20
  - lib/lambert_ruby.rb
22
21
  - ext/lambert_ruby/lambert/src/lambert.c
22
+ - ext/lambert_ruby/lambert/src/rgf93.c
23
23
  - ext/lambert_ruby/lambert/tests/test_lambert_cunit.c
24
24
  - ext/lambert_ruby/lambert.c
25
25
  - ext/lambert_ruby/lambert_ruby.c
26
26
  - ext/lambert_ruby/lambert/src/lambert.h
27
+ - ext/lambert_ruby/lambert/src/rgf93.h
27
28
  - ext/lambert_ruby/lambert.h
28
29
  - ext/lambert_ruby/extconf.rb
29
- homepage: https://github.com/YaGeek/lambert-ruby
30
- licenses:
31
- - GPL-2
30
+ homepage: http://rubygems.org/gems/lambert_ruby
31
+ licenses: []
32
32
  metadata: {}
33
33
  post_install_message:
34
34
  rdoc_options: []
@@ -36,12 +36,12 @@ require_paths:
36
36
  - lib
37
37
  required_ruby_version: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - ! '>='
39
+ - - ">="
40
40
  - !ruby/object:Gem::Version
41
41
  version: '0'
42
42
  required_rubygems_version: !ruby/object:Gem::Requirement
43
43
  requirements:
44
- - - ! '>='
44
+ - - ">="
45
45
  - !ruby/object:Gem::Version
46
46
  version: '0'
47
47
  requirements: []
@@ -49,6 +49,5 @@ rubyforge_project:
49
49
  rubygems_version: 2.0.3
50
50
  signing_key:
51
51
  specification_version: 4
52
- summary: Ruby wrapper for the lambert library that converts Lambert coordinates to
53
- WGS84
52
+ summary: Ruby wrapper for the lambert library
54
53
  test_files: []