geoprojection 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b21a5ce188fe4283f22a8ffeae14392942981c101d010f5ae9e9d0f0a67d410e
4
+ data.tar.gz: 76ac0d07a358785a9505cbcfe4830181b6fe4d7a3b3d923ccf512b13ea906dae
5
+ SHA512:
6
+ metadata.gz: 9979de234b5ac3661a96561a5e9b836b11351e82d60dd1aece15726a06a1235537324f9baaca026412d7c03712bae235b0ff50951bb0565897e45b717d55f6e1
7
+ data.tar.gz: 3f572c2025e219ceddb69f6b41e5a87ea84b71ed1ea8a23b3f7c4ab5848a812338af1ee2a34bf3e4b89402bbc3541a6db4461da28002d570bb1b6a44a4e3aea4
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,6 @@
1
+ AllCops:
2
+ NewCops: enable
3
+
4
+ Metrics/BlockLength:
5
+ Exclude:
6
+ - 'spec/**/*_spec.rb'
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.6.9
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in geoprojection.gemspec
6
+ gemspec
7
+
8
+ gem 'rake', '~> 13.0'
9
+
10
+ gem 'devpack', '~> 0.4.0'
11
+ gem 'gnuplot', '~> 2.6'
12
+ gem 'rspec', '~> 3.0'
13
+ gem 'rspec-its', '~> 1.3'
14
+ gem 'rubocop', '~> 1.28'
15
+ gem 'rubocop-rake', '~> 0.6.0'
16
+ gem 'rubocop-rspec', '~> 2.10'
17
+ gem 'strong_versions', '~> 0.4.5'
data/Gemfile.lock ADDED
@@ -0,0 +1,77 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ geoprojection (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.2)
10
+ concurrent-ruby (1.1.10)
11
+ devpack (0.4.0)
12
+ diff-lcs (1.5.0)
13
+ gnuplot (2.6.2)
14
+ i18n (1.10.0)
15
+ concurrent-ruby (~> 1.0)
16
+ paint (2.2.1)
17
+ parallel (1.22.1)
18
+ parser (3.1.2.0)
19
+ ast (~> 2.4.1)
20
+ rainbow (3.1.1)
21
+ rake (13.0.6)
22
+ regexp_parser (2.3.1)
23
+ rexml (3.2.5)
24
+ rspec (3.11.0)
25
+ rspec-core (~> 3.11.0)
26
+ rspec-expectations (~> 3.11.0)
27
+ rspec-mocks (~> 3.11.0)
28
+ rspec-core (3.11.0)
29
+ rspec-support (~> 3.11.0)
30
+ rspec-expectations (3.11.0)
31
+ diff-lcs (>= 1.2.0, < 2.0)
32
+ rspec-support (~> 3.11.0)
33
+ rspec-its (1.3.0)
34
+ rspec-core (>= 3.0.0)
35
+ rspec-expectations (>= 3.0.0)
36
+ rspec-mocks (3.11.1)
37
+ diff-lcs (>= 1.2.0, < 2.0)
38
+ rspec-support (~> 3.11.0)
39
+ rspec-support (3.11.0)
40
+ rubocop (1.28.2)
41
+ parallel (~> 1.10)
42
+ parser (>= 3.1.0.0)
43
+ rainbow (>= 2.2.2, < 4.0)
44
+ regexp_parser (>= 1.8, < 3.0)
45
+ rexml
46
+ rubocop-ast (>= 1.17.0, < 2.0)
47
+ ruby-progressbar (~> 1.7)
48
+ unicode-display_width (>= 1.4.0, < 3.0)
49
+ rubocop-ast (1.17.0)
50
+ parser (>= 3.1.1.0)
51
+ rubocop-rake (0.6.0)
52
+ rubocop (~> 1.0)
53
+ rubocop-rspec (2.10.0)
54
+ rubocop (~> 1.19)
55
+ ruby-progressbar (1.11.0)
56
+ strong_versions (0.4.5)
57
+ i18n (>= 0.5)
58
+ paint (~> 2.0)
59
+ unicode-display_width (2.1.0)
60
+
61
+ PLATFORMS
62
+ x86_64-linux
63
+
64
+ DEPENDENCIES
65
+ devpack (~> 0.4.0)
66
+ geoprojection!
67
+ gnuplot (~> 2.6)
68
+ rake (~> 13.0)
69
+ rspec (~> 3.0)
70
+ rspec-its (~> 1.3)
71
+ rubocop (~> 1.28)
72
+ rubocop-rake (~> 0.6.0)
73
+ rubocop-rspec (~> 2.10)
74
+ strong_versions (~> 0.4.5)
75
+
76
+ BUNDLED WITH
77
+ 2.3.11
data/Makefile ADDED
@@ -0,0 +1,5 @@
1
+ .PHONY: test
2
+ test:
3
+ bundle exec rspec
4
+ bundle exec rubocop
5
+ bundle exec strong_versions
data/README.md ADDED
@@ -0,0 +1,32 @@
1
+ # Geoprojection
2
+
3
+ Toolkit for translating distances (kilometers) from co-ordinates (latitude, longitude) onto geographically-precise (within reason) projections.
4
+
5
+ ## Installation
6
+
7
+ Install the gem and add to the application's Gemfile by executing:
8
+
9
+ $ bundle add geoprojection
10
+
11
+ If bundler is not being used to manage dependencies, install the gem by executing:
12
+
13
+ $ gem install geoprojection
14
+
15
+ ## Usage
16
+
17
+ ### Ellipse
18
+
19
+ Provide a center point (latitude, longitude) and a distance (kilometers) to calculate a projected ellipse at the given coordinates. An array of `[latitude, longitude]` polygon points is provided.
20
+
21
+ The default number of points is `36`. This can be overridden with the `points` parameter to `Geoprojection::Ellipse.new`.
22
+
23
+ ```ruby
24
+ ellipse = Geoprojection::Ellipse.new(latitude: 50.8169, longitude: 0.1367, distance: 10, points: 36)
25
+ ellipse.points
26
+ ```
27
+
28
+ The actual returned points will be N+1, as the start and end point are identical to provide a complete polygon.
29
+
30
+ ## Contributing
31
+
32
+ Make changes, run `make test`, create a pull request.
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Geoprojection
4
+ # Elliptical projection of a center point (lat, long) with a provided distance from the center.
5
+ class Ellipse
6
+ EQUATOR_KM_PER_LATITUDE_DEGREE = 110.567
7
+ EQUATOR_KM_PER_LONGITUDE_DEGREE = 111.321
8
+ DEGREES_PER_RADIAN = Math::PI / 180
9
+
10
+ def initialize(latitude:, longitude:, distance:, points: 36)
11
+ @latitude = latitude
12
+ @longitude = longitude
13
+ @distance = distance
14
+ @points = points
15
+ end
16
+
17
+ def points
18
+ # Create a complete polygon by joining the last and first points.
19
+ projected_points + [projected_points.first]
20
+ end
21
+
22
+ private
23
+
24
+ def projected_points
25
+ @projected_points ||= @points.times.map do |index|
26
+ theta = step * index
27
+ [derived_x(theta), derived_y(theta)]
28
+ end
29
+ end
30
+
31
+ def derived_x(theta)
32
+ @longitude + (DEGREES_PER_RADIAN * @distance * longitude_distortion * Math.cos(DEGREES_PER_RADIAN * theta))
33
+ end
34
+
35
+ def derived_y(theta)
36
+ @latitude + (DEGREES_PER_RADIAN * @distance * latitude_distortion * Math.sin(DEGREES_PER_RADIAN * theta))
37
+ end
38
+
39
+ def step
40
+ @step ||= 360.0 / @points
41
+ end
42
+
43
+ def longitude_distortion
44
+ @longitude_distortion ||= 1 / (EQUATOR_KM_PER_LONGITUDE_DEGREE * Math.cos(DEGREES_PER_RADIAN * @latitude))
45
+ end
46
+
47
+ def latitude_distortion
48
+ @latitude_distortion ||= 1 / (EQUATOR_KM_PER_LATITUDE_DEGREE / @latitude)
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Geoprojection
4
+ VERSION = '0.1.0'
5
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'geoprojection/version'
4
+ require_relative 'geoprojection/ellipse'
5
+
6
+ module Geoprojection
7
+ class Error < StandardError; end
8
+ end
@@ -0,0 +1,4 @@
1
+ module Geoprojection
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: geoprojection
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Bob Farrell
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-05-11 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Write a longer description or delete this line.
14
+ email:
15
+ - git@bob.frl
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".rspec"
21
+ - ".rubocop.yml"
22
+ - ".ruby-version"
23
+ - Gemfile
24
+ - Gemfile.lock
25
+ - Makefile
26
+ - README.md
27
+ - Rakefile
28
+ - lib/geoprojection.rb
29
+ - lib/geoprojection/ellipse.rb
30
+ - lib/geoprojection/version.rb
31
+ - sig/geoprojection.rbs
32
+ homepage: https://github.com/bobf/geoprojection
33
+ licenses: []
34
+ metadata:
35
+ homepage_uri: https://github.com/bobf/geoprojection
36
+ source_code_uri: https://github.com/bobf/geoprojection
37
+ changelog_uri: https://github.com/bobf/geoprojection
38
+ rubygems_mfa_required: 'true'
39
+ post_install_message:
40
+ rdoc_options: []
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 2.6.0
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ requirements: []
54
+ rubygems_version: 3.0.3.1
55
+ signing_key:
56
+ specification_version: 4
57
+ summary: Write a short summary, because RubyGems requires one.
58
+ test_files: []