Add a test for Character placement within a string.
Currently the characters on bends end up on ugly angles.
This commit is contained in:
parent
d3ec70aff9
commit
d29c825299
8 changed files with 247 additions and 0 deletions
BIN
demo/data/test/charplacement.dbf
Normal file
BIN
demo/data/test/charplacement.dbf
Normal file
Binary file not shown.
BIN
demo/data/test/charplacement.shp
Normal file
BIN
demo/data/test/charplacement.shp
Normal file
Binary file not shown.
BIN
demo/data/test/charplacement.shx
Normal file
BIN
demo/data/test/charplacement.shx
Normal file
Binary file not shown.
25
demo/data/test/raw/charplacement.gfs
Normal file
25
demo/data/test/raw/charplacement.gfs
Normal file
|
@ -0,0 +1,25 @@
|
|||
<GMLFeatureClassList>
|
||||
<GMLFeatureClass>
|
||||
<Name>charplacement</Name>
|
||||
<ElementPath>charplacement</ElementPath>
|
||||
<DatasetSpecificInfo>
|
||||
<FeatureCount>1</FeatureCount>
|
||||
<ExtentXMin>1.00000</ExtentXMin>
|
||||
<ExtentXMax>2.00000</ExtentXMax>
|
||||
<ExtentYMin>1.00000</ExtentYMin>
|
||||
<ExtentYMax>5.00000</ExtentYMax>
|
||||
</DatasetSpecificInfo>
|
||||
<PropertyDefn>
|
||||
<Name>NAME</Name>
|
||||
<ElementPath>NAME</ElementPath>
|
||||
<Type>String</Type>
|
||||
<Width>0</Width>
|
||||
</PropertyDefn>
|
||||
<PropertyDefn>
|
||||
<Name>CLASS</Name>
|
||||
<ElementPath>CLASS</ElementPath>
|
||||
<Type>String</Type>
|
||||
<Width>0</Width>
|
||||
</PropertyDefn>
|
||||
</GMLFeatureClass>
|
||||
</GMLFeatureClassList>
|
99
demo/data/test/raw/charplacement.gml
Normal file
99
demo/data/test/raw/charplacement.gml
Normal file
|
@ -0,0 +1,99 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<ogr:FeatureCollection
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="charplacement.xsd"
|
||||
xmlns:ogr="http://ogr.maptools.org/"
|
||||
xmlns:gml="http://www.opengis.net/gml">
|
||||
<gml:boundedBy>
|
||||
<gml:Box>
|
||||
<gml:coord><gml:X>0</gml:X><gml:Y>0</gml:Y></gml:coord>
|
||||
<gml:coord><gml:X>13</gml:X><gml:Y>-13</gml:Y></gml:coord>
|
||||
</gml:Box>
|
||||
</gml:boundedBy>
|
||||
<gml:featureMember>
|
||||
|
||||
<ogr:charplacement fid="F0">
|
||||
<ogr:geometryProperty><gml:LineString><gml:coordinates>2,-1 1,-3 2,-5</gml:coordinates></gml:LineString></ogr:geometryProperty>
|
||||
<ogr:NAME>Road Name</ogr:NAME>
|
||||
<ogr:CLASS>TRIANGLE</ogr:CLASS>
|
||||
</ogr:charplacement>
|
||||
<ogr:charplacement fid="F1">
|
||||
<ogr:geometryProperty><gml:LineString><gml:coordinates>3,-1 4,-3 3,-5</gml:coordinates></gml:LineString></ogr:geometryProperty>
|
||||
<ogr:NAME>Road Name</ogr:NAME>
|
||||
<ogr:CLASS>TRIANGLE</ogr:CLASS>
|
||||
</ogr:charplacement>
|
||||
|
||||
<ogr:charplacement fid="F7">
|
||||
<ogr:geometryProperty><gml:LineString><gml:coordinates>
|
||||
1,-12 13,-12
|
||||
</gml:coordinates></gml:LineString></ogr:geometryProperty>
|
||||
<ogr:NAME>Road Name</ogr:NAME>
|
||||
<ogr:CLASS>STRAIGHT</ogr:CLASS>
|
||||
</ogr:charplacement>
|
||||
<ogr:charplacement fid="F8">
|
||||
<ogr:geometryProperty><gml:LineString><gml:coordinates>
|
||||
1,-13 2,-13 5,-13 10,-13 13,-13
|
||||
</gml:coordinates></gml:LineString></ogr:geometryProperty>
|
||||
<ogr:NAME>Road Name</ogr:NAME>
|
||||
<ogr:CLASS>STRAIGHT</ogr:CLASS>
|
||||
</ogr:charplacement>
|
||||
|
||||
<ogr:charplacement fid="F9">
|
||||
<ogr:geometryProperty><gml:LineString><gml:coordinates>6,-1 5,-3 5,-5</gml:coordinates></gml:LineString></ogr:geometryProperty>
|
||||
<ogr:NAME>Road Name</ogr:NAME>
|
||||
<ogr:CLASS>BEND</ogr:CLASS>
|
||||
</ogr:charplacement>
|
||||
<ogr:charplacement fid="F10">
|
||||
<ogr:geometryProperty><gml:LineString><gml:coordinates>7,-1 8,-3 8,-5</gml:coordinates></gml:LineString></ogr:geometryProperty>
|
||||
<ogr:NAME>Road Name</ogr:NAME>
|
||||
<ogr:CLASS>BEND</ogr:CLASS>
|
||||
</ogr:charplacement>
|
||||
<ogr:charplacement fid="F11">
|
||||
<ogr:geometryProperty><gml:LineString><gml:coordinates>5,-6 5,-8 6,-10</gml:coordinates></gml:LineString></ogr:geometryProperty>
|
||||
<ogr:NAME>Road Name</ogr:NAME>
|
||||
<ogr:CLASS>BEND</ogr:CLASS>
|
||||
</ogr:charplacement>
|
||||
<ogr:charplacement fid="F12">
|
||||
<ogr:geometryProperty><gml:LineString><gml:coordinates>8,-6 8,-8 7,-10</gml:coordinates></gml:LineString></ogr:geometryProperty>
|
||||
<ogr:NAME>Road Name</ogr:NAME>
|
||||
<ogr:CLASS>BEND</ogr:CLASS>
|
||||
</ogr:charplacement>
|
||||
|
||||
<ogr:charplacement fid="F13">
|
||||
<ogr:geometryProperty><gml:LineString><gml:coordinates>10.055915,-1.00031738281 10.6649858,-1.077712483 11.274056,-1.26950068 11.77921,-1.55298308 12.191993,-1.92815928 12.51529,-2.369132 12.746218,-2.8329032 12.884774,-3.2968745 12.930959,-3.875339</gml:coordinates></gml:LineString></ogr:geometryProperty>
|
||||
<ogr:NAME>Road Name</ogr:NAME>
|
||||
<ogr:CLASS>CURVE</ogr:CLASS>
|
||||
</ogr:charplacement>
|
||||
<ogr:charplacement fid="F14">
|
||||
<ogr:geometryProperty><gml:LineString><gml:coordinates>10.0555,-8.875339 10.6645708,-8.7979439 11.273641,-8.6061557 11.778795,-8.3226733 12.191578,-7.9474971 12.514875,-7.5065244 12.745803,-7.0427532 12.884359,-6.5787819 12.930544,-6.0003174</gml:coordinates></gml:LineString></ogr:geometryProperty>
|
||||
<ogr:NAME>Road Name</ogr:NAME>
|
||||
<ogr:CLASS>CURVE</ogr:CLASS>
|
||||
</ogr:charplacement>
|
||||
|
||||
<ogr:charplacement fid="F15">
|
||||
<ogr:geometryProperty><gml:LineString><gml:coordinates>
|
||||
9.055915,-2.00031738281 9.6649858,-2.077712483 10.274056,-2.26950068 10.77921,-2.55298308 11.191993,-2.92815928 11.51529,-3.369132 11.746218,-3.8329032 11.884774,-4.2968745 11.930959,-4.875339
|
||||
11.930544,-5.0003174 11.884359,-5.5787819 11.745803,-6.0427532 11.514875,-6.5065244 11.191578,-6.9474971 10.778795,-7.3226733 10.273641,-7.6061557 9.6645708,-7.7979439 9.0555,-7.875339
|
||||
</gml:coordinates></gml:LineString></ogr:geometryProperty>
|
||||
<ogr:NAME>Road Name</ogr:NAME>
|
||||
<ogr:CLASS>CURVE</ogr:CLASS>
|
||||
</ogr:charplacement>
|
||||
|
||||
<ogr:charplacement fid="F16">
|
||||
<ogr:geometryProperty><gml:LineString><gml:coordinates>
|
||||
9.0435048,-10.5550195 9.480786,-10.2191668 9.963148,-10.0731439 10.540222,-10.2495527 10.968444,-10.525815 11.419238,-10.8336443 12.01882,-10.9565825 12.559787,-10.7996079 12.956495,-10.4089966
|
||||
</gml:coordinates></gml:LineString></ogr:geometryProperty>
|
||||
<ogr:NAME>Road Name</ogr:NAME>
|
||||
<ogr:CLASS>SQUIGGLE</ogr:CLASS>
|
||||
</ogr:charplacement>
|
||||
|
||||
<ogr:charplacement fid="F16">
|
||||
<ogr:geometryProperty><gml:LineString><gml:coordinates>
|
||||
1,-9 1.4,-10 1.8,-9 2.2,-10 2.6,-9 3.0,-10 3.4,-9 3.8,-10 4.2,-9 4.6,-10
|
||||
</gml:coordinates></gml:LineString></ogr:geometryProperty>
|
||||
<ogr:NAME>Long ZigZag Road Name</ogr:NAME>
|
||||
<ogr:CLASS>ZIGZAG</ogr:CLASS>
|
||||
</ogr:charplacement>
|
||||
|
||||
</gml:featureMember>
|
||||
</ogr:FeatureCollection>
|
36
demo/data/test/raw/charplacement.xsd
Normal file
36
demo/data/test/raw/charplacement.xsd
Normal file
|
@ -0,0 +1,36 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<xs:schema targetNamespace="http://ogr.maptools.org/" xmlns:ogr="http://ogr.maptools.org/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:gml="http://www.opengis.net/gml" elementFormDefault="qualified" version="1.0">
|
||||
<xs:import namespace="http://www.opengis.net/gml" schemaLocation="http://schemas.opengeospatial.net/gml/2.1.2/feature.xsd"/><xs:element name="FeatureCollection" type="ogr:FeatureCollectionType" substitutionGroup="gml:_FeatureCollection"/>
|
||||
<xs:complexType name="FeatureCollectionType">
|
||||
<xs:complexContent>
|
||||
<xs:extension base="gml:AbstractFeatureCollectionType">
|
||||
<xs:attribute name="lockId" type="xs:string" use="optional"/>
|
||||
<xs:attribute name="scope" type="xs:string" use="optional"/>
|
||||
</xs:extension>
|
||||
</xs:complexContent>
|
||||
</xs:complexType>
|
||||
<xs:element name="charplacement" type="ogr:charplacement_Type" substitutionGroup="gml:_Feature"/>
|
||||
<xs:complexType name="charplacement_Type">
|
||||
<xs:complexContent>
|
||||
<xs:extension base="gml:AbstractFeatureType">
|
||||
<xs:sequence>
|
||||
<xs:element name="geometryProperty" type="gml:GeometryPropertyType" nillable="true" minOccurs="1" maxOccurs="1"/>
|
||||
<xs:element name="NAME" nillable="true" minOccurs="0" maxOccurs="1">
|
||||
<xs:simpleType>
|
||||
<xs:restriction base="xs:string">
|
||||
<xs:maxLength value="60"/>
|
||||
</xs:restriction>
|
||||
</xs:simpleType>
|
||||
</xs:element>
|
||||
<xs:element name="CLASS" nillable="true" minOccurs="0" maxOccurs="1">
|
||||
<xs:simpleType>
|
||||
<xs:restriction base="xs:string">
|
||||
<xs:maxLength value="60"/>
|
||||
</xs:restriction>
|
||||
</xs:simpleType>
|
||||
</xs:element>
|
||||
</xs:sequence>
|
||||
</xs:extension>
|
||||
</xs:complexContent>
|
||||
</xs:complexType>
|
||||
</xs:schema>
|
|
@ -13,3 +13,8 @@ rm -f displacement.shp displacement.shx displacement.dbf
|
|||
ogr2ogr -f "ESRI Shapefile" displacement raw/displacement.gml
|
||||
mv displacement/* ./
|
||||
rmdir displacement
|
||||
|
||||
rm -f charplacement.shp charplacement.shx charplacement.dbf
|
||||
ogr2ogr -f "ESRI Shapefile" charplacement raw/charplacement.gml
|
||||
mv charplacement/* ./
|
||||
rmdir charplacement
|
||||
|
|
82
demo/test/charplacement.py
Normal file
82
demo/test/charplacement.py
Normal file
|
@ -0,0 +1,82 @@
|
|||
# $Id: rundemo.py 577 2008-01-03 11:39:10Z artem $
|
||||
#
|
||||
# This file is part of Mapnik (c++ mapping toolkit)
|
||||
# Copyright (C) 2005 Jean-Francois Doyon
|
||||
#
|
||||
# Mapnik is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
# Import everything. In this case this is safe, in more complex systems, you
|
||||
# will want to be more selective.
|
||||
|
||||
try:
|
||||
from mapnik import *
|
||||
except:
|
||||
print '\n\nThe mapnik library and python bindings must have been compiled and \
|
||||
installed successfully before running this script.\n\n'
|
||||
raise
|
||||
|
||||
m = Map(690,690,"+proj=latlong +ellps=WGS84")
|
||||
|
||||
m.background = Color(255,100,100,255)
|
||||
|
||||
road_style = Style()
|
||||
|
||||
#Road
|
||||
road_rule = Rule()
|
||||
road_stroke = Stroke(Color('white'), 1)
|
||||
road_stroke.opacity = 0.7
|
||||
#road_rule.filter = Filter("[CLASS] = 'BENDUNDER' or [CLASS] = 'BENDOVER'")
|
||||
road_rule.symbols.append(LineSymbolizer(road_stroke))
|
||||
road_style.rules.append(road_rule);
|
||||
|
||||
#Road text
|
||||
text_symbolizer = TextSymbolizer('NAME', 'DejaVu Sans Book', 20, Color('black'))
|
||||
text_symbolizer.label_placement=label_placement.LINE_PLACEMENT
|
||||
text_symbolizer.minimum_distance = 0
|
||||
#text_symbolizer.max_char_angle_delta = 40
|
||||
#text_symbolizer.force_odd_labels = 1
|
||||
text_symbolizer.label_spacing = 20
|
||||
text_symbolizer.label_position_tolerance = 50
|
||||
text_symbolizer.minimum_distance = 5
|
||||
text_symbolizer.avoid_edges = 0
|
||||
text_symbolizer.halo_fill = Color('yellow')
|
||||
text_symbolizer.halo_radius = 1
|
||||
road_rule = Rule()
|
||||
#road_rule.filter = Filter("[CLASS] = 'BENDUNDER' or [CLASS] = 'BENDOVER'")
|
||||
road_rule.symbols.append(text_symbolizer)
|
||||
road_style.rules.append(road_rule)
|
||||
|
||||
|
||||
road_layer = Layer('road')
|
||||
road_layer.datasource = Shapefile(file='../data/test/charplacement')
|
||||
|
||||
m.append_style('road', road_style)
|
||||
road_layer.styles.append('road')
|
||||
m.layers.append(road_layer)
|
||||
|
||||
# Draw map
|
||||
|
||||
# Set the initial extent of the map.
|
||||
m.zoom_to_box(Envelope(0,0,14,-14))
|
||||
|
||||
|
||||
# Render
|
||||
im = Image(m.width,m.height)
|
||||
render(m, im)
|
||||
|
||||
# Save image to file
|
||||
save_to_file('output.png', 'png',im) # true-colour RGBA
|
||||
|
||||
print "Done\n"
|
Loading…
Reference in a new issue