2013-05-16 30 views
2

對不起,令人不安。 我不能使我的地圖,我不知道爲什麼......在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 !!!!

回答

3

問題是您正在應用LineSymbolizer指向數據。您需要將PointSymbolizerMarkersSymbolizer應用於點數據。

此外,Mapnik 2.1及以上版本支持直接從CSV文件中讀取,因此您不需要使用VRT和OGR插件,儘管兩者的工作方式都相似。

+0

不錯!很多! – Gabriel