Skip to content

Commit e9ee2bd

Browse files
committed
Add support for compressed grid files
1 parent 403ece2 commit e9ee2bd

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## [Unreleased]
44

5+
## [5.8.0] - 2024-02-03
6+
### Added
7+
- Support for compressed grid files to reduce distribution sizes
8+
59
## [5.7.0] - 2024-01-27
610
### Changed
711
- Updates to data for Canada, Denmark, France, Germany and USA
@@ -317,8 +321,9 @@ Initial release of this fork (based off of v2.3 of original)
317321
- Eastings and northings are rounded to 1m, and lat/long to 5dp (approx 1m) to avoid any misconceptions that precision is the same thing as accuracy.
318322
- When calculating surface distances, a more accurate mean radius is now used rather than that derived from historical definitions of a nautical mile
319323

320-
[Unreleased]: https://github.com/dvdoug/PHPCoord/compare/v5.7.0..master
324+
[Unreleased]: https://github.com/dvdoug/PHPCoord/compare/v5.8.0..master
321325

326+
[5.8.0]: https://github.com/dvdoug/PHPCoord/compare/v5.7.0..v5.8.0
322327
[5.7.0]: https://github.com/dvdoug/PHPCoord/compare/v5.6.0..v5.7.0
323328
[5.6.0]: https://github.com/dvdoug/PHPCoord/compare/v5.5.0..v5.6.0
324329
[5.5.0]: https://github.com/dvdoug/PHPCoord/compare/v5.4.0..v5.5.0

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"license": "(MIT and proprietary)",
1414
"require": {
1515
"php": "^8.0",
16+
"ext-zip": "*",
1617
"composer-runtime-api": "^2.1",
1718
"composer/pcre": "^3.1",
1819
"opis/json-schema": "^2.3"

src/CoordinateOperation/GridFile.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,33 @@
99
namespace PHPCoord\CoordinateOperation;
1010

1111
use SplFileObject;
12+
use ZipArchive;
1213

1314
use function assert;
15+
use function file_exists;
16+
use function sys_get_temp_dir;
17+
use function str_ends_with;
1418

1519
/**
1620
* @internal
1721
*/
1822
class GridFile extends SplFileObject
1923
{
24+
public function __construct(string $filename)
25+
{
26+
if (str_ends_with($filename, '.zip')) {
27+
$zip = new ZipArchive();
28+
$zip->open($filename);
29+
$filename = sys_get_temp_dir() . '/' . $zip->getNameIndex(0); // only 1 file inside
30+
31+
if (!file_exists($filename)) {
32+
$zip->extractTo(sys_get_temp_dir());
33+
}
34+
}
35+
36+
parent::__construct($filename);
37+
}
38+
2039
public function fgets(): string
2140
{
2241
$result = parent::fgets();

0 commit comments

Comments
 (0)