Skip to content

Commit

Permalink
- Nodrošināts Python2 un Python3 valodas atbalsts
Browse files Browse the repository at this point in the history
- Python klasē veikti strukturāli labojumi, lai izvairītos no jauna klases objekta izveides
- Citi sīki labojumi un optimizācijas
  • Loading branch information
arvislacis committed Dec 23, 2015
1 parent 2c69d5f commit 0cf4c0a
Show file tree
Hide file tree
Showing 5 changed files with 184 additions and 170 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ Lai salīdzinātu koordinātu pārveidojumu rezultātus, īpaši veicot jaunu pr

Saraksts ar projektā pašlaik pieejamajām programmēšanas valodām - valodas, kurām izstrādāta koordinātu pārveidošanas klase `lks92-wgs84.*`:

| Programmēšanas valoda | Klases autors | Pēdējo izmaiņu datums |
|:---------------------:|:------------------------------------------------:|:---------------------:|
| JavaScript | [Arvis Lācis](https://github.com/arvislacis) | 22.12.2015. |
| PHP | [Arvis Lācis](https://github.com/arvislacis) | 23.12.2015. |
| Python | [Dāvis Mičulis](https://github.com/DavisMiculis) | 23.12.2015. |
| Programmēšanas valoda | Klases autors | Pēdējo būtisko izmaiņu datums |
|:---------------------:|:------------------------------------------------:|:-----------------------------:|
| JavaScript | [Arvis Lācis](https://github.com/arvislacis) | 22.12.2015. |
| PHP | [Arvis Lācis](https://github.com/arvislacis) | 23.12.2015. |
| Python2/Python3 | [Dāvis Mičulis](https://github.com/DavisMiculis) | 24.12.2015. |

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,
gan citu interesentu puses.
Expand Down
20 changes: 10 additions & 10 deletions javascript/lks92-wgs84.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ var LKS92WGS84 = function() {

// Aprēķina ģeogrāfisko platumu centrālā meridiāna punktam
getFootpointLatitude = function(y) {
var y_, alpha_, beta_, gamma_, delta_, epsilon_, n;
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));
y_ = 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 y_ + (beta_ * Math.sin(2 * y_)) + (gamma_ * Math.sin(4 * y_)) + (delta_ * Math.sin(6 * y_)) + (epsilon_ * Math.sin(8 * y_));
alpha = ((A_AXIS + 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)
Expand Down Expand Up @@ -135,7 +135,7 @@ var LKS92WGS84 = function() {
xy[1] = xy[1] * SCALE + OFFSET_Y;

if (xy[1] < 0) {
xy[1] = xy[1] + 10000000;
xy[1] += 10000000;
}

return xy;
Expand Down
18 changes: 9 additions & 9 deletions php/lks92-wgs84.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ private static function getArcLengthOfMeridian($phi)
private static function getFootpointLatitude($y)
{
$n = (self::$A_AXIS - self::$B_AXIS) / (self::$A_AXIS + self::$B_AXIS);
$alpha_ = ((self::$A_AXIS + self::$B_AXIS) / 2) * (1 + (pow($n, 2) / 4) + (pow($n, 4) / 64));
$y_ = $y / $alpha_;
$beta_ = (3 * $n / 2) + (-27 * pow($n, 3) / 32) + (269 * pow($n, 5) / 512);
$gamma_ = (21 * pow($n, 2) / 16) + (-55 * pow($n, 4) / 32);
$delta_ = (151 * pow($n, 3) / 96) + (-417 * pow($n, 5) / 128);
$epsilon_ = (1097 * pow($n, 4) / 512);

return $y_ + ($beta_ * sin(2 * $y_)) + ($gamma_ * sin(4 * $y_)) + ($delta_ * sin(6 * $y_)) + ($epsilon_ * sin(8 * $y_));
$alpha = ((self::$A_AXIS + self::$B_AXIS) / 2) * (1 + (pow($n, 2) / 4) + (pow($n, 4) / 64));
$yd = $y / $alpha;
$beta = (3 * $n / 2) + (-27 * pow($n, 3) / 32) + (269 * pow($n, 5) / 512);
$gamma = (21 * pow($n, 2) / 16) + (-55 * pow($n, 4) / 32);
$delta = (151 * pow($n, 3) / 96) + (-417 * pow($n, 5) / 128);
$epsilon = (1097 * pow($n, 4) / 512);

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

// Pārveido punkta ģeogrāfiskā platuma, garuma koordinātas par x, y koordinātām (bez pārvietojuma un mērogojuma)
Expand Down Expand Up @@ -131,7 +131,7 @@ public static function convertLatLonToXY(array $coordinates)
$xy[1] = $xy[1] * self::$SCALE + self::$OFFSET_Y;

if ($xy[1] < 0) {
$xy[1] = $xy[1] + 10000000;
$xy[1] += 10000000;
}

return $xy;
Expand Down
35 changes: 22 additions & 13 deletions python/example.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,34 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import math
import lks92_wgs84
from lks92_wgs84 import LKS92WGS84

def testCase(coordinates):
converted = LKS92WGS84.convertXYToLatLon(LKS92WGS84.convertLatLonToXY(coordinates))

if round(converted[0] * math.pow(10, 8)) / math.pow(10, 8) == round(coordinates[0] * math.pow(10, 8)) / math.pow(10, 8) and round(converted[1] * math.pow(10, 8)) / math.pow(10, 8) == round(coordinates[1] * math.pow(10, 8)) / math.pow(10, 8):
result = "izpildās"
else:
result = "neizpildās"

LKS92WGS84 = lks92_wgs84.LKS92WGS84()
return result

def TestCase(coordinates):
converted = LKS92WGS84.convertXYToLatLon(LKS92WGS84.convertLatLonToXY(coordinates))
def testCase2(coordinates, lksValidate):
converted = LKS92WGS84.convertLatLonToXY(coordinates)

if round(converted[0] * math.pow(10, 8)) / math.pow(10, 8) == round(coordinates[0] * math.pow(10, 8)) / math.pow(10, 8) and round(converted[1] * math.pow(10, 8)) / math.pow(10, 8) == round(coordinates[1] * math.pow(10, 8)) / math.pow(10, 8):
result = "izpildās"
else:
result = "neizpildās"
if round(converted[0], 2) == lksValidate[0] and round(converted[1], 2) == lksValidate[1]:
result = "izpildās"
else:
result = "neizpildās"

return result
return result

coordinates = [58.079501574948, 25.189986971284]
print "\"Baltās naktis\" - Latvijas tālākais ziemeļu punkts [" + str(coordinates[0]) + "," + str(coordinates[1]) + "] => " + TestCase(coordinates)
print("\"Baltās naktis\" - Latvijas tālākais ziemeļu punkts [" + str(coordinates[0]) + "," + str(coordinates[1]) + "] => " + testCase(coordinates) + " => " + testCase2(coordinates, [570181.00, 438180.00]))
coordinates = [56.172282784562, 28.095216442873]
print "\"Austras koks\" - Latvijas tālākais austrumu punkts [" + str(coordinates[0]) + "," + str(coordinates[1]) + "] => " + TestCase(coordinates)
print("\"Austras koks\" - Latvijas tālākais austrumu punkts [" + str(coordinates[0]) + "," + str(coordinates[1]) + "] => " + testCase(coordinates) + " => " + testCase2(coordinates, [754190.00, 232806.00]))
coordinates = [55.675228242509, 26.580528487143]
print "\"Saules puķe\" - Latvijas tālākais dienvidu punkts [" + str(coordinates[0]) + "," + str(coordinates[1]) + "] => " + TestCase(coordinates)
print("\"Saules puķe\" - Latvijas tālākais dienvidu punkts [" + str(coordinates[0]) + "," + str(coordinates[1]) + "] => " + testCase(coordinates) + " => " + testCase2(coordinates, [662269.00, 172953.00]))
coordinates = [56.377008455189, 20.979185882058]
print "\"Zaļais stars\" - Latvijas galējais rietumu punkts [" + str(coordinates[0]) + "," + str(coordinates[1]) + "] => " + TestCase(coordinates)
print("\"Zaļais stars\" - Latvijas galējais rietumu punkts [" + str(coordinates[0]) + "," + str(coordinates[1]) + "] => " + testCase(coordinates) + " => " + testCase2(coordinates, [313470.00, 252137.00]))
Loading

0 comments on commit 0cf4c0a

Please sign in to comment.