Skip to content

Commit

Permalink
Add support for compressed grid files
Browse files Browse the repository at this point in the history
  • Loading branch information
dvdoug committed Feb 3, 2024
1 parent 403ece2 commit e9ee2bd
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## [Unreleased]

## [5.8.0] - 2024-02-03
### Added
- Support for compressed grid files to reduce distribution sizes

## [5.7.0] - 2024-01-27
### Changed
- Updates to data for Canada, Denmark, France, Germany and USA
Expand Down Expand Up @@ -317,8 +321,9 @@ Initial release of this fork (based off of v2.3 of original)
- 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.
- When calculating surface distances, a more accurate mean radius is now used rather than that derived from historical definitions of a nautical mile

[Unreleased]: https://github.com/dvdoug/PHPCoord/compare/v5.7.0..master
[Unreleased]: https://github.com/dvdoug/PHPCoord/compare/v5.8.0..master

[5.8.0]: https://github.com/dvdoug/PHPCoord/compare/v5.7.0..v5.8.0
[5.7.0]: https://github.com/dvdoug/PHPCoord/compare/v5.6.0..v5.7.0
[5.6.0]: https://github.com/dvdoug/PHPCoord/compare/v5.5.0..v5.6.0
[5.5.0]: https://github.com/dvdoug/PHPCoord/compare/v5.4.0..v5.5.0
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"license": "(MIT and proprietary)",
"require": {
"php": "^8.0",
"ext-zip": "*",
"composer-runtime-api": "^2.1",
"composer/pcre": "^3.1",
"opis/json-schema": "^2.3"
Expand Down
19 changes: 19 additions & 0 deletions src/CoordinateOperation/GridFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,33 @@
namespace PHPCoord\CoordinateOperation;

use SplFileObject;
use ZipArchive;

use function assert;
use function file_exists;
use function sys_get_temp_dir;
use function str_ends_with;

/**
* @internal
*/
class GridFile extends SplFileObject
{
public function __construct(string $filename)
{
if (str_ends_with($filename, '.zip')) {
$zip = new ZipArchive();
$zip->open($filename);
$filename = sys_get_temp_dir() . '/' . $zip->getNameIndex(0); // only 1 file inside

if (!file_exists($filename)) {
$zip->extractTo(sys_get_temp_dir());
}
}

parent::__construct($filename);
}

public function fgets(): string
{
$result = parent::fgets();
Expand Down

0 comments on commit e9ee2bd

Please sign in to comment.