PHP GD - 将图像扭曲为墨卡托投影视图

发布于 2024-10-28 19:16:18 字数 219 浏览 6 评论 0原文

我有一个根据数据库中的数据渲染的图像。 我需要使用墨卡托投影方法将此图像转换为扭曲图像,当我换行时带有它的 3D 球体看起来会很逼真。

有谁知道我需要使用什么公式来制作扭曲的图像?

我正在使用 PHP 和 GD。

谢谢。

i have an image that rendered from data i have on my DB.
i need to convert this image, with Mercator Projection method, to distorted image that when i'll wrap a 3d sphere with it it'll looks realistic.

do anyone know what are the formulas i need to use to make the distorted image?

i'm using PHP with GD.

thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

纸伞微斜 2024-11-04 19:16:18

如果您打算使用普通的图形技术将其包裹在球体周围,我认为您严格意义上不希望使用墨卡托投影,因为这在两极不起作用。

球体的普通 3D 纹理映射只是一个 2:1 纵横比位图,其中 X 轴直接映射到 [0, 360) 经度,Y 轴映射到 [-90 , +90] 纬度。

因此,只需从数据库中获取纬度/经度值,并将它们线性缩放到像素坐标,例如(假设 [0, 0] 位于左上角,[w, h] 是位图的大小):

x = (longitude + 180) * w
y = (90 - latitude) * h

编辑 - 我误读了问题,没有意识到您已经有图像。如果 AIUI 原始图像是墨卡托投影中的图像,那么您的问题只是撤消该图像垂直轴的非线性缩放。水平轴可以保持不变,因为墨卡托使用线性刻度来表示经度。

If you're planning to use normal graphics techniques to wrap this around a sphere I don't think you strictly want to use Mercator projection as that doesn't work at the poles.

The normal 3D texture mapping for spheres is simply a 2:1 aspect ratio bitmap, where the X axis maps directly to [0, 360) degrees of longitude and the Y axis to [-90, +90] degrees of latitude.

So just take your lat/long values from your database and scale them linearly to pixel coordinates, e.g. (assuming [0, 0] is at top left and [w, h] is the size of the bitmap):

x = (longitude + 180) * w
y = (90 - latitude) * h

EDIT - I misread the question and didn't realise you already have an image. If AIUI that original image is the one that's in Mercator projection, then your problem is simply to undo the non-linear scaling of that image's vertical axis. The horizontal axis can remain unchanged because Mercator uses a linear scale for longitude.

糖粟与秋泊 2024-11-04 19:16:18

如果您的图像经过地理参考,那么也许应该将其移至 https://gis.stackexchange.com/

您可以查看 GDAL(免费+开源地理空间数据抽象库)来进行这种重投影。有一个可用的 PHP 绑定,称为 PHP Mapscript。不过,我认为可用的文档很少。

为了使用 PHP 地图脚本,您还必须设置一个 UMN 地图服务器(作为网络服务器的 cgi 脚本运行)并让它进行重新投影。您需要做大量的工作来设置和配置它,然后将其发挥到极限以满足您的需求。

If your image is georefrenced, then maybe this should be moved to https://gis.stackexchange.com/.

YOu could look at GDAL, the free+opensource Geospatial Data Abstraction Library, for this kind of reprojection. There is a PHP binding available, called PHP mapscript. I think there is little documentation available, though.

In order to use PHP mapscript, you'd also have to also set up a UMN mapserver (running as a cgi script of a webserver) and let it do the reprojection. YOu need to do a lot of work to set up and configure it and then push it to its limits to fit your needs.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文