gpt4 book ai didi

python - 在 Mapnik 中渲染我的 map

转载 作者:太空宇宙 更新时间:2023-11-04 01:27:47 51 4
gpt4 key购买 nike

抱歉打扰了。我无法渲染我的 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 应用于点数据。您需要将 PointSymbolizerMarkersSymbolizer 应用于点数据。

此外,Mapnik 2.1 及更高版本支持直接从 CSV 文件读取,因此您无需使用 VRT 和 OGR 插件,尽管两者的工作方式应该相似。

关于python - 在 Mapnik 中渲染我的 map ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16580497/

51 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com