ruby_mapnik 0.1

Sign up to get free protection for your applications and to get access to all the features.
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,69 @@
1
+ =begin
2
+ Copyright (C) 2011 Elliot Laster
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
5
+ this software and associated documentation files (the ‘Software’), to deal in
6
+ the Software without restriction, including without limitation the rights to
7
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8
+ of the Software, and to permit persons to whom the Software is furnished to do
9
+ so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all
12
+ copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ SOFTWARE.
21
+ =end
22
+ module Mapnik
23
+
24
+ class LayerStyleContainer
25
+
26
+ extend Forwardable
27
+
28
+ def_delegators :@collection, :empty?, :any?, :length, :first, :count
29
+
30
+ def initialize(collection)
31
+ @collection = collection
32
+ end
33
+
34
+ def layer=(layer)
35
+ @layer = layer
36
+ end
37
+
38
+ def <<(object)
39
+ @layer.send(:__append_style__, object)
40
+ @collection << object
41
+ end
42
+
43
+ alias :push :<<
44
+
45
+ end
46
+
47
+ class Layer
48
+
49
+ attr_writer :map
50
+
51
+ def style(override_style_name = nil)
52
+ style_name = override_style_name || name
53
+ style = Mapnik::Style.new
54
+ yield style
55
+ @map.styles[style_name] = style
56
+ styles << style_name
57
+ end
58
+
59
+ def styles
60
+ styles = LayerStyleContainer.new(__style_list__)
61
+ styles.layer = self
62
+ styles
63
+ end
64
+
65
+ private :__style_list__, :__append_style__
66
+
67
+ end
68
+
69
+ end
@@ -0,0 +1,144 @@
1
+ =begin
2
+ Copyright (C) 2011 Elliot Laster
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
5
+ this software and associated documentation files (the ‘Software’), to deal in
6
+ the Software without restriction, including without limitation the rights to
7
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8
+ of the Software, and to permit persons to whom the Software is furnished to do
9
+ so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all
12
+ copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ SOFTWARE.
21
+ =end
22
+ module Mapnik
23
+
24
+ class MapStyleContainer < Hash
25
+
26
+ def map=(map)
27
+ @map = map
28
+ end
29
+
30
+ def []=(key, object)
31
+ @map.send(:__insert_style__, key, object)
32
+ super(key, object)
33
+ end
34
+
35
+ def delete(key)
36
+ @map.send(:__remove_style__, key)
37
+ super(key)
38
+ end
39
+
40
+ end
41
+
42
+ class MapLayerContainer
43
+
44
+ extend Forwardable
45
+
46
+ def_delegators :@collection, :empty?, :any?, :length, :first, :[], :count
47
+
48
+ def initialize(collection)
49
+ @collection = collection
50
+ end
51
+
52
+ def <<(object)
53
+ @map.send(:__add_layer__, object)
54
+ @collection << (object)
55
+ end
56
+
57
+ alias :push :<<
58
+
59
+ def clear
60
+ (0..length-1).each{|index| remove_object_at_index(index)}
61
+ @collection.clear
62
+ end
63
+
64
+ def delete_at(index)
65
+ remove_object_at_index(index)
66
+ @collection.delete_at(index)
67
+ end
68
+
69
+ def map=(map)
70
+ @map = map
71
+ end
72
+
73
+ def pop
74
+ delete_at(length - 1) unless length.zero?
75
+ end
76
+
77
+ private
78
+
79
+ def remove_object_at_index(index)
80
+ @map.send(:__remove_layer__, index)
81
+ end
82
+
83
+ end
84
+
85
+ class Map
86
+
87
+ class << self
88
+
89
+ # @return [Mapnik::Map]
90
+ def from_xml(xml, strict = false, base_path = "")
91
+ map = new
92
+ __load_map_string__(map, xml, strict, base_path)
93
+ map
94
+ end
95
+
96
+ # @return [Mapnik::Map]
97
+ def from_file(filename, strict = false)
98
+ map = new
99
+ __load_map__(map, filename, strict)
100
+ map
101
+ end
102
+
103
+ end
104
+
105
+ # @return [Mapnik::Style]
106
+ def style(name)
107
+ style = Mapnik::Style.new
108
+ yield style
109
+ styles[name] = style
110
+ end
111
+
112
+ # @return [Mapnik::StyleContainer]
113
+ def styles
114
+ styles = MapStyleContainer[__styles__]
115
+ styles.map = self
116
+ styles
117
+ end
118
+
119
+ # @return [Mapnik::Layer]
120
+ def layer(name, srs = nil)
121
+ layer = Mapnik::Layer.new(name, srs)
122
+ layer.map = self
123
+ yield layer
124
+ layers << layer
125
+ end
126
+
127
+ # @return [Mapnik::MapLayerContainer]
128
+ def layers
129
+ layers = MapLayerContainer.new(__layers__)
130
+ layers.map = self
131
+ layers
132
+ end
133
+
134
+ # @return [nil]
135
+ def render_to_file(filename)
136
+ __render_to_file__(filename)
137
+ end
138
+
139
+ private :__styles__, :__insert_style__, :__remove_style__, :__layers__,
140
+ :__add_layer__, :__remove_layer__
141
+
142
+ end
143
+
144
+ end
@@ -0,0 +1,46 @@
1
+ =begin
2
+ Copyright (C) 2011 Elliot Laster
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
5
+ this software and associated documentation files (the ‘Software’), to deal in
6
+ the Software without restriction, including without limitation the rights to
7
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8
+ of the Software, and to permit persons to whom the Software is furnished to do
9
+ so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all
12
+ copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ SOFTWARE.
21
+ =end
22
+ module Mapnik
23
+ class Projection
24
+
25
+ def forward(obj)
26
+ case
27
+ when obj.class == Mapnik::Envelope
28
+ __forward_env__(obj)
29
+ when obj.class == Mapnik::Coord2d
30
+ __forward_pt__(obj)
31
+ end
32
+ end
33
+
34
+ def inverse(obj)
35
+ case
36
+ when obj.class == Mapnik::Envelope
37
+ __inverse_env__(obj)
38
+ when obj.class == Mapnik::Coord2d
39
+ __inverse_pt__(obj)
40
+ end
41
+ end
42
+
43
+ private :__forward_pt__, :__forward_env__, :__inverse_pt__, :__inverse_env__
44
+
45
+ end
46
+ end
@@ -0,0 +1,55 @@
1
+ =begin
2
+ Copyright (C) 2011 Elliot Laster
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
5
+ this software and associated documentation files (the ‘Software’), to deal in
6
+ the Software without restriction, including without limitation the rights to
7
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8
+ of the Software, and to permit persons to whom the Software is furnished to do
9
+ so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all
12
+ copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ SOFTWARE.
21
+ =end
22
+ module Mapnik
23
+
24
+ class ColorizerStopCollection
25
+
26
+ extend Forwardable
27
+
28
+ def_delegators :@collection, :empty?, :any?, :length, :first, :count
29
+
30
+ def initialize(collection)
31
+ @collection = collection
32
+ end
33
+
34
+ def delegate=(object)
35
+ @delegate = object
36
+ end
37
+
38
+ def <<(stop)
39
+ @delegate.__add_stop__(stop)
40
+ @collection << stop
41
+ end
42
+
43
+ end
44
+
45
+ class RasterColorizer
46
+
47
+ def stops
48
+ stops = ColorizerStopCollection.new(__stops__)
49
+ stops.delegate = self
50
+ stops
51
+ end
52
+
53
+ end
54
+
55
+ end
@@ -0,0 +1,107 @@
1
+ =begin
2
+ Copyright (C) 2011 Elliot Laster
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
5
+ this software and associated documentation files (the ‘Software’), to deal in
6
+ the Software without restriction, including without limitation the rights to
7
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8
+ of the Software, and to permit persons to whom the Software is furnished to do
9
+ so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all
12
+ copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ SOFTWARE.
21
+ =end
22
+ module Mapnik
23
+
24
+ class RuleSymbolContainer < Array
25
+
26
+ extend Forwardable
27
+
28
+ def_delegators :@collection, :empty?, :any?, :length, :first, :count, :[]
29
+
30
+ def initialize(collection)
31
+ @collection = collection
32
+ end
33
+
34
+ def rule=(rule)
35
+ @rule = rule
36
+ end
37
+
38
+ def <<(object)
39
+ symbolizer_object = Mapnik::Symbolizer.from_subtype(object)
40
+ @rule.send(:__append_symbol__, symbolizer_object)
41
+ @collection << symbolizer_object
42
+ end
43
+
44
+ alias :push :<<
45
+
46
+ def delete_at(index)
47
+ remove_object_at_index(index)
48
+ @collection.delete_at(index)
49
+ end
50
+
51
+ def pop
52
+ delete_at(length - 1) unless length.zero?
53
+ end
54
+
55
+ def clear
56
+ (0..length-1).each{|index| remove_object_at_index(index)}
57
+ @collection.clear
58
+ end
59
+
60
+ private
61
+
62
+ def remove_object_at_index(index)
63
+ @rule.send(:__remove_symbol__, index)
64
+ end
65
+
66
+ end
67
+
68
+ class Rule
69
+
70
+ def polygon
71
+ polygon = Mapnik::PolygonSymbolizer.new
72
+ yield polygon
73
+ symbols << polygon
74
+ end
75
+
76
+ def fill=(color)
77
+ polygon = Mapnik::PolygonSymbolizer.new
78
+ polygon.fill = color
79
+ symbols << polygon
80
+ end
81
+
82
+ def line
83
+ stroke = Mapnik::Stroke.new(Mapnik::Color.new, 1.0)
84
+ yield stroke
85
+ line = Mapnik::LineSymbolizer.new
86
+ line.stroke = stroke
87
+ symbols << line
88
+ end
89
+
90
+ def text(expression_text)
91
+ exp = Mapnik::Expression.parse(expression_text)
92
+ text = Mapnik::TextSymbolizer.new(exp, 'DejaVu Sans Book', 10, Mapnik::Color.new)
93
+ yield text
94
+ symbols << text
95
+ end
96
+
97
+ def symbols
98
+ symbol_container = RuleSymbolContainer.new(__symbols__)
99
+ symbol_container.rule = self
100
+ symbol_container
101
+ end
102
+
103
+ private :__symbols__, :__append_symbol__, :__remove_symbol__
104
+
105
+ end
106
+ end
107
+
@@ -0,0 +1,58 @@
1
+ =begin
2
+ Copyright (C) 2011 Elliot Laster
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
5
+ this software and associated documentation files (the ‘Software’), to deal in
6
+ the Software without restriction, including without limitation the rights to
7
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8
+ of the Software, and to permit persons to whom the Software is furnished to do
9
+ so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all
12
+ copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ SOFTWARE.
21
+ =end
22
+ module Mapnik
23
+
24
+ class StrokeDashContainer
25
+
26
+ extend Forwardable
27
+
28
+ def_delegators :@collection, :empty?, :any?, :length, :first, :count, :[]
29
+
30
+ def initialize(collection)
31
+ @collection = collection.map{|x| {:length => x[0], :gap => x[1]}}
32
+ end
33
+
34
+ def stroke=(stroke)
35
+ @stroke = stroke
36
+ end
37
+
38
+ def <<(dash_hash)
39
+ @stroke.send(:__add_dash__, dash_hash[:length], dash_hash[:gap])
40
+ end
41
+
42
+ alias :push :<<
43
+
44
+ end
45
+
46
+ class Stroke
47
+
48
+ def dashes
49
+ dashes = StrokeDashContainer.new(__dashes__)
50
+ dashes.stroke = self
51
+ dashes
52
+ end
53
+
54
+ private :__dashes__, :__add_dash__
55
+
56
+ end
57
+
58
+ end
@@ -0,0 +1,66 @@
1
+ =begin
2
+ Copyright (C) 2011 Elliot Laster
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
5
+ this software and associated documentation files (the ‘Software’), to deal in
6
+ the Software without restriction, including without limitation the rights to
7
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8
+ of the Software, and to permit persons to whom the Software is furnished to do
9
+ so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all
12
+ copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ SOFTWARE.
21
+ =end
22
+ module Mapnik
23
+
24
+ class StyleRuleContainer
25
+
26
+ extend Forwardable
27
+
28
+ def_delegators :@collection, :empty?, :any?, :length, :first, :count
29
+
30
+ def initialize(collection)
31
+ @collection = collection
32
+ end
33
+
34
+ def style=(style)
35
+ @style = style
36
+ end
37
+
38
+ def <<(object)
39
+ @style.send(:__add_rule__, object)
40
+ @collection << object
41
+ end
42
+
43
+ alias :push :<<
44
+
45
+ end
46
+
47
+ class Style
48
+
49
+ def rule(filter_string = 'true')
50
+ rule = Mapnik::Rule.new
51
+ rule.filter = Mapnik::Expression.parse(filter_string)
52
+ yield rule
53
+ self.rules << rule
54
+ end
55
+
56
+ def rules
57
+ rules = StyleRuleContainer.new(__rules__)
58
+ rules.style = self
59
+ rules
60
+ end
61
+
62
+ private :__rules__, :__add_rule__
63
+
64
+ end
65
+
66
+ end
@@ -0,0 +1,93 @@
1
+ =begin
2
+ Copyright (C) 2011 Elliot Laster
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
5
+ this software and associated documentation files (the ‘Software’), to deal in
6
+ the Software without restriction, including without limitation the rights to
7
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8
+ of the Software, and to permit persons to whom the Software is furnished to do
9
+ so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all
12
+ copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ SOFTWARE.
21
+ =end
22
+ module Mapnik
23
+
24
+ class Tile
25
+
26
+ # 900913
27
+ DEFAULT_OUTPUT_PROJECTION = "+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"
28
+ DEFAULT_HEIGHT = 256
29
+ DEFAULT_WIDTH = 256
30
+
31
+ include Math
32
+
33
+ attr_accessor :min_x, :min_y, :max_x, :max_y,
34
+ :zoom, :x, :y, :output_projection,
35
+ :height, :width
36
+
37
+ def initialize(zoom, x, y, projection = nil)
38
+ @zoom = zoom.to_i
39
+ @x = x.to_i
40
+ @y = y.to_i
41
+ @output_projection = projection || DEFAULT_OUTPUT_PROJECTION.dup
42
+ @height = DEFAULT_HEIGHT
43
+ @width = DEFAULT_WIDTH
44
+ setup_bounds
45
+ end
46
+
47
+ def render(map, filename)
48
+ map.height = @height
49
+ map.width = @width
50
+ map.zoom_to_box(forwarded_envelope)
51
+ map.render_to_file(filename)
52
+ end
53
+
54
+ def render_to_string(map)
55
+ map.height = @height
56
+ map.width = @width
57
+ map.zoom_to_box(forwarded_envelope)
58
+ map.render_to_string('png')
59
+ end
60
+
61
+ def envelope
62
+ @envelope ||= Mapnik::Envelope.new(@min_x, @min_y, @max_x, @max_y)
63
+ end
64
+
65
+ def forwarded_envelope
66
+ projection = Mapnik::Projection.new(@output_projection)
67
+ projection.forward(envelope)
68
+ end
69
+
70
+ private
71
+
72
+ def setup_map_for_render(map)
73
+ map.height = @height
74
+ map.width = @width
75
+ map.zoom_to_box(forwarded_envelope)
76
+ end
77
+
78
+ def setup_bounds
79
+ @max_x, @min_y = zoom_x_y_to_lat_lng(@zoom, @x, @y)
80
+ @min_x, @max_y = zoom_x_y_to_lat_lng(@zoom, @x + 1, @y + 1)
81
+ end
82
+
83
+ def zoom_x_y_to_lat_lng(zoom, x, y)
84
+ n = 2.0 ** zoom
85
+ lon_deg = x / n * 360.0 - 180.0
86
+ lat_rad = atan(sinh(Math::PI * (1 - 2 * y / n)))
87
+ lat_deg = lat_rad * 180.0 / Math::PI
88
+ [lon_deg, lat_deg]
89
+ end
90
+
91
+ end
92
+
93
+ end
@@ -0,0 +1,48 @@
1
+ =begin
2
+ Copyright (C) 2011 Elliot Laster
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
5
+ this software and associated documentation files (the ‘Software’), to deal in
6
+ the Software without restriction, including without limitation the rights to
7
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8
+ of the Software, and to permit persons to whom the Software is furnished to do
9
+ so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all
12
+ copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ SOFTWARE.
21
+ =end
22
+ require 'forwardable'
23
+
24
+ path = File.expand_path(File.dirname(__FILE__))
25
+
26
+ require 'ruby_mapnik_config'
27
+ require "#{path}/ruby_mapnik/ruby_mapnik"
28
+ require "#{path}/ruby_mapnik/mapnik/rule"
29
+ require "#{path}/ruby_mapnik/mapnik/style"
30
+ require "#{path}/ruby_mapnik/mapnik/layer"
31
+ require "#{path}/ruby_mapnik/mapnik/map"
32
+ require "#{path}/ruby_mapnik/mapnik/stroke"
33
+ require "#{path}/ruby_mapnik/mapnik/projection"
34
+ require "#{path}/ruby_mapnik/mapnik/font_engine"
35
+ require "#{path}/ruby_mapnik/mapnik/raster_colorizer"
36
+ require "#{path}/ruby_mapnik/mapnik/tile"
37
+
38
+
39
+ module Mapnik
40
+ VERSION = '0.1'
41
+
42
+ FontEngine.register_fonts(FONT_PATH)
43
+ DatasourceCache.register(INPUT_PLUGIN_PATH)
44
+
45
+ if DatasourceCache.available_plugins.empty?
46
+ puts "RUBY-MAPNIK WARNING: No datasource plugins were found!"
47
+ end
48
+ end
data/script/console ADDED
@@ -0,0 +1,2 @@
1
+ #!/bin/bash
2
+ (cd lib && irb -r ruby_mapnik)
@@ -0,0 +1 @@
1
+ GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]