Mapnik xml configuration

Resources

Official Help: Mapnik the Configuration XML

basis

Map Style object contains objects, Layer objects. Then Rule Style object contains objects, Layer objects specified Style object used by StyleName. Layer DataSource object contains object itself, to set the DataSource object layer data source.

<Map background-color="white" srs="+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +towgs84=446.448,-125.157,542.06,0.1502,0.247,0.8421,-20.4894 +units=m +no_defs">
  <Style name="TidalWater_FullColour">
    <Rule>
      <MinScaleDenominator>1000</MinScaleDenominator>
      <MaxScaleDenominator>25000</MaxScaleDenominator>
      <PolygonSymbolizer fill="#D5F4F8"/>
    </Rule>
  </Style>
  <Layer>
    <StyleName>TidalWater_FullColour</StyleName>
    <Datasource>
      <Parameter name="file">./OS-VectorMap-District/st/ST_TidalWater.shp</Parameter>
      <Parameter name="type">shape</Parameter>
    </Datasource>
  </Layer>
</Map>

mind Mapping

Here Insert Picture Description

XML Basic Configuration

Map Object

Mapnik XML configuration Master Objects

Attributes Explanation
background-color
map background color
# 000000 example, the opacity is controlled by the last two digits of the 8-bit value. # 00000000 represents a transparent background, the default value is # 000000FF.
background-image
map background image
May be used in Mapnik2, a picture may be used to set the background color, the color of the filling in place.
buffer-size
buffer size
font-directory
font directory
maximum-extent
the maximum display range
Setting (projection) of the maximum display range of the map, such as -20037508.34, -20037508.34, 20,037,508.34, 20,037,508.34
minimum-version
lowest version
The minimum version of the statement to be used in conjunction with style sheets mapnik
srs
coordinate system
Map rendering coordinate system, such as '+ proj = latlong + datum = WGS84', the reference coordinate system may epsg

Child nodes:

Child node name Explanation
<DataSource>
Data Source
<FileSource>
文件源
<FontSet>
字体集
为后备字体定义字体集(如果在第一个字体中找不到字符,则在列表中找到之前继续执行)
<Include>
用于包装通过XInclude包含的文件中的所有上下文的容器标记
<Layer>
图层
<Style>
样式

Style对象

包含许多Rule对象的集合。用来定义对象的渲染方式,一个Mapnik的配置文件可以有不限制数量的样式对象。Layer对象引用来Style对象来渲染地理数据。

属性 说明
filter-mode
过滤模式
默认是all,会应用所有的rule对象;还可以设置first,当一个Rule对象匹配成功后则停止。
name
名称
每个配置文件都需要是唯一的Style对象的名称。样式由Layer通过相应的StyleName参数引用
opacity
不透明度
样式级别不透明度:1表示完全不透明,而0表示完全透明,.5表示50%透明

子节点:

属性 说明
<Rule>
Rule对象
定义渲染的规则

Rule对象

可以指定特定缩放级别显示指定的符号。

属性 说明
name
名称
Rule对象的名称,可选参数
title
标题

子节点:

子节点名称 说明
<MinScaleDenominator>
最小比例尺
此规则适用的最小地图比例尺, [ScaleAndPpi scale] >= minScaleDenominator - 1e-6时可见
<MaxScaleDenominator>
最大比例尺
此规则使用的最大地图比例尺, [ScaleAndPpi scale] < MaxScaleDenominator + 1e-6时可见
<Filter>
属性过滤条件
支持比较运算符:大于&gt、大于等于&gt;=,小于&lt,小于等于&lt;=,等于=
支持逻辑运算符:andornot
支持正则匹配,.match
<ElseFilter/>
其他过滤条件
包含<ElseFilter /> 标签的Rule对象,.在当前Rule的匹配中,如果没有可以匹配到的(符合最大最小比例尺或过滤条件)规则,就会执行ElseFilter过滤条件。
<PointSymbolizer>
点符号
<LineSymbolizer>
线符号
<LinePatternSymbolizer>
线图案符号
<MarkersSymbolizer>
点符号
<ShieldSymbolizer>
盾牌符号
<PolygonSymbolizer>
面符号
<PolygonPatternSymbolizer>
面图案符号
<TextSymbolizer>
文本符号
<RasterSymbolizer>
栅格符号
<BuildingSymbolizer>
建筑符号
指定渲染多边形的伪3D效果,为它们提供类似建筑物的外观
<GroupSymbolizer>
组符号
指定多个道路防护罩或其他标签的渲染,组合后当成一个点对象对一个要素进行渲染。
<DebugSymbolizer>
调试符号

补充:
Here Insert Picture Description

Layer对象

图层对象通过设置StyleName来引用Style。

属性 说明
cache-features 默认为off,设置这个参数为on,当图层有多个样式附加到图层上市将会触发mapnik尝试缓存这些要素到内存中。(mapnik>2版本生效)
clear-label-cache Default “off”. Setting this to “on” clears the internal placement detector list, causing the items of this layer, and from this layer on, to be rendered without taking previous rendered items into account (‘clear collision avoidance list’)
minzoom 最小缩放级别,默认0.0
maxzoom 最大缩放级别,默认1.797693134862316e+308
name 图层的名称
srs 默认继承自Map.srs。引用Proj.4格式的坐标系,例如 +proj=latlong +datum=WGS84
status 状态,默认是on,on代表打开图层,off代表关闭图层。也可以是0和1
title 默认为""
queryable 默认 false

子节点:

子节点名称 说明
<Datasource> 要渲染的数据源
<StyleName> 定义的样式的名字,必须包含与Style.name属性完全相同的字符串。

DataSource对象

属性 说明
name 数据源模板的名称
base 指定继承的数据源模板
type 支持的类型有:
shape: ESRI shapefile
postgis: Postgis table or query
pgraster: Postgis table or query (containing or returning raster)
raster:Tiled or stripped TIFF
gdal: GDAL supported raster dataset (not build by default)
ogr:OGR supported vector datasource (not build by default)
osm: OpenStreetMap (not build by default)
estimate_extent boolean,告诉Mapnik估计图层的范围(true)或(false)
extent 如果estimate_extent设置为false,请手动输入范围。

base:

<Map>
  <Datasource name="shapes">
   <Paramaeter name="base">/home/foo/shapes</Parameter>
  </Datasource>
  <Layer name="lay">
    <Datasource base="shapes">
      <Parameter name="file">places</Parameter>
    </Datasource>
  </Layer>
</Map>

XML符号配置

PointSymbolizer(点符号)

使用png,tiff,svg图形符号来渲染点。可以使用ShiedSymbolizer将文本标签和图形符号组合起来。如果你想改变符号的offset(偏移量)请使用MarkerSymbolizer
Here Insert Picture Description

属性 说明
file
文件
图片路径
width
(removed)
默认4px
height
(removed)
默认4px
type
(removed)
png tiff svg 默认值none
allow-overlap
允许重叠
允许文本和点图片叠加,true/false,默认值false
opacity
不透明度
0.0 - 1.0
transform
转换
SVG transform
ignore-placement
允许后面的点/盾牌符号叠加此符号。默认值false
comp-op Compositing,默认值none

LineSymbolizer(线符号)

属性 说明
stroke 线的颜色,CSS颜色,比如‘green’#A3D979,默认值为black
stroke-width 线的宽度,单位是像素,默认是1.0
stroke-opacity 线不透明度,0代表完全透明,1代表不透明,.5代表50%透明
stroke-linejoin miter(尖角)、round(圆角)、bevel(斜角),默认值为miter
stroke-linecap round(向线条的每个末端添加圆形线帽)、butt(向线条的每个末端添加平直的边缘)、square(向线条的每个末端添加正方形线帽),默认值是butt
stroke-dasharray 一对长度值[a,b],其中(a)是短划线长度,(b)是间隙长度。也支持两个以上的值(例如,不是用笔划开始线,而是用间隙开始)。
comp-op Compositing
smooth 值在0.0-1.0之间。1表示完全平滑的线,0表示没有变化。默认是值0.0

LinePatternSymbolizer(线图案符号)

指定重复的png,tiff或svg符号的渲染以创建一条线,如下图所示的悬崖。
Here Insert Picture Description

属性 说明
file 图片文件的路径,默认为none,要求mapnik>=2.0
base base path where to search for file
width
(removed)
默认4px
height
(removed)
默认4px
type
(removed)
png tiff,默认none
comp-op Compositing

MarkersSymbolizer

指定将tiff,png或svg图像渲染为方向标记。可以用作PointSymbolizer的替代方案,以更好地控制图像的定位。
Here Insert Picture Description

属性 说明
allow-overlap 允许符号叠加其它符号,默认是false
spacing 点与点之间的间隔距离,默认是100pixel
max-error 标记可以从指定位置移动以避免碰撞的最大量。该值是“间隔”的一部分,例如spacing = 100,max_error = 0.2然后标记可以移动的最大值是20像素,如果这还不够,则根本不绘制
file 用于标记的SVG文件
transform SVG transform
opacity 不透明度,默认1.0
fill 点符号填充颜色,比如#FFFFFF,默认是blue
stroke 外边线颜色,CSS颜色 - 颜色值,例如“green”或#A3D979。默认值是black
stroke-width 外边线宽度
stroke-opacity 外边线不透明度
width 标记像素的宽度,默认10px
height 标记像素的高度,默认10px
placement “point”, “interior”(内部), “line”, “vertex-first” (mapnik >= 3), “vertex-last” (mapnik >= 3)。
默认值:line (mapnik <=2.0.x) point (mapnik >= 2.1)
ignore-placement “true” or “false”,默认false
marker-type “arrow”(箭头) “ellipse”(椭圆)
默认值:“arrow” if line placement, “ellipse” if point placement

ShieldSymbolizer(盾牌符号)

指定在某一点渲染png,tiff或svg图形符号和标签文本。
实际上,这是TextSymbolizer和PointSymbolizer的(工作)组合。如果您尝试分开使用TextSymbolizerPointSymbolizer,您将经常看到没有文本的点和/或没有点的文本。
Here Insert Picture Description
支持TextSymbolizer的所有配置选项,一下是额外的配置选项。

属性 说明
base 基本符号模板
file 用于盾牌背景的文件
opacity 用于盾牌的图像的不透明度,默认1
text-opacity 放置在盾牌顶部的文字的不透明度
unlock-image 如果为true,盾牌图像不会移动,默认为false
shield-dx 盾牌图像和文字的水平偏移量,默认为0
shield-dy 盾牌图像和文字的垂直偏移量,默认为0
transform Transform image

base
Add <FileSource name="foo">/home/bar/baz/</FileSource> to the beginning of your stylesheet and then use <ShieldSymbolizer base="foo" name="bridge" /> to refer to /home/bar/baz/bridge.
dx,dy
dx,dy仅用来移动文本,对shield无效。

属性 说明
shield-dx
shield-dy
Move shield only
dx,dy With unlock_image = true: move text only.
With unlock_image = false: move text and shield
unlock_image True: Shield base point is always the input line/point (usecase: labeling bus stations).
False: Shield base point is the center of the text (i.e. depends on dx,dy,vertical-alignment, horizontal-alignment) (usecase: highway shields)

placement
placement =“line”仅表示ShieldSymbolizer沿着一条线放置,而对于TextSymbolizer,它也会旋转文本。添加spacing参数以使ShieldSymbolizer沿线重复,否则placement =“line”placement =“point”将看起来相同

PolygonSymbolizer(面填充符号)

属性 说明
fill css颜色,默认是“grey”,填充颜​​色以指定多边形,默认为rgba(128,128,128,1),表示灰色且完全不透明(alpha = 1),与rgb(128,128,128)相同。
fill-opacity 多边形的不透明度(指定alpha的另一种方法)。可与rgba颜色组合使用,并将与颜色的现有alpha分量相乘
gamma 0.0-1.0之间,多边形边缘的抗锯齿级别 - 基本上是伽玛1(默认)意味着完全抗锯齿,而较小的伽玛降低了抗锯齿级别,导致更多锯齿状的多边形边缘。如果您希望背景颜色不“透过”,则可能需要降低伽马值。
comp-op Compositing

PolygonPatternSymbolizer(面图案填充符号)

渲染由多边形包围的区域,用重复的tiff,png或svg图像填充它。PolygonSymbolizer的替代方案。
Here Insert Picture Description

属性 说明
file 图片文件的路径,默认为none
width
(removed)
默认4px
height
(removed)
默认4px
type
(removed)
png tiff,默认none
comp-op Compositing

TextSymbolizer

RasterSymbolizer

BuildingSymbolizer

渲染多边形的伪3D效果,为它们提供类似建筑物的外观。
Here Insert Picture Description

属性 说明
fill css colour,默认gray
fill-opacity 填充不透明度,默认值为1.0
height float (static value or expression)
<BuildingSymbolizer fill="#000000" height="8" fill-opacity="1" /

Height表达式:

<BuildingSymbolizer fill="#000000" height="[height_db]" fill-opacity="1" />

GroupSymbolizer

DebugSymbolizer(略)

PostGIS配置

PostGIS配置优化

  1. Datasource那块的table参数使用查询而不是表名,不要将所有的列都查询出来
    这种方式会查询所有的列

    <Parameter name="table">planet_osm_point</Parameter>
    

    查询需要的列,减少查询列的数量

    (select way,place from planet_osm_point where place is not null) as foo
    
  2. 控制要遍历查询行的数量,可以设置过滤条件

     <Parameter name="table">(select * from planet_osm_point where place is not null) as foo</Parameter>
    

    如果你指向渲染rivers, canals, drains, and streams

    (SELECT * from planet_osm_line where waterway in ('river','canal','drain','stream')) as foo
    

    如果你指向渲染road tunnels

    (SELECT * from planet_osm_line where highway is not null and tunnel in ('yes','true','1')) as foo
    
  3. 将Filtering过滤条件移动到PostGIS的where语句中

  4. 简化过滤条件,优化SQL

  5. 创建索引
    创建索引可以使查询更快

     CREATE INDEX idx_buildings_the_geom ON buildings USING gist(the_geom);
    

    如果过滤或者排序指定的字段,可以堆这个字段配置索引

     CREATE INDEX idx_buildings_code ON buildings USING btree(code);
    
  6. Use asynchronous PostGIS datasource

  7. 一般的Postgresql保持数据库优化。
    你应该打开autovacuum。如果您有正在更新的数据源(例如OpenStreetMap数据),则需要定期对数据库进行ANALYZEREINDEX。您应该不时运行此SQL命令维护

    ANALYZE; REINDEX;
    

    根据您的需要,您可能还希望定期对数据进行CLUSTER

  8. 使用extent参数
    如果没有设置extent参数,mapnik执行查询的sql大概如下:

    SELECT ST_XMin(ext),ST_YMin(ext),ST_XMax(ext),ST_YMax(ext)
    FROM (SELECT ST_Extent(geom) as ext from planet_osm_line) as tmp
    

    这回导致每次查询都会去数据库中从整个结果中遍历查询。有三个参数可以避免整个问题:
    extent_from_subquery

    <Parameter name="extent_from_subquery">true</Parameter>
    

    优点:准确估计范围
    缺点:性能仅在小结果集上获得
    先决条件:

    • table参数使用子查询(而不是只是用一个表名)
    • extent参数没有设置
    • estimate_extent参数没有设置成false

    extent

    <Parameter name="extent">-20037508,-19929239,20037508,19929239</Parameter>
    

    优点:没有数据库开销
    缺点:

    • 如果源数据的更改影响范围,则需要更新XML
    • Less accurate - not because [I do not know - and cutting calculations related to it? ]

    Cover the following parameters:

    • extent_from_subquery
    • estimate_extent

    estimate_extent

    <Parameter name="estimate_extent">true</Parameter>
    

    Advantages: range than without setting any parameters faster; for large result sets significant
    drawbacks: For PostgreSQL> = 8.0.0 statistics from the VACUUM ANALYZEcollection, the result will be a range of 95% of the actual data
    to cover the following parameters: extent_from_subquery

Guess you like

Origin blog.csdn.net/yh0503/article/details/90765757