rozi 0.0.7 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +255 -0
- data/lib/rozi.rb +6 -3
- data/lib/rozi/file_wrapper_base.rb +52 -0
- data/lib/rozi/module_functions.rb +19 -69
- data/lib/rozi/name_search.rb +176 -0
- data/lib/rozi/{ozi_functions.rb → shared.rb} +36 -9
- data/lib/rozi/tracks.rb +170 -0
- data/lib/rozi/version.rb +1 -1
- data/lib/rozi/waypoints.rb +315 -0
- data/test/rozi/file_wrapper_base_test.rb +29 -0
- data/test/rozi/module_functions_test.rb +11 -72
- data/test/rozi/name_search_test.rb +248 -0
- data/test/rozi/{ozi_functions_test.rb → shared_test.rb} +25 -5
- data/test/rozi/tracks_test.rb +105 -0
- data/test/rozi/waypoints_test.rb +268 -0
- data/test/test_data/expected_output_1.nst +6 -0
- data/{test_data → test/test_data}/expected_output_1.plt +9 -9
- data/{test_data → test/test_data}/expected_output_1.wpt +7 -7
- data/test/test_data/input_1.wpt +6 -0
- metadata +128 -34
- data/README.rdoc +0 -127
- data/lib/rozi/name.rb +0 -23
- data/lib/rozi/name_search_text.rb +0 -43
- data/lib/rozi/name_search_text_writer.rb +0 -71
- data/lib/rozi/track.rb +0 -67
- data/lib/rozi/track_point.rb +0 -39
- data/lib/rozi/track_writer.rb +0 -50
- data/lib/rozi/waypoint.rb +0 -90
- data/lib/rozi/waypoint_writer.rb +0 -38
- data/test/rozi/name_search_text_test.rb +0 -28
- data/test/rozi/name_search_text_writer_test.rb +0 -114
- data/test/rozi/track_point_test.rb +0 -32
- data/test/rozi/track_test.rb +0 -25
- data/test/rozi/track_writer_test.rb +0 -62
- data/test/rozi/waypoint_test.rb +0 -31
- data/test/rozi/waypoint_writer_test.rb +0 -60
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3ccf96a25f5bebe5718bedc9c7f067e0fbc32c0a
|
4
|
+
data.tar.gz: e400fe4c0b3a95ce13b1d5c691d0001c5914a71d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2b407b84881ab7bf52db3fbefb684a8bcab2472ea8cab3f3c666800efcf0da9fb46efbbd21822cedb18d1e25ad167730e99429249e6596b98b8c017546112649
|
7
|
+
data.tar.gz: 0641fde6d7cde525057f6c9ed56f23d01487282ddddfee01c735965e438a16e06c1cd92346a7db7afe007eea0c8000495471a4c08eaa568a8448fe58c96633c4
|
data/README.md
ADDED
@@ -0,0 +1,255 @@
|
|
1
|
+
|
2
|
+
[![Rubygems][rubygems-badge]][rubygems]
|
3
|
+
[![API Documentation][yard-badge]][docs]
|
4
|
+
|
5
|
+
# Rozi
|
6
|
+
|
7
|
+
Rozi is a Ruby gem for working with all Ozi Explorer file formats. Currently
|
8
|
+
the implemented functionality is:
|
9
|
+
|
10
|
+
- Creating and writing waypoints to files (.wpt)
|
11
|
+
- Reading waypoints from files
|
12
|
+
- Creating and writing tracks to files (.plt)
|
13
|
+
- Creating Name Search Text files (.nst)
|
14
|
+
|
15
|
+
## Files
|
16
|
+
|
17
|
+
Text based file formats read by Ozi Explorer should be encoded as ISO-8859-1 and
|
18
|
+
use CRLF line endings (`\r\n`). Rozi will handle this for you, as long as you
|
19
|
+
use the methods that accept file paths. Rozi internally uses the
|
20
|
+
[`Rozi.open_file`][Rozi.open_file] function, which creates and returns (or
|
21
|
+
yields) a `File` instance with the correct encoding settings for both reading
|
22
|
+
and writing Ozi Explorer file formats.
|
23
|
+
|
24
|
+
Example:
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
Rozi.open_file("file_path.wpt", "w") { |file|
|
28
|
+
file.write("Østre aker\n") # Writes "Østre aker\r\n" in ISO-8859-1
|
29
|
+
}
|
30
|
+
|
31
|
+
Rozi.open_file("file_path.wpt", "r") { |file|
|
32
|
+
file.read # Reads "Østre aker\n" as UTF-8
|
33
|
+
}
|
34
|
+
```
|
35
|
+
|
36
|
+
## Datums
|
37
|
+
|
38
|
+
Rozi performs input validation on datums. If you try to set the datum property
|
39
|
+
of an object to a datum that isn't supported by Ozi Explorer, Rozi will raise an
|
40
|
+
exception. The constant [`Rozi::DATUMS`][Rozi::DATUMS] contains all datums that
|
41
|
+
Ozi Explorer supports.
|
42
|
+
|
43
|
+
## Colors
|
44
|
+
|
45
|
+
Any time you set colors in Rozi, you can either use the three-byte integer
|
46
|
+
representation that Ozi Explorer expects, or you can use a hex string like
|
47
|
+
"RRGGBB" and Rozi will convert it for you. Example:
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
# Identical
|
51
|
+
Rozi::Waypoint.new(bg_color: "ABCDEF")
|
52
|
+
Rozi::Waypoint.new(bg_color: 0xEFCDAB)
|
53
|
+
Rozi::Waypoint.new(bg_color: 15715755)
|
54
|
+
```
|
55
|
+
|
56
|
+
## Creating waypoint files
|
57
|
+
|
58
|
+
Rozi defines a `WaypointFile` class, which mimics the standard library `File`
|
59
|
+
class. The waypoint file class has two important methods:
|
60
|
+
|
61
|
+
- [`#write_properties`][Rozi::WaypointFile#write_properties]
|
62
|
+
- [`#write_waypoint`][Rozi::WaypointFile#write_waypoint]
|
63
|
+
|
64
|
+
The waypoint file "properties" are the file-wide data contained in the top 4
|
65
|
+
lines of the file. In the case of waypoint files, that's just the waypoint file
|
66
|
+
version and the geodetic datum.
|
67
|
+
|
68
|
+
To write file properties, the file *must be empty*. Here's an example:
|
69
|
+
|
70
|
+
```ruby
|
71
|
+
properties = Rozi::WaypointFileProperties.new(version: "1.1", datum: "WGS 84")
|
72
|
+
|
73
|
+
wpt = Rozi::WaypointFile.open("/path/to/file.wpt", "w")
|
74
|
+
wpt.write_properties(properties)
|
75
|
+
```
|
76
|
+
|
77
|
+
The properties displayed here happens to be the defaults for Rozi, so you can
|
78
|
+
skip this step if they work for you. When writing the first waypoint, the
|
79
|
+
default properties will be added first.
|
80
|
+
|
81
|
+
Here's how you write waypoints:
|
82
|
+
|
83
|
+
```ruby
|
84
|
+
wpt = Rozi::WaypointFile.open("/path/to/file.wpt", "w")
|
85
|
+
|
86
|
+
wpt.write_waypoint Rozi::Waypoint.new(
|
87
|
+
name: "Foo", latitude: 12.34, longitude: 56.78
|
88
|
+
)
|
89
|
+
wpt.write_waypoint Rozi::Waypoint.new(
|
90
|
+
name: "Bar", latitude: 12.34, longitude: 56.78
|
91
|
+
)
|
92
|
+
|
93
|
+
wpt.close
|
94
|
+
```
|
95
|
+
|
96
|
+
Alternatively, you can use a block for `WaypointFile.open`, just like with
|
97
|
+
`File.open`:
|
98
|
+
|
99
|
+
```ruby
|
100
|
+
Rozi::WaypointFile.open("/path/to/file.wpt", "w") { |wpt|
|
101
|
+
# ...
|
102
|
+
}
|
103
|
+
```
|
104
|
+
|
105
|
+
Rozi also provides the function `Rozi.write_waypoints` for opening a file,
|
106
|
+
writing properties, writing waypoints and closing the file in one step. Example:
|
107
|
+
|
108
|
+
```ruby
|
109
|
+
waypoints = [
|
110
|
+
Rozi::Waypoint.new(name: "Foo", latitude: 12.34, longitude: 56.78),
|
111
|
+
Rozi::Waypoint.new(name: "Bar", latitude: 12.34, longitude: 56.78)
|
112
|
+
]
|
113
|
+
|
114
|
+
Rozi.write_waypoints(waypoints, "/path/to/file.wpt", datum: "WGS 84")
|
115
|
+
```
|
116
|
+
|
117
|
+
WGS 84 is the default datum, so specifying it is unnecessary, but it illustrates
|
118
|
+
how waypoint file properties can be set using keyword arguments.
|
119
|
+
|
120
|
+
See:
|
121
|
+
|
122
|
+
- [`Rozi.write_waypoints`][Rozi.write_waypoints]
|
123
|
+
- [`Rozi::WaypointFileProperties`][Rozi::WaypointFileProperties]
|
124
|
+
- [`Rozi::Waypoint`][Rozi::Waypoint]
|
125
|
+
- [`Rozi::WaypointFile`][Rozi::WaypointFile]
|
126
|
+
|
127
|
+
## Reading waypoint files
|
128
|
+
|
129
|
+
Reading waypoints from waypoint files is even easier than writing them:
|
130
|
+
|
131
|
+
```ruby
|
132
|
+
wpt = Rozi::WaypointFile.open("/path/to/file.wpt", "r")
|
133
|
+
|
134
|
+
properties = wpt.read_properties
|
135
|
+
|
136
|
+
# The most basic reading method
|
137
|
+
first_waypoint = wpt.read_waypoint
|
138
|
+
second_waypoint = wpt.read_waypoint
|
139
|
+
|
140
|
+
# Iterating over all the waypoints in the file
|
141
|
+
wpt.each_waypoint { |waypoint|
|
142
|
+
puts "#{waypoint.name} - #{waypoint.latitude},#{waypoint.longitude}"
|
143
|
+
}
|
144
|
+
|
145
|
+
# Reading all waypoints into an array
|
146
|
+
waypoints = wpt.each_waypoint.to_a
|
147
|
+
```
|
148
|
+
|
149
|
+
See:
|
150
|
+
|
151
|
+
- [`Rozi::WaypointFile`][Rozi::WaypointFile]
|
152
|
+
|
153
|
+
## Creating track files
|
154
|
+
|
155
|
+
Creating track files is very similar to creating waypoint files. Instead of the
|
156
|
+
`WaypointFile` class, you use the `TrackFile` class. Instead of writing
|
157
|
+
`Waypoint` objects, you write `TrackPoint` objects. Instead of using
|
158
|
+
`WaypointFileProperties`, you use `TrackProperties`.
|
159
|
+
|
160
|
+
One thing to note about track files is that the file-wide properties contain a
|
161
|
+
lot more information. They contain the track color, track width, track
|
162
|
+
description and much more. See [`Rozi::TrackProperties`][Rozi::TrackProperties]
|
163
|
+
for more information.
|
164
|
+
|
165
|
+
Rozi also has a `Rozi.write_waypoints` equivalent for writing tracks:
|
166
|
+
|
167
|
+
```ruby
|
168
|
+
track_points = [
|
169
|
+
Rozi::TrackPoint(latitude: 12.34, longitude: 56.78),
|
170
|
+
Rozi::TrackPoint(latitude: 23.45, longitude: 67.89)
|
171
|
+
]
|
172
|
+
|
173
|
+
Rozi.write_track(track_points, "/path/to/file.plt", color: "FF0000")
|
174
|
+
```
|
175
|
+
|
176
|
+
See:
|
177
|
+
|
178
|
+
- [`Rozi.write_track`][Rozi.write_track]
|
179
|
+
- [`Rozi::TrackProperties`][Rozi::TrackProperties]
|
180
|
+
- [`Rozi::TrackPoint`][Rozi::TrackPoint]
|
181
|
+
- [`Rozi::TrackFile`][Rozi::TrackFile]
|
182
|
+
|
183
|
+
## Creating name search text files
|
184
|
+
|
185
|
+
See [Ozi Explorer: Name Search][name-search] for information about Name Search.
|
186
|
+
An NST file has to be converted into a Name Database using the ["Name Search
|
187
|
+
Creator"][name-search-creator] tool before they can be used by Ozi Explorer.
|
188
|
+
|
189
|
+
Rozi aims to be consistent and intuitive, so creating NST files is pretty much
|
190
|
+
the exact same process as creating waypoint files and track files:
|
191
|
+
|
192
|
+
```ruby
|
193
|
+
properties = Rozi::NameSearchProperties.new(
|
194
|
+
datum: "WGS 84", comment: "Generated by Rozi!"
|
195
|
+
)
|
196
|
+
|
197
|
+
nst = Rozi::NameSearchTextFile.open("/path/to/file.nst", "w")
|
198
|
+
|
199
|
+
nst.write_properties(properties)
|
200
|
+
nst.write_name Rozi::Name.new(name: "Foo", latitude: 12.34, longitude: 56.78)
|
201
|
+
nst.write_name Rozi::Name.new(name: "Bar", latitude: 23.45, longitude: 67.89)
|
202
|
+
|
203
|
+
nst.close
|
204
|
+
```
|
205
|
+
|
206
|
+
Or using the module function:
|
207
|
+
|
208
|
+
```ruby
|
209
|
+
names = [
|
210
|
+
Rozi::Name.new(name: "Foo", latitude: 12.34, longitude: 56.78),
|
211
|
+
Rozi::Name.new(name: "Bar", latitude: 23.45, longitude: 67.89)
|
212
|
+
]
|
213
|
+
|
214
|
+
Rozi.write_nst(
|
215
|
+
names, "/path/to/file.nst", datum: "WGS 84", comment: "Generated by Rozi!"
|
216
|
+
)
|
217
|
+
```
|
218
|
+
|
219
|
+
See:
|
220
|
+
|
221
|
+
- [`Rozi.write_nst`][Rozi.write_nst]
|
222
|
+
- [`Rozi::NameSearchProperties`][Rozi::NameSearchProperties]
|
223
|
+
- [`Rozi::Name`][Rozi::Name]
|
224
|
+
- [`Rozi::NameSearchFile`][Rozi::NameSearchFile]
|
225
|
+
|
226
|
+
|
227
|
+
|
228
|
+
[rubygems]: https://rubygems.org/gems/rozi
|
229
|
+
[docs]: http://www.rubydoc.info/gems/rozi
|
230
|
+
[rubygems-badge]: https://badge.fury.io/rb/rozi.svg
|
231
|
+
[yard-badge]: http://b.repl.ca/v1/yard-docs-blue.png
|
232
|
+
|
233
|
+
[name-search]: http://www.oziexplorer3.com/namesearch/wnamesrch.html
|
234
|
+
[name-search-creator]: http://www.oziexplorer3.com/namesearch/namesearch_setup.exe
|
235
|
+
|
236
|
+
[Rozi.open_file]: http://www.rubydoc.info/gems/rozi/Rozi#open_file-class_method
|
237
|
+
|
238
|
+
[Rozi::DATUMS]: http://www.rubydoc.info/gems/rozi/Rozi#DATUMS-constant
|
239
|
+
|
240
|
+
[Rozi::WaypointFile#write_properties]: http://www.rubydoc.info/gems/rozi/Rozi/WaypointFile#write_properties-instance_method
|
241
|
+
[Rozi::WaypointFile#write_waypoint]: http://www.rubydoc.info/gems/rozi/Rozi/WaypointFile#write_waypoint-instance_method
|
242
|
+
[Rozi.write_waypoints]: http://www.rubydoc.info/gems/rozi/Rozi#write_waypoints-class_method
|
243
|
+
[Rozi::WaypointFileProperties]: http://www.rubydoc.info/gems/rozi/Rozi/WaypointFileProperties
|
244
|
+
[Rozi::Waypoint]: http://www.rubydoc.info/gems/rozi/Rozi/Waypoint
|
245
|
+
[Rozi::WaypointFile]: http://www.rubydoc.info/gems/rozi/Rozi/WaypointFile
|
246
|
+
|
247
|
+
[Rozi.write_track]: http://www.rubydoc.info/gems/rozi/Rozi#write_track-class_method
|
248
|
+
[Rozi::TrackProperties]: http://www.rubydoc.info/gems/rozi/Rozi/TrackProperties
|
249
|
+
[Rozi::TrackPoint]: http://www.rubydoc.info/gems/rozi/Rozi/TrackPoint
|
250
|
+
[Rozi::TrackFile]: http://www.rubydoc.info/gems/rozi/Rozi/TrackFile
|
251
|
+
|
252
|
+
[Rozi.write_nst]: http://www.rubydoc.info/gems/rozi/Rozi#write_nst-class_method
|
253
|
+
[Rozi::NameSearchProperties]: http://www.rubydoc.info/gems/rozi/Rozi/NameSearchProperties
|
254
|
+
[Rozi::Name]: http://www.rubydoc.info/gems/rozi/Rozi/Name
|
255
|
+
[Rozi::NameSearchFile]: http://www.rubydoc.info/gems/rozi/Rozi/NameSearchFile
|
data/lib/rozi.rb
CHANGED
@@ -1,13 +1,16 @@
|
|
1
1
|
|
2
|
+
require "datastruct"
|
3
|
+
|
2
4
|
module Rozi
|
5
|
+
extend self
|
3
6
|
|
4
|
-
|
7
|
+
ROOT = File.expand_path("../", File.dirname(__FILE__))
|
5
8
|
|
6
9
|
##
|
7
10
|
# Loads all ruby files under lib/rozi. Called automatically when requiring
|
8
11
|
# "rozi.rb".
|
9
12
|
#
|
10
|
-
def
|
13
|
+
def require_lib
|
11
14
|
this_dir = File.absolute_path(File.dirname(__FILE__))
|
12
15
|
source_files = Dir[File.join(this_dir, "rozi/**/*.rb")]
|
13
16
|
|
@@ -17,4 +20,4 @@ module Rozi
|
|
17
20
|
end
|
18
21
|
end
|
19
22
|
|
20
|
-
Rozi.require_lib
|
23
|
+
Rozi.require_lib
|
@@ -0,0 +1,52 @@
|
|
1
|
+
|
2
|
+
module Rozi
|
3
|
+
##
|
4
|
+
# Base class for classes that wrap file objects
|
5
|
+
#
|
6
|
+
class FileWrapperBase
|
7
|
+
attr_accessor :file
|
8
|
+
|
9
|
+
##
|
10
|
+
# Behaves like +File#open+, but returns/yields a {WaypointFile} object
|
11
|
+
#
|
12
|
+
def self.open(file_path, mode="r")
|
13
|
+
file = Rozi.open_file(file_path, mode)
|
14
|
+
wrapper = self.new(file)
|
15
|
+
|
16
|
+
if block_given?
|
17
|
+
begin
|
18
|
+
return yield wrapper
|
19
|
+
ensure
|
20
|
+
wrapper.close unless wrapper.closed?
|
21
|
+
end
|
22
|
+
else
|
23
|
+
return wrapper
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def initialize(file)
|
28
|
+
@file = file
|
29
|
+
end
|
30
|
+
|
31
|
+
##
|
32
|
+
# @return [nil]
|
33
|
+
#
|
34
|
+
def close
|
35
|
+
@file.close
|
36
|
+
end
|
37
|
+
|
38
|
+
##
|
39
|
+
# @return [Boolean]
|
40
|
+
#
|
41
|
+
def closed?
|
42
|
+
@file.closed?
|
43
|
+
end
|
44
|
+
|
45
|
+
##
|
46
|
+
# @return [nil]
|
47
|
+
#
|
48
|
+
def rewind
|
49
|
+
@file.rewind
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -1,30 +1,37 @@
|
|
1
1
|
|
2
2
|
module Rozi
|
3
|
-
|
4
3
|
module_function
|
5
4
|
|
6
5
|
##
|
7
|
-
# Opens a file
|
8
|
-
#
|
6
|
+
# Opens a file with the correct settings for usage with Ozi Explorer
|
7
|
+
#
|
8
|
+
# The file instance has UTF-8 internal encoding and ISO-8859-1 external
|
9
|
+
# encoding. When writing, all line endings are converted to CRLF. When
|
10
|
+
# reading, all line endings are converted to LF.
|
9
11
|
#
|
10
|
-
# @overload
|
12
|
+
# @overload open_file(path, mode="r")
|
11
13
|
#
|
12
14
|
# @param [String] path
|
13
15
|
# @return [File]
|
14
16
|
#
|
15
|
-
# @overload
|
17
|
+
# @overload open_file(path, mode="r")
|
16
18
|
#
|
17
|
-
# Can be called with a block, just file +File.open+.
|
19
|
+
# Can be called with a block, just like file +File.open+.
|
18
20
|
#
|
19
21
|
# @yieldparam [File] file
|
20
22
|
# @return [void]
|
21
23
|
#
|
22
|
-
def
|
23
|
-
file = File.open(path,
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
24
|
+
def open_file(path, mode="r")
|
25
|
+
file = File.open(path, mode)
|
26
|
+
opts = {undef: :replace, replace: "?"}
|
27
|
+
|
28
|
+
if mode.include? "w"
|
29
|
+
opts[:crlf_newline] = true
|
30
|
+
else
|
31
|
+
opts[:universal_newline] = true
|
32
|
+
end
|
33
|
+
|
34
|
+
file.set_encoding("ISO-8859-1", "UTF-8", opts)
|
28
35
|
|
29
36
|
if block_given?
|
30
37
|
yield file
|
@@ -35,61 +42,4 @@ module Rozi
|
|
35
42
|
return file
|
36
43
|
end
|
37
44
|
end
|
38
|
-
|
39
|
-
##
|
40
|
-
# Writes an array of waypoints to a file.
|
41
|
-
#
|
42
|
-
# @see Rozi::WaypointWriter#write
|
43
|
-
#
|
44
|
-
def write_waypoints(waypoints, file)
|
45
|
-
@@wpt_writer ||= WaypointWriter.new
|
46
|
-
|
47
|
-
if file.is_a? String
|
48
|
-
open_file_for_writing(file) { |f|
|
49
|
-
@@wpt_writer.write(waypoints, f)
|
50
|
-
}
|
51
|
-
else
|
52
|
-
@@wpt_writer.write(waypoints, file)
|
53
|
-
end
|
54
|
-
|
55
|
-
return nil
|
56
|
-
end
|
57
|
-
|
58
|
-
##
|
59
|
-
# Writes a track to a file.
|
60
|
-
#
|
61
|
-
# @see Rozi::TrackWriter#write
|
62
|
-
#
|
63
|
-
def write_track(track, file)
|
64
|
-
@@track_writer ||= TrackWriter.new
|
65
|
-
|
66
|
-
if file.is_a? String
|
67
|
-
open_file_for_writing(file) { |f|
|
68
|
-
@@track_writer.write(track, f)
|
69
|
-
}
|
70
|
-
else
|
71
|
-
@@track_writer.write(track, file)
|
72
|
-
end
|
73
|
-
|
74
|
-
return nil
|
75
|
-
end
|
76
|
-
|
77
|
-
##
|
78
|
-
# Writes a {Rozi::NameSearchText} object to a file.
|
79
|
-
#
|
80
|
-
# @see Rozi::NameSearchTextWriter#write
|
81
|
-
#
|
82
|
-
def write_nst(nst, file)
|
83
|
-
@@nst_writer ||= NameSearchTextWriter.new
|
84
|
-
|
85
|
-
if file.is_a? String
|
86
|
-
open_file_for_writing(file) { |f|
|
87
|
-
@@nst_writer.write(nst, f)
|
88
|
-
}
|
89
|
-
else
|
90
|
-
@@nst_writer.write(nst, file)
|
91
|
-
end
|
92
|
-
|
93
|
-
return nil
|
94
|
-
end
|
95
45
|
end
|