zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    selectHelper
    Windows Server 2003 下实现网络负载均衡(2) (转)
    顺序栈
    线性表链式存储
    线性表顺序存储
    Swift
    组件化
    swift
    Swift
    Swift
  • 原文地址:https://www.cnblogs.com/TTonly/p/10349945.html
Copyright © 2011-2022 走看看