Skip to content

Commit

Permalink
- Pievienota TypeScript programmēšanas valodas koordinātu pārveidošan…
Browse files Browse the repository at this point in the history
…as klase

- Būtiskas izmaiņas JavaScript klases struktūrā, pamatojoties uz TypeScript ģenerēto JavaScript izejas pirmkoda datni
- Nelielas izmaiņas pārējo klašu tabulācijā
  • Loading branch information
arvislacis committed Jan 21, 2016
1 parent 4feb9a0 commit 986eaf3
Show file tree
Hide file tree
Showing 13 changed files with 442 additions and 103 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ Saraksts ar projektā pašlaik pieejamajām programmēšanas valodām - valodas,
| C++ | [Arvis Lācis](https://github.com/arvislacis) | 21.01.2016. |
| C# | [Arvis Lācis](https://github.com/arvislacis) | 28.12.2015. |
| Java | [Arvis Lācis](https://github.com/arvislacis) | 11.01.2016. |
| JavaScript | [Arvis Lācis](https://github.com/arvislacis) | 22.12.2015. |
| JavaScript | [Arvis Lācis](https://github.com/arvislacis) | 22.01.2016. |
| PHP | [Arvis Lācis](https://github.com/arvislacis) | 23.12.2015. |
| Python2/Python3 | [Dāvis Mičulis](https://github.com/DavisMiculis) | 24.12.2015. |
| TypeScript | [Arvis Lācis](https://github.com/arvislacis) | 22.01.2016. |
| Visual Basic | [Arvis Lācis](https://github.com/arvislacis) | 21.01.2016. |

Laika gaitā plānots projektu papildināt ar citām, mazāk vai vairāk, populārām programmēšanas valodām gan no projekta autora,
Expand Down
15 changes: 8 additions & 7 deletions c#/LKS92WGS84.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ private static double[] convertMapLatLngToXY(double phi, double lambda, double l

// y koordināta
xy[1] = getArcLengthOfMeridian(phi) + (t / 2 * N * Math.Pow(Math.Cos(phi), 2) * Math.Pow(l, 2)) + (t / 24 * N * Math.Pow(Math.Cos(phi), 4) * l4coef * Math.Pow(l, 4)) + (t / 720 * N * Math.Pow(Math.Cos(phi), 6) * l6coef * Math.Pow(l, 6)) + (t / 40320 * N * Math.Pow(Math.Cos(phi), 8) * l8coef * Math.Pow(l, 8));

return xy;
}

Expand All @@ -83,25 +84,25 @@ private static double[] convertMapXYToLatLon(double x, double y, double lambda0)

double x1frac = 1 / (Nfpow * cf);

Nfpow *= Nf; // Nf^2
Nfpow *= Nf; // Nf^2
double x2frac = tf / (2 * Nfpow);

Nfpow *= Nf; // Nf^3
Nfpow *= Nf; // Nf^3
double x3frac = 1 / (6 * Nfpow * cf);

Nfpow *= Nf; // Nf^4
Nfpow *= Nf; // Nf^4
double x4frac = tf / (24 * Nfpow);

Nfpow *= Nf; // Nf^5
Nfpow *= Nf; // Nf^5
double x5frac = 1 / (120 * Nfpow * cf);

Nfpow *= Nf; // Nf^6
Nfpow *= Nf; // Nf^6
double x6frac = tf / (720 * Nfpow);

Nfpow *= Nf; // Nf^7
Nfpow *= Nf; // Nf^7
double x7frac = 1 / (5040 * Nfpow * cf);

Nfpow *= Nf; // Nf^8
Nfpow *= Nf; // Nf^8
double x8frac = tf / (40320 * Nfpow);

double x2poly = -1 - nuf2;
Expand Down
29 changes: 15 additions & 14 deletions c++/LKS92WGS84.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
class LKS92WGS84
{
// Koordinātu pārveidojumos izmantotās konstantes
constexpr static double PI = M_PI; // Skaitlis pi
constexpr static double A_AXIS = 6378137; // Elipses modeļa lielā ass (a)
constexpr static double B_AXIS = 6356752.31414; // Elipses modeļa mazā ass (b)
constexpr static double CENTRAL_MERIDIAN = PI * 24 / 180; // Centrālais meridiāns
constexpr static double OFFSET_X = 500000; // Koordinātu nobīde horizontālās (x) ass virzienā
constexpr static double OFFSET_Y = -6000000; // Koordinātu nobīde vertikālās (y) ass virzienā
constexpr static double SCALE = 0.9996; // Kartes mērogojuma faktors (reizinātājs)
constexpr static double PI = M_PI; // Skaitlis pi
constexpr static double A_AXIS = 6378137; // Elipses modeļa lielā ass (a)
constexpr static double B_AXIS = 6356752.31414; // Elipses modeļa mazā ass (b)
constexpr static double CENTRAL_MERIDIAN = PI * 24 / 180; // Centrālais meridiāns
constexpr static double OFFSET_X = 500000; // Koordinātu nobīde horizontālās (x) ass virzienā
constexpr static double OFFSET_Y = -6000000; // Koordinātu nobīde vertikālās (y) ass virzienā
constexpr static double SCALE = 0.9996; // Kartes mērogojuma faktors (reizinātājs)

// Aprēķina loka garumu no ekvatora līdz dotā punkta ģeogrāfiskajam platumam
private: static double getArcLengthOfMeridian(double phi)
Expand Down Expand Up @@ -62,6 +62,7 @@ class LKS92WGS84

// y koordināta
xy[1] = getArcLengthOfMeridian(phi) + (t / 2 * N * pow(cos(phi), 2) * pow(l, 2)) + (t / 24 * N * pow(cos(phi), 4) * l4coef * pow(l, 4)) + (t / 720 * N * pow(cos(phi), 6) * l6coef * pow(l, 6)) + (t / 40320 * N * pow(cos(phi), 8) * l8coef * pow(l, 8));

return xy;
}

Expand All @@ -83,25 +84,25 @@ class LKS92WGS84

double x1frac = 1 / (Nfpow * cf);

Nfpow *= Nf; // Nf^2
Nfpow *= Nf; // Nf^2
double x2frac = tf / (2 * Nfpow);

Nfpow *= Nf; // Nf^3
Nfpow *= Nf; // Nf^3
double x3frac = 1 / (6 * Nfpow * cf);

Nfpow *= Nf; // Nf^4
Nfpow *= Nf; // Nf^4
double x4frac = tf / (24 * Nfpow);

Nfpow *= Nf; // Nf^5
Nfpow *= Nf; // Nf^5
double x5frac = 1 / (120 * Nfpow * cf);

Nfpow *= Nf; // Nf^6
Nfpow *= Nf; // Nf^6
double x6frac = tf / (720 * Nfpow);

Nfpow *= Nf; // Nf^7
Nfpow *= Nf; // Nf^7
double x7frac = 1 / (5040 * Nfpow * cf);

Nfpow *= Nf; // Nf^8
Nfpow *= Nf; // Nf^8
double x8frac = tf / (40320 * Nfpow);

double x2poly = -1 - nuf2;
Expand Down
15 changes: 8 additions & 7 deletions java/LKS92WGS84.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ private static double[] convertMapLatLngToXY(double phi, double lambda, double l

// y koordināta
xy[1] = getArcLengthOfMeridian(phi) + (t / 2 * N * Math.pow(Math.cos(phi), 2) * Math.pow(l, 2)) + (t / 24 * N * Math.pow(Math.cos(phi), 4) * l4coef * Math.pow(l, 4)) + (t / 720 * N * Math.pow(Math.cos(phi), 6) * l6coef * Math.pow(l, 6)) + (t / 40320 * N * Math.pow(Math.cos(phi), 8) * l8coef * Math.pow(l, 8));

return xy;
}

Expand All @@ -83,25 +84,25 @@ private static double[] convertMapXYToLatLon(double x, double y, double lambda0)

double x1frac = 1 / (Nfpow * cf);

Nfpow *= Nf; // Nf^2
Nfpow *= Nf; // Nf^2
double x2frac = tf / (2 * Nfpow);

Nfpow *= Nf; // Nf^3
Nfpow *= Nf; // Nf^3
double x3frac = 1 / (6 * Nfpow * cf);

Nfpow *= Nf; // Nf^4
Nfpow *= Nf; // Nf^4
double x4frac = tf / (24 * Nfpow);

Nfpow *= Nf; // Nf^5
Nfpow *= Nf; // Nf^5
double x5frac = 1 / (120 * Nfpow * cf);

Nfpow *= Nf; // Nf^6
Nfpow *= Nf; // Nf^6
double x6frac = tf / (720 * Nfpow);

Nfpow *= Nf; // Nf^7
Nfpow *= Nf; // Nf^7
double x7frac = 1 / (5040 * Nfpow * cf);

Nfpow *= Nf; // Nf^8
Nfpow *= Nf; // Nf^8
double x8frac = tf / (40320 * Nfpow);

double x2poly = -1 - nuf2;
Expand Down
106 changes: 56 additions & 50 deletions javascript/LKS92WGS84.js
Original file line number Diff line number Diff line change
@@ -1,53 +1,57 @@
var LKS92WGS84 = function() {
// publicStatic objekts paredzēts tikai JavaScript un tam līdzīgo programmēšanas valodu risinājumiem
var publicStatic = {},
var LKS92WGS84 = (function()
{
// Koordinātu pārveidojumos izmantotās konstantes
PI = Math.PI, // Skaitlis pi
A_AXIS = 6378137, // Elipses modeļa lielā ass (a)
B_AXIS = 6356752.31414, // Elipses modeļa mazā ass (b)
CENTRAL_MERIDIAN = PI * 24 / 180, // Centrālais meridiāns
OFFSET_X = 500000, // Koordinātu nobīde horizontālās (x) ass virzienā
OFFSET_Y = -6000000, // Koordinātu nobīde vertikālās (y) ass virzienā
SCALE = 0.9996, // Kartes mērogojuma faktors (reizinātājs)
LKS92WGS84.PI = Math.PI; // Skaitlis pi
LKS92WGS84.A_AXIS = 6378137; // Elipses modeļa lielā ass (a)
LKS92WGS84.B_AXIS = 6356752.31414; // Elipses modeļa mazā ass (b)
LKS92WGS84.CENTRAL_MERIDIAN = LKS92WGS84.PI * 24 / 180; // Centrālais meridiāns
LKS92WGS84.OFFSET_X = 500000; // Koordinātu nobīde horizontālās (x) ass virzienā
LKS92WGS84.OFFSET_Y = -6000000; // Koordinātu nobīde vertikālās (y) ass virzienā
LKS92WGS84.SCALE = 0.9996; // Kartes mērogojuma faktors (reizinātājs)

function LKS92WGS84() {}

// Aprēķina loka garumu no ekvatora līdz dotā punkta ģeogrāfiskajam platumam
getArcLengthOfMeridian = function(phi) {
LKS92WGS84.getArcLengthOfMeridian = function(phi)
{
var alpha, beta, gamma, delta, epsilon, n;

n = (A_AXIS - B_AXIS) / (A_AXIS + B_AXIS);
alpha = ((A_AXIS + B_AXIS) / 2) * (1 + (Math.pow(n, 2) / 4) + (Math.pow(n, 4) / 64));
n = (LKS92WGS84.A_AXIS - LKS92WGS84.B_AXIS) / (LKS92WGS84.A_AXIS + LKS92WGS84.B_AXIS);
alpha = ((LKS92WGS84.A_AXIS + LKS92WGS84.B_AXIS) / 2) * (1 + (Math.pow(n, 2) / 4) + (Math.pow(n, 4) / 64));
beta = (-3 * n / 2) + (9 * Math.pow(n, 3) / 16) + (-3 * Math.pow(n, 5) / 32);
gamma = (15 * Math.pow(n, 2) / 16) + (-15 * Math.pow(n, 4) / 32);
delta = (-35 * Math.pow(n, 3) / 48) + (105 * Math.pow(n, 5) / 256);
epsilon = (315 * Math.pow(n, 4) / 512);

return alpha * (phi + (beta * Math.sin(2 * phi)) + (gamma * Math.sin(4 * phi)) + (delta * Math.sin(6 * phi)) + (epsilon * Math.sin(8 * phi)));
},
};

// Aprēķina ģeogrāfisko platumu centrālā meridiāna punktam
getFootpointLatitude = function(y) {
LKS92WGS84.getFootpointLatitude = function(y)
{
var yd, alpha, beta, gamma, delta, epsilon, n;

n = (A_AXIS - B_AXIS) / (A_AXIS + B_AXIS);
alpha = ((A_AXIS + B_AXIS) / 2) * (1 + (Math.pow(n, 2) / 4) + (Math.pow(n, 4) / 64));
n = (LKS92WGS84.A_AXIS - LKS92WGS84.B_AXIS) / (LKS92WGS84.A_AXIS + LKS92WGS84.B_AXIS);
alpha = ((LKS92WGS84.A_AXIS + LKS92WGS84.B_AXIS) / 2) * (1 + (Math.pow(n, 2) / 4) + (Math.pow(n, 4) / 64));
yd = y / alpha;
beta = (3 * n / 2) + (-27 * Math.pow(n, 3) / 32) + (269 * Math.pow(n, 5) / 512);
gamma = (21 * Math.pow(n, 2) / 16) + (-55 * Math.pow(n, 4) / 32);
delta = (151 * Math.pow(n, 3) / 96) + (-417 * Math.pow(n, 5) / 128);
epsilon = (1097 * Math.pow(n, 4) / 512);

return yd + (beta * Math.sin(2 * yd)) + (gamma * Math.sin(4 * yd)) + (delta * Math.sin(6 * yd)) + (epsilon * Math.sin(8 * yd));
},
};

// Pārveido punkta ģeogrāfiskā platuma, garuma koordinātas par x, y koordinātām (bez pārvietojuma un mērogojuma)
convertMapLatLngToXY = function(phi, lambda, lambda0) {
LKS92WGS84.convertMapLatLngToXY = function(phi, lambda, lambda0)
{
var N, nu2, ep2, t, t2, l,
l3coef, l4coef, l5coef, l6coef, l7coef, l8coef,
xy = [0, 0];

ep2 = (Math.pow(A_AXIS, 2) - Math.pow(B_AXIS, 2)) / Math.pow(B_AXIS, 2);
ep2 = (Math.pow(LKS92WGS84.A_AXIS, 2) - Math.pow(LKS92WGS84.B_AXIS, 2)) / Math.pow(LKS92WGS84.B_AXIS, 2);
nu2 = ep2 * Math.pow(Math.cos(phi), 2);
N = Math.pow(A_AXIS, 2) / (B_AXIS * Math.sqrt(1 + nu2));
N = Math.pow(LKS92WGS84.A_AXIS, 2) / (LKS92WGS84.B_AXIS * Math.sqrt(1 + nu2));
t = Math.tan(phi);
t2 = t * t;

Expand All @@ -63,22 +67,24 @@ var LKS92WGS84 = function() {
xy[0] = N * Math.cos(phi) * l + (N / 6 * Math.pow(Math.cos(phi), 3) * l3coef * Math.pow(l, 3)) + (N / 120 * Math.pow(Math.cos(phi), 5) * l5coef * Math.pow(l, 5)) + (N / 5040 * Math.pow(Math.cos(phi), 7) * l7coef * Math.pow(l, 7));

// y koordināta
xy[1] = getArcLengthOfMeridian(phi) + (t / 2 * N * Math.pow(Math.cos(phi), 2) * Math.pow(l, 2)) + (t / 24 * N * Math.pow(Math.cos(phi), 4) * l4coef * Math.pow(l, 4)) + (t / 720 * N * Math.pow(Math.cos(phi), 6) * l6coef * Math.pow(l, 6)) + (t / 40320 * N * Math.pow(Math.cos(phi), 8) * l8coef * Math.pow(l, 8));
xy[1] = LKS92WGS84.getArcLengthOfMeridian(phi) + (t / 2 * N * Math.pow(Math.cos(phi), 2) * Math.pow(l, 2)) + (t / 24 * N * Math.pow(Math.cos(phi), 4) * l4coef * Math.pow(l, 4)) + (t / 720 * N * Math.pow(Math.cos(phi), 6) * l6coef * Math.pow(l, 6)) + (t / 40320 * N * Math.pow(Math.cos(phi), 8) * l8coef * Math.pow(l, 8));

return xy;
},
};

// Pārveido punkta x, y koordinātas par ģeogrāfiskā platuma, garuma koordinātām (bez pārvietojuma un mērogojuma)
convertMapXYToLatLon = function(x, y, lambda0) {
LKS92WGS84.convertMapXYToLatLon = function(x, y, lambda0)
{
var phif, Nf, Nfpow, nuf2, ep2, tf, tf2, tf4, cf,
x1frac, x2frac, x3frac, x4frac, x5frac, x6frac, x7frac, x8frac,
x2poly, x3poly, x4poly, x5poly, x6poly, x7poly, x8poly,
latLng = [0, 0];

phif = getFootpointLatitude(y);
ep2 = (Math.pow(A_AXIS, 2) - Math.pow(B_AXIS, 2)) / Math.pow(B_AXIS, 2);
phif = LKS92WGS84.getFootpointLatitude(y);
ep2 = (Math.pow(LKS92WGS84.A_AXIS, 2) - Math.pow(LKS92WGS84.B_AXIS, 2)) / Math.pow(LKS92WGS84.B_AXIS, 2);
cf = Math.cos(phif);
nuf2 = ep2 * Math.pow(cf, 2);
Nf = Math.pow(A_AXIS, 2) / (B_AXIS * Math.sqrt(1 + nuf2));
Nf = Math.pow(LKS92WGS84.A_AXIS, 2) / (LKS92WGS84.B_AXIS * Math.sqrt(1 + nuf2));
Nfpow = Nf;

tf = Math.tan(phif);
Expand All @@ -87,25 +93,25 @@ var LKS92WGS84 = function() {

x1frac = 1 / (Nfpow * cf);

Nfpow *= Nf; // Nf^2
Nfpow *= Nf; // Nf^2
x2frac = tf / (2 * Nfpow);

Nfpow *= Nf; // Nf^3
Nfpow *= Nf; // Nf^3
x3frac = 1 / (6 * Nfpow * cf);

Nfpow *= Nf; // Nf^4
Nfpow *= Nf; // Nf^4
x4frac = tf / (24 * Nfpow);

Nfpow *= Nf; // Nf^5
Nfpow *= Nf; // Nf^5
x5frac = 1 / (120 * Nfpow * cf);

Nfpow *= Nf; // Nf^6
Nfpow *= Nf; // Nf^6
x6frac = tf / (720 * Nfpow);

Nfpow *= Nf; // Nf^7
Nfpow *= Nf; // Nf^7
x7frac = 1 / (5040 * Nfpow * cf);

Nfpow *= Nf; // Nf^8
Nfpow *= Nf; // Nf^8
x8frac = tf / (40320 * Nfpow);

x2poly = -1 - nuf2;
Expand All @@ -126,13 +132,14 @@ var LKS92WGS84 = function() {
};

// Pārveido punkta ģeogrāfiskā platuma, garuma koordinātas par x, y koordinātām (ar pārvietojumu un mērogojumu)
publicStatic.convertLatLonToXY = function(coordinates) {
var lat = coordinates[0] * PI / 180,
lng = coordinates[1] * PI / 180,
xy = convertMapLatLngToXY(lat, lng, CENTRAL_MERIDIAN);
LKS92WGS84.convertLatLonToXY = function(coordinates)
{
var lat = coordinates[0] * LKS92WGS84.PI / 180,
lng = coordinates[1] * LKS92WGS84.PI / 180,
xy = LKS92WGS84.convertMapLatLngToXY(lat, lng, LKS92WGS84.CENTRAL_MERIDIAN);

xy[0] = xy[0] * SCALE + OFFSET_X;
xy[1] = xy[1] * SCALE + OFFSET_Y;
xy[0] = xy[0] * LKS92WGS84.SCALE + LKS92WGS84.OFFSET_X;
xy[1] = xy[1] * LKS92WGS84.SCALE + LKS92WGS84.OFFSET_Y;

if (xy[1] < 0) {
xy[1] += 10000000;
Expand All @@ -142,18 +149,17 @@ var LKS92WGS84 = function() {
};

// Pārveido punkta x, y koordinātas par ģeogrāfiskā platuma, garuma koordinātām (ar pārvietojumu un mērogojumu)
publicStatic.convertXYToLatLon = function(coordinates) {
var x = (coordinates[0] - OFFSET_X) / SCALE,
y = (coordinates[1] - OFFSET_Y) / SCALE,
latLng = convertMapXYToLatLon(x, y, CENTRAL_MERIDIAN);
LKS92WGS84.convertXYToLatLon = function(coordinates)
{
var x = (coordinates[0] - LKS92WGS84.OFFSET_X) / LKS92WGS84.SCALE,
y = (coordinates[1] - LKS92WGS84.OFFSET_Y) / LKS92WGS84.SCALE,
latLng = LKS92WGS84.convertMapXYToLatLon(x, y, LKS92WGS84.CENTRAL_MERIDIAN);

latLng[0] = latLng[0] / PI * 180;
latLng[1] = latLng[1] / PI * 180;
latLng[0] = latLng[0] / LKS92WGS84.PI * 180;
latLng[1] = latLng[1] / LKS92WGS84.PI * 180;

return latLng;
};

return publicStatic;
};

LKS92WGS84 = LKS92WGS84();
return LKS92WGS84;
})();
6 changes: 4 additions & 2 deletions javascript/example.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
</head>
<body>
<script>
function testCase(coordinates) {
function testCase(coordinates)
{
var converted = LKS92WGS84.convertXYToLatLon(LKS92WGS84.convertLatLonToXY(coordinates)),
result;

Expand All @@ -19,7 +20,8 @@
return result;
}

function testCase2(coordinates, lksValidate) {
function testCase2(coordinates, lksValidate)
{
var converted = LKS92WGS84.convertLatLonToXY(coordinates),
result;

Expand Down
Loading

0 comments on commit 986eaf3

Please sign in to comment.