1

GeoDjango教程解释了如何将世界边界插入到空间数据库中。

我想用这些数据在 HTML 中创建一个世界地图,同时带有maparea标签。类似的东西

我只是不知道如何检索每个国家/地区的坐标(对于area'scoords属性是必需的)。

from world.models import WorldBorders

for country in WorldBorders.objects.all():
    print u'<area shape="poly" title="%s" alt="%s" coords="%s" />' % (v.name, v.name, "???")

谢谢 !

4

2 回答 2

0

要在 SVG 中使用纬度/经度,您需要将它们投影到像素 (x/y) 空间中。一个简单的转换可能如下所示:

>>> x = (lon + 180) / 360 * image_width
>>> y = (90 - lat) / 180 * image_height

对于 where 的图像image_width == 2 * image_height,这将为您提供类似于发布链接的地图(看起来像equirectangular projection)。

要使用不同的投影(例如Mercator),请在应用转换之前使用 GeoDjango 中的GEOSGeometry.transform方法。

于 2010-06-11T18:00:14.340 回答
0

In the worldborders example, the attribute mpoly is where the geographic polygon is actually stored.

In your example, you're going to want to access v.mpoly

You're not going to be able to use it directly however because mpoly is itself a MultiPolygon field. Consider a country like Canada that has a bunch of islands, each island and the main landmass is a polygon. So to arrive at your points and a complete description of Canada's borders you need to:

  1. Iterate over the polygons inside of multipolygon. Each polygon corresponds to an area (so your assumption in the example of one area per country is wrong).
  2. Iterate over the points inside of each polygon.
  3. Convert your point coordinates (latitude/longitude) into the coordinates used by your svg graphic.
于 2010-06-05T18:32:17.067 回答