Python使用XML操作mapnik,实现复杂标注(Multi line text symbolizer)

test.py

import mapnik
stylesheet = 'world_style.xml'
image = 'world_style.png'
m = mapnik.Map(1200, 800)
mapnik.load_map(m, stylesheet)
m.zoom_all() 
mapnik.render_to_file(m, image)
print "rendered image to '%s'" % image

world_style.xml

<Map background-color="#c4dff6" srs="+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over" font-directory="./fonts" maximum-extent="-20037508.34,-20037508.34,20037508.34,20037508.34">

  <Style name="My Style">
    <Rule>
<!-- 复杂标注 -->
    <TextSymbolizer face-name="DejaVu Sans Bold" size="12" placement="point" dy="3" wrap-width="35" allow-overlap="0">
        [NAME]+'-'+[LEVEL]
        ++'&#10;'<Format face-name="DejaVu Sans Oblique" size="9">'-'</Format>
        +'&#10;'<Format face-name="DejaVu Sans Oblique" size="9">'('+[POSTAL]+')'+'-'+[LabelRank]</Format>
    </TextSymbolizer>

    </Rule>
  </Style>

  <Layer name="world" srs="+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs">
    <StyleName>My Style</StyleName>
    <Datasource>
      <Parameter name="type">shape</Parameter>
      <Parameter name="file">ne_110m_admin_0_countries.shp</Parameter>
    </Datasource>
  </Layer>
</Map>

效果图:
成果
参考:

http://blog.csdn.net/u010924834/article/details/56291059
http://mapnik.org/news/text_formating
https://github.com/mapnik/mapnik/issues/3158

转载于:https://www.cnblogs.com/TTonly/p/10349945.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值