最简单的方法实际上是使用KML文件。安装simplekml模块,然后运行数组以创建KML文件。import simplekml
kml = simplekml.Kml()
for i, coord in enumerate(coords):
# assuming coord is a lat, lon tuple
kml.newpoint(name="Point %s" % i, coords=[coord])
kml.save("GPS_tracking_data.kml")
现在您可以将其作为数据源加载到mapnik中并绘制出来import mapnik
# Setup the map
map_canvas = mapnik.Map(width_in_px, height_in_px)
map_canvas.background = mapnik.Color('rgb(0,0,0,0)') # transparent
# Create a symbolizer to draw the points
style = mapnik.Style()
rule = mapnik.Rule()
point_symbolizer = mapnik.MarkersSymbolizer()
point_symbolizer.allow_overlap = True
point_symbolizer.opacity = 0.5 # semi-transparent
rule.symbols.append(point_symbolizer)
style.rules.append(rule)
map_canvas.append_style('GPS_tracking_points', style)
# Create a layer to hold the ponts
layer = mapnik.Layer('GPS_tracking_points')
layer.datasource = mapnik.Ogr(file="GPS_tracking_data.kml", layer_by_index=0)
layer.styles.append('GPS_tracking_points')
map_canvas.layers.append(layer)
# Save the map
map_canvas.zoom_all()
mapnik.render_to_file(map_canvas, 'GPS_tracking_points.png', 'png')
那就差不多了。python+mapnik的文档有点弱,但是如果引用的话,您应该能够在此基础上构建