-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlambertjs.cc
137 lines (101 loc) · 3.55 KB
/
lambertjs.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#include <node.h>
#include <v8.h>
extern "C" {
#include "lambert/src/lambert.h"
#include <math.h>
}
using namespace v8;
bool checkArgue(const Arguments& args)
{
if(args.Length() <2)
{
if (args.Length() < 2) {
ThrowException(Exception::TypeError(String::New("Wrong number of arguments!")));
return false;
}
}
if(!args[0]->IsObject() || !args[1]->IsNumber())
{
ThrowException(Exception::TypeError(String::New("Wrong arguments!")));
return false;
}
Local<Object> jsObj = args[0]->ToObject();
if(!jsObj->HasRealNamedProperty(String::New("x")) || !jsObj->HasRealNamedProperty(String::New("y")) || !jsObj->HasRealNamedProperty(String::New("z")))
{
ThrowException(Exception::TypeError(String::New("Object has no property x,y and z!")));
return false;
}
if(!jsObj->Get(String::New("x"))->IsNumber() || !jsObj->Get(String::New("y"))->IsNumber() || !jsObj->Get(String::New("z"))->IsNumber() )
{
ThrowException(Exception::TypeError(String::New("x,y and z properties are not all numbers!")));
return false;
}
long long val = args[1]->ToInteger()->Value();
if(val > 5 || val < 0)
{
ThrowException(Exception::TypeError(String::New("Incorrect zone was given!")));
return false;
}
return true;
}
Handle<Value> lambertTowgs84(const Arguments& args){
HandleScope scope;
if(!checkArgue(args))
{
return scope.Close(Undefined());
}
double lat, lon, h;
Local<Object> jsObj = args[0]->ToObject();
lon = jsObj->Get(String::New("x"))->NumberValue();
lat = jsObj->Get(String::New("y"))->NumberValue();
h = jsObj->Get(String::New("z"))->NumberValue();
long long val = args[1]->ToInteger()->Value();
YGLambertZone zone = (YGLambertZone) val;
YGPoint org = YGMeterPoint(lon,lat,h);
org = YGPointConvertWGS84(org,zone);
Local<Object> point = Object::New();
point->Set(String::NewSymbol("x"),Number::New(org.x));
point->Set(String::NewSymbol("y"),Number::New(org.y));
point->Set(String::NewSymbol("z"),Number::New(org.z));
return scope.Close(point);
}
Handle<Value> lambertTowgs84Deg(const Arguments& args ){
HandleScope scope;
if(!checkArgue(args))
{
return scope.Close(Undefined());
}
double lat, lon, h;
Local<Object> jsObj = args[0]->ToObject();
lon = jsObj->Get(String::New("x"))->NumberValue();
lat = jsObj->Get(String::New("y"))->NumberValue();
h = jsObj->Get(String::New("z"))->NumberValue();
long long val = args[1]->ToInteger()->Value();
YGLambertZone zone = (YGLambertZone) val;
YGPoint org = YGMeterPoint(lon,lat,h);
org = YGPointConvertWGS84(org,zone);
Local<Object> point = Object::New();
point->Set(String::NewSymbol("x"),Number::New(org.x));
point->Set(String::NewSymbol("y"),Number::New(org.y));
point->Set(String::NewSymbol("z"),Number::New(org.z));
return scope.Close(point);
}
void init(Handle<Object> exports) {
exports->Set(String::NewSymbol("lambertTowgs84"),
FunctionTemplate::New(lambertTowgs84)->GetFunction());
exports->Set(String::NewSymbol("lambertTowgs84Deg"),
FunctionTemplate::New(lambertTowgs84Deg)->GetFunction());
exports->Set(String::NewSymbol("LambertI"),
Number::New(LAMBERT_I));
exports->Set(String::NewSymbol("LambertII"),
Number::New(LAMBERT_II));
exports->Set(String::NewSymbol("LambertIII"),
Number::New(LAMBERT_III));
exports->Set(String::NewSymbol("LambertIV"),
Number::New(LAMBERT_IV));
exports->Set(String::NewSymbol("LambertIIExtended"),
Number::New(LAMBERT_II_E));
exports->Set(String::NewSymbol("Lambert93"),
Number::New(LAMBERT_93));
}
NODE_MODULE(lambertjs, init)