如何自动从Wikipedia创建灰度地图的ImageMap? [英] How to Automatically Create ImageMaps of Grey Maps from Wikipedia?

查看:77
本文介绍了如何自动从Wikipedia创建灰度地图的ImageMap?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用Wikipedia灰度图的各种成员的项目: http://en.wikipedia .org/wiki/Wikipedia:Blank_maps .我会根据用户通过选择形状或选中复选框所选择的国家,州或省来用颜色填充颜色.

I have a project using various members of Wikipedia's grey maps: http://en.wikipedia.org/wiki/Wikipedia:Blank_maps. I fill them in with colors depending on which countries, states or provinces a user selects by clicking on the shape or by checking a checkbox.

我想编写一个脚本,通过某种方式获取国家,州或省的边界的X和Y像素位置(尽管没有这些实体的名称)来自动创建每个国家,州或省的图像映射,稍后再填写.我已经手工制作了世界地图,并找到了一个开源的美国地图图像地图演示.现在,我想更快地创建地图.

I would like to write a script that creates imagemaps automatically of each country, state or province by somehow getting the X and Y pixel location of the borders of a country, state or province albeit without the names of these entities, which I will fill in later. I have already done the World map by hand and found a open source US map image map demo. I would now like to create my maps more rapidly.

我使用PHP和GD填充形状,因此我想也可以使用形状的一个中心像素位置.有什么建议?可以使用此脚本,但仍需手动操作: http://www.boutell.com/mapedit/也具有魔杖功能.效果很好,但我再次感到可以自动完成.

I use PHP and GD to floodfill the shapes, so I guess I could use one central pixel location of the shapes as well. Any suggestions? This script is a possibility but is still somewhat manual: http://abhinavsingh.com/blog/2009/03/using-image-maps-in-javascript-a-demo-application/. Also Mapedit, http://www.boutell.com/mapedit/, has a magic wand feature that works pretty well, but again I have a feeling this can be done automatically.

推荐答案

我看到我可以使用GD PHP的imagecolorat并遍历所有像素来查找黑色像素.这有效:

I see I can use GD PHP's imagecolorat and cycle through all the pixels to find those that are black. This works:

<?php
$im = ImageCreateFromPNG("india.png");
$width = imagesx($im);
$height = imagesy($im);
for ($cy=0;$cy<$height;$cy++) {
  echo '<p>';
  for ($cx=0;$cx<$width;$cx++) {
    $rgb = ImageColorAt($im, $cx, $cy);
    $col = imagecolorsforindex($im, $rgb); 
if ($col["red"] == 0 && $col["green"] == 0 && $col["blue"] ==0){
    echo $cx.", ".$cy." ";
  } else {echo "";}
}
}
?>

有人能建议如何在巨大的多面体中找到多边形,这是由于在印度的黑白2色地图上运行上述代码而产生的,其中所有边界均为黑色,各州和印度洋内部是白色的吗?

Can anybody suggest how to find the polygons in the huge multipolygon complex that results from running the above code on say a black and white 2 color map of India, where all the borders are black and the interior of the states and Indian Ocean is white??

这是印度的图片: http://wherehaveibeen.info/images/india.png,现在需要将图像地图的坐标弄得一团糟,需要将其拆分为单独的多边形: http://wherehaveibeen.info/images/black.php

Here is image of India: http://wherehaveibeen.info/images/india.png and the mess now of the coordinates for the imagemap that needs to be split up into separate polygons: http://wherehaveibeen.info/images/black.php

这篇关于如何自动从Wikipedia创建灰度地图的ImageMap?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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