Auto Calculating LAEA and code in Building::save
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
<?php
|
||||
|
||||
class Building extends mfBaseModel {
|
||||
protected $forcestr = ['street','zip','phone','gps_lat','gps_long','email','note'];
|
||||
|
||||
private $network;
|
||||
private $pop;
|
||||
private $type;
|
||||
@@ -39,4 +41,79 @@ class Building extends mfBaseModel {
|
||||
return $this->$name;
|
||||
}
|
||||
|
||||
public function getNewObjectCode() {
|
||||
if(!$this->zip) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$cc = "AT";
|
||||
$zip = $this->zip;
|
||||
|
||||
for($try = 16; $try > 0; $try--) {
|
||||
$rnd[0] = random_int(0, 255);
|
||||
$rnd[1] = random_int(0, 255);
|
||||
$rnd[2] = random_int(0, 255);
|
||||
$rnd[3] = random_int(0, 255);
|
||||
|
||||
$code = "$cc-$zip-";
|
||||
foreach($rnd as $r) {
|
||||
$code .= dechex($r);
|
||||
}
|
||||
|
||||
if(BuildingModel::search(['code' => $code])) {
|
||||
$this->log->warn(__FILE__."::getNewObjectCode: New Code already in use. Trying again for a maximum of $try times.");
|
||||
} else {
|
||||
// code is unique
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//var_dump($code);
|
||||
//var_dump($try);exit;
|
||||
|
||||
if($try == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $code;
|
||||
}
|
||||
|
||||
public function getLaeaCoordinates() {
|
||||
if(!$this->gps_lat || !$this->gps_lat) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Elipsenparameter der Erdoberfläche
|
||||
$a = 6378137;
|
||||
$e = 0.081819191;
|
||||
|
||||
// Lage des Ausgangspunktes in natürlichen Koordinaten und Korrekturwerte in Meter
|
||||
$latO = 0.907571211;
|
||||
$lonO = 0.174532925;
|
||||
$FE = 4321000;
|
||||
$FN = 3210000;
|
||||
|
||||
// Mathematische Konstanten
|
||||
$qP = 1.99553108748562;
|
||||
$qO = 1.56982570415136;
|
||||
$PI = M_PI;
|
||||
|
||||
// Umrechnung der Eingabekoordinaten in rad
|
||||
$Lat = $this->gps_lat * $PI / 180;
|
||||
$Lon = $this->gps_long * $PI / 180;
|
||||
|
||||
// Berechnungen
|
||||
$q = (1 - $e ** 2) * ((sin($Lat) / (1 - $e ** 2 * sin($Lat) ** 2)) - ((1 / (2 * $e)) * log((1 - $e * sin($Lat)) / (1 + $e * sin($Lat)))));
|
||||
$beta = asin($q / $qP);
|
||||
$betaO = asin($qO / $qP);
|
||||
$Rq = $a * ($qP / 2) ** 0.5;
|
||||
$b = $Rq * (2 / (1 + Sin($betaO) * Sin($beta) + Cos($betaO) * Cos($beta) * Cos($Lon - $lonO))) ** 0.5;
|
||||
$D = $a * (Cos($latO) / (1 - $e ** 2 * Sin($latO) ** 2) ** 0.5) / ($Rq * Cos($betaO));
|
||||
$East = floor(($FE + (($b * $D) * (Cos($beta) * Sin($Lon - $lonO))))/100);
|
||||
$North = floor(($FN + ($b / $D) * ((Cos($betaO) * Sin($beta)) - (Sin($betaO) * Cos($beta) * Cos($Lon - $lonO))))/100);
|
||||
$Gridcell = "100mN{$North}E{$East}";
|
||||
|
||||
return $Gridcell;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user