ruby_mapnik 0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (179) hide show
  1. data/.autotest +35 -0
  2. data/.gemtest +0 -0
  3. data/.yardopts +1 -0
  4. data/Gemfile +12 -0
  5. data/LICENSE +19 -0
  6. data/Manifest.txt +177 -0
  7. data/README.rdoc +84 -0
  8. data/Rakefile +43 -0
  9. data/demo/data/COPYRIGHT.txt +3 -0
  10. data/demo/data/TM_WORLD_BORDERS_SIMPL_0.3_MOD.dbf +0 -0
  11. data/demo/data/TM_WORLD_BORDERS_SIMPL_0.3_MOD.prj +1 -0
  12. data/demo/data/TM_WORLD_BORDERS_SIMPL_0.3_MOD.shp +0 -0
  13. data/demo/data/TM_WORLD_BORDERS_SIMPL_0.3_MOD.shx +0 -0
  14. data/demo/data/boundaries.dbf +0 -0
  15. data/demo/data/boundaries.prj +1 -0
  16. data/demo/data/boundaries.sbx +0 -0
  17. data/demo/data/boundaries.shp +0 -0
  18. data/demo/data/boundaries.shx +0 -0
  19. data/demo/data/boundaries_l.dbf +0 -0
  20. data/demo/data/boundaries_l.prj +1 -0
  21. data/demo/data/boundaries_l.sbx +0 -0
  22. data/demo/data/boundaries_l.shp +0 -0
  23. data/demo/data/boundaries_l.shx +0 -0
  24. data/demo/data/ontdrainage.dbf +0 -0
  25. data/demo/data/ontdrainage.prj +1 -0
  26. data/demo/data/ontdrainage.sbx +0 -0
  27. data/demo/data/ontdrainage.shp +0 -0
  28. data/demo/data/ontdrainage.shx +0 -0
  29. data/demo/data/popplaces.dbf +0 -0
  30. data/demo/data/popplaces.prj +1 -0
  31. data/demo/data/popplaces.sbx +0 -0
  32. data/demo/data/popplaces.shp +0 -0
  33. data/demo/data/popplaces.shx +0 -0
  34. data/demo/data/qcdrainage.dbf +0 -0
  35. data/demo/data/qcdrainage.prj +1 -0
  36. data/demo/data/qcdrainage.sbx +0 -0
  37. data/demo/data/qcdrainage.shp +0 -0
  38. data/demo/data/qcdrainage.shx +0 -0
  39. data/demo/data/roads.dbf +0 -0
  40. data/demo/data/roads.prj +1 -0
  41. data/demo/data/roads.sbx +0 -0
  42. data/demo/data/roads.shp +0 -0
  43. data/demo/data/roads.shx +0 -0
  44. data/demo/data/test/charplacement.dbf +0 -0
  45. data/demo/data/test/charplacement.shp +0 -0
  46. data/demo/data/test/charplacement.shx +0 -0
  47. data/demo/data/test/displacement.dbf +0 -0
  48. data/demo/data/test/displacement.shp +0 -0
  49. data/demo/data/test/displacement.shx +0 -0
  50. data/demo/data/test/overlap.dbf +0 -0
  51. data/demo/data/test/overlap.shp +0 -0
  52. data/demo/data/test/overlap.shx +0 -0
  53. data/demo/data/test/raw/charplacement.gfs +25 -0
  54. data/demo/data/test/raw/charplacement.gml +99 -0
  55. data/demo/data/test/raw/charplacement.xsd +36 -0
  56. data/demo/data/test/raw/displacement.gfs +25 -0
  57. data/demo/data/test/raw/displacement.gml +173 -0
  58. data/demo/data/test/raw/displacement.xsd +36 -0
  59. data/demo/data/test/raw/overlap.gfs +25 -0
  60. data/demo/data/test/raw/overlap.gml +127 -0
  61. data/demo/data/test/raw/overlap.xsd +36 -0
  62. data/demo/data/test/raw/textspacing.gfs +25 -0
  63. data/demo/data/test/raw/textspacing.gml +117 -0
  64. data/demo/data/test/raw/textspacing.xsd +36 -0
  65. data/demo/data/test/readme.txt +3 -0
  66. data/demo/data/test/regenerate.sh +20 -0
  67. data/demo/data/test/textspacing.dbf +0 -0
  68. data/demo/data/test/textspacing.shp +0 -0
  69. data/demo/data/test/textspacing.shx +0 -0
  70. data/demo/rundemo.rb +139 -0
  71. data/demo/sinatra/demo.rb +31 -0
  72. data/demo/sinatra/public/css/demo_map.css +7 -0
  73. data/demo/sinatra/public/index.html +13 -0
  74. data/demo/sinatra/public/javascripts/demo_map.js +42 -0
  75. data/ext/ruby_mapnik/_mapnik.cpp +54 -0
  76. data/ext/ruby_mapnik/_mapnik.h +69 -0
  77. data/ext/ruby_mapnik/_mapnik_color.rb.cpp +179 -0
  78. data/ext/ruby_mapnik/_mapnik_color.rb.h +32 -0
  79. data/ext/ruby_mapnik/_mapnik_coord.rb.cpp +145 -0
  80. data/ext/ruby_mapnik/_mapnik_coord.rb.h +32 -0
  81. data/ext/ruby_mapnik/_mapnik_datasource.rb.cpp +150 -0
  82. data/ext/ruby_mapnik/_mapnik_datasource.rb.h +32 -0
  83. data/ext/ruby_mapnik/_mapnik_datasource_cache.rb.cpp +79 -0
  84. data/ext/ruby_mapnik/_mapnik_datasource_cache.rb.h +32 -0
  85. data/ext/ruby_mapnik/_mapnik_envelope.rb.cpp +220 -0
  86. data/ext/ruby_mapnik/_mapnik_envelope.rb.h +32 -0
  87. data/ext/ruby_mapnik/_mapnik_expression.rb.cpp +91 -0
  88. data/ext/ruby_mapnik/_mapnik_expression.rb.h +32 -0
  89. data/ext/ruby_mapnik/_mapnik_feature.rb.cpp +56 -0
  90. data/ext/ruby_mapnik/_mapnik_feature.rb.h +32 -0
  91. data/ext/ruby_mapnik/_mapnik_font_engine.rb.cpp +71 -0
  92. data/ext/ruby_mapnik/_mapnik_font_engine.rb.h +32 -0
  93. data/ext/ruby_mapnik/_mapnik_geometry.rb.cpp +73 -0
  94. data/ext/ruby_mapnik/_mapnik_geometry.rb.h +32 -0
  95. data/ext/ruby_mapnik/_mapnik_glyph_symbolizer.rb.cpp +250 -0
  96. data/ext/ruby_mapnik/_mapnik_glyph_symbolizer.rb.h +32 -0
  97. data/ext/ruby_mapnik/_mapnik_layer.rb.cpp +237 -0
  98. data/ext/ruby_mapnik/_mapnik_layer.rb.h +32 -0
  99. data/ext/ruby_mapnik/_mapnik_line_pattern_symbolizer.rb.cpp +70 -0
  100. data/ext/ruby_mapnik/_mapnik_line_pattern_symbolizer.rb.h +32 -0
  101. data/ext/ruby_mapnik/_mapnik_line_symbolizer.rb.cpp +43 -0
  102. data/ext/ruby_mapnik/_mapnik_line_symbolizer.rb.h +32 -0
  103. data/ext/ruby_mapnik/_mapnik_map.rb.cpp +435 -0
  104. data/ext/ruby_mapnik/_mapnik_map.rb.h +32 -0
  105. data/ext/ruby_mapnik/_mapnik_markers_symbolizer.rb.cpp +139 -0
  106. data/ext/ruby_mapnik/_mapnik_markers_symbolizer.rb.h +32 -0
  107. data/ext/ruby_mapnik/_mapnik_point_symbolizer.rb.cpp +147 -0
  108. data/ext/ruby_mapnik/_mapnik_point_symbolizer.rb.h +32 -0
  109. data/ext/ruby_mapnik/_mapnik_polygon_pattern_symbolizer.rb.cpp +92 -0
  110. data/ext/ruby_mapnik/_mapnik_polygon_pattern_symbolizer.rb.h +32 -0
  111. data/ext/ruby_mapnik/_mapnik_polygon_symbolizer.rb.cpp +89 -0
  112. data/ext/ruby_mapnik/_mapnik_polygon_symbolizer.rb.h +32 -0
  113. data/ext/ruby_mapnik/_mapnik_projection.rb.cpp +98 -0
  114. data/ext/ruby_mapnik/_mapnik_projection.rb.h +32 -0
  115. data/ext/ruby_mapnik/_mapnik_raster_colorizer.rb.cpp +162 -0
  116. data/ext/ruby_mapnik/_mapnik_raster_colorizer.rb.h +32 -0
  117. data/ext/ruby_mapnik/_mapnik_raster_symbolizer.rb.cpp +53 -0
  118. data/ext/ruby_mapnik/_mapnik_raster_symbolizer.rb.h +32 -0
  119. data/ext/ruby_mapnik/_mapnik_rule.rb.cpp +99 -0
  120. data/ext/ruby_mapnik/_mapnik_rule.rb.h +32 -0
  121. data/ext/ruby_mapnik/_mapnik_shield_symbolizer.rb.cpp +86 -0
  122. data/ext/ruby_mapnik/_mapnik_shield_symbolizer.rb.h +32 -0
  123. data/ext/ruby_mapnik/_mapnik_stroke.rb.cpp +188 -0
  124. data/ext/ruby_mapnik/_mapnik_stroke.rb.h +32 -0
  125. data/ext/ruby_mapnik/_mapnik_style.rb.cpp +76 -0
  126. data/ext/ruby_mapnik/_mapnik_style.rb.h +32 -0
  127. data/ext/ruby_mapnik/_mapnik_symbolizer.rb.cpp +77 -0
  128. data/ext/ruby_mapnik/_mapnik_symbolizer.rb.h +32 -0
  129. data/ext/ruby_mapnik/_mapnik_text_symbolizer.rb.cpp +521 -0
  130. data/ext/ruby_mapnik/_mapnik_text_symbolizer.rb.h +32 -0
  131. data/ext/ruby_mapnik/extconf.rb +78 -0
  132. data/ext/ruby_mapnik/ruby_mapnik.cpp +31 -0
  133. data/lib/ruby_mapnik/mapnik/font_engine.rb +35 -0
  134. data/lib/ruby_mapnik/mapnik/layer.rb +69 -0
  135. data/lib/ruby_mapnik/mapnik/map.rb +144 -0
  136. data/lib/ruby_mapnik/mapnik/projection.rb +46 -0
  137. data/lib/ruby_mapnik/mapnik/raster_colorizer.rb +55 -0
  138. data/lib/ruby_mapnik/mapnik/rule.rb +107 -0
  139. data/lib/ruby_mapnik/mapnik/stroke.rb +58 -0
  140. data/lib/ruby_mapnik/mapnik/style.rb +66 -0
  141. data/lib/ruby_mapnik/mapnik/tile.rb +93 -0
  142. data/lib/ruby_mapnik.rb +48 -0
  143. data/script/console +2 -0
  144. data/test/data/TM_WORLD_BORDERS_SIMPL_0.3_MOD.dbf +0 -0
  145. data/test/data/TM_WORLD_BORDERS_SIMPL_0.3_MOD.prj +1 -0
  146. data/test/data/TM_WORLD_BORDERS_SIMPL_0.3_MOD.shp +0 -0
  147. data/test/data/TM_WORLD_BORDERS_SIMPL_0.3_MOD.shx +0 -0
  148. data/test/data/test_map.xml +15 -0
  149. data/test/test_helper.rb +27 -0
  150. data/test/test_line_pattern_symbolizer.rb +26 -0
  151. data/test/test_mapnik_color.rb +66 -0
  152. data/test/test_mapnik_coord.rb +112 -0
  153. data/test/test_mapnik_datasource.rb +49 -0
  154. data/test/test_mapnik_envelope.rb +232 -0
  155. data/test/test_mapnik_expression.rb +19 -0
  156. data/test/test_mapnik_feature.rb +33 -0
  157. data/test/test_mapnik_font_engine.rb +13 -0
  158. data/test/test_mapnik_geometry.rb +72 -0
  159. data/test/test_mapnik_glyph_symbolizer.rb +96 -0
  160. data/test/test_mapnik_layer.rb +137 -0
  161. data/test/test_mapnik_line_symbolizer.rb +25 -0
  162. data/test/test_mapnik_map.rb +191 -0
  163. data/test/test_mapnik_markers_symbolizer.rb +46 -0
  164. data/test/test_mapnik_point_symbolizer.rb +53 -0
  165. data/test/test_mapnik_polygon_symbolizer.rb +44 -0
  166. data/test/test_mapnik_projection.rb +46 -0
  167. data/test/test_mapnik_raster_colorizer.rb +56 -0
  168. data/test/test_mapnik_raster_symbolizer.rb +40 -0
  169. data/test/test_mapnik_rule.rb +63 -0
  170. data/test/test_mapnik_shield_symbolizer.rb +193 -0
  171. data/test/test_mapnik_stroke.rb +94 -0
  172. data/test/test_mapnik_style.rb +28 -0
  173. data/test/test_mapnik_symbolizer.rb +9 -0
  174. data/test/test_mapnik_text_symbolizer.rb +232 -0
  175. data/test/test_polygon_pattern_symbolizer.rb +34 -0
  176. data/test/test_ruby_mapnik.rb +34 -0
  177. data/yard/lib/yard/parser/generic_parser.rb +72 -0
  178. data/yard/lib/yard_generic.rb +18 -0
  179. metadata +322 -0
@@ -0,0 +1,15 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <Map srs="+proj=latlong +datum=WGS84" background-color="rgb(0,0,255)">
3
+ <Style name="My Style">
4
+ <Rule>
5
+ <PolygonSymbolizer fill="rgb(255,0,0)"/>
6
+ </Rule>
7
+ </Style>
8
+ <Layer name="world" srs="+proj=latlong +datum=WGS84">
9
+ <StyleName>My Style</StyleName>
10
+ <Datasource>
11
+ <Parameter name="file">TM_WORLD_BORDERS_SIMPL_0.3_MOD</Parameter>
12
+ <Parameter name="type">shape</Parameter>
13
+ </Datasource>
14
+ </Layer>
15
+ </Map>
@@ -0,0 +1,27 @@
1
+ =begin
2
+ ******************************************************************************
3
+ *
4
+ * Copyright (C) 2011 Elliot Laster
5
+ *
6
+ * This library is free software; you can redistribute it and/or
7
+ * modify it under the terms of the GNU Lesser General Public
8
+ * License as published by the Free Software Foundation; either
9
+ * version 2.1 of the License, or (at your option) any later version.
10
+ *
11
+ * This library is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ * Lesser General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU Lesser General Public
17
+ * License along with this library; if not, write to the Free Software
18
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
+ *
20
+ ******************************************************************************
21
+ =end
22
+ require "test/unit"
23
+ require "ruby_mapnik"
24
+
25
+ unless defined?(SHAPEFILE)
26
+ SHAPEFILE = "#{File.expand_path(File.dirname(__FILE__))}/data/TM_WORLD_BORDERS_SIMPL_0.3_MOD"
27
+ end
@@ -0,0 +1,26 @@
1
+ require "test_helper"
2
+
3
+ class TestLinePatternSymbolizer < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @filename = "/my/file.png"
7
+ path_expression = Mapnik::PathExpression.parse("/my/file.png")
8
+ @sym = Mapnik::LinePatternSymbolizer.new(path_expression)
9
+ end
10
+
11
+ def test_presence
12
+ assert Mapnik::LinePatternSymbolizer
13
+ end
14
+
15
+ def test_should_instantiate
16
+ assert @sym
17
+ end
18
+
19
+ def test_should_get_and_set_filename
20
+ assert_equal @filename, @sym.filename
21
+ new_filename = "/something/else.png"
22
+ @sym.filename = new_filename
23
+ assert_equal new_filename, @sym.filename
24
+ end
25
+
26
+ end
@@ -0,0 +1,66 @@
1
+ =begin
2
+ ******************************************************************************
3
+ *
4
+ * Copyright (C) 2011 Elliot Laster
5
+ *
6
+ * This library is free software; you can redistribute it and/or
7
+ * modify it under the terms of the GNU Lesser General Public
8
+ * License as published by the Free Software Foundation; either
9
+ * version 2.1 of the License, or (at your option) any later version.
10
+ *
11
+ * This library is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ * Lesser General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU Lesser General Public
17
+ * License along with this library; if not, write to the Free Software
18
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
+ *
20
+ ******************************************************************************
21
+ =end
22
+ require 'test_helper'
23
+ class TestMapnikColor < Test::Unit::TestCase
24
+
25
+ def test_should_instantiate_and_update_values
26
+ values = {:red => 0, :green => 0, :blue => 0, :alpha => 0}
27
+ color = Mapnik::Color.new("#000")
28
+ color.alpha = 0
29
+ values.each do |key, value|
30
+ assert_equal(value, color.send("#{key}"))
31
+ color.send("#{key}=", value + 1)
32
+ assert_equal(value + 1, color.send("#{key}"))
33
+ end
34
+
35
+ end
36
+
37
+ def test_should_instantiate_with_a_css_hex_value
38
+ color = Mapnik::Color.new("#ff0000")
39
+ assert_equal 255, color.red
40
+ assert_equal 0, color.green
41
+ assert_equal 0, color.blue
42
+ end
43
+
44
+ def test_should_instantiate_with_a_rgb_value
45
+ red = 34
46
+ green = 120
47
+ blue = 134
48
+ color = Mapnik::Color.new(red, green, blue)
49
+ assert_equal red, color.red
50
+ assert_equal green, color.green
51
+ assert_equal blue, color.blue
52
+ end
53
+
54
+ def test_should_instantiate_with_a_rgba_value
55
+ red = 34
56
+ green = 120
57
+ blue = 134
58
+ alpha = 0
59
+ color = Mapnik::Color.new(red, green, blue, alpha)
60
+ assert_equal red, color.red
61
+ assert_equal green, color.green
62
+ assert_equal blue, color.blue
63
+ assert_equal alpha, color.alpha
64
+ end
65
+
66
+ end
@@ -0,0 +1,112 @@
1
+ =begin
2
+ ******************************************************************************
3
+ *
4
+ * Copyright (C) 2011 Elliot Laster
5
+ *
6
+ * This library is free software; you can redistribute it and/or
7
+ * modify it under the terms of the GNU Lesser General Public
8
+ * License as published by the Free Software Foundation; either
9
+ * version 2.1 of the License, or (at your option) any later version.
10
+ *
11
+ * This library is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ * Lesser General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU Lesser General Public
17
+ * License along with this library; if not, write to the Free Software
18
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
+ *
20
+ ******************************************************************************
21
+ =end
22
+ require 'test_helper'
23
+ class TestMapnikCoord < Test::Unit::TestCase
24
+
25
+ def test_should_hang_onto_and_update_values
26
+ coord2d = Mapnik::Coord2d.new(1, 2)
27
+ assert_equal(1, coord2d.x)
28
+ assert_equal(2, coord2d.y)
29
+
30
+ coord2d.x = 2
31
+ coord2d.y = 4
32
+ assert_equal(2, coord2d.x)
33
+ assert_equal(4, coord2d.y)
34
+ end
35
+
36
+ def test_should_be_equal_to_another_coord_if_the_x_and_ys_match
37
+ coord2d = Mapnik::Coord2d.new(1,2)
38
+ other_coord = Mapnik::Coord2d.new(coord2d.x, coord2d.y)
39
+ assert other_coord.object_id != coord2d.object_id
40
+ assert_equal(other_coord.x, coord2d.x)
41
+ assert_equal(other_coord.y, coord2d.y)
42
+ assert_equal(other_coord, coord2d)
43
+
44
+ other_coord.x += 3
45
+ assert_not_equal(other_coord, coord2d)
46
+ other_coord.x = coord2d.x
47
+ assert_equal(other_coord, coord2d)
48
+
49
+ other_coord.y += 3
50
+ assert_not_equal(other_coord, coord2d)
51
+ other_coord.y = coord2d.y
52
+ assert_equal(other_coord, coord2d)
53
+
54
+ other_coord.x += 3
55
+ other_coord.y += 3
56
+ assert_not_equal(other_coord, coord2d)
57
+ end
58
+
59
+ # These could be refactored, I suppose...
60
+ def test_should_return_a_new_coord_when_multiplied_by_a_number
61
+ start_x = 1
62
+ start_y = 2
63
+ factor = 3
64
+ coord2d = Mapnik::Coord2d.new(start_x, start_y)
65
+ multiplied_coord = coord2d * factor
66
+ assert_not_equal(coord2d.object_id, multiplied_coord.object_id)
67
+ assert_equal(coord2d.x * factor, multiplied_coord.x)
68
+ assert_equal(coord2d.y * factor, multiplied_coord.y)
69
+ assert_equal(coord2d.x, start_x)
70
+ assert_equal(coord2d.y, start_y)
71
+ end
72
+
73
+ def test_should_return_a_new_coord_when_added_to_by_a_number
74
+ start_x = 1
75
+ start_y = 2
76
+ factor = 3
77
+ coord2d = Mapnik::Coord2d.new(start_x, start_y)
78
+ added_coord = coord2d + factor
79
+ assert_not_equal(coord2d.object_id, added_coord.object_id)
80
+ assert_equal(coord2d.x + factor, added_coord.x)
81
+ assert_equal(coord2d.y + factor, added_coord.y)
82
+ assert_equal(coord2d.x, start_x)
83
+ assert_equal(coord2d.y, start_y)
84
+ end
85
+
86
+ def test_should_return_a_new_coord_when_subtracted_from_by_a_number
87
+ start_x = 1
88
+ start_y = 2
89
+ factor = 3
90
+ coord2d = Mapnik::Coord2d.new(start_x, start_y)
91
+ subtracted_coord = coord2d - factor
92
+ assert_not_equal(coord2d.object_id, subtracted_coord.object_id)
93
+ assert_equal(coord2d.x - factor, subtracted_coord.x)
94
+ assert_equal(coord2d.y - factor, subtracted_coord.y)
95
+ assert_equal(coord2d.x, start_x)
96
+ assert_equal(coord2d.y, start_y)
97
+ end
98
+
99
+ def test_should_return_a_new_coord_when_divided_by_a_number
100
+ start_x = 1
101
+ start_y = 2
102
+ factor = 3
103
+ coord2d = Mapnik::Coord2d.new(start_x, start_y)
104
+ divided_coord = coord2d / factor
105
+ assert_not_equal(coord2d.object_id, divided_coord.object_id)
106
+ assert_equal(coord2d.x / factor, divided_coord.x)
107
+ assert_equal(coord2d.y / factor, divided_coord.y)
108
+ assert_equal(coord2d.x, start_x)
109
+ assert_equal(coord2d.y, start_y)
110
+ end
111
+
112
+ end
@@ -0,0 +1,49 @@
1
+ =begin
2
+ ******************************************************************************
3
+ *
4
+ * Copyright (C) 2011 Elliot Laster
5
+ *
6
+ * This library is free software; you can redistribute it and/or
7
+ * modify it under the terms of the GNU Lesser General Public
8
+ * License as published by the Free Software Foundation; either
9
+ * version 2.1 of the License, or (at your option) any later version.
10
+ *
11
+ * This library is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ * Lesser General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU Lesser General Public
17
+ * License along with this library; if not, write to the Free Software
18
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
+ *
20
+ ******************************************************************************
21
+ =end
22
+ require 'test_helper'
23
+ class TestMapnikDatasource < Test::Unit::TestCase
24
+
25
+ def setup
26
+ @datasource_params = {
27
+ :type => 'shape',
28
+ :file => SHAPEFILE
29
+ }
30
+ @datasource = Mapnik::Datasource.create(@datasource_params)
31
+ end
32
+
33
+ def test_should_create_a_new_datasource
34
+ assert @datasource
35
+ end
36
+
37
+ def test_should_have_an_envelope
38
+ assert @datasource.envelope.kind_of?(Mapnik::Envelope)
39
+ end
40
+
41
+ # def test_should_have_a_descriptor
42
+ # raise @datasource.descriptor.inspect
43
+ # end
44
+
45
+ def test_should_get_params
46
+ assert_equal @datasource_params, @datasource.params
47
+ end
48
+
49
+ end
@@ -0,0 +1,232 @@
1
+ =begin
2
+ ******************************************************************************
3
+ *
4
+ * Copyright (C) 2011 Elliot Laster
5
+ *
6
+ * This library is free software; you can redistribute it and/or
7
+ * modify it under the terms of the GNU Lesser General Public
8
+ * License as published by the Free Software Foundation; either
9
+ * version 2.1 of the License, or (at your option) any later version.
10
+ *
11
+ * This library is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ * Lesser General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU Lesser General Public
17
+ * License along with this library; if not, write to the Free Software
18
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
+ *
20
+ ******************************************************************************
21
+ =end
22
+ require "test_helper"
23
+
24
+ class TestMapnikEnvelope < Test::Unit::TestCase
25
+
26
+ def test_presence
27
+ assert Mapnik::Envelope
28
+ end
29
+
30
+ def test_should_instantiate
31
+ assert Mapnik::Envelope.new(1,1,5,5)
32
+ end
33
+
34
+ def test_should_set_attributes_correctly
35
+ min_x = 1
36
+ min_y = 2
37
+ max_x = 3
38
+ max_y = 4
39
+ envelope = Mapnik::Envelope.new(min_x, min_y, max_x, max_y)
40
+ assert_equal(min_x, envelope.min_x)
41
+ assert_equal(min_y, envelope.min_y)
42
+ assert_equal(max_x, envelope.max_x)
43
+ assert_equal(max_y, envelope.max_y)
44
+ end
45
+
46
+ def test_equality
47
+ envelope1 = Mapnik::Envelope.new(0, 0, 10, 10)
48
+ envelope2 = Mapnik::Envelope.new(0, 0, 10, 10)
49
+ assert_equal(envelope1, envelope2)
50
+ envelope1.re_center_to_xy!(7, 7)
51
+ assert_not_equal(envelope1, envelope2)
52
+ envelope1.re_center_to_coord!(envelope2.center)
53
+ assert_equal(envelope1, envelope2)
54
+ end
55
+
56
+ def test_should_return_center
57
+ envelope = Mapnik::Envelope.new(0, 0, 100, 50)
58
+ assert center = envelope.center
59
+ assert_equal 50, center.x
60
+ assert_equal 25, center.y
61
+ end
62
+
63
+ def test_should_return_height
64
+ envelope = Mapnik::Envelope.new(0,0,10,10)
65
+ assert_equal(10, envelope.height)
66
+ end
67
+
68
+ def test_should_update_height
69
+ envelope = Mapnik::Envelope.new(0,0,10,10)
70
+ assert_equal(10, envelope.height)
71
+ envelope.height = 20
72
+ assert_equal 20, envelope.height
73
+ assert_equal 15, envelope.max_y
74
+ assert_equal(-5, envelope.min_y)
75
+ end
76
+
77
+ def test_should_return_width
78
+ envelope = Mapnik::Envelope.new(0,0,10,10)
79
+ assert_equal(10, envelope.width)
80
+ end
81
+
82
+ def test_should_update_width
83
+ envelope = Mapnik::Envelope.new(0,0,10,10)
84
+ assert_equal(10, envelope.width)
85
+ envelope.width = 20
86
+ assert_equal 20, envelope.width
87
+ assert_equal 15, envelope.max_x
88
+ assert_equal(-5, envelope.min_x)
89
+ end
90
+
91
+ def test_should_recenter_to_xy
92
+ envelope = Mapnik::Envelope.new(0,0,10,10)
93
+ assert_equal 5, envelope.center.x
94
+ assert_equal 5, envelope.center.y
95
+ height_before = envelope.height
96
+ width_before = envelope.width
97
+
98
+ envelope.re_center_to_xy!(7,6)
99
+
100
+ assert_equal 7, envelope.center.x
101
+ assert_equal 6, envelope.center.y
102
+ assert_equal height_before, envelope.height
103
+ assert_equal width_before, envelope.width
104
+ end
105
+
106
+ def test_should_recenter_to_coord
107
+ envelope = Mapnik::Envelope.new(0,0,10,10)
108
+ assert_equal 5, envelope.center.x
109
+ assert_equal 5, envelope.center.y
110
+ height_before = envelope.height
111
+ width_before = envelope.width
112
+
113
+ envelope.re_center_to_coord!(Mapnik::Coord2d.new(7,6))
114
+
115
+ assert_equal 7, envelope.center.x
116
+ assert_equal 6, envelope.center.y
117
+ assert_equal height_before, envelope.height
118
+ assert_equal width_before, envelope.width
119
+ end
120
+
121
+ def test_should_know_if_it_contains_an_xy
122
+ envelope = Mapnik::Envelope.new(0,0,10,10)
123
+ assert !envelope.contains_xy?(11, 11)
124
+ assert envelope.contains_xy?(5, 5)
125
+ end
126
+
127
+ def test_should_know_if_it_contains_a_coord
128
+ envelope = Mapnik::Envelope.new(0,0,10,10)
129
+ assert !envelope.contains_coord?(Mapnik::Coord2d.new(11, 11))
130
+ assert envelope.contains_coord?(Mapnik::Coord2d.new(5, 5))
131
+ end
132
+
133
+ def test_should_know_if_it_contains_another_envelope
134
+ envelope = Mapnik::Envelope.new(0,0,10,10)
135
+ assert !envelope.contains_envelope?(Mapnik::Envelope.new(20,20,30,30))
136
+ assert !envelope.contains_envelope?(Mapnik::Envelope.new(9,9,12,12))
137
+ assert envelope.contains_envelope?(Mapnik::Envelope.new(5,5,6,6))
138
+ end
139
+
140
+ def test_should_know_if_it_intersects_an_xy
141
+ envelope = Mapnik::Envelope.new(0,0,10,10)
142
+ assert !envelope.intersects_xy?(11, 11)
143
+ assert envelope.intersects_xy?(5, 5)
144
+ end
145
+
146
+ def test_should_know_if_it_intersects_a_coord
147
+ envelope = Mapnik::Envelope.new(0,0,10,10)
148
+ assert !envelope.intersects_coord?(Mapnik::Coord2d.new(11, 11))
149
+ assert envelope.intersects_coord?(Mapnik::Coord2d.new(5, 5))
150
+ end
151
+
152
+ def test_should_know_if_it_intersects_another_envelope
153
+ envelope = Mapnik::Envelope.new(0,0,10,10)
154
+ assert !envelope.intersects_envelope?(Mapnik::Envelope.new(20,20,30,30))
155
+ assert envelope.intersects_envelope?(Mapnik::Envelope.new(9,9,12,12))
156
+ assert envelope.intersects_envelope?(Mapnik::Envelope.new(5,5,6,6))
157
+ end
158
+
159
+ def test_should_expand_to_include_an_xy
160
+ envelope = Mapnik::Envelope.new(0,0,10,10)
161
+ assert !envelope.contains_xy?(11, 11)
162
+ height_before = envelope.height
163
+ width_before = envelope.width
164
+
165
+ envelope.expand_to_include_xy!(11, 11)
166
+
167
+ assert envelope.contains_xy?(11, 11)
168
+ assert_equal height_before + 1, envelope.height
169
+ assert_equal width_before + 1, envelope.width
170
+ end
171
+
172
+ def test_should_expand_to_include_a_coord
173
+ envelope = Mapnik::Envelope.new(0,0,10,10)
174
+ coord = Mapnik::Coord2d.new(11, 11)
175
+ assert !envelope.contains_coord?(coord)
176
+ height_before = envelope.height
177
+ width_before = envelope.width
178
+
179
+ envelope.expand_to_include_coord!(coord)
180
+
181
+ assert envelope.contains_coord?(coord)
182
+ assert_equal height_before + 1, envelope.height
183
+ assert_equal width_before + 1, envelope.width
184
+ end
185
+
186
+ def test_should_expand_to_include_an_envelope
187
+ envelope = Mapnik::Envelope.new(0,0,10,10)
188
+ other_envelope = Mapnik::Envelope.new(11, 11, 12, 12)
189
+ assert !envelope.contains_envelope?(other_envelope)
190
+ height_before = envelope.height
191
+ width_before = envelope.width
192
+
193
+ envelope.expand_to_include_envelope!(other_envelope)
194
+
195
+ assert envelope.contains_envelope?(other_envelope)
196
+ assert_equal height_before + 2, envelope.height
197
+ assert_equal width_before + 2, envelope.width
198
+ end
199
+
200
+ def test_should_provide_an_intersection
201
+ envelope = Mapnik::Envelope.new(0,0,10,10)
202
+ other_envelope = Mapnik::Envelope.new(9,9,12,12)
203
+ assert envelope.intersects_envelope?(other_envelope)
204
+
205
+ intersection = envelope.intersection(other_envelope)
206
+
207
+ assert_not_equal(intersection, envelope)
208
+ assert_not_equal(other_envelope, intersection)
209
+ assert envelope.contains_envelope?(intersection)
210
+ assert other_envelope.contains_envelope?(intersection)
211
+ end
212
+
213
+ def test_should_clip
214
+ envelope = Mapnik::Envelope.new(0,0,10,10)
215
+ width_before = envelope.width
216
+ other_envelope = Mapnik::Envelope.new(9,9,12,12)
217
+ assert envelope.intersects_envelope?(other_envelope)
218
+
219
+ envelope.clip!(other_envelope)
220
+
221
+ assert envelope.intersects_envelope?(other_envelope)
222
+ assert_not_equal(width_before, envelope.width)
223
+ end
224
+
225
+ def test_validity
226
+ envelope = Mapnik::Envelope.new(0,0,-1,-1)
227
+ assert envelope.min_x <= envelope.max_x
228
+ assert envelope.min_y <= envelope.max_y
229
+ assert envelope.valid?
230
+ end
231
+
232
+ end
@@ -0,0 +1,19 @@
1
+ require "test_helper"
2
+
3
+ class TestMapnikExpression < Test::Unit::TestCase
4
+
5
+ def test_presence
6
+ assert Mapnik::Expression
7
+ assert Mapnik::PathExpression
8
+ end
9
+
10
+ def test_should_evaluate
11
+ expression = "([place]='town')"
12
+ assert_equal expression, Mapnik::Expression.parse(expression).to_s
13
+ end
14
+
15
+ def test_should_parse_path
16
+ assert Mapnik::PathExpression.parse("/my/path.png")
17
+ end
18
+
19
+ end
@@ -0,0 +1,33 @@
1
+ require "test_helper"
2
+
3
+ class TestMapnikFeature < Test::Unit::TestCase
4
+
5
+ def test_presence
6
+ assert Mapnik::Feature
7
+ end
8
+
9
+ def test_should_instantiate
10
+ feature_id = 12
11
+ assert feature = Mapnik::Feature.new(feature_id)
12
+ assert_equal feature_id, feature.id
13
+ assert_equal "feature ( id:#{feature_id})", feature.to_s.gsub("\n", '')
14
+ end
15
+
16
+ def test_should_return_number_of_geometries
17
+ assert feature = Mapnik::Feature.new(1)
18
+ assert_equal 0, feature.number_of_geometries
19
+ end
20
+
21
+ def test_should_return_its_envelope
22
+ assert feature = Mapnik::Feature.new(1)
23
+ assert feature.envelope.kind_of?(Mapnik::Envelope)
24
+ end
25
+
26
+ def test_should_add_a_geometry
27
+ feature = Mapnik::Feature.new(1)
28
+ assert_equal(0, feature.number_of_geometries)
29
+ feature.add_geometry("POINT(30 10)")
30
+ assert_equal(1, feature.number_of_geometries)
31
+ end
32
+
33
+ end
@@ -0,0 +1,13 @@
1
+ require "test_helper"
2
+
3
+ class TestMapnikFontEngine < Test::Unit::TestCase
4
+
5
+ def test_presence
6
+ assert Mapnik::FontEngine
7
+ end
8
+
9
+ def test_face_name
10
+ assert Mapnik::FontEngine.face_names.instance_of?(Array)
11
+ end
12
+
13
+ end
@@ -0,0 +1,72 @@
1
+ require "test_helper"
2
+
3
+ class TestMapnikGeometry < Test::Unit::TestCase
4
+
5
+ def test_presence
6
+ assert Mapnik::GeometryType
7
+ assert Mapnik::Geometry2d
8
+ assert Mapnik::GeometryType::Point
9
+ assert Mapnik::GeometryType::LineString
10
+ assert Mapnik::GeometryType::Polygon
11
+ assert Mapnik::GeometryType::MultiPoint
12
+ assert Mapnik::GeometryType::MultiLineString
13
+ end
14
+
15
+ def test_should_make_point_from_wkt
16
+ point = Mapnik::Geometry2d.from_wkt("POINT(30 10)")
17
+ assert_equal Mapnik::GeometryType::Point, point.type
18
+ assert_equal 30, point.envelope.min_x
19
+ assert_equal 30, point.envelope.max_x
20
+ assert_equal 10, point.envelope.max_y
21
+ assert_equal 10, point.envelope.min_y
22
+ assert_equal 0, point.area
23
+ end
24
+
25
+ def test_should_make_linestring_from_wkt
26
+ linestring = Mapnik::Geometry2d.from_wkt("LINESTRING (29 11, 12 30, 41 40)")
27
+ assert_equal Mapnik::GeometryType::LineString, linestring.type
28
+ assert_equal 12, linestring.envelope.min_x
29
+ assert_equal 41, linestring.envelope.max_x
30
+ assert_equal 40, linestring.envelope.max_y
31
+ assert_equal 11, linestring.envelope.min_y
32
+ # assert_equal 0, linestring.area -> Not sure what the correct value is here
33
+ end
34
+
35
+ def test_should_make_polygon_from_wkt
36
+ polygon = Mapnik::Geometry2d.from_wkt("POLYGON ((30 10, 10 20, 20 40, 40 40, 30 10))")
37
+ assert_equal Mapnik::GeometryType::Polygon, polygon.type
38
+ assert_equal 10, polygon.envelope.min_x
39
+ assert_equal 40, polygon.envelope.max_x
40
+ assert_equal 40, polygon.envelope.max_y
41
+ assert_equal 10, polygon.envelope.min_y
42
+ # assert_equal 0, polygon.area
43
+ end
44
+
45
+ def test_should_make_multipoint_from_wkt
46
+ multipoint = Mapnik::Geometry2d.from_wkt("MULTIPOINT (10 40, 40 30, 20 20, 30 10)")
47
+ assert_equal Mapnik::GeometryType::MultiPoint, multipoint.type
48
+ assert_equal 10, multipoint.envelope.min_x
49
+ assert_equal 40, multipoint.envelope.max_x
50
+ assert_equal 40, multipoint.envelope.max_y
51
+ assert_equal 10, multipoint.envelope.min_y
52
+ end
53
+
54
+ def test_should_make_multilinestring_from_wkt
55
+ multi_line = Mapnik::Geometry2d.from_wkt("MULTILINESTRING ((10 10, 20 20, 10 40), (40 40, 30 30, 40 20, 30 10))")
56
+ assert_equal Mapnik::GeometryType::MultiLineString, multi_line.type
57
+ assert_equal 10, multi_line.envelope.min_x
58
+ assert_equal 40, multi_line.envelope.max_x
59
+ assert_equal 40, multi_line.envelope.max_y
60
+ assert_equal 10, multi_line.envelope.min_y
61
+ end
62
+
63
+ def test_should_make_multipolygon_from_wkt
64
+ multi_polygon = Mapnik::Geometry2d.from_wkt("MULTIPOLYGON (((30 20, 10 40, 45 40, 30 20)), ((15 5, 40 10, 10 20, 5 10, 15 5)))")
65
+ assert_equal Mapnik::GeometryType::MultiPolygon, multi_polygon.type
66
+ assert_equal 5, multi_polygon.envelope.min_x
67
+ assert_equal 45, multi_polygon.envelope.max_x
68
+ assert_equal 40, multi_polygon.envelope.max_y
69
+ assert_equal 5, multi_polygon.envelope.min_y
70
+ end
71
+
72
+ end