PHP地图投影 [英] PHP Map projections

查看:107
本文介绍了PHP地图投影的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将自己Google搜索处死. 我正在尝试编写2个php函数,这些函数将在Mercator和平面非投影(网格)地图中从纬度和经度返回X和Y. 问题是我进行的每一次计算都假设您的地图在拐角处具有相同的纬度和经度,然后结果以米为单位.嗯

I have Googled myself to death.. I am attempting to write 2 php functions that will return X and Y from Lat and Long, in both Mercator and flat non-projected (grid) maps. Problem being every calculation I have ran across assumes your map(s) has the same lat and lon at the corners, and then the result is in meters. ugh

这是我所拥有的..不同大小,不同纬度,长4个角的地图. 我下载了Proj4 php端口,但是有了零文档和我需要的更多代码,我不堪重负...

Here is what I have .. maps of different sizes, different lat's, long's at the 4 corners. I downloaded the Proj4 php port, but with zero documentation and more code then I need, I was over whelmed ...

帮助!!

推荐答案

上一个答案中的比例方法不起作用.墨卡托投影非常非线性.

The proportional approach in the previous answer won't work. Mercator projections are quite non-linear.

这是我将生成的图像叠加到Google或Bing地图上的方式.就我而言,我正在创建将要覆盖的多边形的GD图像.在GD库中执行多边形比在地图提供者API中更快.

Here's how I overlay generated images onto a Google or Bing map. In my case, I'm creating a GD image of polygons that will be the overlay. It's much faster to do the polygons in the GD library than the map providers APIs.

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

First, set up scaling from a standard latitude longitude to a WGS84 projection. Degrees to mercator x-y coordinates in meters.

http://gisgeography.com/wgs84-world-geodetic-system/

//$ minlat =最小图像纬度

// $minlat = minimum image latitude

//$ minlon =最小图像经度

// $minlon = minimum image longitude

//$ maxlat =最大图像纬度

// $maxlat = maximum image latitude

//$ maxlon =最大图像经度

// $maxlon = maximum image longitude

//$ latbounds =图片高度(以像素为单位)

// $latbounds = Image height (in pixels)

//$ lonbounds =图片宽度(以像素为单位)

// $lonbounds = Image width (in pixels)

$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坐标.

Then for each latitude/longitude I want to calculate the actual X-Y coordinates on the image.

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

// $lon1 = the longitude of the point to be converted into image coordinates

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

// $lat1 = the latitude of the point to be converted into image coordates

X很简单

$x = (int) ((abs($lon1-$minlon)/$lonrange)*$lonbounds);

Y有点难,首先要计算到WGS84,然后再映射到图像.最后一步,因为显示顺序是颠倒的,所以要反转Y坐标.

Y is a bit harder, first calculating to WGS84, and then mapping to the image. Last step, inverting the Y coordinates since the display order is upside down.

$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​​库中的示例显示叠加层.

when the image file is complete, use GD to save the image and then use the example in the API library to display your overlay.

https://developers.google.com/maps/documentation/javascript/examples/overlay-simple

这篇关于PHP地图投影的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆