map_print 0.1.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6dab073cc345466b64e2a4c61f06bc08edc4604b
4
+ data.tar.gz: b4c5678c67565e3372759c90b10becb8ab25f961
5
+ SHA512:
6
+ metadata.gz: bc8bfa8a173e93068ece013326b663c7f12e828bb6a9f43afb35ca4f4ae7fadb240b364a503a2ad10da372ed2069485005e15b860a6c3fd30725749e30a74d0f
7
+ data.tar.gz: 9c250065b686fb6c121ad5aba9a2fe3655f7577ed53baad3cdd3bd58d7ed9ae61753a5ef864c790fe9dbfbe6f9ffa8ade5172b56e07fc1100c5ef24b307c84e6
data/.gitignore ADDED
@@ -0,0 +1,35 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /doc/
21
+ /rdoc/
22
+
23
+ ## Environment normalisation:
24
+ /.bundle/
25
+ /vendor/bundle
26
+ /lib/bundler/man/
27
+
28
+ # for a library or gem, you might want to ignore these files since the code is
29
+ # intended to run in multiple environments; otherwise, check them in:
30
+ # Gemfile.lock
31
+ # .ruby-version
32
+ # .ruby-gemset
33
+
34
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
35
+ .rvmrc
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ map-print
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.2.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in map_print.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,32 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ map_print (0.1.0)
5
+ geo-distance (~> 0.1)
6
+ mini_magick (~> 4.3)
7
+ prawn (~> 2.0)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ geo-distance (0.1.2)
13
+ mini_magick (4.3.6)
14
+ minitest (5.8.2)
15
+ pdf-core (0.6.0)
16
+ prawn (2.0.2)
17
+ pdf-core (~> 0.6.0)
18
+ ttfunk (~> 1.4.0)
19
+ rake (10.4.2)
20
+ ttfunk (1.4.0)
21
+
22
+ PLATFORMS
23
+ ruby
24
+
25
+ DEPENDENCIES
26
+ bundler (~> 1.10)
27
+ map_print!
28
+ minitest
29
+ rake (~> 10.0)
30
+
31
+ BUNDLED WITH
32
+ 1.10.6
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Andreas Fast
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,38 @@
1
+ # MapPrint
2
+
3
+ MapPrint allows for exporting many map sources and GeoJSON to a pdf file. Allowing to specify map element, text/image elements as well as printing a legend with the reference and a scale bar.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'map_print'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install map_print
20
+
21
+ ## Usage
22
+
23
+ map_print file.pdf
24
+
25
+ ## Development
26
+
27
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
28
+
29
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
30
+
31
+ ## Contributing
32
+
33
+ Bug reports and pull requests are welcome on GitHub at https://github.com/afast/map_print.
34
+
35
+
36
+ ## License
37
+
38
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "map_print"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/map_print ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "map_print"
5
+
6
+ MapPrint.print ARGV[0]
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,41 @@
1
+ require 'map_print/lat_lng'
2
+ require 'map_print/osm/tile'
3
+ require 'map_print/osm/tile_factory'
4
+
5
+ module MapPrint
6
+ class Core
7
+ def self.print(path)
8
+ puts path
9
+ sw = LatLng.new(-35.026862, -58.425003)
10
+ ne = LatLng.new(-29.980172, -52.959305)
11
+ osm = OSM::TileFactory.new('http://a.tile.openstreetmap.org/${z}/${x}/${y}.png', sw, ne, 7)
12
+
13
+ osm.tiles.collect &:download
14
+
15
+ MiniMagick::Tool::Montage.new do |montage|
16
+ montage.mode('concatenate')
17
+ montage.tile("#{osm.x_size}x#{osm.y_size}")
18
+ montage.merge! osm.tiles.collect(&:path)
19
+ montage << 'output.jpg'
20
+ end
21
+
22
+ puts osm.px_offset
23
+
24
+ osm.tiles.each &:delete
25
+
26
+ image = MiniMagick::Image.new('output.jpg')
27
+ width = image.width - osm.px_offset[:left] - osm.px_offset[:right]
28
+ height = image.height - osm.px_offset[:top] - osm.px_offset[:bottom]
29
+ puts "width – old: #{image.width} - new #{width}"
30
+ puts "height – old: #{image.height} - new #{height}"
31
+
32
+ image.crop("#{width}x#{height}+#{osm.px_offset[:left]}+#{osm.px_offset[:top]}").repage("#{width}x#{height}")
33
+
34
+ Prawn::Document.generate(path) do
35
+ image 'output.jpg', width: 500, at: [0, 700]
36
+ end
37
+
38
+ #File.delete 'output.jpg' if File.exist?('output.jpg')
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,24 @@
1
+ module MapPrint
2
+ class LatLng
3
+ attr_accessor :lat, :lng
4
+
5
+ def initialize(lat, lng)
6
+ @lat = lat
7
+ @lng = lng
8
+ end
9
+
10
+ def get_slippy_map_tile_number(zoom)
11
+ return @get_slippy_map_tile_number if @get_slippy_map_tile_number
12
+
13
+ lat_rad = @lat / 180 * Math::PI
14
+ n = 2.0 ** zoom
15
+ x = (@lng + 180.0) / 360.0 * n
16
+ y = (1.0 - Math::log(Math::tan(lat_rad) + (1 / Math::cos(lat_rad))) / Math::PI) / 2.0 * n
17
+
18
+ @get_slippy_map_tile_number = {x: x.to_i, y: y.to_i, offset: {x: x - x.to_i, y: y - y.to_i}}
19
+ end
20
+
21
+ def diff_in_meters(lat_lng)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,91 @@
1
+ require 'open-uri'
2
+
3
+ module MapPrint
4
+ module OSM
5
+ class Tile
6
+ attr_reader :path
7
+
8
+ METERS_PER_PIXELS = {
9
+ 0 => 26862156543.031,
10
+ 1 => 8078271.521,
11
+ 2 => 7739135.761,
12
+ 3 => 6919567.881,
13
+ 4 => 889783.941,
14
+ 5 => 214891.9771,
15
+ 6 => 222445.9801721,
16
+ 7 => 161731222.991,
17
+ 8 => 11611.5001,
18
+ 9 => 52305.751,
19
+ 10 => 152.871,
20
+ 11 => 76.4371,
21
+ 12 => 38.2191,
22
+ 13 => 519.1091,
23
+ 14 => 9.55461,
24
+ 15 => 4.77731,
25
+ 16 => 2.38871,
26
+ 17 => 1.19431,
27
+ 18 => 0.5972
28
+ }
29
+
30
+ class << self
31
+ def meters_per_pixel(zoom)
32
+ METERS_PER_PIXELS[zoom]
33
+ end
34
+ end
35
+
36
+ def initialize(x, y, z, base_url=nil)
37
+ @base_url = base_url
38
+ @x = x
39
+ @y = y
40
+ @z = z
41
+ @path = "#{@x}-#{@y}-#{@z}.png"
42
+ end
43
+
44
+ def coords
45
+ {x: @x, y: @y, z: @z}
46
+ end
47
+
48
+ def download
49
+ puts "getting url #{get_url}"
50
+
51
+ delete
52
+ @image = open(get_url).read
53
+ File.open @path, 'wb' do |f|
54
+ f.write @image
55
+ end
56
+ end
57
+
58
+ def delete
59
+ File.delete @path if File.exist?(@path)
60
+ end
61
+
62
+ def get_pixel_difference(lat_lng)
63
+ tile_lat_lng = tile_number_to_lat_lng
64
+ puts '================'
65
+ puts lat_lng.lat
66
+ puts lat_lng.lng
67
+ puts tile_lat_lng
68
+ puts '================'
69
+
70
+ x_pixels = GeoDistance.distance(lat_lng.lat, lat_lng.lng, lat_lng.lat, tile_lat_lng[:lng]).meters.number / METERS_PER_PIXELS[@z]
71
+ y_pixels = GeoDistance.distance(lat_lng.lat, lat_lng.lng, tile_lat_lng[:lat], lat_lng.lng).meters.number / METERS_PER_PIXELS[@z]
72
+
73
+ { x: x_pixels, y: y_pixels }
74
+ end
75
+
76
+ def tile_number_to_lat_lng
77
+ n = 2.0 ** @z
78
+ lon_deg = @x / n * 360.0 - 180.0
79
+ lat_rad = Math::atan(Math::sinh(Math::PI * (1 - 2 * @y / n)))
80
+ lat_deg = 180.0 * (lat_rad / Math::PI)
81
+
82
+ { lat: lat_deg, lng: lon_deg }
83
+ end
84
+
85
+ private
86
+ def get_url
87
+ @base_url.gsub('${x}', @x.to_s).gsub('${y}', @y.to_s).gsub('${z}', @z.to_s)
88
+ end
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,68 @@
1
+ module MapPrint
2
+ module OSM
3
+ class TileFactory
4
+ def initialize(base_url, sw_lat_lng, ne_lat_lng, zoom)
5
+ @base_url = base_url
6
+ @sw_lat_lng = sw_lat_lng
7
+ @ne_lat_lng = ne_lat_lng
8
+ @zoom = zoom
9
+ end
10
+
11
+ def px_offset
12
+ return @px_offset if @px_offset
13
+ offset = {}
14
+
15
+ offset[:top] = (ne_offset[:y] * 256).to_i
16
+ offset[:right] = 256 - (ne_offset[:x] * 256).to_i
17
+ offset[:bottom] = 256 - (sw_offset[:y] * 256).to_i
18
+ offset[:left] = (sw_offset[:x] * 256).to_i
19
+ @px_offset = offset
20
+ end
21
+
22
+ def tiles
23
+ return @tiles if @tiles
24
+
25
+ @tiles = []
26
+ y_array.each do |y|
27
+ x_array.each do |x|
28
+ @tiles << Tile.new(x, y, @zoom, @base_url)
29
+ end
30
+ end
31
+
32
+ @tiles
33
+ end
34
+
35
+ def x_size
36
+ x_array.size
37
+ end
38
+
39
+ def y_size
40
+ y_array.size
41
+ end
42
+
43
+ def ne_offset
44
+ @ne_lat_lng.get_slippy_map_tile_number(@zoom)[:offset]
45
+ end
46
+
47
+ def sw_offset
48
+ @sw_lat_lng.get_slippy_map_tile_number(@zoom)[:offset]
49
+ end
50
+
51
+ def x_array
52
+ return @x_array if @x_array
53
+
54
+ x1 = @sw_lat_lng.get_slippy_map_tile_number(@zoom)[:x]
55
+ x2 = @ne_lat_lng.get_slippy_map_tile_number(@zoom)[:x]
56
+ @x_array ||= x1 < x2 ? x1..x2 : (x2..x1).to_a
57
+ end
58
+
59
+ def y_array
60
+ return @y_array if @y_array
61
+
62
+ y1 = @sw_lat_lng.get_slippy_map_tile_number(@zoom)[:y]
63
+ y2 = @ne_lat_lng.get_slippy_map_tile_number(@zoom)[:y]
64
+ @y_array ||= y1 < y2 ? y1..y2 : (y2..y1).to_a
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,3 @@
1
+ module MapPrint
2
+ VERSION = '0.1.0'
3
+ end
data/lib/map_print.rb ADDED
@@ -0,0 +1,17 @@
1
+ require 'map_print/version'
2
+ require 'prawn'
3
+ require 'mini_magick'
4
+ require 'geo-distance'
5
+
6
+ module MapPrint
7
+ # Your code goes here...
8
+ end
9
+
10
+ require 'map_print/core'
11
+
12
+
13
+ module MapPrint
14
+ def self.print(path)
15
+ MapPrint::Core.print(path)
16
+ end
17
+ end
data/map_print.gemspec ADDED
@@ -0,0 +1,36 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'map_print/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'map_print'
8
+ spec.version = MapPrint::VERSION
9
+ spec.authors = ['Andreas Fast']
10
+ spec.email = ['andis.machine@gmail.com']
11
+
12
+ spec.summary = %q{Easily export maps to pdf}
13
+ spec.description = %q{MapPrint allows to export many map sources and GeoJSON objects to a pdf file, along with legend and text elements to create rich maps.}
14
+ spec.homepage = 'http://github.com/afast/map_print'
15
+ spec.license = 'MIT'
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
21
+ else
22
+ raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = 'exe'
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ['lib']
29
+
30
+ spec.add_development_dependency 'bundler', '~> 1.10'
31
+ spec.add_development_dependency 'rake', '~> 10.0'
32
+ spec.add_development_dependency 'minitest', '~> 5.8'
33
+ spec.add_dependency 'prawn', '~> 2.0'
34
+ spec.add_dependency 'mini_magick', '~> 4.3'
35
+ spec.add_dependency 'geo-distance', '~> 0.1'
36
+ end
metadata ADDED
@@ -0,0 +1,148 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: map_print
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Andreas Fast
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-11-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.8'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.8'
55
+ - !ruby/object:Gem::Dependency
56
+ name: prawn
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: mini_magick
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '4.3'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '4.3'
83
+ - !ruby/object:Gem::Dependency
84
+ name: geo-distance
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.1'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.1'
97
+ description: MapPrint allows to export many map sources and GeoJSON objects to a pdf
98
+ file, along with legend and text elements to create rich maps.
99
+ email:
100
+ - andis.machine@gmail.com
101
+ executables: []
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - ".ruby-gemset"
107
+ - ".ruby-version"
108
+ - Gemfile
109
+ - Gemfile.lock
110
+ - LICENSE.txt
111
+ - README.md
112
+ - Rakefile
113
+ - bin/console
114
+ - bin/map_print
115
+ - bin/setup
116
+ - lib/map_print.rb
117
+ - lib/map_print/core.rb
118
+ - lib/map_print/lat_lng.rb
119
+ - lib/map_print/osm/tile.rb
120
+ - lib/map_print/osm/tile_factory.rb
121
+ - lib/map_print/version.rb
122
+ - map_print.gemspec
123
+ homepage: http://github.com/afast/map_print
124
+ licenses:
125
+ - MIT
126
+ metadata:
127
+ allowed_push_host: https://rubygems.org
128
+ post_install_message:
129
+ rdoc_options: []
130
+ require_paths:
131
+ - lib
132
+ required_ruby_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ required_rubygems_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ requirements: []
143
+ rubyforge_project:
144
+ rubygems_version: 2.4.8
145
+ signing_key:
146
+ specification_version: 4
147
+ summary: Easily export maps to pdf
148
+ test_files: []