Code Duplication    Length = 152-153 lines in 2 locations

htdocs/lib2/logic/coordinate.class.php 1 location

@@ 124-275 (lines=152) @@
121
    }
122
123
    // array(zone, letter, north, east)
124
    public function getUTM()
125
    {
126
        /* Copyright (c) 2006, HELMUT H. HEIMEIER
127
           Permission is hereby granted, free of charge, to any person obtaining a
128
           copy of this software and associated documentation files (the "Software"),
129
           to deal in the Software without restriction, including without limitation
130
           the rights to use, copy, modify, merge, publish, distribute, sublicense,
131
           and/or sell copies of the Software, and to permit persons to whom the
132
           Software is furnished to do so, subject to the following conditions:
133
           The above copyright notice and this permission notice shall be included
134
           in all copies or substantial portions of the Software.*/
135
136
        /* Die Funktion wandelt geographische Koordinaten in UTM Koordinaten
137
           um. Geographische Länge lw und Breite bw müssen im WGS84 Datum
138
           gegeben sein. Berechnet werden UTM Zone, Ostwert ew und Nordwert nw.*/
139
140
        //Geographische Länge lw und Breite bw im WGS84 Datum
141
        if ($this->nLon == 0 || $this->nLat == 0) {
142
            return [
143
                'zone' => '',
144
                'letter' => '',
145
                'north' => 'N ' . 0,
146
                'east' => 'E ' . 0,
147
            ];
148
        }
149
        if ($this->nLon <= - 180 || $this->nLon > 180 || $this->nLat <= - 80 || $this->nLat >= 84) {
150
            // Werte nicht im Bereich des UTM Systems -180° <= nLon < +180°, -80° < nLat < 84° N
151
            return [
152
                '',
153
                '',
154
                0,
155
                0,
156
            ];
157
        }
158
        $lw = (float) $this->nLon;
159
        $bw = (float) $this->nLat;
160
161
        //WGS84 Datum
162
        //Große Halbachse a und Abplattung f
163
        $a = 6378137.000;
164
        $f = 3.35281068e-3;
165
        $b_sel = 'CDEFGHJKLMNPQRSTUVWXX';
166
167
        //Polkrümmungshalbmesser c
168
        $c = $a / (1 - $f);
169
170
        //Quadrat der zweiten numerischen Exzentrizität
171
        $ex2 = (2 * $f - $f * $f) / ((1 - $f) * (1 - $f));
172
        $ex4 = $ex2 * $ex2;
173
        $ex6 = $ex4 * $ex2;
174
        $ex8 = $ex4 * $ex4;
175
176
        //Koeffizienten zur Berechnung der Meridianbogenlänge
177
        $e0 = $c * (pi() / 180) * (1 - 3 * $ex2 / 4 + 45 * $ex4 / 64 - 175 * $ex6 / 256 + 11025 * $ex8 / 16384);
178
        $e2 = $c * (-3 * $ex2 / 8 + 15 * $ex4 / 32 - 525 * $ex6 / 1024 + 2205 * $ex8 / 4096);
179
        $e4 = $c * (15 * $ex4 / 256 - 105 * $ex6 / 1024 + 2205 * $ex8 / 16384);
180
        $e6 = $c * (-35 * $ex6 / 3072 + 315 * $ex8 / 12288);
181
182
        //Längenzone lz und Breitenzone (Band) bz
183
        $lzn = intval(($lw + 180) / 6) + 1;
184
185
        if ($bw >= 56.0 && $bw < 64.0 && $lw >= 3.0 && $lw < 12.0) {
186
            $lzn = 32;
187
        }
188
189
        // Special zones for Svalbard.
190
        if ($bw >= 72.0 && $bw < 84.0) {
191
            if ($lw >= 0.0 && $lw < 9.0) {
192
                $lzn = 31;
193
            } elseif ($lw >= 9.0 && $lw < 21.0) {
194
                $lzn = 33;
195
            } elseif ($lw >= 21.0 && $lw < 33.0) {
196
                $lzn = 35;
197
            } elseif ($lw >= 33.0 && $lw < 42.0) {
198
                $lzn = 37;
199
            }
200
        }
201
202
        $lz = "$lzn";
203
        if ($lzn < 10) {
204
            $lz = '0' . $lzn;
205
        }
206
        $bd = (int) (1 + ($bw + 80) / 8);
207
        $bz = substr($b_sel, $bd - 1, 1);
208
209
        //Geographische Breite in Radianten br
210
        $br = $bw * pi() / 180;
211
212
        $tan1 = tan($br);
213
        $tan2 = $tan1 * $tan1;
214
        $tan4 = $tan2 * $tan2;
215
216
        $cos1 = cos($br);
217
        $cos2 = $cos1 * $cos1;
218
        $cos4 = $cos2 * $cos2;
219
        $cos3 = $cos2 * $cos1;
220
        $cos5 = $cos4 * $cos1;
221
222
        $etasq = $ex2 * $cos2;
223
224
        //Querkrümmungshalbmesser nd
225
        $nd = $c / sqrt(1 + $etasq);
226
227
        //Meridianbogenlänge g aus gegebener geographischer Breite bw
228
        $g = ($e0 * $bw) + ($e2 * sin(2 * $br)) + ($e4 * sin(4 * $br)) + ($e6 * sin(6 * $br));
229
230
        //Längendifferenz dl zum Bezugsmeridian lh
231
        $lh = ($lzn - 30) * 6 - 3;
232
        $dl = ($lw - $lh) * pi() / 180;
233
        $dl2 = $dl * $dl;
234
        $dl4 = $dl2 * $dl2;
235
        $dl3 = $dl2 * $dl;
236
        $dl5 = $dl4 * $dl;
237
238
        //Maßstabsfaktor auf dem Bezugsmeridian bei UTM Koordinaten m = 0.9996
239
        //Nordwert nw und Ostwert ew als Funktion von geographischer Breite und Länge
240
241
        if ($bw < 0) {
242
            $nw = 10e6 + 0.9996 * ($g + $nd * $cos2 * $tan1 * $dl2 / 2 +
243
                    $nd * $cos4 * $tan1 * (5 - $tan2 + 9 * $etasq) * $dl4 / 24);
244
        } else {
245
            $nw = 0.9996 * ($g + $nd * $cos2 * $tan1 * $dl2 / 2 +
246
                    $nd * $cos4 * $tan1 * (5 - $tan2 + 9 * $etasq) * $dl4 / 24);
247
        }
248
        $ew = 0.9996 * ($nd * $cos1 * $dl + $nd * $cos3 * (1 - $tan2 + $etasq) * $dl3 / 6 +
249
                $nd * $cos5 * (5 - 18 * $tan2 + $tan4) * $dl5 / 120) + 500000;
250
251
        $nk = $nw - (int) $nw;
252
        if ($nk < 0.5) {
253
            $nw = '' . (int) $nw;
254
        } else {
255
            $nw = '' . ((int) $nw + 1);
256
        }
257
258
        while (strlen($nw) < 7) {
259
            $nw = '0' . $nw;
260
        }
261
262
        $nk = $ew - (int) $ew;
263
        if ($nk < 0.5) {
264
            $ew = '0' . (int) $ew;
265
        } else {
266
            $ew = '0' . intval($ew + 1);
267
        }
268
269
        return [
270
            'zone' => $lz,
271
            'letter' => $bz,
272
            'north' => 'N ' . floor($nw),
273
            'east' => 'E ' . floor($ew),
274
        ];
275
    }
276
277
    // return string
278
    public function getGK()

htdocs_symfony/src/Repository/CoordinatesRepository.php 1 location

@@ 177-329 (lines=153) @@
174
     *
175
     * @return array|string[]
176
     */
177
    public function getUTM()
178
    : array
179
    {
180
        /* Copyright (c) 2006, HELMUT H. HEIMEIER
181
           Permission is hereby granted, free of charge, to any person obtaining a
182
           copy of this software and associated documentation files (the "Software"),
183
           to deal in the Software without restriction, including without limitation
184
           the rights to use, copy, modify, merge, publish, distribute, sublicense,
185
           and/or sell copies of the Software, and to permit persons to whom the
186
           Software is furnished to do so, subject to the following conditions:
187
           The above copyright notice and this permission notice shall be included
188
           in all copies or substantial portions of the Software.*/
189
190
        /* Die Funktion wandelt geographische Koordinaten in UTM Koordinaten
191
           um. Geographische Länge lw und Breite bw müssen im WGS84 Datum
192
           gegeben sein. Berechnet werden UTM Zone, Ostwert ew und Nordwert nw.*/
193
194
        //Geographische Länge lw und Breite bw im WGS84 Datum
195
        if ($this->nLon == 0 || $this->nLat == 0) {
196
            return [
197
                'zone' => '',
198
                'letter' => '',
199
                'north' => 'N ' . 0,
200
                'east' => 'E ' . 0,
201
            ];
202
        }
203
        if ($this->nLon <= - 180 || $this->nLon > 180 || $this->nLat <= - 80 || $this->nLat >= 84) {
204
            // Werte nicht im Bereich des UTM Systems -180° <= nLon < +180°, -80° < nLat < 84° N
205
            return [
206
                '',
207
                '',
208
                0,
209
                0,
210
            ];
211
        }
212
        $lw = (float) $this->nLon;
213
        $bw = (float) $this->nLat;
214
215
        //WGS84 Datum
216
        //Große Halbachse a und Abplattung f
217
        $a = 6378137.000;
218
        $f = 3.35281068e-3;
219
        $b_sel = 'CDEFGHJKLMNPQRSTUVWXX';
220
221
        //Polkrümmungshalbmesser c
222
        $c = $a / (1 - $f);
223
224
        //Quadrat der zweiten numerischen Exzentrizität
225
        $ex2 = (2 * $f - $f * $f) / ((1 - $f) * (1 - $f));
226
        $ex4 = $ex2 * $ex2;
227
        $ex6 = $ex4 * $ex2;
228
        $ex8 = $ex4 * $ex4;
229
230
        //Koeffizienten zur Berechnung der Meridianbogenlänge
231
        $e0 = $c * (pi() / 180) * (1 - 3 * $ex2 / 4 + 45 * $ex4 / 64 - 175 * $ex6 / 256 + 11025 * $ex8 / 16384);
232
        $e2 = $c * (- 3 * $ex2 / 8 + 15 * $ex4 / 32 - 525 * $ex6 / 1024 + 2205 * $ex8 / 4096);
233
        $e4 = $c * (15 * $ex4 / 256 - 105 * $ex6 / 1024 + 2205 * $ex8 / 16384);
234
        $e6 = $c * (- 35 * $ex6 / 3072 + 315 * $ex8 / 12288);
235
236
        //Längenzone lz und Breitenzone (Band) bz
237
        $lzn = intval(($lw + 180) / 6) + 1;
238
239
        if ($bw >= 56.0 && $bw < 64.0 && $lw >= 3.0 && $lw < 12.0) {
240
            $lzn = 32;
241
        }
242
243
        // Special zones for Svalbard.
244
        if ($bw >= 72.0 && $bw < 84.0) {
245
            if ($lw >= 0.0 && $lw < 9.0) {
246
                $lzn = 31;
247
            } elseif ($lw >= 9.0 && $lw < 21.0) {
248
                $lzn = 33;
249
            } elseif ($lw >= 21.0 && $lw < 33.0) {
250
                $lzn = 35;
251
            } elseif ($lw >= 33.0 && $lw < 42.0) {
252
                $lzn = 37;
253
            }
254
        }
255
256
        $lz = "$lzn";
257
        if ($lzn < 10) {
258
            $lz = '0' . $lzn;
259
        }
260
        $bd = (int) (1 + ($bw + 80) / 8);
261
        $bz = substr($b_sel, $bd - 1, 1);
262
263
        //Geographische Breite in Radianten br
264
        $br = $bw * pi() / 180;
265
266
        $tan1 = tan($br);
267
        $tan2 = $tan1 * $tan1;
268
        $tan4 = $tan2 * $tan2;
269
270
        $cos1 = cos($br);
271
        $cos2 = $cos1 * $cos1;
272
        $cos4 = $cos2 * $cos2;
273
        $cos3 = $cos2 * $cos1;
274
        $cos5 = $cos4 * $cos1;
275
276
        $etasq = $ex2 * $cos2;
277
278
        //Querkrümmungshalbmesser nd
279
        $nd = $c / sqrt(1 + $etasq);
280
281
        //Meridianbogenlänge g aus gegebener geographischer Breite bw
282
        $g = ($e0 * $bw) + ($e2 * sin(2 * $br)) + ($e4 * sin(4 * $br)) + ($e6 * sin(6 * $br));
283
284
        //Längendifferenz dl zum Bezugsmeridian lh
285
        $lh = ($lzn - 30) * 6 - 3;
286
        $dl = ($lw - $lh) * pi() / 180;
287
        $dl2 = $dl * $dl;
288
        $dl4 = $dl2 * $dl2;
289
        $dl3 = $dl2 * $dl;
290
        $dl5 = $dl4 * $dl;
291
292
        //Maßstabsfaktor auf dem Bezugsmeridian bei UTM Koordinaten m = 0.9996
293
        //Nordwert nw und Ostwert ew als Funktion von geographischer Breite und Länge
294
295
        if ($bw < 0) {
296
            $nw = 10e6 + 0.9996 * ($g + $nd * $cos2 * $tan1 * $dl2 / 2 +
297
                                   $nd * $cos4 * $tan1 * (5 - $tan2 + 9 * $etasq) * $dl4 / 24);
298
        } else {
299
            $nw = 0.9996 * ($g + $nd * $cos2 * $tan1 * $dl2 / 2 +
300
                            $nd * $cos4 * $tan1 * (5 - $tan2 + 9 * $etasq) * $dl4 / 24);
301
        }
302
        $ew = 0.9996 * ($nd * $cos1 * $dl + $nd * $cos3 * (1 - $tan2 + $etasq) * $dl3 / 6 +
303
                        $nd * $cos5 * (5 - 18 * $tan2 + $tan4) * $dl5 / 120) + 500000;
304
305
        $nk = $nw - (int) $nw;
306
        if ($nk < 0.5) {
307
            $nw = '' . (int) $nw;
308
        } else {
309
            $nw = '' . ((int) $nw + 1);
310
        }
311
312
        while (strlen($nw) < 7) {
313
            $nw = '0' . $nw;
314
        }
315
316
        $nk = $ew - (int) $ew;
317
        if ($nk < 0.5) {
318
            $ew = '0' . (int) $ew;
319
        } else {
320
            $ew = '0' . intval($ew + 1);
321
        }
322
323
        return [
324
            'zone' => $lz,
325
            'letter' => $bz,
326
            'north' => 'N' . floor($nw),
327
            'east' => 'E' . floor($ew),
328
        ];
329
    }
330
331
    /**
332
     * Gauß Krüger