在Mapnik中渲染我的地图

时间:2013-05-16 06:33:29

标签: python xml mapnik

抱歉令人不安。 我无法渲染我的地图,我不知道为什么......

我使用ogr读取了一个csv文件,该文件使用我创建的.vrt文件,与csv相关联:

然后,我有一个简单的代码来渲染我的地图,但我无法工作:创建了一个空白背景的地图,没有任何内容......

我收到警告,但我认为这是正常的:

Warning 1: The 'LON' and/or 'LAT' fields of the source layer are not declared as numeric fields,
so the spatial filter cannot be turned into an attribute filter on them

你有什么想法吗?

谢谢!

我的 .csv (称为 ZZZ.csv ),只是开头和有趣的字段:

RecordID,VehId,DateTime,LAT,LON
0,2232,2012-04-07 18:54:39,32.801926,-116.871742
0,2232,2012-04-07 18:54:40,32.801888,-116.871727
0,2232,2012-04-07 18:54:41,32.801849,-116.871704

我的 .vrt

<OGRVRTDataSource>
<OGRVRTLayer name="ZZZ">
    <SrcDataSource>ZZZ.csv</SrcDataSource>
    <GeometryType>wkbPoint</GeometryType>
    <LayerSRS>WGS84</LayerSRS>
    <GeometryField encoding="PointFromColumns" x="LON" y="LAT"/>
</OGRVRTLayer>
</OGRVRTDataSource>

我的python模块渲染卡片: “”module mapniktest“”“

import mapnik
#Defining the envelope
MIN_LAT = 30
MAX_LAT = +35
MIN_LON = -120
MAX_LON =-110
MAP_WIDTH = 1000
MAP_HEIGHT = 500

#defining the datasource: the .vrt above
datasource = mapnik.Ogr(file="ZZZ.vrt",layer = "ZZZ")

#Creating layer, rules and styles
layer = mapnik.Layer("ZZZ")
layer.datasource = datasource
layer.styles.append("LineStyle")
stroke = mapnik.Stroke()
stroke.color = mapnik.Color("#008000")
stroke.add_dash(50, 100)
symbol = mapnik.LineSymbolizer(stroke)

rule = mapnik.Rule()
rule.symbols.append(symbol)
style = mapnik.Style()
style.rules.append(rule)
print style

#creating the map
map = mapnik.Map(MAP_WIDTH, MAP_HEIGHT, "+proj=longlat +datum=WGS84")
map.append_style("LineStyle", style)
map.background = mapnik.Color("#8080a0")
map.layers.append(layer)

#displaying the map
map.zoom_to_box(mapnik.Envelope(MIN_LON, MIN_LAT, MAX_LON, MAX_LAT))
mapnik.render_to_file(map, "map.png")

THKS !!!!

1 个答案:

答案 0 :(得分:3)

问题在于您正在应用LineSymbolizer来指向数据。您需要应用PointSymbolizerMarkersSymbolizer来指向数据。

Mapnik 2.1及更高版本也支持直接从CSV文件中读取,因此您不需要使用VRT和OGR插件,尽管两者都应该类似。