Passed
Push — master ( 2b8bad...6fb66b )
by Doug
25:16
created

UTMPoint::convert()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 1
b 0
f 0
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\CoordinateReferenceSystem;
13
use PHPCoord\CoordinateReferenceSystem\Geographic;
14
use PHPCoord\CoordinateReferenceSystem\Geographic2D;
15
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...
16
use PHPCoord\CoordinateSystem\Cartesian;
17
use PHPCoord\Geometry\BoundingArea;
18
use PHPCoord\Geometry\Extents\RegionMap;
0 ignored issues
show
Bug introduced by
The type PHPCoord\Geometry\Extents\RegionMap 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...
19
use PHPCoord\UnitOfMeasure\Length\Length;
20
use function str_replace;
21
22
class UTMPoint extends ProjectedPoint
23
{
24
    public const HEMISPHERE_NORTH = 'N';
25
26
    public const HEMISPHERE_SOUTH = 'S';
27
28
    /**
29
     * Zone number.
30
     */
31
    protected int $zone;
32
33
    /**
34
     * Hemisphere (N or S).
35
     */
36
    protected string $hemisphere;
37
38
    /**
39
     * Base CRS.
40
     * @deprecated use $this->crs->getBaseCRS()
41
     */
42
    protected Geographic2D $baseCRS;
43
44 72
    public function __construct(Geographic2D $crs, Length $easting, Length $northing, int $zone, string $hemisphere, ?DateTimeInterface $epoch = null)
45
    {
46 72
        $this->zone = $zone;
47 72
        $this->hemisphere = $hemisphere;
48 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

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