Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP地图投影_Php_Proj - Fatal编程技术网

PHP地图投影

PHP地图投影,php,proj,Php,Proj,我在谷歌上搜索到了自己的死亡。。 我正在尝试编写两个php函数,在墨卡托和平面非投影网格图中,从Lat和Long返回X和Y。 问题是,我遇到的每一个计算都假设你们的地图在角上有相同的纬度和经度,然后结果是以米为单位的。啊 这是我的。。不同尺寸的地图,不同的纬度,四个角的长线。 我下载了Proj4PHP端口,但是没有任何文档和我需要的更多代码,我已经厌倦了 救命 这假定您的横向/纵向坐标是十进制值,并且在地图的可见范围内不改变北/南或东/西方向。如果这样做,这些值应保持为单一格式,并设为负数,例如

我在谷歌上搜索到了自己的死亡。。 我正在尝试编写两个php函数,在墨卡托和平面非投影网格图中,从Lat和Long返回X和Y。 问题是,我遇到的每一个计算都假设你们的地图在角上有相同的纬度和经度,然后结果是以米为单位的。啊

这是我的。。不同尺寸的地图,不同的纬度,四个角的长线。 我下载了Proj4PHP端口,但是没有任何文档和我需要的更多代码,我已经厌倦了


救命

这假定您的横向/纵向坐标是十进制值,并且在地图的可见范围内不改变北/南或东/西方向。如果这样做,这些值应保持为单一格式,并设为负数,例如:1.0s将变为-1.0n

首先,您需要设置以下变量,或者使用PHP查找这些变量,或者如果您在脚本中已经知道它们:

$width=//width of image
$height=//height of image

$long_at_left=//Longitude of left-hand coordinates
$long_at_right=//Longitude of right-hand coordinates
$lat_at_left=//Latitude of left-hand coordinates
$lat_at_right=//Latitude of right-hand coordinates

$target_long=//Longitude you want to find
$target_lat=//Latitude you want to find
然后使用:

$xtarget=$target_long-$long_at_left;
$ytarget=$target_lat-$lat_at_top;

$xdist=$long_at_left-$long_at_right;
$ydist=$lat_at_top-$lat_at_bottom;

$x=round(($xtarget/$xdist)*$width); //Percentage of distance times width
$y=round(($ytarget/$ydist)*$height); //Percentage of distance times height

或者是那种形式的东西就可以了。

前面答案中的比例方法不起作用。墨卡托投影是非常非线性的

下面是我如何将生成的图像叠加到Google或Bing地图上的。在我的例子中,我正在创建一个多边形的GD图像,该图像将作为覆盖。在GD库中执行多边形比在map providers API中执行多边形要快得多

首先,设置从标准经纬度到WGS84投影的缩放。墨卡托x-y坐标的度数,单位为米

//$minlat=最小图像纬度

//$minlon=最小图像经度

//$maxlat=最大图像纬度

//$maxlon=最大图像经度

//$latbounds=以像素为单位的图像高度

$lonrange = abs($maxlon - $minlon);
$WGS84min = log(tan((90.+$minlat)*M_PI/360.))/(M_PI/180.);
$WGS84min = (int) ($WGS84min * 2037598.34/180);
$WGS84max = log(tan((90.+$maxlat)*M_PI/360.))/(M_PI/180.);
$WGS84max = (int) ($WGS84max * 2037598.34/180);
$WGS84diff = $WGS84max - $WGS84min;
$WGS84factor = $latbounds/$WGS84diff;
//$lonbounds=以像素为单位的图像宽度

$lonrange = abs($maxlon - $minlon);
$WGS84min = log(tan((90.+$minlat)*M_PI/360.))/(M_PI/180.);
$WGS84min = (int) ($WGS84min * 2037598.34/180);
$WGS84max = log(tan((90.+$maxlat)*M_PI/360.))/(M_PI/180.);
$WGS84max = (int) ($WGS84max * 2037598.34/180);
$WGS84diff = $WGS84max - $WGS84min;
$WGS84factor = $latbounds/$WGS84diff;
然后,对于每个纬度/经度,我要计算图像上的实际X-Y坐标

//$lon1=要转换为图像坐标的点的经度

//$lat1=要转换为图像坐标的点的纬度

X很容易

$x = (int) ((abs($lon1-$minlon)/$lonrange)*$lonbounds);
Y有点难,首先计算WGS84,然后映射到图像。最后一步,反转Y坐标,因为显示顺序是颠倒的

$y1 = log(tan((90.+$lat1)*M_PI/360.))/(M_PI/180.);
$y1 = $y1 * 2037598.34/180;
$y1 = (int) (($y1- $WGS84min)*$WGS84factor);
$y  = $latbounds - $y1;
图像文件完成后,使用GD保存图像,然后使用API库中的示例显示覆盖


只是想澄清一下——你有一张代表地图的图像,其中横向/纵向线条是完全垂直/水平的,你要么知道所有角落的横向/纵向,要么知道一个角落的横向/纵向,然后知道比例?你想取一个落在那个区域的lat/long,并将它转换成该图像的X-Y坐标吗?是的,lat/long是完美的水平/垂直,我在所有角落都有lat/long,需要为给定的lat/long点找到X-Y