amanzi-sld 0.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.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Craig Taverner
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,131 @@
1
+ = Amanzi::SLD
2
+
3
+ A Ruby DSL for simpler SLD creation for styling maps
4
+
5
+ Map styles are often defined using SLD, or Style Layer Descriptor documents.
6
+ These XML documents are very long, verbose and complex to maintain.
7
+ Amanzi:SLD is a simpler DSL designed to generate SLD documents, but using a
8
+ very much simpler syntax. Many common cases might be a single line only,
9
+ while the simplest SLD is usually a dozen lines or more.
10
+
11
+ === What is SLD?
12
+
13
+ There are great tutorials on the GeoServer wiki for SLD styling. Please take
14
+ a look at {GeoServer Styling}[http://docs.geoserver.org/stable/en/user/styling/index.html]
15
+
16
+ In brief, SLD is an XML syntax for specifying map layer styling. That is how
17
+ to draw map layers. This includes simple things like what color and
18
+ thickness a line should be as well as more complex topics like applying the
19
+ style only to geometries matching certain filters and combining styles to
20
+ create interesting effects. In principle it should be possible to create
21
+ maps as good looking as one normally sees on sites like maps.google.com and
22
+ openstreetmap.org.
23
+
24
+ === Why use Amanzi::SLD?
25
+
26
+ Well, The very simplest document in Amanzi::SLD is three lines long, while the
27
+ same one in normal XML is almost 30 lines long. Consider:
28
+
29
+ require 'amanzi/sld'
30
+ sld = Amanzi::SLD::Document.new('Test')
31
+ sld.add_line_symbolizer :stroke => '#3050e0'
32
+
33
+ This will become the SLD document:
34
+
35
+ <?xml version="1.0" encoding="ISO-8859-1"?>
36
+ <StyledLayerDescriptor xmlns:xlink="http://www.w3.org/1999/xlink"
37
+ xsi:schemaLocation="http://www.opengis.net/sld
38
+ http://schemas.opengis.net/sld/1.0.0/StyledLayerDescriptor.xsd"
39
+ xmlns:ogc="http://www.opengis.net/ogc" version="1.0.0"
40
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
41
+ xmlns="http://www.opengis.net/sld">
42
+ <NamedLayer>
43
+ <Name>Test</Name>
44
+ <UserStyle>
45
+ <Name>Test</Name>
46
+ <FeatureTypeStyle>
47
+ <Rule>
48
+ <LineSymbolizer>
49
+ <Stroke>
50
+ <CssParameter name="stroke">#000000</CssParameter>
51
+ <CssParameter name="stroke-width">1</CssParameter>
52
+ </Stroke>
53
+ </LineSymbolizer>
54
+ </Rule>
55
+ </FeatureTypeStyle>
56
+ <FeatureTypeStyle>
57
+ <Rule>
58
+ <LineSymbolizer>
59
+ <Stroke>
60
+ <CssParameter name="stroke">#000000</CssParameter>
61
+ <CssParameter name="stroke-width">1</CssParameter>
62
+ </Stroke>
63
+ </LineSymbolizer>
64
+ </Rule>
65
+ </FeatureTypeStyle>
66
+ </UserStyle>
67
+ </NamedLayer>
68
+ </StyledLayerDescriptor>
69
+
70
+ === How to get started?
71
+
72
+ The easiest way to get started would be to install the ruby gem using:
73
+
74
+ sudo gem install amanzi-sld
75
+
76
+ There is a chance that the gem is not yet available, in which case your next
77
+ option is to download from source using:
78
+
79
+ git clone git://github.com/craigtaverner/amanzi-sld.git
80
+ cd amanzi-sld
81
+ rake install
82
+
83
+ Then you can create your ruby script with an appropriate content, for
84
+ example:
85
+
86
+ require 'rubygems'
87
+ require 'amanzi/sld'
88
+
89
+ sld = Amanzi::SLD::Document.new 'My SLD Document'
90
+
91
+ sld.add_line_symbolizer
92
+ :stroke => '#004400',
93
+ :stroke_width => 2,
94
+ :geometry => 'LineString'
95
+
96
+ sld.add_polygon_symbolizer
97
+ :stroke => '#004400',
98
+ :stroke_width => 2,
99
+ :geometry => 'Polygon'
100
+
101
+ === Advanced options
102
+
103
+ I will write this up when I get a chance. In the meantime I recommend
104
+ looking at the more complex examples in the examples/ directory. Better yet,
105
+ run them and see what the output looks like.
106
+ * test.rb
107
+ * This actually uses several redundant combinations of syntax to test the SLD as well as the underlying XML DSL on which it is based
108
+ * This is also run by the normal rake tests, called from test/test_file.rb
109
+ * The file test.sld is the expected output which the test will compare with
110
+ * osm.rb
111
+ * This advanced example works with the OpenStreetMap model imported into Neo4j Spatial, and then exposed as one or more layers to GeoServer or uDig
112
+ * I know the colors are ugly, but it is just a demonstration of some of the options available, including labeling
113
+ * Have a look at {Neo4j Spatial}[http://github.com/neo4j/neo4j-spatial] for more on the data being styled. That project actually uses Amanzi:SLD for some of the default styles being built into the OSM DataStore.
114
+ * osm_highway_shp.rb
115
+ * This example works with the highway Shapefile generated from OSM data by CloudMade. See the {CloudMade downloads}[http://downloads.cloudmade.com]
116
+
117
+ You can also read the test code in the test/ directory for information on some of the syntax options being tested.
118
+
119
+ == Note on Patches/Pull Requests
120
+
121
+ * Fork the project.
122
+ * Make your feature addition or bug fix.
123
+ * Add tests for it. This is important so I don't break it in a
124
+ future version unintentionally.
125
+ * Commit, do not mess with rakefile, version, or history.
126
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
127
+ * Send me a pull request. Bonus points for topic branches.
128
+
129
+ == Copyright
130
+
131
+ Copyright (c) 2010 Craig Taverner. See LICENSE for details.
@@ -0,0 +1,54 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "amanzi-sld"
8
+ gem.summary = "A Ruby DSL for simpler SLD creation for styling maps"
9
+ gem.description = "Map styles are often defined using SLD, or Style Layer Descriptor documents. These XML documents are very long, verbose and complex to maintain. Amanzi:SLD is a simpler DSL designed to generate SLD documents, but using a very much simpler syntax. Many common cases might be a single line only, while the simplest SLD is usually a dozen lines or more."
10
+ gem.email = "craig@amanzi.com"
11
+ gem.homepage = "http://github.com/craigtaverner/amanzi-sld"
12
+ gem.authors = ["Craig Taverner"]
13
+ gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
14
+ gem.add_development_dependency "differ", ">= 0.1"
15
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+ end
17
+ Jeweler::GemcutterTasks.new
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
20
+ end
21
+
22
+ require 'rake/testtask'
23
+ Rake::TestTask.new(:test) do |test|
24
+ test.libs << 'lib' << 'test'
25
+ test.pattern = 'test/**/test_*.rb'
26
+ test.verbose = true
27
+ end
28
+
29
+ begin
30
+ require 'rcov/rcovtask'
31
+ Rcov::RcovTask.new do |test|
32
+ test.libs << 'test'
33
+ test.pattern = 'test/**/test_*.rb'
34
+ test.verbose = true
35
+ end
36
+ rescue LoadError
37
+ task :rcov do
38
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
39
+ end
40
+ end
41
+
42
+ task :test => :check_dependencies
43
+
44
+ task :default => :test
45
+
46
+ require 'rake/rdoctask'
47
+ Rake::RDocTask.new do |rdoc|
48
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
49
+
50
+ rdoc.rdoc_dir = 'rdoc'
51
+ rdoc.title = "amanzi-sld #{version}"
52
+ rdoc.rdoc_files.include('README*')
53
+ rdoc.rdoc_files.include('lib/**/*.rb')
54
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,70 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{amanzi-sld}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Craig Taverner"]
12
+ s.date = %q{2010-11-02}
13
+ s.description = %q{Map styles are often defined using SLD, or Style Layer Descriptor documents. These XML documents are very long, verbose and complex to maintain. Amanzi:SLD is a simpler DSL designed to generate SLD documents, but using a very much simpler syntax. Many common cases might be a single line only, while the simplest SLD is usually a dozen lines or more.}
14
+ s.email = %q{craig@amanzi.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "amanzi-sld.gemspec",
27
+ "examples/osm.rb",
28
+ "examples/osm_highway_shp.rb",
29
+ "examples/test.rb",
30
+ "examples/test.sld",
31
+ "lib/amanzi-sld.rb",
32
+ "lib/amanzi/sld.rb",
33
+ "lib/amanzi/xml.rb",
34
+ "test/helper.rb",
35
+ "test/test_file.rb",
36
+ "test/test_sld.rb",
37
+ "test/test_xml.rb"
38
+ ]
39
+ s.homepage = %q{http://github.com/craigtaverner/amanzi-sld}
40
+ s.rdoc_options = ["--charset=UTF-8"]
41
+ s.require_paths = ["lib"]
42
+ s.rubygems_version = %q{1.3.7}
43
+ s.summary = %q{A Ruby DSL for simpler SLD creation for styling maps}
44
+ s.test_files = [
45
+ "test/test_file.rb",
46
+ "test/test_xml.rb",
47
+ "test/test_sld.rb",
48
+ "test/helper.rb",
49
+ "examples/osm.rb",
50
+ "examples/test.rb",
51
+ "examples/osm_highway_shp.rb"
52
+ ]
53
+
54
+ if s.respond_to? :specification_version then
55
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
56
+ s.specification_version = 3
57
+
58
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
59
+ s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
60
+ s.add_development_dependency(%q<differ>, [">= 0.1"])
61
+ else
62
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
63
+ s.add_dependency(%q<differ>, [">= 0.1"])
64
+ end
65
+ else
66
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
67
+ s.add_dependency(%q<differ>, [">= 0.1"])
68
+ end
69
+ end
70
+
@@ -0,0 +1,55 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # This script uses the amanzi-sld DSL to create a sample SLD file
4
+ # for styling a number of layers in a typical OSM data model.
5
+ # This example should work with a layer containing all geometries.
6
+
7
+ require 'amanzi/sld'
8
+
9
+ Amanzi::SLD::Config.config[:geometry_property] = 'the_geom'
10
+ Amanzi::SLD::Config.config[:verbose] = true
11
+
12
+ sld = Amanzi::SLD::Document.new "Example Neo4j Spatial OSM Style"
13
+
14
+ sld.comment "A catch-all style for all ways, drawn first so it only shows if anyther style does not apply"
15
+ sld.add_line_symbolizer(:stroke => '#dddddd')
16
+
17
+ sld.comment "A catch-all style for all Polygons"
18
+ sld.add_polygon_symbolizer(
19
+ :fill => '#aaaaaa',
20
+ :fill_opacity => '0.4',
21
+ :stroke => '#ffe0e0',
22
+ :geometry => 'Polygon'
23
+ )
24
+
25
+ sld.comment "Color areas of land-use"
26
+ sld.add_polygon_symbolizer(
27
+ :fill => '#d0d0d0',
28
+ :fill_opacity => '0.6',
29
+ :stroke => '#e0e0e0',
30
+ :geometry => 'Polygon'
31
+ ) do |f|
32
+ f.property.exists? 'landuse'
33
+ end
34
+
35
+ # Old code below, copied from test.rb
36
+
37
+ sld.comment "A catch-all style for all ways, drawn first so it only shows if anyther style does not apply"
38
+ sld.
39
+ add_line_symbolizer(:stroke_width => 7, :stroke => '#303030').
40
+ add_line_symbolizer(:stroke_width => 5, :stroke => '#e0e0ff') do |f|
41
+ puts "Setting up AND filters: #{f.inspect}"
42
+ f.op(:and) do |f|
43
+ puts "Setting up property filters: #{f.inspect}"
44
+ f.property.exists? :highway
45
+ f.op(:or) do |f|
46
+ f.property[:highway] = 'secondary'
47
+ f.property[:highway] = 'tertiary'
48
+ end
49
+ end
50
+ end
51
+
52
+ puts sld.to_xml(:tab => ' ')
53
+
54
+ #HTML::Document.test
55
+
@@ -0,0 +1,103 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # This SLD should work with OSM standard export to SHP format, as provided by CloudMade
4
+ # on their downloads pages. In those files the properties are all provided as values
5
+ # of the TYPE parameter. I tested this on an extract from Berlin and it handles a range
6
+ # of zoom levels.
7
+
8
+ # In case you are running this from source
9
+ $:<< 'lib'
10
+ $:<< '../lib'
11
+
12
+ # In case you have amanzi/sld as a ruby gem
13
+ require 'rubygems'
14
+ require 'amanzi/sld'
15
+
16
+ # Define some common filtering rules
17
+ major_highways = Proc.new do |f|
18
+ f.op(:or) do |f|
19
+ f.property[:TYPE] = 'primary'
20
+ f.property[:TYPE] = 'motorway'
21
+ end
22
+ end
23
+
24
+ highways = Proc.new do |f|
25
+ f.op(:or) do |f|
26
+ f.property[:TYPE] = 'primary'
27
+ f.property[:TYPE] = 'secondary'
28
+ f.property[:TYPE] = 'motorway'
29
+ end
30
+ end
31
+
32
+ main_roads = Proc.new do |f|
33
+ f.op(:or) do |f|
34
+ f.property[:TYPE] = 'primary'
35
+ f.property[:TYPE] = 'secondary'
36
+ f.property[:TYPE] = 'tertiary'
37
+ f.property[:TYPE] = 'motorway'
38
+ f.property[:TYPE] = 'residential'
39
+ end
40
+ end
41
+
42
+ sld = Amanzi::SLD::Document.new "OSM Highways"
43
+
44
+ # when zoomed out, draw only main highways
45
+ sld.add_line_symbolizer :stroke => '#b0b0b0', :stroke_width => 1, :min_scale => 70000 do |f|
46
+ highways.call f
47
+ end
48
+ sld.add_line_symbolizer :stroke => '#b0b0b0', :stroke_width => 3, :min_scale => 70000 do |f|
49
+ major_highways.call f
50
+ end
51
+ sld.add_line_symbolizer :stroke => '#f0f0a0', :stroke_width => 2, :min_scale => 70000 do |f|
52
+ major_highways.call f
53
+ end
54
+
55
+ # moderate zoom, show main roads only
56
+ sld.add_line_symbolizer :stroke => '#b0b0b0', :stroke_width => 1, :max_scale => 70000, :min_scale => 35000 do |f|
57
+ main_roads.call f
58
+ end
59
+ sld.add_line_symbolizer :stroke => '#b0b0b0', :stroke_width => 3, :max_scale => 70000, :min_scale => 35000 do |f|
60
+ highways.call f
61
+ end
62
+ sld.add_line_symbolizer :stroke => '#f0f0a0', :stroke_width => 2, :max_scale => 70000, :min_scale => 35000 do |f|
63
+ highways.call f
64
+ end
65
+
66
+ # zoomed in more, show all roads with some width and draw main and highways over that
67
+ sld.add_line_symbolizer :stroke => '#d0d0d0', :stroke_width => 2, :max_scale => 35000, :min_scale => 15000
68
+ sld.add_line_symbolizer :stroke => '#909090', :stroke_width => 3, :max_scale => 35000, :min_scale => 15000 do |f|
69
+ highways.call f
70
+ end
71
+ sld.add_line_symbolizer :stroke => '#b0b0b0', :stroke_width => 1, :max_scale => 35000, :min_scale => 15000
72
+ sld.add_line_symbolizer :stroke => '#b0f0f0', :stroke_width => 1, :max_scale => 35000, :min_scale => 15000 do |f|
73
+ main_roads.call f
74
+ end
75
+ sld.add_line_symbolizer :stroke => '#f0f0a0', :stroke_width => 2, :max_scale => 35000, :min_scale => 15000 do |f|
76
+ highways.call f
77
+ end
78
+
79
+ # zoomed in the most, show all roads, and highlight main roads and highways
80
+ sld.add_line_symbolizer :stroke => '#909090', :stroke_width => 3, :max_scale => 15000
81
+ sld.add_line_symbolizer :stroke => '#f0f0f0', :stroke_width => 2, :max_scale => 15000
82
+ sld.add_line_symbolizer :stroke => '#909090', :stroke_width => 5, :max_scale => 15000 do |f|
83
+ main_roads.call f
84
+ end
85
+
86
+ sld.add_line_symbolizer :stroke => '#909090', :stroke_width => 7, :max_scale => 15000 do |f|
87
+ highways.call f
88
+ end
89
+
90
+ sld.add_line_symbolizer :stroke => '#e0e0e0', :stroke_width => 3, :max_scale => 15000 do |f|
91
+ main_roads.call f
92
+ end
93
+
94
+ sld.add_line_symbolizer :stroke => '#f0f0a0', :stroke_width => 5, :max_scale => 15000 do |f|
95
+ highways.call f
96
+ end
97
+
98
+ #sld.add_text_symbolizer :property => 'name', :font_size => 18, :halo => 2, :max_scale => 15000 do |f|
99
+ # highways.call f
100
+ #end
101
+
102
+ puts sld.to_xml :tab => ' '
103
+