抱歉打扰了。 我无法渲染我的 map ,我不知道为什么...
我使用 ogr 读取了一个 csv 文件,它使用了我创建的与 csv 关联的 .vrt 文件:
然后,我有一个简单的代码来渲染我的 map ,但我无法正常工作:创建了一张背景为空的 map ,上面什么都没有...
我收到警告,但我认为这是正常的:
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 模块: """模块 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")
谢谢!!!!
请您参考如下方法:
问题是您正在将 LineSymbolizer 应用于点数据。您需要将 PointSymbolizer 或 MarkersSymbolizer 应用于点数据。
此外,Mapnik 2.1 及更高版本支持直接从 CSV 文件读取,因此您无需使用 VRT 和 OGR 插件,尽管两者的工作方式应该相似。
