ruby_mapnik 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +35 -0
- data/.gemtest +0 -0
- data/.yardopts +1 -0
- data/Gemfile +12 -0
- data/LICENSE +19 -0
- data/Manifest.txt +177 -0
- data/README.rdoc +84 -0
- data/Rakefile +43 -0
- data/demo/data/COPYRIGHT.txt +3 -0
- data/demo/data/TM_WORLD_BORDERS_SIMPL_0.3_MOD.dbf +0 -0
- data/demo/data/TM_WORLD_BORDERS_SIMPL_0.3_MOD.prj +1 -0
- data/demo/data/TM_WORLD_BORDERS_SIMPL_0.3_MOD.shp +0 -0
- data/demo/data/TM_WORLD_BORDERS_SIMPL_0.3_MOD.shx +0 -0
- data/demo/data/boundaries.dbf +0 -0
- data/demo/data/boundaries.prj +1 -0
- data/demo/data/boundaries.sbx +0 -0
- data/demo/data/boundaries.shp +0 -0
- data/demo/data/boundaries.shx +0 -0
- data/demo/data/boundaries_l.dbf +0 -0
- data/demo/data/boundaries_l.prj +1 -0
- data/demo/data/boundaries_l.sbx +0 -0
- data/demo/data/boundaries_l.shp +0 -0
- data/demo/data/boundaries_l.shx +0 -0
- data/demo/data/ontdrainage.dbf +0 -0
- data/demo/data/ontdrainage.prj +1 -0
- data/demo/data/ontdrainage.sbx +0 -0
- data/demo/data/ontdrainage.shp +0 -0
- data/demo/data/ontdrainage.shx +0 -0
- data/demo/data/popplaces.dbf +0 -0
- data/demo/data/popplaces.prj +1 -0
- data/demo/data/popplaces.sbx +0 -0
- data/demo/data/popplaces.shp +0 -0
- data/demo/data/popplaces.shx +0 -0
- data/demo/data/qcdrainage.dbf +0 -0
- data/demo/data/qcdrainage.prj +1 -0
- data/demo/data/qcdrainage.sbx +0 -0
- data/demo/data/qcdrainage.shp +0 -0
- data/demo/data/qcdrainage.shx +0 -0
- data/demo/data/roads.dbf +0 -0
- data/demo/data/roads.prj +1 -0
- data/demo/data/roads.sbx +0 -0
- data/demo/data/roads.shp +0 -0
- data/demo/data/roads.shx +0 -0
- data/demo/data/test/charplacement.dbf +0 -0
- data/demo/data/test/charplacement.shp +0 -0
- data/demo/data/test/charplacement.shx +0 -0
- data/demo/data/test/displacement.dbf +0 -0
- data/demo/data/test/displacement.shp +0 -0
- data/demo/data/test/displacement.shx +0 -0
- data/demo/data/test/overlap.dbf +0 -0
- data/demo/data/test/overlap.shp +0 -0
- data/demo/data/test/overlap.shx +0 -0
- data/demo/data/test/raw/charplacement.gfs +25 -0
- data/demo/data/test/raw/charplacement.gml +99 -0
- data/demo/data/test/raw/charplacement.xsd +36 -0
- data/demo/data/test/raw/displacement.gfs +25 -0
- data/demo/data/test/raw/displacement.gml +173 -0
- data/demo/data/test/raw/displacement.xsd +36 -0
- data/demo/data/test/raw/overlap.gfs +25 -0
- data/demo/data/test/raw/overlap.gml +127 -0
- data/demo/data/test/raw/overlap.xsd +36 -0
- data/demo/data/test/raw/textspacing.gfs +25 -0
- data/demo/data/test/raw/textspacing.gml +117 -0
- data/demo/data/test/raw/textspacing.xsd +36 -0
- data/demo/data/test/readme.txt +3 -0
- data/demo/data/test/regenerate.sh +20 -0
- data/demo/data/test/textspacing.dbf +0 -0
- data/demo/data/test/textspacing.shp +0 -0
- data/demo/data/test/textspacing.shx +0 -0
- data/demo/rundemo.rb +139 -0
- data/demo/sinatra/demo.rb +31 -0
- data/demo/sinatra/public/css/demo_map.css +7 -0
- data/demo/sinatra/public/index.html +13 -0
- data/demo/sinatra/public/javascripts/demo_map.js +42 -0
- data/ext/ruby_mapnik/_mapnik.cpp +54 -0
- data/ext/ruby_mapnik/_mapnik.h +69 -0
- data/ext/ruby_mapnik/_mapnik_color.rb.cpp +179 -0
- data/ext/ruby_mapnik/_mapnik_color.rb.h +32 -0
- data/ext/ruby_mapnik/_mapnik_coord.rb.cpp +145 -0
- data/ext/ruby_mapnik/_mapnik_coord.rb.h +32 -0
- data/ext/ruby_mapnik/_mapnik_datasource.rb.cpp +150 -0
- data/ext/ruby_mapnik/_mapnik_datasource.rb.h +32 -0
- data/ext/ruby_mapnik/_mapnik_datasource_cache.rb.cpp +79 -0
- data/ext/ruby_mapnik/_mapnik_datasource_cache.rb.h +32 -0
- data/ext/ruby_mapnik/_mapnik_envelope.rb.cpp +220 -0
- data/ext/ruby_mapnik/_mapnik_envelope.rb.h +32 -0
- data/ext/ruby_mapnik/_mapnik_expression.rb.cpp +91 -0
- data/ext/ruby_mapnik/_mapnik_expression.rb.h +32 -0
- data/ext/ruby_mapnik/_mapnik_feature.rb.cpp +56 -0
- data/ext/ruby_mapnik/_mapnik_feature.rb.h +32 -0
- data/ext/ruby_mapnik/_mapnik_font_engine.rb.cpp +71 -0
- data/ext/ruby_mapnik/_mapnik_font_engine.rb.h +32 -0
- data/ext/ruby_mapnik/_mapnik_geometry.rb.cpp +73 -0
- data/ext/ruby_mapnik/_mapnik_geometry.rb.h +32 -0
- data/ext/ruby_mapnik/_mapnik_glyph_symbolizer.rb.cpp +250 -0
- data/ext/ruby_mapnik/_mapnik_glyph_symbolizer.rb.h +32 -0
- data/ext/ruby_mapnik/_mapnik_layer.rb.cpp +237 -0
- data/ext/ruby_mapnik/_mapnik_layer.rb.h +32 -0
- data/ext/ruby_mapnik/_mapnik_line_pattern_symbolizer.rb.cpp +70 -0
- data/ext/ruby_mapnik/_mapnik_line_pattern_symbolizer.rb.h +32 -0
- data/ext/ruby_mapnik/_mapnik_line_symbolizer.rb.cpp +43 -0
- data/ext/ruby_mapnik/_mapnik_line_symbolizer.rb.h +32 -0
- data/ext/ruby_mapnik/_mapnik_map.rb.cpp +435 -0
- data/ext/ruby_mapnik/_mapnik_map.rb.h +32 -0
- data/ext/ruby_mapnik/_mapnik_markers_symbolizer.rb.cpp +139 -0
- data/ext/ruby_mapnik/_mapnik_markers_symbolizer.rb.h +32 -0
- data/ext/ruby_mapnik/_mapnik_point_symbolizer.rb.cpp +147 -0
- data/ext/ruby_mapnik/_mapnik_point_symbolizer.rb.h +32 -0
- data/ext/ruby_mapnik/_mapnik_polygon_pattern_symbolizer.rb.cpp +92 -0
- data/ext/ruby_mapnik/_mapnik_polygon_pattern_symbolizer.rb.h +32 -0
- data/ext/ruby_mapnik/_mapnik_polygon_symbolizer.rb.cpp +89 -0
- data/ext/ruby_mapnik/_mapnik_polygon_symbolizer.rb.h +32 -0
- data/ext/ruby_mapnik/_mapnik_projection.rb.cpp +98 -0
- data/ext/ruby_mapnik/_mapnik_projection.rb.h +32 -0
- data/ext/ruby_mapnik/_mapnik_raster_colorizer.rb.cpp +162 -0
- data/ext/ruby_mapnik/_mapnik_raster_colorizer.rb.h +32 -0
- data/ext/ruby_mapnik/_mapnik_raster_symbolizer.rb.cpp +53 -0
- data/ext/ruby_mapnik/_mapnik_raster_symbolizer.rb.h +32 -0
- data/ext/ruby_mapnik/_mapnik_rule.rb.cpp +99 -0
- data/ext/ruby_mapnik/_mapnik_rule.rb.h +32 -0
- data/ext/ruby_mapnik/_mapnik_shield_symbolizer.rb.cpp +86 -0
- data/ext/ruby_mapnik/_mapnik_shield_symbolizer.rb.h +32 -0
- data/ext/ruby_mapnik/_mapnik_stroke.rb.cpp +188 -0
- data/ext/ruby_mapnik/_mapnik_stroke.rb.h +32 -0
- data/ext/ruby_mapnik/_mapnik_style.rb.cpp +76 -0
- data/ext/ruby_mapnik/_mapnik_style.rb.h +32 -0
- data/ext/ruby_mapnik/_mapnik_symbolizer.rb.cpp +77 -0
- data/ext/ruby_mapnik/_mapnik_symbolizer.rb.h +32 -0
- data/ext/ruby_mapnik/_mapnik_text_symbolizer.rb.cpp +521 -0
- data/ext/ruby_mapnik/_mapnik_text_symbolizer.rb.h +32 -0
- data/ext/ruby_mapnik/extconf.rb +78 -0
- data/ext/ruby_mapnik/ruby_mapnik.cpp +31 -0
- data/lib/ruby_mapnik/mapnik/font_engine.rb +35 -0
- data/lib/ruby_mapnik/mapnik/layer.rb +69 -0
- data/lib/ruby_mapnik/mapnik/map.rb +144 -0
- data/lib/ruby_mapnik/mapnik/projection.rb +46 -0
- data/lib/ruby_mapnik/mapnik/raster_colorizer.rb +55 -0
- data/lib/ruby_mapnik/mapnik/rule.rb +107 -0
- data/lib/ruby_mapnik/mapnik/stroke.rb +58 -0
- data/lib/ruby_mapnik/mapnik/style.rb +66 -0
- data/lib/ruby_mapnik/mapnik/tile.rb +93 -0
- data/lib/ruby_mapnik.rb +48 -0
- data/script/console +2 -0
- data/test/data/TM_WORLD_BORDERS_SIMPL_0.3_MOD.dbf +0 -0
- data/test/data/TM_WORLD_BORDERS_SIMPL_0.3_MOD.prj +1 -0
- data/test/data/TM_WORLD_BORDERS_SIMPL_0.3_MOD.shp +0 -0
- data/test/data/TM_WORLD_BORDERS_SIMPL_0.3_MOD.shx +0 -0
- data/test/data/test_map.xml +15 -0
- data/test/test_helper.rb +27 -0
- data/test/test_line_pattern_symbolizer.rb +26 -0
- data/test/test_mapnik_color.rb +66 -0
- data/test/test_mapnik_coord.rb +112 -0
- data/test/test_mapnik_datasource.rb +49 -0
- data/test/test_mapnik_envelope.rb +232 -0
- data/test/test_mapnik_expression.rb +19 -0
- data/test/test_mapnik_feature.rb +33 -0
- data/test/test_mapnik_font_engine.rb +13 -0
- data/test/test_mapnik_geometry.rb +72 -0
- data/test/test_mapnik_glyph_symbolizer.rb +96 -0
- data/test/test_mapnik_layer.rb +137 -0
- data/test/test_mapnik_line_symbolizer.rb +25 -0
- data/test/test_mapnik_map.rb +191 -0
- data/test/test_mapnik_markers_symbolizer.rb +46 -0
- data/test/test_mapnik_point_symbolizer.rb +53 -0
- data/test/test_mapnik_polygon_symbolizer.rb +44 -0
- data/test/test_mapnik_projection.rb +46 -0
- data/test/test_mapnik_raster_colorizer.rb +56 -0
- data/test/test_mapnik_raster_symbolizer.rb +40 -0
- data/test/test_mapnik_rule.rb +63 -0
- data/test/test_mapnik_shield_symbolizer.rb +193 -0
- data/test/test_mapnik_stroke.rb +94 -0
- data/test/test_mapnik_style.rb +28 -0
- data/test/test_mapnik_symbolizer.rb +9 -0
- data/test/test_mapnik_text_symbolizer.rb +232 -0
- data/test/test_polygon_pattern_symbolizer.rb +34 -0
- data/test/test_ruby_mapnik.rb +34 -0
- data/yard/lib/yard/parser/generic_parser.rb +72 -0
- data/yard/lib/yard_generic.rb +18 -0
- metadata +322 -0
@@ -0,0 +1,96 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class TestMapnikGlyphSymbolizer < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
expression = Mapnik::Expression.parse("[g]")
|
7
|
+
@sym = Mapnik::GlyphSymbolizer.new("DejaVu Sans Book",expression)
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_presence
|
11
|
+
assert Mapnik::GlyphSymbolizer
|
12
|
+
assert Mapnik::AngleMode::AZIMUTH
|
13
|
+
assert Mapnik::AngleMode::TRIGONOMETRIC
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_should_get_and_set_face_name
|
17
|
+
assert_equal 'DejaVu Sans Book', @sym.face_name
|
18
|
+
new_face_name = 'DejaVu Sans'
|
19
|
+
@sym.face_name = new_face_name
|
20
|
+
assert_equal new_face_name, @sym.face_name
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_should_get_and_set_char
|
24
|
+
assert @sym.char.instance_of?(Mapnik::Expression)
|
25
|
+
@sym.char = Mapnik::Expression.parse("[t]")
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_should_get_and_set_allow_overlap
|
29
|
+
@sym.allow_overlap = true
|
30
|
+
assert @sym.allow_overlap?
|
31
|
+
@sym.allow_overlap = false
|
32
|
+
assert !@sym.allow_overlap?
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_should_get_and_set_avoid_edges
|
36
|
+
@sym.avoid_edges = true
|
37
|
+
assert @sym.avoid_edges?
|
38
|
+
@sym.avoid_edges = false
|
39
|
+
assert !@sym.avoid_edges?
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_should_get_and_set_displacement
|
43
|
+
assert @sym.displacement
|
44
|
+
new_vals = [1,2]
|
45
|
+
@sym.displacement = new_vals
|
46
|
+
assert_equal new_vals, @sym.displacement
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_should_get_and_set_halo_fill
|
50
|
+
assert @sym.halo_fill.instance_of?(Mapnik::Color)
|
51
|
+
white = Mapnik::Color.new("#fff")
|
52
|
+
@sym.halo_fill = white
|
53
|
+
assert_equal white, @sym.halo_fill
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_should_get_and_set_halo_radius
|
57
|
+
assert_equal 0, @sym.halo_radius
|
58
|
+
@sym.halo_radius = 1
|
59
|
+
assert_equal 1, @sym.halo_radius
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_should_get_and_set_size
|
63
|
+
@sym.size = Mapnik::Expression.parse("[12]")
|
64
|
+
assert @sym.size.instance_of?(Mapnik::Expression)
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_should_get_and_set_angle
|
68
|
+
@sym.angle = Mapnik::Expression.parse("[90]")
|
69
|
+
assert @sym.angle.instance_of?(Mapnik::Expression)
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_should_get_and_set_angle_mode
|
73
|
+
@sym.angle_mode = Mapnik::AngleMode::AZIMUTH
|
74
|
+
assert_equal Mapnik::AngleMode::AZIMUTH, @sym.angle_mode
|
75
|
+
@sym.angle_mode = Mapnik::AngleMode::TRIGONOMETRIC
|
76
|
+
assert_equal Mapnik::AngleMode::TRIGONOMETRIC, @sym.angle_mode
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_should_get_and_set_value
|
80
|
+
@sym.value = Mapnik::Expression.parse("[town]")
|
81
|
+
assert @sym.value.instance_of?(Mapnik::Expression)
|
82
|
+
end
|
83
|
+
|
84
|
+
# FIXME: Need Expression equality?
|
85
|
+
def test_should_get_and_set_color
|
86
|
+
@sym.color = Mapnik::Expression.parse("[90, 90, 90]")
|
87
|
+
assert @sym.angle.instance_of?(Mapnik::Expression)
|
88
|
+
end
|
89
|
+
|
90
|
+
# TODO: Colorizer support
|
91
|
+
# def test_should_get_and_set_colorizer
|
92
|
+
# colorizer = Mapnik::RasterColorizer.new
|
93
|
+
# @sym.colorizer = colorizer
|
94
|
+
# end
|
95
|
+
|
96
|
+
end
|
@@ -0,0 +1,137 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class TestMapnikLayer < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_presence
|
6
|
+
assert Mapnik::Layer
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_should_initialize
|
10
|
+
assert layer = Mapnik::Layer.new("My Layer", "+proj=latlong +datum=WGS84")
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_should_have_datasource
|
14
|
+
layer = build_layer
|
15
|
+
assert layer.datasource.envelope
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_should_have_same_enevelope_as_datasource
|
19
|
+
layer = build_layer
|
20
|
+
assert layer.envelope.kind_of?(Mapnik::Envelope)
|
21
|
+
assert_equal layer.envelope, layer.datasource.envelope
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_should_get_and_set_name
|
25
|
+
layer = build_layer
|
26
|
+
name_before = layer.name
|
27
|
+
new_name = name_before + "BUT DIFFERENT"
|
28
|
+
layer.name = new_name
|
29
|
+
assert_equal new_name, layer.name
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_should_get_and_set_title
|
33
|
+
layer = build_layer
|
34
|
+
title_before = layer.title
|
35
|
+
new_title = title_before + "BUT DIFFERENT"
|
36
|
+
layer.title = new_title
|
37
|
+
assert_equal new_title, layer.title
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_should_get_and_set_abstract
|
41
|
+
layer = build_layer
|
42
|
+
abstract_before = layer.abstract
|
43
|
+
new_abstract = abstract_before + "BUT DIFFERENT"
|
44
|
+
layer.abstract = new_abstract
|
45
|
+
assert_equal new_abstract, layer.abstract
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_should_get_and_set_srs
|
49
|
+
layer = build_layer
|
50
|
+
srs_before = layer.srs
|
51
|
+
new_srs = '+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs'
|
52
|
+
layer.srs = new_srs
|
53
|
+
assert_equal new_srs, layer.srs
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_should_get_and_set_min_zoom
|
57
|
+
layer = build_layer
|
58
|
+
min_zoom_before = layer.min_zoom
|
59
|
+
new_min_zoom = min_zoom_before + 1.2
|
60
|
+
layer.min_zoom = new_min_zoom
|
61
|
+
assert_equal new_min_zoom, layer.min_zoom
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_should_get_and_set_max_zoom
|
65
|
+
layer = build_layer
|
66
|
+
max_zoom_before = layer.max_zoom
|
67
|
+
new_max_zoom = max_zoom_before + 1.2
|
68
|
+
layer.max_zoom = new_max_zoom
|
69
|
+
assert_equal new_max_zoom, layer.max_zoom
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_should_know_if_it_is_visible_at_a_given_scale
|
73
|
+
layer = build_layer
|
74
|
+
layer.min_zoom = 0.0
|
75
|
+
assert layer.visible_at_scale?(1.0/1000000)
|
76
|
+
layer.min_zoom = 2.0
|
77
|
+
assert !layer.visible_at_scale?(1.0/1000000)
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_should_know_if_it_is_active
|
81
|
+
layer = build_layer
|
82
|
+
assert layer.active?
|
83
|
+
layer.active = false
|
84
|
+
assert !layer.active?
|
85
|
+
layer.active = true
|
86
|
+
assert layer.active?
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_should_know_if_it_is_queryable
|
90
|
+
layer = build_layer
|
91
|
+
assert !layer.queryable?
|
92
|
+
layer.queryable = true
|
93
|
+
assert layer.queryable?
|
94
|
+
layer.queryable = false
|
95
|
+
assert !layer.queryable?
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_should_know_if_it_should_cache_features
|
99
|
+
layer = build_layer
|
100
|
+
assert !layer.cache_features?
|
101
|
+
layer.cache_features = true
|
102
|
+
assert layer.cache_features?
|
103
|
+
layer.cache_features = false
|
104
|
+
assert !layer.cache_features?
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_should_know_if_it_should_clear_its_label_cache
|
108
|
+
layer = build_layer
|
109
|
+
assert !layer.clear_label_cache?
|
110
|
+
layer.clear_label_cache = true
|
111
|
+
assert layer.clear_label_cache?
|
112
|
+
layer.clear_label_cache = false
|
113
|
+
assert !layer.clear_label_cache?
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_should_have_styles
|
117
|
+
layer = build_layer
|
118
|
+
assert layer.styles.instance_of?(Mapnik::LayerStyleContainer)
|
119
|
+
assert layer.styles.empty?
|
120
|
+
style_name = 'My Style'
|
121
|
+
layer.styles << style_name
|
122
|
+
assert !layer.styles.empty?
|
123
|
+
assert_equal style_name, layer.styles.first
|
124
|
+
end
|
125
|
+
|
126
|
+
private
|
127
|
+
|
128
|
+
def build_layer
|
129
|
+
layer = Mapnik::Layer.new("My Layer", "+proj=latlong +datum=WGS84")
|
130
|
+
layer.datasource = Mapnik::Datasource.create(
|
131
|
+
:type => 'shape',
|
132
|
+
:file => SHAPEFILE
|
133
|
+
)
|
134
|
+
layer
|
135
|
+
end
|
136
|
+
|
137
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class TestMapnikLineSymbolizer < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_presence
|
6
|
+
assert Mapnik::LineSymbolizer
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_should_instantiate
|
10
|
+
assert Mapnik::LineSymbolizer.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_should_get_and_set_stroke
|
14
|
+
line = Mapnik::LineSymbolizer.new
|
15
|
+
stroke_before = line.stroke
|
16
|
+
assert stroke_before.kind_of?(Mapnik::Stroke)
|
17
|
+
|
18
|
+
new_stroke = Mapnik::Stroke.new(Mapnik::Color.new("#fff"), 1.0)
|
19
|
+
line.stroke = new_stroke
|
20
|
+
|
21
|
+
# Once Equality for strokes is established
|
22
|
+
# assert_equal new_stroke, line.stroke
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,191 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class TestMapnikMap < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@map = Mapnik::Map.new
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_should_initialize
|
10
|
+
assert @map
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_should_have_envelope
|
14
|
+
assert @map.envelope.kind_of?(Mapnik::Envelope)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_should_have_styles
|
18
|
+
assert @map.styles.instance_of?(Mapnik::MapStyleContainer)
|
19
|
+
assert @map.styles.empty?
|
20
|
+
|
21
|
+
key = "My Style"
|
22
|
+
@map.styles[key] = Mapnik::Style.new
|
23
|
+
assert @map.styles.any?
|
24
|
+
assert @map.styles[key].is_a?(Mapnik::Style)
|
25
|
+
|
26
|
+
@map.styles.delete(key)
|
27
|
+
assert @map.styles.empty?
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_should_have_buffered_envelope
|
31
|
+
envelope_before = @map.envelope
|
32
|
+
assert_equal 0, @map.buffer_size
|
33
|
+
buffered_envelope_before = @map.buffered_envelope
|
34
|
+
assert_equal envelope_before, buffered_envelope_before
|
35
|
+
|
36
|
+
@map.buffer_size = 1
|
37
|
+
|
38
|
+
assert_equal 1, @map.buffer_size
|
39
|
+
assert_equal envelope_before, @map.envelope
|
40
|
+
assert_not_equal buffered_envelope_before, @map.buffered_envelope
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_should_pan
|
44
|
+
center_before = @map.envelope.center
|
45
|
+
@map.pan(-1,-1)
|
46
|
+
assert_not_equal center_before, @map.envelope.center
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_should_get_and_set_background
|
50
|
+
assert @map.background.nil?
|
51
|
+
color = Mapnik::Color.new("#fff")
|
52
|
+
@map.background = color
|
53
|
+
assert_equal color, @map.background
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_should_zoom
|
57
|
+
scale_before = @map.scale
|
58
|
+
@map.zoom(2)
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_should_zoom_all
|
62
|
+
# Override since there are no layers
|
63
|
+
@map.maximum_extent = Mapnik::Envelope.new(-180,-90,180,90)
|
64
|
+
@map.zoom_all
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_should_resize
|
68
|
+
width_before = @map.width
|
69
|
+
height_before = @map.height
|
70
|
+
|
71
|
+
new_width = width_before + 1
|
72
|
+
new_height = height_before + 1
|
73
|
+
@map.resize(new_width, new_height)
|
74
|
+
assert_equal(new_width, @map.width)
|
75
|
+
assert_equal(new_height, @map.height)
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_should_have_scale
|
79
|
+
assert @map.scale.kind_of?(Float)
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_should_zoom_to_box
|
83
|
+
box = Mapnik::Envelope.new(1,1,1,1)
|
84
|
+
@map.zoom_to_box(box)
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_mapnik_base_path
|
88
|
+
assert @map.base_path.kind_of?(String)
|
89
|
+
assert_equal "", @map.base_path
|
90
|
+
new_base_path = "/some/path"
|
91
|
+
@map.base_path = new_base_path
|
92
|
+
assert_equal new_base_path, @map.base_path
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_should_get_and_set_buffer_size
|
96
|
+
assert_equal 0, @map.buffer_size
|
97
|
+
new_buffer_size = 1
|
98
|
+
@map.buffer_size = new_buffer_size
|
99
|
+
assert_equal new_buffer_size, @map.buffer_size
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_should_get_and_set_height
|
103
|
+
assert_equal 400, @map.height
|
104
|
+
new_height = 401
|
105
|
+
@map.height = new_height
|
106
|
+
assert_equal new_height, @map.height
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_should_get_and_set_maximum_extent
|
110
|
+
assert_nil @map.maximum_extent
|
111
|
+
new_max_extent = Mapnik::Envelope.new(-180,-90,180,90)
|
112
|
+
@map.maximum_extent = new_max_extent
|
113
|
+
assert_equal new_max_extent, @map.maximum_extent
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_should_get_and_set_srs
|
117
|
+
assert_equal "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs", @map.srs
|
118
|
+
new_srs = "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs +over"
|
119
|
+
@map.srs = new_srs
|
120
|
+
assert_equal new_srs, @map.srs
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_should_get_and_set_width
|
124
|
+
width_before = @map.width
|
125
|
+
new_width = width_before + 1
|
126
|
+
@map.width = new_width
|
127
|
+
assert_equal new_width, @map.width
|
128
|
+
end
|
129
|
+
|
130
|
+
def test_should_have_layers
|
131
|
+
assert @map.layers.empty?
|
132
|
+
layer = Mapnik::Layer.new("My Layer", "+proj=latlong +datum=WGS84")
|
133
|
+
@map.layers << layer
|
134
|
+
assert @map.layers.any?
|
135
|
+
|
136
|
+
@map.layers.clear
|
137
|
+
assert @map.layers.empty?
|
138
|
+
end
|
139
|
+
|
140
|
+
def test_should_output_to_xml
|
141
|
+
map = build_complete_map
|
142
|
+
assert map.to_xml.instance_of?(String)
|
143
|
+
assert map.to_xml.include?("<?xml")
|
144
|
+
end
|
145
|
+
|
146
|
+
def test_should_render_to_file
|
147
|
+
map = build_complete_map
|
148
|
+
filename = File.join(File.expand_path(File.dirname(__FILE__)), "../tmp/world.png")
|
149
|
+
assert_equal 0, File.size(filename) if File.exists?(filename)
|
150
|
+
map.render_to_file(filename)
|
151
|
+
File.delete(filename)
|
152
|
+
end
|
153
|
+
|
154
|
+
def test_should_load_from_xml_string
|
155
|
+
map_1 = build_complete_map
|
156
|
+
map_2 = Mapnik::Map.from_xml(map_1.to_xml)
|
157
|
+
assert_equal map_1.layers.count, map_2.layers.count
|
158
|
+
assert_equal map_1.srs, map_2.srs
|
159
|
+
end
|
160
|
+
|
161
|
+
def test_should_load_from_file
|
162
|
+
file_path = File.join(File.expand_path(File.dirname(__FILE__)), "data", "test_map.xml")
|
163
|
+
map = Mapnik::Map.from_file(file_path)
|
164
|
+
assert map.layers.any?
|
165
|
+
assert map.styles['My Style']
|
166
|
+
end
|
167
|
+
|
168
|
+
private
|
169
|
+
|
170
|
+
def build_complete_map
|
171
|
+
map = Mapnik::Map.new
|
172
|
+
map.width = 600
|
173
|
+
map.height = 300
|
174
|
+
map.srs = "+proj=latlong +datum=WGS84"
|
175
|
+
map.background = Mapnik::Color.new("#0000FF")
|
176
|
+
style = Mapnik::Style.new
|
177
|
+
rule = Mapnik::Rule.new
|
178
|
+
poly = Mapnik::PolygonSymbolizer.new
|
179
|
+
poly.fill = Mapnik::Color.new("#FF0088")
|
180
|
+
rule.symbols << poly
|
181
|
+
style.rules << rule
|
182
|
+
map.styles["My Style"]=style
|
183
|
+
layer = Mapnik::Layer.new('world',"+proj=latlong +datum=WGS84")
|
184
|
+
layer.datasource = Mapnik::Datasource.create(:type => "shape", :file => SHAPEFILE)
|
185
|
+
layer.styles << "My Style"
|
186
|
+
map.layers << layer
|
187
|
+
map.zoom_to_box(layer.envelope)
|
188
|
+
map
|
189
|
+
end
|
190
|
+
|
191
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class TestMarkersSymbolizer < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@filename = "/my/file.png"
|
7
|
+
path_expression = Mapnik::PathExpression.parse("/my/file.png")
|
8
|
+
@sym = Mapnik::MarkersSymbolizer.new(path_expression)
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_should_instantiate
|
12
|
+
assert @sym
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_should_get_and_set_filename
|
16
|
+
assert_equal @filename, @sym.filename
|
17
|
+
new_filename = "/something/else.png"
|
18
|
+
@sym.filename = new_filename
|
19
|
+
assert_equal new_filename, @sym.filename
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_should_get_and_set_allow_overlap
|
23
|
+
@sym.allow_overlap = true
|
24
|
+
assert @sym.allow_overlap?
|
25
|
+
@sym.allow_overlap = false
|
26
|
+
assert !@sym.allow_overlap?
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_should_get_and_set_spacing
|
30
|
+
@sym.spacing = 90
|
31
|
+
assert_equal 90, @sym.spacing
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_should_get_and_set_max_error
|
35
|
+
@sym.max_error = 90
|
36
|
+
assert_equal 90, @sym.max_error
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_should_get_and_set_opacity
|
40
|
+
assert_equal 1, @sym.opacity
|
41
|
+
# new_opacity = 0.5
|
42
|
+
# @sym.opacity = new_opacity
|
43
|
+
# assert_equal new_opacity, @sym.opacity
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class TestMapnikPointSymbolizer < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@sym = Mapnik::PointSymbolizer.new
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_presence
|
10
|
+
assert Mapnik::PointSymbolizer
|
11
|
+
assert Mapnik::PointPlacement::CENTROID
|
12
|
+
assert Mapnik::PointPlacement::INTERIOR
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_should_initialize
|
16
|
+
assert @sym
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_should_get_and_set_filename
|
20
|
+
assert_equal "", @sym.filename
|
21
|
+
new_filename = "/my/incredible/graphic.png"
|
22
|
+
@sym.filename = new_filename
|
23
|
+
assert_equal new_filename, @sym.filename
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_should_get_and_set_allows_overlap
|
27
|
+
assert !@sym.allows_overlap?
|
28
|
+
@sym.allows_overlap = true
|
29
|
+
assert @sym.allows_overlap?
|
30
|
+
@sym.allows_overlap = false
|
31
|
+
assert !@sym.allows_overlap?
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_should_get_and_set_opacity
|
35
|
+
assert_equal 1, @sym.opacity
|
36
|
+
new_opacity = 0.5
|
37
|
+
@sym.opacity = new_opacity
|
38
|
+
assert_equal new_opacity, @sym.opacity
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_should_get_and_set_ignore_placement
|
42
|
+
assert !@sym.ignores_placement?
|
43
|
+
@sym.ignores_placement = true
|
44
|
+
assert @sym.ignores_placement?
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_should_get_and_set_placement
|
48
|
+
assert_equal Mapnik::PointPlacement::CENTROID, @sym.placement
|
49
|
+
@sym.placement = Mapnik::PointPlacement::INTERIOR
|
50
|
+
assert_equal Mapnik::PointPlacement::INTERIOR, @sym.placement
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class TestMapnikPolygonSymbolizer < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_presence
|
6
|
+
assert Mapnik::PolygonSymbolizer
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_should_instantiate
|
10
|
+
assert Mapnik::PolygonSymbolizer.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_should_get_and_set_fill_to_a_color
|
14
|
+
polygon = Mapnik::PolygonSymbolizer.new
|
15
|
+
color_before = polygon.fill
|
16
|
+
assert color_before.kind_of?(Mapnik::Color)
|
17
|
+
|
18
|
+
new_color = Mapnik::Color.new("#000")
|
19
|
+
polygon.fill = new_color
|
20
|
+
|
21
|
+
assert [:red, :green, :blue, :alpha].all?{|x| polygon.fill.send(x) == new_color.send(x)}
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_should_get_and_set_opacity
|
25
|
+
polygon = Mapnik::PolygonSymbolizer.new
|
26
|
+
opacity_before = polygon.opacity
|
27
|
+
assert_equal 1, opacity_before
|
28
|
+
|
29
|
+
new_opacity = 0.5
|
30
|
+
polygon.opacity = new_opacity
|
31
|
+
assert_equal new_opacity, polygon.opacity
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_should_get_and_set_gamma
|
35
|
+
polygon = Mapnik::PolygonSymbolizer.new
|
36
|
+
gamma_before = polygon.gamma
|
37
|
+
assert_equal 1, gamma_before
|
38
|
+
|
39
|
+
new_gamma = 0.5
|
40
|
+
polygon.gamma = new_gamma
|
41
|
+
assert_equal new_gamma, polygon.gamma
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class TestMapnikProjection < Test::Unit::TestCase
|
4
|
+
|
5
|
+
PARAMS = '+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs'
|
6
|
+
|
7
|
+
def test_presence
|
8
|
+
assert Mapnik::Projection
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_should_instantiate_and_return_params
|
12
|
+
assert proj = Mapnik::Projection.new(PARAMS)
|
13
|
+
assert_equal PARAMS, proj.params
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_should_return_expanded_params
|
17
|
+
assert proj = Mapnik::Projection.new(PARAMS)
|
18
|
+
assert_not_equal PARAMS, proj.expanded_params
|
19
|
+
assert proj.expanded_params.include?(PARAMS)
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_should_respond_to_geographic
|
23
|
+
assert Mapnik::Projection.new(PARAMS).geographic?
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_should_inverse_points
|
27
|
+
proj = Mapnik::Projection.new(PARAMS)
|
28
|
+
assert proj.inverse(Mapnik::Coord2d.new(2,3))
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_should_inverse_envelopes
|
32
|
+
proj = Mapnik::Projection.new(PARAMS)
|
33
|
+
assert proj.inverse(Mapnik::Envelope.new(2,3,4,5))
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_should_forward_points
|
37
|
+
proj = Mapnik::Projection.new(PARAMS)
|
38
|
+
assert proj.forward(Mapnik::Coord2d.new(2,3))
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_should_forward_envelopes
|
42
|
+
proj = Mapnik::Projection.new(PARAMS)
|
43
|
+
assert proj.forward(Mapnik::Envelope.new(2,3,4,5))
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class TestMapnikRasterColorizer < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@colorizer = Mapnik::RasterColorizer.new
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_presence
|
10
|
+
assert Mapnik::RasterColorizer
|
11
|
+
["INHERIT","LINEAR","DISCRETE","EXACT"].each do |colorizer_mode|
|
12
|
+
assert Mapnik::ColorizerMode.const_get(colorizer_mode)
|
13
|
+
end
|
14
|
+
assert Mapnik::ColorizerStop
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_should_get_and_set_default_color
|
18
|
+
color = Mapnik::Color.new("#fff")
|
19
|
+
@colorizer.default_color = color
|
20
|
+
assert_equal 255, @colorizer.default_color.red
|
21
|
+
assert_equal 255, @colorizer.default_color.green
|
22
|
+
assert_equal 255, @colorizer.default_color.blue
|
23
|
+
assert_equal 255, @colorizer.default_color.alpha
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_should_get_and_set_default_mode
|
27
|
+
["LINEAR", "DISCRETE","EXACT"].each do |mode_name|
|
28
|
+
const = Mapnik::ColorizerMode.const_get(mode_name)
|
29
|
+
@colorizer.default_mode = const
|
30
|
+
assert_equal const, @colorizer.default_mode
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_should_get_and_set_epsilon
|
35
|
+
@colorizer.epsilon = 5
|
36
|
+
assert_equal 5, @colorizer.epsilon
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_should_instantiate_a_stop
|
40
|
+
value = 45.5
|
41
|
+
mode = Mapnik::ColorizerMode::EXACT
|
42
|
+
color = Mapnik::Color.new("#fff")
|
43
|
+
assert stop = Mapnik::ColorizerStop.new(value,mode,color)
|
44
|
+
assert_equal value, stop.value
|
45
|
+
assert_equal mode, stop.mode
|
46
|
+
assert_equal color, stop.color
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_should_get_and_add_stops
|
50
|
+
assert @colorizer.stops.empty?
|
51
|
+
stop = Mapnik::ColorizerStop.new(45.45, Mapnik::ColorizerMode::EXACT, Mapnik::Color.new("#fff"))
|
52
|
+
@colorizer.stops << stop
|
53
|
+
assert_equal @colorizer.stops.first, stop
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|