PHP - 从边界数据生成世界地图

发布于 2024-08-14 11:12:31 字数 653 浏览 3 评论 0原文

我找到了所有国家/地区边界的形状数据和一个处理它的类,并且编写了一个脚本,将经度和纬度转换为图像上的像素位置,并使用 imagefilledpolygon 绘制国家/地区代码>和<代码>图像线。一切都很好,除了:

1)我有一个可以更改的 $scale 变量。当 $scale=1 时,图像大小为 360x180 像素(1 像素 = 1 度纬度/经度)。理想情况下,我想要的最终图像约为 $scale = 2 (720x360),但是 1 像素厚的边界线看起来很厚。所以我认为最好的解决方案是以 $scale=10 生成地图,然后调整生成图像的大小。问题是 imagecopyresized 在调整大小时不会进行抗锯齿,并且会留下一个锯齿状的图像,如何调整大小和抗锯齿?

2)生成一个国家的多边形的点数是很多的。该计划是使用相同的代码生成 HTML 图像地图,将国家/地区链接起来。然而,我担心目前图像映射有太多点(文件大小可能太大)。我最初的方法是跳过 x 个点,这会取得一些成功,如果我处理 10 个点中的 1 个,我基本上会得到可接受的结果。理想情况下我会更少......当我尝试四分之一时,我发现一些国家边界重叠,并且国家之间存在一些差距(但一些更繁忙的海岸线看起来更好)。在保持合理的准确性水平的同时减少点数的明智方法是什么?

如果有人感兴趣,我将发布代码(一旦完成)。

I have found the shape data for the borders of all the countries and a class to process it and I have written a script to convert the longitude and latitude to a pixel location on an image and to draw the countries using imagefilledpolygon and imageline. Everything is working great except:

1) I have a $scale variable that I can change. At $scale=1 the image is 360x180 pixel (1 pixel = 1 degree latitude/longitude). Ideally the final image I want would be about $scale = 2 (720x360) however the borderlines at 1 pixel thick look very thick. So I thought the best solution would be to generate the map at $scale=10 and then resize the generated image. The problem is imagecopyresized does not antialias when it resizes and it leaves me with a really jagged image, how can I resize and antialias?

2) The number of points to generate a polygon of a country is a LOT. The plan is to use the same code to produce an HTML imagemap to make the countries into links. However I fear at the moment there are too many points for an imagemap (the file size might be too big). My initial approach was to skip x amount of points, which lead to some success, If I process 1 in 10 points I get an acceptable result mostly. Ideally I would have even less... when I tried 1 in 40 I found some country borders overlapped and there were some gaps between countries (but some of the busier coastlines looked better). What is a sensible way to reduce the number of points whilst maintaining a reasonable level of accuracy?

If anyone is interested I'll post the code (once it's finished.)

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

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

发布评论

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

评论(4

夏见 2024-08-21 11:12:31

For the simplification/approximation of the curves take a look at https://en.wikipedia.org/wiki/Ramer-Douglas-Peucker_algorithm

沧笙踏歌 2024-08-21 11:12:31

所以我没有任何代码,它更多地只是解决第二个问题的想法。生成地图的类可以采用 x/y 坐标并确定您所在的国家/地区吗?

如果可以的话,您可以避免使用图像映射,而只需使用 javascript 来确定点击的 x/y 坐标。将其解析为一个位置并像平常一样对其进行操作。当然,这样做的缺点是,如果关闭 javascript,它将无法工作。

听起来不错。

So I don't have any code for this, its more of just an idea for your second problem. Can your classes that generate the map take an x/y coordinate and determine which country you are in?

If you can, than you could avoid using an image map and just use javascript to determine what the x/y coordinate of the click was. Resolve this into a location and act on it as you would normally. Downside of this of course is that if javascript is turned off it won't work.

Sounds neat though.

情绪少女 2024-08-21 11:12:31

解决了第一个问题:

imagecopyresampled 是我需要的函数,而不是 imagecopyresized

Solved the first one:

imagecopyresampled is the function I needed not imagecopyresized

南风几经秋 2024-08-21 11:12:31

对于问题的第二部分,您需要做的不是使用每 10 个点,而是仅使用那些向地图添加内容的点。您可以尝试仅使用距离最后渲染的点超过某个阈值距离的点。这意味着在较密集的区域,您使用的点较少,但当它们间隔开时,您可以根据需要使用尽可能多的点。

For the second part of your problem, what you need to do is not use every 10th point, but only use the ones that add something to the map. You could try only using a point if it is over some threshold distance from the last point rendered. That would mean in denser areas you use less points, but when they're spaced out you use as many as you need.

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