academe / proj4php
Proj4JS的PHP版本。这仍然是一个非常正在进行中的工作。
Requires
- php: >=5.3.0
This package is auto-updated.
Last update: 2024-09-06 08:57:31 UTC
README
注意:我将通过Pull Request修复在此处发现的所有问题,并将此包保留在此处,但它不再被积极开发。有一个完整的Proj4JS PHP端口 - packagist - 具有一些优秀的基于composer的特性,该特性来源于proj4JS。我还在这里尝试一些替代方法,希望这些方法能够被proj4php吸收。这个包是在proj4JS非常新且不完整的时候开始的。这两个项目都一直在向前发展,并在支持更大范围的投影方面超越了它。
我只是想做一些简单的转换和变换,结果就成了这样。我可能是个完美主义者。
Proj4JS已经将MGRS处理分离到一个单独的模块中,可能是因为许可问题。目前将其包含在这个库中,但它已经从原始版本中进行了大量的重构和重写。
主要的Mgrs类混合了静态方法(返回新的对象,如Mgrs、LatLong、Square、Utm对象)和操作当前对象的方法。我打算让它更清楚地表明哪个方法做什么。它只是从JavaScript库中继承了大部分内容,部分是从我对JavaScript库如何工作的学习曲线中继承的。
Mgrs
命名空间:Academe\Proj4Php\Mgrs
LatLong和Square类实现了最小接口,以支持作为独立模块的UTM和MGRS类(Academe\Proj4Php\Mgrs中的任何内容都不依赖于其他内容)。这可能会有所改变,具体取决于Mgrs是否被分离到一个单独的库中,或者与主Proj4Php库上的其他坐标类更紧密地耦合。这可能会取决于继承的许可证。
LatLong类包含纬度和经度。
$latitude = 53.0;
$longitude = -5.5;
$lat_long = new LatLong($latitude, $longitude);
$lat_long = new LatLong(array($latitude, $longitude));
Square类包含两个LatLong类,以标记边界框的对角角落。
$square = new Square($lat_long_bottom_left, $lat_long_top_right);
Utm类包含UTM坐标。
// From base UTM values.
$utm = new Utm($northing, $easting, $zone_number, $zone_letter);
// From latitude/longitude coordinates (WGS84 ellipsoid).
$utm = Utm::fromLatLong($latitude, $longitude);
$utm = Utm::fromLatLong($lat_long);
// Back to lat/long.
$lat_long = $utm->toLatLong();
// To a UTM grid reference string.
$grid_reference = $utm->toGridReference(); // '39L 198447 8893330'
$grid_reference = (string)$utm;
$grid_reference = $utm->toGridReference('%z$l%EE%NN'); // '39L0198447E8893330N'
UTM网格参考格式字段是
- %z 区号
- %l 区字母
- %h 半球字母(N或S)
- %e 东西方向
- %n 南北方向
- %E 东西方向左填充到7位数字
- %N 南北方向左填充到7位数字
Mgrs类通过其引用转换方法扩展了Utm。
// Create from base UTM values.
$mgrs = new Mgrs($northing, $easting, $zone_number, $zone_letter);
// From lat/long (same as for Utm)
$mgrs = Mgrs::fromLatLong($latitude, $longitude);
$mgrs = Mgrs::fromLatLong($lat_long);
// From a MGRS grid reference.
// The accuracy of the reference is noted and stored with the reference.
$mgrs = Mgrs::fromGridReference($mgrs_grid_reference);
// To a MGRS grid reference string.
// Template is optional, defaulting to '%z%l%k%e%n'.
// The accuracy is optional 0 to 5, defaulting to 5.
$grid_reference = $mgrs->toGridReference($template, $accuracy);
// To a single lat/long coordinate in the *centre* of the square according to
// teh accuracy, to one metre.
// $accuracy is optional, and defaults to the accuracy of the current coordinate.
$lat_long = $mgrs->toPoint($accuracy);
// The bottom left coordinate, disregarding the accuracy (like toPoint with the
// maximum accuracy of 5).
$lat_long = $mgrs->toLatLong();
// To a Square region.
// The accuracy is optional 0 to 5, defaulting to 5.
$square = $mgrs->toSquare($accuracy);
MGRS网格参考格式字段是
- %z 区号
- %l 区字母
- %k 100km区域ID(两个字母)
- %e 东西方向,到当前精度
- %n 南北方向,到当前精度
实例化Utm、Mgrs、LatLong或Square类始终需要某种形式的有效坐标。
参考资料
- http://www.luomus.fi/en/utm-mgrs-atlas-florae-europaeae
UTM/MGRS网格系统的描述 - http://www.earthpoint.us/convert.aspx
良好的测试转换网站 - http://en.wikipedia.org/wiki/Military_grid_reference_system
MGRS网格参考格式定义和示例 - http://therucksack.tripod.com/MiBSAR/LandNav/UTM/UTM.htm
关于UTM网格参考工作原理的精彩描述,包括极地地区。强调地图阅读者和用户如何使用该系统。