我需要一些帮助来将纬度/经度对推断为方形网格。网格是 200x200 单元格。每个单元格为 1NM*1NM。起始纬度/经度对是网格的西南角。
例如,第 0 列和第 0 行应该是前四个坐标对,以构成 1NM*1NM 的第一个网格单元。第 0 列第 1 行应该是接下来的四个坐标对,以使下一个网格单元位于第一个网格单元之上。在 200 行之后,移动到下一列,依此类推。
我曾尝试使用以下 PHP 代码进行此操作,但似乎无法正确推断数据。
<?php
header('Content-Type:text/plain');
// southwest coordinate pair (starting point)
$lat = 38.883672;
$lon = -105.698848;
for($col = 0; $col < 200; $col++) {
$startLat = $startLat2 = 0;
$startLon = $startLon2 = 0;
if($col > 0) {
$lat = Extrapolate($lat, $lon, 1.0, 90)[0];
$lon = Extrapolate($lat, $lon, 1.0, 90)[1];
}
$debug = sprintf("%s,%s\r\n", $lat, $lon);
for($row = 0; $row < 200; $row++) {
if($row == 0) {
$startLat = Extrapolate($lat, $lon, 1.0, 360)[0];
$startLon = Extrapolate($lat, $lon, 1.0, 360)[1];
$startLat2 = Extrapolate($lat, $lon, 1.0, 90)[0];
$startLon2 = Extrapolate($lat, $lon, 1.0, 90)[1];
$nextLat = $startLat;
$nextLon = $startLon;
$nextLat2 = $startLat2;
$nextLon2 = $startLon2;
$debug .= sprintf("%s,%s\r\n", $startLat, $startLon);
$debug .= sprintf("%s,%s\r\n", $startLat2, $startLon2);
}
else {
$nextLat = Extrapolate($nextLat, $nextLon, 1.0, 360)[0];
$nextLon = Extrapolate($nextLat, $nextLon, 1.0, 360)[1];
$nextLat2 = Extrapolate($nextLat2, $nextLon2, 1.0, 90)[0];
$nextLon2 = Extrapolate($nextLat2, $nextLon2, 1.0, 90)[1];
$debug .= sprintf("%s,%s\r\n", $nextLat, $nextLon);
$debug .= sprintf("%s,%s\r\n", $nextLat2, $nextLon2);
}
}
echo $debug;
}
function Extrapolate($lat1,$long1,$d,$angle)
{
# Earth Radious in KM
$R = 6378.14;
# Degree to Radian
$latitude1 = $lat1 * (M_PI/180);
$longitude1 = $long1 * (M_PI/180);
$brng = $angle * (M_PI/180);
# Distance to NM
$d *= 1.85200;
$latitude2 = asin(sin($latitude1)*cos($d/$R) + cos($latitude1)*sin($d/$R)*cos($brng));
$longitude2 = $longitude1 + atan2(sin($brng)*sin($d/$R)*cos($latitude1),cos($d/$R)-sin($latitude1)*sin($latitude2));
# back to degrees
$latitude2 = $latitude2 * (180/M_PI);
$longitude2 = $longitude2 * (180/M_PI);
$lat2 = round ($latitude2,6);
$long2 = round ($longitude2,6);
// Push in array and get back
$coords[0] = $lat2;
$coords[1] = $long2;
return $coords;
}