Add test for text displacement.
This commit is contained in:
parent
76e18f8a4a
commit
02fe8ba276
8 changed files with 278 additions and 0 deletions
BIN
demo/data/test/displacement.dbf
Normal file
BIN
demo/data/test/displacement.dbf
Normal file
Binary file not shown.
BIN
demo/data/test/displacement.shp
Normal file
BIN
demo/data/test/displacement.shp
Normal file
Binary file not shown.
BIN
demo/data/test/displacement.shx
Normal file
BIN
demo/data/test/displacement.shx
Normal file
Binary file not shown.
25
demo/data/test/raw/displacement.gfs
Normal file
25
demo/data/test/raw/displacement.gfs
Normal file
|
@ -0,0 +1,25 @@
|
|||
<GMLFeatureClassList>
|
||||
<GMLFeatureClass>
|
||||
<Name>displacement</Name>
|
||||
<ElementPath>displacement</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>
|
129
demo/data/test/raw/displacement.gml
Normal file
129
demo/data/test/raw/displacement.gml
Normal file
|
@ -0,0 +1,129 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<ogr:FeatureCollection
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="displacement.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:displacement fid="F0">
|
||||
<ogr:geometryProperty><gml:LineString><gml:coordinates>1,-3 1,-2</gml:coordinates></gml:LineString></ogr:geometryProperty>
|
||||
<ogr:NAME>Road</ogr:NAME>
|
||||
<ogr:CLASS>CLOCKWISE</ogr:CLASS>
|
||||
</ogr:displacement>
|
||||
<ogr:displacement fid="F0">
|
||||
<ogr:geometryProperty><gml:LineString><gml:coordinates>1,-2 2,-1</gml:coordinates></gml:LineString></ogr:geometryProperty>
|
||||
<ogr:NAME>Road</ogr:NAME>
|
||||
<ogr:CLASS>CLOCKWISE</ogr:CLASS>
|
||||
</ogr:displacement>
|
||||
<ogr:displacement fid="F0">
|
||||
<ogr:geometryProperty><gml:LineString><gml:coordinates>2,-1 3,-1</gml:coordinates></gml:LineString></ogr:geometryProperty>
|
||||
<ogr:NAME>Road</ogr:NAME>
|
||||
<ogr:CLASS>CLOCKWISE</ogr:CLASS>
|
||||
</ogr:displacement>
|
||||
<ogr:displacement fid="F0">
|
||||
<ogr:geometryProperty><gml:LineString><gml:coordinates>3,-1 4,-2</gml:coordinates></gml:LineString></ogr:geometryProperty>
|
||||
<ogr:NAME>Road</ogr:NAME>
|
||||
<ogr:CLASS>CLOCKWISE</ogr:CLASS>
|
||||
</ogr:displacement>
|
||||
<ogr:displacement fid="F0">
|
||||
<ogr:geometryProperty><gml:LineString><gml:coordinates>4,-2 4,-3</gml:coordinates></gml:LineString></ogr:geometryProperty>
|
||||
<ogr:NAME>Road</ogr:NAME>
|
||||
<ogr:CLASS>CLOCKWISE</ogr:CLASS>
|
||||
</ogr:displacement>
|
||||
<ogr:displacement fid="F0">
|
||||
<ogr:geometryProperty><gml:LineString><gml:coordinates>4,-3 3,-4</gml:coordinates></gml:LineString></ogr:geometryProperty>
|
||||
<ogr:NAME>Road</ogr:NAME>
|
||||
<ogr:CLASS>CLOCKWISE</ogr:CLASS>
|
||||
</ogr:displacement>
|
||||
<ogr:displacement fid="F0">
|
||||
<ogr:geometryProperty><gml:LineString><gml:coordinates>3,-4 2,-4</gml:coordinates></gml:LineString></ogr:geometryProperty>
|
||||
<ogr:NAME>Road</ogr:NAME>
|
||||
<ogr:CLASS>CLOCKWISE</ogr:CLASS>
|
||||
</ogr:displacement>
|
||||
<ogr:displacement fid="F0">
|
||||
<ogr:geometryProperty><gml:LineString><gml:coordinates>2,-4 1,-3</gml:coordinates></gml:LineString></ogr:geometryProperty>
|
||||
<ogr:NAME>Road</ogr:NAME>
|
||||
<ogr:CLASS>CLOCKWISE</ogr:CLASS>
|
||||
</ogr:displacement>
|
||||
|
||||
<ogr:displacement fid="F0">
|
||||
<ogr:geometryProperty><gml:LineString><gml:coordinates>5,-3 6,-4</gml:coordinates></gml:LineString></ogr:geometryProperty>
|
||||
<ogr:NAME>Road</ogr:NAME>
|
||||
<ogr:CLASS>ANTICLOCKWISE</ogr:CLASS>
|
||||
</ogr:displacement>
|
||||
<ogr:displacement fid="F0">
|
||||
<ogr:geometryProperty><gml:LineString><gml:coordinates>6,-4 7,-4</gml:coordinates></gml:LineString></ogr:geometryProperty>
|
||||
<ogr:NAME>Road</ogr:NAME>
|
||||
<ogr:CLASS>ANTICLOCKWISE</ogr:CLASS>
|
||||
</ogr:displacement>
|
||||
<ogr:displacement fid="F0">
|
||||
<ogr:geometryProperty><gml:LineString><gml:coordinates>7,-4 8,-3</gml:coordinates></gml:LineString></ogr:geometryProperty>
|
||||
<ogr:NAME>Road</ogr:NAME>
|
||||
<ogr:CLASS>ANTICLOCKWISE</ogr:CLASS>
|
||||
</ogr:displacement>
|
||||
<ogr:displacement fid="F0">
|
||||
<ogr:geometryProperty><gml:LineString><gml:coordinates>8,-3 8,-2</gml:coordinates></gml:LineString></ogr:geometryProperty>
|
||||
<ogr:NAME>Road</ogr:NAME>
|
||||
<ogr:CLASS>ANTICLOCKWISE</ogr:CLASS>
|
||||
</ogr:displacement>
|
||||
<ogr:displacement fid="F0">
|
||||
<ogr:geometryProperty><gml:LineString><gml:coordinates>8,-2 7,-1</gml:coordinates></gml:LineString></ogr:geometryProperty>
|
||||
<ogr:NAME>Road</ogr:NAME>
|
||||
<ogr:CLASS>ANTICLOCKWISE</ogr:CLASS>
|
||||
</ogr:displacement>
|
||||
<ogr:displacement fid="F0">
|
||||
<ogr:geometryProperty><gml:LineString><gml:coordinates>7,-1 6,-1</gml:coordinates></gml:LineString></ogr:geometryProperty>
|
||||
<ogr:NAME>Road</ogr:NAME>
|
||||
<ogr:CLASS>ANTICLOCKWISE</ogr:CLASS>
|
||||
</ogr:displacement>
|
||||
<ogr:displacement fid="F0">
|
||||
<ogr:geometryProperty><gml:LineString><gml:coordinates>6,-1 5,-2</gml:coordinates></gml:LineString></ogr:geometryProperty>
|
||||
<ogr:NAME>Road</ogr:NAME>
|
||||
<ogr:CLASS>ANTICLOCKWISE</ogr:CLASS>
|
||||
</ogr:displacement>
|
||||
<ogr:displacement fid="F0">
|
||||
<ogr:geometryProperty><gml:LineString><gml:coordinates>5,-2 5,-3</gml:coordinates></gml:LineString></ogr:geometryProperty>
|
||||
<ogr:NAME>Road</ogr:NAME>
|
||||
<ogr:CLASS>ANTICLOCKWISE</ogr:CLASS>
|
||||
</ogr:displacement>
|
||||
|
||||
<ogr:displacement fid="F0">
|
||||
<ogr:geometryProperty><gml:LineString><gml:coordinates>
|
||||
1,-6.5 2,-5.5 3,-5 4,-5 5,-5.5 6,-6.5
|
||||
</gml:coordinates></gml:LineString></ogr:geometryProperty>
|
||||
<ogr:NAME>Long Road Name To Go Around The Whole Curve!</ogr:NAME>
|
||||
<ogr:CLASS>CURVE</ogr:CLASS>
|
||||
</ogr:displacement>
|
||||
|
||||
<ogr:displacement fid="F0">
|
||||
<ogr:geometryProperty><gml:LineString><gml:coordinates>
|
||||
1,-7 2,-8 3,-8.5 4,-8.5 5,-8 6,-7
|
||||
</gml:coordinates></gml:LineString></ogr:geometryProperty>
|
||||
<ogr:NAME>Long Road Name To Go Around The Whole Curve!</ogr:NAME>
|
||||
<ogr:CLASS>CURVE</ogr:CLASS>
|
||||
</ogr:displacement>
|
||||
|
||||
<ogr:displacement fid="F0">
|
||||
<ogr:geometryProperty><gml:LineString><gml:coordinates>
|
||||
3,-8.5 2,-9.5 1.5,-10.5 1.5,-11.5 2,-12.5 3,-13.5
|
||||
</gml:coordinates></gml:LineString></ogr:geometryProperty>
|
||||
<ogr:NAME>Long Road Name To Go Around The Whole Curve!</ogr:NAME>
|
||||
<ogr:CLASS>VERTCURVE</ogr:CLASS>
|
||||
</ogr:displacement>
|
||||
<ogr:displacement fid="F0">
|
||||
<ogr:geometryProperty><gml:LineString><gml:coordinates>
|
||||
4,-8.5 5,-9.5 5.5,-10.5 5.5,-11.5 5,-12.5 4,-13.5
|
||||
</gml:coordinates></gml:LineString></ogr:geometryProperty>
|
||||
<ogr:NAME>Long Road Name To Go Around The Whole Curve!</ogr:NAME>
|
||||
<ogr:CLASS>VERTCURVE</ogr:CLASS>
|
||||
</ogr:displacement>
|
||||
|
||||
</gml:featureMember>
|
||||
</ogr:FeatureCollection>
|
36
demo/data/test/raw/displacement.xsd
Normal file
36
demo/data/test/raw/displacement.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="displacement" type="ogr:displacement_Type" substitutionGroup="gml:_Feature"/>
|
||||
<xs:complexType name="displacement_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>
|
|
@ -8,3 +8,8 @@ rm -f overlap.shp overlap.shx overlap.dbf
|
|||
ogr2ogr -f "ESRI Shapefile" overlap raw/overlap.gml
|
||||
mv overlap/* ./
|
||||
rmdir overlap
|
||||
|
||||
rm -f displacement.shp displacement.shx displacement.dbf
|
||||
ogr2ogr -f "ESRI Shapefile" displacement raw/displacement.gml
|
||||
mv displacement/* ./
|
||||
rmdir displacement
|
||||
|
|
83
demo/test/displacement.py
Normal file
83
demo/test/displacement.py
Normal file
|
@ -0,0 +1,83 @@
|
|||
# $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.line_cap = line_cap.ROUND_CAP
|
||||
road_stroke.line_join = line_join.ROUND_JOIN
|
||||
#road_rule.filter = Filter("[CLASS] = 'CROSS'")
|
||||
road_rule.symbols.append(LineSymbolizer(road_stroke))
|
||||
road_style.rules.append(road_rule);
|
||||
|
||||
#Road text
|
||||
text_symbolizer = TextSymbolizer('NAME', 'DejaVu Sans Book', 10, 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
|
||||
#FIXME: Displacement cannot be set from python so we can't set it here, lol!
|
||||
text_symbolizer.label_spacing = 60
|
||||
text_symbolizer.label_position_tolerance = 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] = 'CROSS'")
|
||||
road_rule.symbols.append(text_symbolizer)
|
||||
road_style.rules.append(road_rule)
|
||||
|
||||
|
||||
road_layer = Layer('road')
|
||||
road_layer.datasource = Shapefile(file='../data/test/displacement')
|
||||
|
||||
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