Updated MetaWriter (markdown)
parent
e2ea311bd1
commit
f8960878fa
1 changed files with 25 additions and 19 deletions
|
@ -2,11 +2,10 @@
|
||||||
<!-- Version: 25 -->
|
<!-- Version: 25 -->
|
||||||
<!-- Last-Modified: 2011/07/23 05:22:36 -->
|
<!-- Last-Modified: 2011/07/23 05:22:36 -->
|
||||||
<!-- Author: herm -->
|
<!-- Author: herm -->
|
||||||
|
|
||||||
# MetaWriter
|
# MetaWriter
|
||||||
|
|
||||||
[[subpage(DevFeature,false)]]
|
MetaWriters are a way of outputting vector features from Mapnik that exactly match the representations of rendered features. The idea is to allow for highly customizable output of specific features rendered into tiles that should also be made available as vectors to a web browser for interactivity. This support was added by Hermann Kraus (mail: herm @@@ scribus.info) in the GSOC project ["Hit Areas"](GSOC2010_Ideas).
|
||||||
|
|
||||||
MetaWriters are a way of outputting vector features from Mapnik that exactly match the representations of rendered features. The idea is to allow for highly customizable output of specific features rendered into tiles that should also be made available as vectors to a web browser for interactivity. This support was added by Hermann Kraus (mail: herm @@@ scribus.info) in the GSOC project "Hit Areas" http://trac.mapnik.org/wiki/GSOC2010/Ideas#Supportforoutputtinghit-areas.
|
|
||||||
|
|
||||||
A blog post on the idea is at: http://mapnik.org/news/2010/jul/06/gsoc2010_halfway/.
|
A blog post on the idea is at: http://mapnik.org/news/2010/jul/06/gsoc2010_halfway/.
|
||||||
|
|
||||||
|
@ -16,13 +15,13 @@ See also Herm's demo, which highlights both visible and invisible features: http
|
||||||
|
|
||||||
[[/images/metawriter_bbox_around_width_plus_stroke.png]]
|
[[/images/metawriter_bbox_around_width_plus_stroke.png]]
|
||||||
|
|
||||||
The above graphic highlights output (geojson) representing the clickable area of a MarkersSymbolizer rendered circle. This circle can change size dynamically depending on the width/height of the shape plus the thickness of the stroke and the bbox output by the MetaWriter will be intelligent to all rendering parameters.
|
The above graphic highlights output (geojson) representing the clickable area of a [[MarkersSymbolizer]] rendered circle. This circle can change size dynamically depending on the width/height of the shape plus the thickness of the stroke and the bbox output by the MetaWriter will be intelligent to all rendering parameters.
|
||||||
|
|
||||||
## MetaWriter Configuration
|
## MetaWriter Configuration
|
||||||
The configuration for a MetaWriter is done as a child element of the Map.
|
The configuration for a MetaWriter is done as a child element of the Map.
|
||||||
|
|
||||||
|
|
||||||
#!xml
|
```xml
|
||||||
<Map>
|
<Map>
|
||||||
|
|
||||||
<MetaWriter name="meta1" type="json" file="map_meta.json"/>
|
<MetaWriter name="meta1" type="json" file="map_meta.json"/>
|
||||||
|
@ -30,6 +29,7 @@ The configuration for a MetaWriter is done as a child element of the Map.
|
||||||
<!--..snip..-->
|
<!--..snip..-->
|
||||||
|
|
||||||
</Map>
|
</Map>
|
||||||
|
```
|
||||||
|
|
||||||
Parameters are:
|
Parameters are:
|
||||||
* `name` (required)
|
* `name` (required)
|
||||||
|
@ -49,6 +49,7 @@ Parameters are:
|
||||||
|
|
||||||
|
|
||||||
## Caveats
|
## Caveats
|
||||||
|
|
||||||
* If no features are encountered no json file is output (unless you pass the option `output-empty="true"`)
|
* If no features are encountered no json file is output (unless you pass the option `output-empty="true"`)
|
||||||
* output projection is currently hardcoded to WGS84/EPSG:4326
|
* output projection is currently hardcoded to WGS84/EPSG:4326
|
||||||
* precision for geometries is currently fixed at 8
|
* precision for geometries is currently fixed at 8
|
||||||
|
@ -58,34 +59,36 @@ Parameters are:
|
||||||
To actually trigger a metawriter to output features you need to attach one to a symbolizer.
|
To actually trigger a metawriter to output features you need to attach one to a symbolizer.
|
||||||
|
|
||||||
Parameters that symbolizers accept (the relate to metawriters) are:
|
Parameters that symbolizers accept (the relate to metawriters) are:
|
||||||
|
|
||||||
* `meta-writer` - the name of the MetaWriter to use
|
* `meta-writer` - the name of the MetaWriter to use
|
||||||
* `meta-output` - attributes to write out for this specific symbolizer
|
* `meta-output` - attributes to write out for this specific symbolizer
|
||||||
|
|
||||||
For example, this would output geojson features (bbox's as polygons) for every point rendered by the symbolizer:
|
For example, this would output geojson features (bbox's as polygons) for every point rendered by the symbolizer:
|
||||||
|
|
||||||
|
```xml
|
||||||
#!xml
|
|
||||||
<PointSymbolizer meta-writer="meta1"/>
|
<PointSymbolizer meta-writer="meta1"/>
|
||||||
|
```
|
||||||
|
|
||||||
Example feature output:
|
Example feature output:
|
||||||
|
|
||||||
#!py
|
```python
|
||||||
{ "type": "Feature",
|
{ "type": "Feature",
|
||||||
"geometry": { "type": "Polygon",
|
"geometry": { "type": "Polygon",
|
||||||
"coordinates": [ [ [11.07451289, 49.45187982], [11.07481352, 49.45187982], [11.07481352, 49.45218044], [11.07451289, 49.45218044] ] ]},
|
"coordinates": [ [ [11.07451289, 49.45187982], [11.07481352, 49.45187982], [11.07481352, 49.45218044], [11.07451289, 49.45218044] ] ]},
|
||||||
"properties": {
|
"properties": {
|
||||||
} },
|
} },
|
||||||
|
```
|
||||||
|
|
||||||
This would do the same but also dump out the values for the attributes of 'amenity' and 'name':
|
This would do the same but also dump out the values for the attributes of 'amenity' and 'name':
|
||||||
|
|
||||||
|
```xml
|
||||||
#!xml
|
|
||||||
<PointSymbolizer meta-writer="meta1" meta-output="amenity,name"/>
|
<PointSymbolizer meta-writer="meta1" meta-output="amenity,name"/>
|
||||||
|
```
|
||||||
|
|
||||||
Example feature output:
|
Example feature output:
|
||||||
|
|
||||||
|
|
||||||
#!py
|
```python
|
||||||
{ "type": "Feature",
|
{ "type": "Feature",
|
||||||
"geometry": { "type": "Polygon",
|
"geometry": { "type": "Polygon",
|
||||||
"coordinates": [ [ [11.07804522, 49.45285684], [11.07834585, 49.45285684], [11.07834585, 49.45315747], [11.07804522, 49.45315747] ] ]},
|
"coordinates": [ [ [11.07804522, 49.45285684], [11.07834585, 49.45285684], [11.07834585, 49.45315747], [11.07804522, 49.45315747] ] ]},
|
||||||
|
@ -93,18 +96,21 @@ Example feature output:
|
||||||
"amenity":"pharmacy",
|
"amenity":"pharmacy",
|
||||||
"name":"Spital Apotheke"
|
"name":"Spital Apotheke"
|
||||||
} },
|
} },
|
||||||
|
```
|
||||||
|
|
||||||
## Dynamically constructing metawriter file path
|
## Dynamically constructing metawriter file path
|
||||||
|
|
||||||
To dynamically contruct a file path for where to write out meta-features you can use variable replacement like:
|
To dynamically contruct a file path for where to write out meta-features you can use variable replacement like:
|
||||||
|
|
||||||
### in your xml
|
### in your xml
|
||||||
|
|
||||||
#!xml
|
```xml
|
||||||
<MetaWriter name="meta1" type="json" file="[tile_dir]/[z]/[x]/[y].json"/>
|
<MetaWriter name="meta1" type="json" file="[tile_dir]/[z]/[x]/[y].json"/>
|
||||||
|
```
|
||||||
|
|
||||||
### in your calling program
|
### in your calling program
|
||||||
|
|
||||||
#!py
|
```python
|
||||||
import os
|
import os
|
||||||
import mapnik2 as mapnik
|
import mapnik2 as mapnik
|
||||||
|
|
||||||
|
@ -121,11 +127,11 @@ To dynamically contruct a file path for where to write out meta-features you can
|
||||||
if not os.path.exists(dir_):
|
if not os.path.exists(dir_):
|
||||||
os.makedirs(dir_)
|
os.makedirs(dir_)
|
||||||
mapnik.render_to_file(m,'%s/%s/%s/%s.png' % (tile_dir,z,x,y))
|
mapnik.render_to_file(m,'%s/%s/%s/%s.png' % (tile_dir,z,x,y))
|
||||||
|
```
|
||||||
|
|
||||||
## Example XML (with PathExpresion)
|
## Example XML (with PathExpresion)
|
||||||
|
|
||||||
#!xml
|
```xml
|
||||||
<Map bgcolor="white" srs="+proj=latlong +datum=WGS84">
|
<Map bgcolor="white" srs="+proj=latlong +datum=WGS84">
|
||||||
|
|
||||||
<MetaWriter name="points" type="json" file="[tile_dir]/[z]/[x]/[y].json"/>
|
<MetaWriter name="points" type="json" file="[tile_dir]/[z]/[x]/[y].json"/>
|
||||||
|
@ -146,11 +152,11 @@ To dynamically contruct a file path for where to write out meta-features you can
|
||||||
</Layer>
|
</Layer>
|
||||||
|
|
||||||
</Map>
|
</Map>
|
||||||
|
```
|
||||||
|
|
||||||
## Example XML (without PathExpresion)
|
## Example XML (without PathExpresion)
|
||||||
|
|
||||||
#!xml
|
```xml
|
||||||
<Map bgcolor="white" srs="+proj=latlong +datum=WGS84">
|
<Map bgcolor="white" srs="+proj=latlong +datum=WGS84">
|
||||||
|
|
||||||
<MetaWriter name="points" type="json" file="points.json"/>
|
<MetaWriter name="points" type="json" file="points.json"/>
|
||||||
|
@ -181,4 +187,4 @@ To dynamically contruct a file path for where to write out meta-features you can
|
||||||
</Layer>
|
</Layer>
|
||||||
|
|
||||||
</Map>
|
</Map>
|
||||||
|
```
|
Loading…
Reference in a new issue