rozi 0.0.7 → 0.1.3

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 (37) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +255 -0
  3. data/lib/rozi.rb +6 -3
  4. data/lib/rozi/file_wrapper_base.rb +52 -0
  5. data/lib/rozi/module_functions.rb +19 -69
  6. data/lib/rozi/name_search.rb +176 -0
  7. data/lib/rozi/{ozi_functions.rb → shared.rb} +36 -9
  8. data/lib/rozi/tracks.rb +170 -0
  9. data/lib/rozi/version.rb +1 -1
  10. data/lib/rozi/waypoints.rb +315 -0
  11. data/test/rozi/file_wrapper_base_test.rb +29 -0
  12. data/test/rozi/module_functions_test.rb +11 -72
  13. data/test/rozi/name_search_test.rb +248 -0
  14. data/test/rozi/{ozi_functions_test.rb → shared_test.rb} +25 -5
  15. data/test/rozi/tracks_test.rb +105 -0
  16. data/test/rozi/waypoints_test.rb +268 -0
  17. data/test/test_data/expected_output_1.nst +6 -0
  18. data/{test_data → test/test_data}/expected_output_1.plt +9 -9
  19. data/{test_data → test/test_data}/expected_output_1.wpt +7 -7
  20. data/test/test_data/input_1.wpt +6 -0
  21. metadata +128 -34
  22. data/README.rdoc +0 -127
  23. data/lib/rozi/name.rb +0 -23
  24. data/lib/rozi/name_search_text.rb +0 -43
  25. data/lib/rozi/name_search_text_writer.rb +0 -71
  26. data/lib/rozi/track.rb +0 -67
  27. data/lib/rozi/track_point.rb +0 -39
  28. data/lib/rozi/track_writer.rb +0 -50
  29. data/lib/rozi/waypoint.rb +0 -90
  30. data/lib/rozi/waypoint_writer.rb +0 -38
  31. data/test/rozi/name_search_text_test.rb +0 -28
  32. data/test/rozi/name_search_text_writer_test.rb +0 -114
  33. data/test/rozi/track_point_test.rb +0 -32
  34. data/test/rozi/track_test.rb +0 -25
  35. data/test/rozi/track_writer_test.rb +0 -62
  36. data/test/rozi/waypoint_test.rb +0 -31
  37. data/test/rozi/waypoint_writer_test.rb +0 -60
@@ -1,127 +0,0 @@
1
- {<img src="https://badge.fury.io/rb/rozi.svg" alt="Gem Version" />}[http://badge.fury.io/rb/rozi]
2
-
3
- = Rozi
4
-
5
- Rozi is a Ruby gem for working with all Ozi Explorer file formats. Currently
6
- the implemented functionality is:
7
-
8
- - Creating Waypoint files.
9
- - Creating Track files.
10
- - Creating Name Search Text (.nst) files.
11
-
12
- == Files.
13
-
14
- Text based file formats read by Ozi Explorer should be encoded as ISO-8859-1
15
- and use CR LF line endings (\\r\\n). If you pass file paths to Rozi's write
16
- functions (rather than file objects) Rozi will handle this for you. If that
17
- isn't an alternative you either have to handle this yourself, or you can use
18
- {Rozi.open_file_for_writing}.
19
-
20
- file = Rozi.open_file_for_writing("file_path.wpt")
21
- file.write("Østre aker\n") # Writes "Østre aker\r\n" in ISO-8859-1.
22
-
23
- # Does the same thing, but closes the file for you when you're done.
24
- Rozi.open_file_for_writing("file_path.wpt") { |file|
25
- file.write("Østre aker\n")
26
- }
27
-
28
- == Colors.
29
-
30
- Any time you set colors in Rozi, you can either use the three-byte integer
31
- representation that Ozi Explorer expects, or you can use a hex string like
32
- "RRGGBB" and Rozi will convert it for you. Example:
33
-
34
- # Identical.
35
- Rozi::Waypoint.new(bg_color: "ABCDEF")
36
- Rozi::Waypoint.new(bg_color: 15715755)
37
-
38
- # Identical.
39
- Rozi::Waypoint.new(bg_color: "FF0000")
40
- Rozi::Waypoint.new(bg_color: 255)
41
-
42
- == Creating Waypoint files.
43
-
44
- Waypoint files are created in Rozi by creating an array of {Rozi::Waypoint}
45
- instances and writing them to a file using {Rozi.write_waypoints}:
46
-
47
- Example:
48
-
49
- waypoints = [
50
- Rozi::Waypoint.new(latitude: -12.7, longitude: -58.0, name: "South America"),
51
- Rozi::Waypoint.new(latitude: 43.7, longitude: -103.7, name: "North America"),
52
- Rozi::Waypoint.new(latitude: 49.6, longitude: 20.9, name: "Europe")
53
- ]
54
-
55
- Rozi.write_waypoints(waypoints, "file_path.wpt")
56
-
57
- Every aspect of the waypoint can be customized on the {Rozi::Waypoint} instance
58
- (display format, symbol, background- and foreground colors, description, font
59
- size etc.)
60
-
61
- == Creating Track files.
62
-
63
- Track files are created in Rozi by creating a {Rozi::Track} instance with two or
64
- more {Rozi::TrackPoint} instances, then writing them to a file using
65
- {Rozi.write_track}.
66
-
67
- Example:
68
-
69
- track = Rozi::Track.new()
70
-
71
- track << Rozi::TrackPoint.new(latitude: 39.8, longitude: -3.4)
72
- track << Rozi::TrackPoint.new(latitude: 46.6, longitude: 3.1)
73
- track << Rozi::TrackPoint.new(latitude: 50.79, longitude: 10.3)
74
- track << Rozi::TrackPoint.new(latitude: 49.04, longitude: 31.5)
75
-
76
- Rozi.write_track(track, "file_path.plt")
77
-
78
- Both {Rozi::Track} and {Rozi::TrackPoint} has lots of customizable attributes to
79
- change the appearance of the track.
80
-
81
- == Creating NST files.
82
-
83
- See {Ozi Explorer: Name
84
- Search}[http://www.oziexplorer3.com/namesearch/wnamesrch.html] for information
85
- about Name Search. An NST file has to be converted into a Name Database using
86
- the {"Name Search
87
- Creator"}[http://www.oziexplorer3.com/namesearch/namesearch_setup.exe] tool
88
- before they can be used by Ozi Explorer.
89
-
90
- In Rozi, an NST file is represented by a {Rozi::NameSearchText} object. This
91
- object lets you control the coordinate system (lat/lng or UTM) of the name
92
- database, as well as the datum, UTM Zone and Hemisphere (if applicable). You can
93
- also add a comment to the top of the exported file using
94
- {Rozi::NameSearchText#comment}. By default, decimal lat/lng coordinates are used
95
- with the WGS 84 datum.
96
-
97
- {Rozi::Name} objects are added to the {Rozi::NameSearchText} instance, which is
98
- then written to a file using {Rozi.write_nst}.
99
-
100
- Example:
101
-
102
- nst = Rozi::NameSearchText.new
103
- nst.comment = "Generated #{Time.now}"
104
-
105
- nst << Rozi::Name.new("Place name", "Feature code", nil, 12.3456, 23.4567)
106
-
107
- Rozi.write_nst(nst, "file_path.nst")
108
-
109
- Example using UTM with the "Norsk" datum:
110
-
111
- nst = Rozi::NameSearchText.new
112
- nst.comment = "Generated #{Time.now}"
113
- nst.utm = true
114
- nst.utm_zone = "33"
115
- nst.datum = "Norsk"
116
- nst.hemisphere = "N"
117
-
118
- nst << Rozi::Name.new("Place name", "Feature code", nil, 67890.12, 56789.01)
119
-
120
- # UTM Zone overridden.
121
- nst << Rozi::Name.new("Place name", "Feature code", "32", 67890.12, 56789.01)
122
-
123
- Rozi.write_nst(nst, "file_path.nst")
124
-
125
- Note, text in name search files (names and feature codes) cannot contain
126
- commas. There is no mechanism for escaping commas or substituting them with
127
- different symbols like in waypoint files.
@@ -1,23 +0,0 @@
1
-
2
- module Rozi
3
-
4
- ##
5
- # This class represents a name in an Ozi Explorer name database.
6
- #
7
- # @note The +name+, +lat+ and +lng+ fields must be set, or runtime errors will
8
- # be raised when attempting to write to file.
9
- #
10
- class Name
11
-
12
- attr_accessor :name, :feature_code, :zone, :lat, :lng
13
-
14
- def initialize(name=nil, feature_code=nil, zone=nil, lat=nil, lng=nil)
15
- @name = name
16
- @feature_code = feature_code
17
- @zone = zone
18
- @lat = lat
19
- @lng = lng
20
- end
21
- end
22
-
23
- end
@@ -1,43 +0,0 @@
1
-
2
- require "rozi/ozi_functions"
3
-
4
- module Rozi
5
-
6
- ##
7
- # A name search text (.nst) file is a text file that can be converted into a
8
- # name database used by Ozi Explorer's "name search" functionality. This class
9
- # represents such a file and can be written to disk using
10
- # {Rozi::NameSearchTextWriter}.
11
- #
12
- class NameSearchText
13
-
14
- attr_accessor :comment, :datum, :names, :latlng,
15
- :utm, :utm_zone, :hemisphere
16
-
17
- include OziFunctions
18
-
19
- def initialize
20
- @comment = ""
21
- @datum = "WGS 84"
22
- @names = []
23
-
24
- @latlng = true
25
- @utm = false
26
- @utm_zone = nil
27
- @hemisphere = nil
28
- end
29
-
30
- def <<(name)
31
- @names << name
32
- end
33
-
34
- def datum=(datum)
35
- if not datum_valid?(datum)
36
- fail ArgumentError, %(Invalid datum: "#{datum}")
37
- end
38
-
39
- @datum = datum
40
- end
41
- end
42
-
43
- end
@@ -1,71 +0,0 @@
1
-
2
- module Rozi
3
-
4
- ##
5
- # A class for writing {Rozi::NameSearchText} objects to files.
6
- #
7
- # @note Text in name search files (names and feature codes) cannot contain
8
- # commas. There is no mechanism for escaping commas or substituting them
9
- # with different symbols like in waypoint files.
10
- #
11
- class NameSearchTextWriter
12
-
13
- ##
14
- # Writes +nst+ to +file+.
15
- #
16
- # @param [Rozi::NameSearchText] nst
17
- # @param [File, StringIO] file an open file object
18
- #
19
- def write(nst, file)
20
- if nst.comment
21
- nst.comment.each_line { |line|
22
- file.write ";#{line.chomp}\n"
23
- }
24
- end
25
-
26
- file.write construct_first_line(nst) << "\n"
27
- file.write construct_second_line(nst) << "\n"
28
-
29
- nst.names.each { |name|
30
- file.write name_to_line(name) << "\n"
31
- }
32
-
33
- return nil
34
- end
35
-
36
- private
37
-
38
- def construct_first_line(nst)
39
- first_line = "#1,"
40
-
41
- if nst.utm
42
- first_line << "UTM,#{nst.utm_zone}"
43
-
44
- if nst.hemisphere
45
- first_line << ",#{nst.hemisphere}"
46
- end
47
- else
48
- first_line << ","
49
- end
50
-
51
- return first_line
52
- end
53
-
54
- def construct_second_line(nst)
55
- "#2,#{nst.datum}"
56
- end
57
-
58
- def name_to_line(name)
59
- if not name.name or not name.lat or not name.lng
60
- fail "name, lat and lng must be set!"
61
- end
62
-
63
- if name.name.include?(",") or name.feature_code.include?(",")
64
- fail ArgumentError, "Text cannot contain commas"
65
- end
66
-
67
- "#{name.name},#{name.feature_code},#{name.zone},#{name.lat},#{name.lng}"
68
- end
69
- end
70
-
71
- end
@@ -1,67 +0,0 @@
1
-
2
- require "rozi/ozi_functions"
3
-
4
- module Rozi
5
-
6
- ##
7
- # This class represents a Track in Ozi Explorer. It contains attributes
8
- # about the track's appearance as well as a list of track points.
9
- #
10
- class Track
11
- attr_accessor :points
12
-
13
- attr_reader :color
14
- attr_accessor :line_width, :description, :skip_value, :type,
15
- :fill_type, :fill_color
16
-
17
- DEFAULTS = {
18
- line_width: 2,
19
- color: 255,
20
- description: "",
21
- skip_value: 1,
22
- type: 0,
23
- fill_type: 0,
24
- fill_color: 0
25
- }
26
-
27
- include OziFunctions
28
-
29
- def initialize(args={})
30
- @points = args[:points] || []
31
-
32
- DEFAULTS.each_pair { |key, value| set(key, value) }
33
-
34
- args.each_pair { |key, value| set(key, value) }
35
- end
36
-
37
- def color=(color)
38
- @color = interpret_color(color)
39
- end
40
-
41
- ##
42
- # @return [Array] the attributes of the track as an Array
43
- #
44
- def attributes
45
- [@line_width, @color, @description, @skip_value,
46
- @type, @fill_type, @fill_color]
47
- end
48
-
49
- ##
50
- # Allows adding points to the track using the `<<` syntax.
51
- #
52
- def <<(point)
53
- @points << point
54
- end
55
-
56
- private
57
-
58
- def set(key, value)
59
- begin
60
- self.send(key.to_s() + "=", value)
61
- rescue NoMethodError
62
- fail ArgumentError, "Not a valid attribute: #{key}"
63
- end
64
- end
65
- end
66
-
67
- end
@@ -1,39 +0,0 @@
1
-
2
- module Rozi
3
-
4
- class TrackPoint
5
- attr_accessor :latitude, :longitude, :break, :altitude, :date,
6
- :date_string, :time_string
7
-
8
- DEFAULTS = {
9
- break: 0,
10
- altitude: -777,
11
- date: 0,
12
- date_string: "",
13
- time_string: ""
14
- }
15
-
16
- def initialize(args={})
17
- DEFAULTS.each_pair { |key, value| set(key, value) }
18
-
19
- args.each_pair { |key, value| set(key, value) }
20
- end
21
-
22
- def to_a
23
- [@latitude, @longitude, @break, @altitude,
24
- @date, @date_string, @time_string]
25
- end
26
-
27
- private
28
-
29
- def set(key, value)
30
- begin
31
- self.send(key.to_s() + "=", value)
32
- rescue NoMethodError
33
- fail ArgumentError, "Not a valid attribute: #{key}"
34
- end
35
- end
36
-
37
- end
38
-
39
- end
@@ -1,50 +0,0 @@
1
-
2
- require "rozi/ozi_functions"
3
-
4
- module Rozi
5
-
6
- class TrackWriter
7
-
8
- include OziFunctions
9
-
10
- ##
11
- # Writes the track to +file+ as an Ozi Explorer track file. The file
12
- # extension should be ".plt".
13
- #
14
- # @param [AddressKit::Ozi::Track] track
15
- # @param [File, String, #write] file
16
- #
17
- def write(track, file)
18
- file.write <<-TEXT.gsub(/^[ ]{8}/, "")
19
- OziExplorer Track Point File Version 2.1
20
- WGS 84
21
- Altitude is in Feet
22
- Reserved 3
23
- TEXT
24
-
25
- file.write(track_attributes_to_text(track))
26
- file.write("\n")
27
-
28
- file.write(track.points.count.to_s() + "\n")
29
-
30
- track.points.each { |point|
31
- file.write(track_point_to_text(point))
32
- file.write("\n")
33
- }
34
- end
35
-
36
- def track_attributes_to_text(track)
37
- attrs = track.attributes
38
- attrs.map! { |item| item.is_a?(String) ? escape_text(item) : item }
39
-
40
- "0,%d,%d,%s,%d,%d,%d,%d" % attrs
41
- end
42
-
43
- def track_point_to_text(point)
44
- p = point.to_a()
45
-
46
- " %.6f,%.6f,%d,%.1f,%.7f,%s,%s" % p
47
- end
48
- end
49
-
50
- end
@@ -1,90 +0,0 @@
1
-
2
- require "rozi/ozi_functions"
3
-
4
- module Rozi
5
-
6
- ##
7
- # Represents a waypoint in Ozi Explorer.
8
- #
9
- class Waypoint
10
-
11
- include OziFunctions
12
-
13
- DISPLAY_FORMATS = {
14
- :number_only => 0,
15
- :name_only => 1,
16
- :number_and_name => 2,
17
- :name_with_dot => 3,
18
- :name_with_symbol => 4,
19
- :symbol_only => 5,
20
- :comment_with_symbol => 6,
21
- :man_overboard => 7,
22
- :marker => 8
23
- }
24
-
25
- attr_accessor :number, :name, :latitude, :longitude, :date, :symbol,
26
- :display_format, :description, :pointer_direction, :altitude,
27
- :font_size, :font_style, :symbol_size
28
-
29
- attr_reader :fg_color, :bg_color
30
-
31
- def initialize(args={})
32
- @number = -1
33
- @name = ""
34
- @latitude = 0.0
35
- @longitude = 0.0
36
- @date = nil
37
- @symbol = 0
38
- @display_format = :name_with_dot
39
- @fg_color = 0
40
- @bg_color = 65535
41
- @description = ""
42
- @pointer_direction = 0
43
- @altitude = -777
44
- @font_size = 6
45
- @font_style = 0
46
- @symbol_size = 17
47
-
48
- args.each_pair { |key, value|
49
- begin
50
- self.send(key.to_s() + "=", value)
51
- rescue NoMethodError
52
- fail ArgumentError, "Not a valid attribute: #{key}"
53
- end
54
- }
55
- end
56
-
57
- def to_a
58
- [@number,
59
- @name,
60
- @latitude,
61
- @longitude,
62
- @date,
63
- @symbol,
64
- DISPLAY_FORMATS[@display_format],
65
- @fg_color,
66
- @bg_color,
67
- @description,
68
- @pointer_direction,
69
- @altitude,
70
- @font_size,
71
- @font_style,
72
- @symbol_size]
73
- end
74
-
75
- ##
76
- # Sets the foreground color. Accepts a hex string or a decimal value.
77
- #
78
- def fg_color=(color)
79
- @fg_color = interpret_color(color)
80
- end
81
-
82
- ##
83
- # Sets the background color. Accepts a hex string or a decimal value.
84
- #
85
- def bg_color=(color)
86
- @bg_color = interpret_color(color)
87
- end
88
- end
89
-
90
- end