Passed
Push — master ( 344e29...cbaf3e )
by Doug
38:02
created

UTMPoint   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Test Coverage

Coverage 94.29%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 33
dl 0
loc 84
ccs 33
cts 35
cp 0.9429
rs 10
c 1
b 0
f 0
wmc 9

7 Methods

Rating   Name   Duplication   Size   Complexity  
A convert() 0 3 1
A __toString() 0 3 1
A calculateDistance() 0 7 2
A getHemisphere() 0 3 1
A getZone() 0 3 1
A getBaseCRS() 0 3 1
A __construct() 0 28 2
1
<?php
2
/**
3
 * PHPCoord.
4
 *
5
 * @author Doug Wright
6
 */
7
declare(strict_types=1);
8
9
namespace PHPCoord;
10
11
use DateTimeInterface;
12
use PHPCoord\CoordinateReferenceSystem\Compound;
13
use PHPCoord\CoordinateReferenceSystem\Geocentric;
14
use PHPCoord\CoordinateReferenceSystem\Geographic;
15
use PHPCoord\CoordinateReferenceSystem\Geographic2D;
16
use PHPCoord\CoordinateReferenceSystem\Geographic3D;
17
use PHPCoord\CoordinateReferenceSystem\Projected;
0 ignored issues
show
Bug introduced by
The type PHPCoord\CoordinateReferenceSystem\Projected was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
18
use PHPCoord\CoordinateReferenceSystem\Vertical;
19
use PHPCoord\CoordinateSystem\Cartesian;
20
use PHPCoord\Geometry\BoundingArea;
21
use PHPCoord\Geometry\RegionMap;
22
use PHPCoord\UnitOfMeasure\Length\Length;
23
24
use function str_replace;
25
26
class UTMPoint extends ProjectedPoint
27
{
28
    public const HEMISPHERE_NORTH = 'N';
29
30
    public const HEMISPHERE_SOUTH = 'S';
31
32
    /**
33
     * Zone number.
34
     */
35
    protected int $zone;
36
37
    /**
38
     * Hemisphere (N or S).
39
     */
40
    protected string $hemisphere;
41
42
    /**
43
     * Base CRS.
44
     * @deprecated use $this->crs->getBaseCRS()
45
     */
46
    protected Geographic2D $baseCRS;
47
48 72
    public function __construct(Geographic2D $crs, Length $easting, Length $northing, int $zone, string $hemisphere, ?DateTimeInterface $epoch = null)
49
    {
50 72
        $this->zone = $zone;
51 72
        $this->hemisphere = $hemisphere;
52 72
        $this->baseCRS = $crs;
0 ignored issues
show
Deprecated Code introduced by
The property PHPCoord\UTMPoint::$baseCRS has been deprecated: use $this->crs->getBaseCRS() ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

52
        /** @scrutinizer ignore-deprecated */ $this->baseCRS = $crs;

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
53
54 72
        $longitudeOrigin = $zone * 6 - 3;
55 72
        if ($hemisphere === self::HEMISPHERE_NORTH) {
56 54
            $boundingArea = BoundingArea::createFromArray([[[[$longitudeOrigin, 0], [$longitudeOrigin, 90], [$longitudeOrigin + 6, 90], [$longitudeOrigin + 6, 0]]]], RegionMap::REGION_GLOBAL);
57 54
            $derivingConversion = 'urn:ogc:def:coordinateOperation:EPSG::' . ($zone + 16000);
58
        } else {
59 18
            $boundingArea = BoundingArea::createFromArray([[[[$longitudeOrigin, -90], [$longitudeOrigin, 0], [$longitudeOrigin + 6, 0], [$longitudeOrigin + 6, -90]]]], RegionMap::REGION_GLOBAL);
60 18
            $derivingConversion = 'urn:ogc:def:coordinateOperation:EPSG::' . ($zone + 16100);
61
        }
62
63 72
        $srid = 'urn:ogc:def:crs,' . str_replace('urn:ogc:def:', '', $crs->getSRID()) . ',' . str_replace('urn:ogc:def:', '', Cartesian::EPSG_2D_AXES_EASTING_NORTHING_E_N_ORIENTATIONS_EAST_NORTH_UOM_M) . ',' . str_replace('urn:ogc:def:', '', $derivingConversion);
64
65 72
        $projectedCRS = new Projected(
66 72
            $srid,
67 72
            Cartesian::fromSRID(Cartesian::EPSG_2D_AXES_EASTING_NORTHING_E_N_ORIENTATIONS_EAST_NORTH_UOM_M),
68 72
            $crs->getDatum(),
69 72
            $boundingArea,
70 72
            "{$crs->getName()} / UTM zone {$zone}{$hemisphere}",
71 72
            $crs,
72 72
            $derivingConversion
73 72
        );
74
75 72
        parent::__construct($projectedCRS, $easting, $northing, null, null, $epoch, null);
76
    }
77
78 18
    public function getZone(): int
79
    {
80 18
        return $this->zone;
81
    }
82
83 18
    public function getHemisphere(): string
84
    {
85 18
        return $this->hemisphere;
86
    }
87
88
    public function getBaseCRS(): Geographic
89
    {
90
        return $this->crs->getBaseCRS();
91
    }
92
93 36
    public function convert(Compound|Geocentric|Geographic2D|Geographic3D|Projected|Vertical $to, bool $ignoreBoundaryRestrictions = false): Point
94
    {
95 36
        return $this->asGeographicPoint()->convert($to, $ignoreBoundaryRestrictions);
96
    }
97
98 27
    public function calculateDistance(Point $to): Length
99
    {
100 27
        if ($this->crs == $to->getCRS()) {
101 9
            return parent::calculateDistance($to);
102
        }
103
104 18
        return $this->asGeographicPoint()->calculateDistance($to);
105
    }
106
107 18
    public function __toString(): string
108
    {
109 18
        return $this->getZone() . $this->getHemisphere() . ' ' . (int) $this->easting->getValue() . ' ' . (int) $this->northing->getValue();
110
    }
111
}
112