geo_works-derivatives 0.5.0 → 0.6.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fd74e4256a47a4aa51bce1260b257cb3521534bd14b4e95a7fa928b574fa327e
4
- data.tar.gz: ee24d60ba5067f5cba81c82598373b46c886ba2e9ace2b6eb67a0c3b8f9f2d68
3
+ metadata.gz: baeb8171c1ebdac8b02b7e748d04658e2da0fceaeda277965af0eed4824db64a
4
+ data.tar.gz: 136fcf622a11c30eea882beee962f8dbca2b53830c415f7129e00aebc04cf8e0
5
5
  SHA512:
6
- metadata.gz: 62e76e0daed6a0c682f0f249fa874e24988f2c2e799428eb427666bcfb8b7554464e7c7858d9677389ef02e1795ae7609042250906672a0fa7f411932f64f2a6
7
- data.tar.gz: ae2422b043ea514fdb690788ec8370d8b4f8f9a9039e6c49d7846097ec02f71041c64bc734259e551078f7926925d44b2705ea23cb4dea25f873582e7401f8b3
6
+ metadata.gz: 6e5aa369904ce63ec509d80868e3867fe7ecf6c6d3671f0a523ca1acf6967620866bae7372e3c5bdb4c8a12b8167f177fa5be3afde332a6e48af94f354a5f23b
7
+ data.tar.gz: 6ca2866e946abb4569d754d5d6b3c6e12a0ed1fb6b84361f88d8c185767bc5c48ea93a3cbcea0bf592bede4afd80d3a1618661a77d7bd5f21d2658f0dcc3cce0
@@ -0,0 +1,57 @@
1
+ ---
2
+ version: 2
3
+ jobs:
4
+ build:
5
+ working_directory: ~/geo_works
6
+ docker:
7
+ - image: circleci/ruby:2.7.5-node-browsers
8
+ steps:
9
+ - checkout
10
+ - run: sudo apt update -y
11
+ - run: sudo apt-get install gdal-bin libgdal-dev libcairo2-dev libpango1.0-dev python3-pip python-is-python3
12
+ - run: sudo sh bin/ci_simple_tiles_install.sh
13
+ # Install Bundler
14
+ - run: gem install bundler -v '2.2.14'
15
+ # Bundle install dependencies
16
+ - run: bundle install --path vendor/bundle
17
+ - persist_to_workspace:
18
+ root: '~/geo_works'
19
+ paths: '*'
20
+ test:
21
+ working_directory: ~/geo_works
22
+ docker:
23
+ - image: circleci/ruby:2.7.5-node-browsers
24
+ steps:
25
+ - attach_workspace:
26
+ at: '~/geo_works'
27
+ - run: sudo apt update -y
28
+ - run: sudo apt-get install gdal-bin libgdal-dev libcairo2-dev libpango1.0-dev python3-pip python-is-python3
29
+ - run: sudo sh bin/ci_simple_tiles_install.sh
30
+ # Install Bundler
31
+ - run: gem install bundler -v '2.2.14'
32
+ # Bundle install dependencies
33
+ - run: bundle install --path vendor/bundle
34
+ - run: bundle exec rspec
35
+ rubocop:
36
+ working_directory: ~/geo_works
37
+ docker:
38
+ - image: circleci/ruby:2.7.5-node-browsers
39
+ steps:
40
+ - attach_workspace:
41
+ at: '~/geo_works'
42
+ # Install Bundler
43
+ - run: gem install bundler -v '2.2.14'
44
+ # Bundle install dependencies
45
+ - run: bundle install --path vendor/bundle
46
+ - run: bundle exec rubocop
47
+ workflows:
48
+ version: 2
49
+ build_accept_deploy:
50
+ jobs:
51
+ - build
52
+ - test:
53
+ requires:
54
+ - build
55
+ - rubocop:
56
+ requires:
57
+ - build
data/.rubocop.yml CHANGED
@@ -2,10 +2,12 @@ inherit_gem:
2
2
  bixby: bixby_default.yml
3
3
  AllCops:
4
4
  DisplayCopNames: true
5
- TargetRubyVersion: 2.3
5
+ NewCops: enable
6
+ TargetRubyVersion: 2.7
6
7
  Exclude:
7
8
  - 'bin/*'
8
9
  - 'vendor/**/*'
10
+ - 'tmp/**/*'
9
11
  Metrics/BlockLength:
10
12
  Exclude:
11
13
  - 'spec/**/*'
data/.tool-versions ADDED
@@ -0,0 +1 @@
1
+ ruby 2.7.5
@@ -0,0 +1,15 @@
1
+ if [ ! -d "tmp/simple-tiles" ]; then
2
+ mkdir -p -m 777 tmp && cd tmp
3
+ wget --no-check-certificate https://github.com/propublica/simple-tiles/archive/master.zip -O simple-tiles.zip
4
+ unzip simple-tiles.zip
5
+ mv simple-tiles-master simple-tiles
6
+ cd simple-tiles
7
+ ./configure -t $PWD && make
8
+ sudo make install
9
+ cd ../..
10
+ fi
11
+ cd tmp/simple-tiles && sudo make install && cd ../..
12
+ # Clean up after the build
13
+ if [ -d "simple-tiles" ]; then
14
+ mv simple-tiles tmp/simple-tiles-build
15
+ fi
@@ -35,8 +35,9 @@ Gem::Specification.new do |spec|
35
35
  spec.add_dependency 'simpler-tiles'
36
36
 
37
37
  spec.add_development_dependency 'bixby'
38
- spec.add_development_dependency 'bundler', '~> 1.16'
38
+ spec.add_development_dependency 'bundler'
39
39
  spec.add_development_dependency 'coveralls'
40
+ spec.add_development_dependency 'pry-byebug'
40
41
  spec.add_development_dependency 'rake', '~> 10.0'
41
42
  spec.add_development_dependency 'rspec', '~> 3.0'
42
43
  end
@@ -11,6 +11,12 @@ module GeoWorks
11
11
  @doc = gdalinfo(path)
12
12
  end
13
13
 
14
+ # Returns raster bounds
15
+ # @return [Hash] bounds
16
+ def bounds
17
+ @bounds = raster_bounds
18
+ end
19
+
14
20
  # Returns the gdal driver name
15
21
  # @return [String] driver name
16
22
  def driver
@@ -31,37 +37,82 @@ module GeoWorks
31
37
 
32
38
  private
33
39
 
34
- # Given an output string from the gdalinfo command, returns
35
- # the gdal driver used to read dataset.
36
- # @return [String] gdal driver name
37
- def driver_name
38
- match = /(?<=Driver:\s).*?(?=\s)/.match(doc)
39
- match ? match[0] : ''
40
- end
41
-
42
- # Runs the gdalinfo command and returns the result as a string.
43
- # @param path [String] path to raster file
44
- # @return [String] output of gdalinfo
45
- def gdalinfo(path)
46
- stdout, _stderr, _status = Open3.capture3("gdalinfo -mm #{path}")
47
- stdout
48
- end
49
-
50
- # Given an output string from the gdalinfo command, returns
51
- # a formatted string for the computed min and max values.
52
- # @return [String] computed min and max values
53
- def raster_min_max
54
- match = %r{(?<=Computed Min/Max=).*?(?=\s)}.match(doc)
55
- match ? match[0].tr(',', ' ') : ''
56
- end
57
-
58
- # Given an output string from the gdalinfo command, returns
59
- # an array containing the raster width and height as strings.
60
- # @return [String] raster size
61
- def raster_size
62
- match = /(?<=Size is ).*/.match(doc)
63
- match ? match[0].tr(',', '') : ''
64
- end
40
+ # Given an output string from the gdalinfo command, returns
41
+ # the gdal driver used to read dataset.
42
+ # @return [String] gdal driver name
43
+ def driver_name
44
+ match = /(?<=Driver:\s).*?(?=\s)/.match(doc)
45
+ match ? match[0] : ''
46
+ end
47
+
48
+ ## Converts coordinate in degrees, minutes, seconds to decimal degrees
49
+ # Example: 74° 25' 55.8" -> 74.43217
50
+ # @param d [String] degrees
51
+ # @param m [String] minutes
52
+ # @param s [String] seconds
53
+ # @return [Float] coordinate in decimal degrees
54
+ def dms_to_dd(d, m, s)
55
+ dd = d.to_f + (m.to_f / 60) + (s.to_f / 3600)
56
+
57
+ # Truncate to 6 decimal places
58
+ # https://observablehq.com/@mourner/latitude-and-longitude-precision
59
+ dd.truncate(6)
60
+ end
61
+
62
+ ## Extracts lon/lat values from gdal_info corner coordinates string
63
+ # Example:
64
+ # ( 546945.000, 4662235.000) ( 74d25'55.80"W, 42d 6'45.83"N) ->
65
+ # [74.432166, 42.11273]
66
+ # @param gdal_string [String] corner corner string from gdal_info
67
+ # @return [Array<Float, Float>] coordinates in decimal degrees
68
+ def extract_coordinates(gdal_string)
69
+ # remove parens and spaces, split into array, and assign elements to variables
70
+ _, _, lon, lat = gdal_string.delete(" ").gsub(")(", ",").delete("(").delete(")").split(",")
71
+ # split coordinate string into degree, minute, second values
72
+ lon = lon.delete("\"W").tr("d", ",").tr("'", ",").split(",")
73
+ lat = lat.delete("\"N").tr("d", ",").tr("'", ",").split(",")
74
+
75
+ # Convert to decimal degrees and return
76
+ [dms_to_dd(*lon), dms_to_dd(*lat)]
77
+ end
78
+
79
+ # Runs the gdalinfo command and returns the result as a string.
80
+ # @param path [String] path to raster file
81
+ # @return [String] output of gdalinfo
82
+ def gdalinfo(path)
83
+ stdout, _stderr, _status = Open3.capture3("gdalinfo -mm #{path}")
84
+ stdout
85
+ end
86
+
87
+ # Given an output string from the gdalinfo command, returns
88
+ # the raster bounding box.
89
+ # @return [Hash] raster bounds
90
+ def raster_bounds
91
+ ul = /(?<=Upper Left\s).*?(?=\n)/.match(doc)
92
+ lr = /(?<=Lower Right\s).*?(?=\n)/.match(doc)
93
+ w, n = extract_coordinates(ul[0])
94
+ e, s = extract_coordinates(lr[0])
95
+
96
+ { north: n, east: e, south: s, west: w }
97
+ rescue StandardError
98
+ ''
99
+ end
100
+
101
+ # Given an output string from the gdalinfo command, returns
102
+ # a formatted string for the computed min and max values.
103
+ # @return [String] computed min and max values
104
+ def raster_min_max
105
+ match = %r{(?<=Computed Min/Max=).*?(?=\s)}.match(doc)
106
+ match ? match[0].tr(',', ' ') : ''
107
+ end
108
+
109
+ # Given an output string from the gdalinfo command, returns
110
+ # an array containing the raster width and height as strings.
111
+ # @return [String] raster size
112
+ def raster_size
113
+ match = /(?<=Size is ).*/.match(doc)
114
+ match ? match[0].tr(',', '') : ''
115
+ end
65
116
  end
66
117
  end
67
118
  end
@@ -37,44 +37,44 @@ module GeoWorks
37
37
 
38
38
  private
39
39
 
40
- # Adds a shapefile layer to a simple tiles map.
41
- # @param in_path [String] file input path
42
- # @param options [Hash] creation options
43
- def add_shapefile_layer(in_path, map)
44
- Dir.glob("#{in_path}/*.shp").each do |shp|
45
- map.layer shp do |l|
46
- l.query %(select * from "#{File.basename shp, '.shp'}") do |q|
47
- q.styles GeoWorks::Derivatives::Config.rendering_config.to_h
48
- end
40
+ # Adds a shapefile layer to a simple tiles map.
41
+ # @param in_path [String] file input path
42
+ # @param options [Hash] creation options
43
+ def add_shapefile_layer(in_path, map)
44
+ Dir.glob("#{in_path}/*.shp").each do |shp|
45
+ map.layer shp do |l|
46
+ l.query %(select * from "#{File.basename shp, '.shp'}") do |q|
47
+ q.styles GeoWorks::Derivatives::Config.rendering_config.to_h
49
48
  end
50
49
  end
51
50
  end
51
+ end
52
52
 
53
- # Re-orders options bounds for use with a simple tiles map.
54
- # @param options [Hash] creation options
55
- # @return [Array] simple tiles map bounds
56
- def simple_tiles_bounds(options)
57
- [options[:bounds][:east],
58
- options[:bounds][:north],
59
- options[:bounds][:west],
60
- options[:bounds][:south]]
61
- end
53
+ # Re-orders options bounds for use with a simple tiles map.
54
+ # @param options [Hash] creation options
55
+ # @return [Array] simple tiles map bounds
56
+ def simple_tiles_bounds(options)
57
+ [options[:bounds][:east],
58
+ options[:bounds][:north],
59
+ options[:bounds][:west],
60
+ options[:bounds][:south]]
61
+ end
62
62
 
63
- # Transforms the size directive into an array.
64
- # @param options [Hash] creation options
65
- # @return [Array] derivative size
66
- def rendering_size(options)
67
- options[:output_size].split(' ').map(&:to_i)
68
- end
63
+ # Transforms the size directive into an array.
64
+ # @param options [Hash] creation options
65
+ # @return [Array] derivative size
66
+ def rendering_size(options)
67
+ options[:output_size].split(' ').map(&:to_i)
68
+ end
69
69
 
70
- # Assigns new values from the vector info command to the creation options hash.
71
- # @param in_path [String] file input path
72
- # @param options [Hash] creation options
73
- def assign_rendering_options(in_path, options)
74
- vector_info = GeoWorks::Derivatives::Processors::Vector::Info.new(in_path)
75
- options[:name] = vector_info.name
76
- options[:bounds] = vector_info.bounds
77
- end
70
+ # Assigns new values from the vector info command to the creation options hash.
71
+ # @param in_path [String] file input path
72
+ # @param options [Hash] creation options
73
+ def assign_rendering_options(in_path, options)
74
+ vector_info = GeoWorks::Derivatives::Processors::Vector::Info.new(in_path)
75
+ options[:name] = vector_info.name
76
+ options[:bounds] = vector_info.bounds
77
+ end
78
78
  end
79
79
  end
80
80
  end
@@ -37,51 +37,51 @@ module GeoWorks
37
37
 
38
38
  private
39
39
 
40
- # Runs the ogrinfo command and returns the result as a string.
41
- # @param path [String] path to vector file or shapefile directory
42
- # @return [String] output of ogrinfo
43
- def ogrinfo(path)
44
- stdout, _stderr, _status = Open3.capture3("ogrinfo -ro -so -al #{path}")
45
- stdout
46
- end
40
+ # Runs the ogrinfo command and returns the result as a string.
41
+ # @param path [String] path to vector file or shapefile directory
42
+ # @return [String] output of ogrinfo
43
+ def ogrinfo(path)
44
+ stdout, _stderr, _status = Open3.capture3("ogrinfo -ro -so -al #{path}")
45
+ stdout
46
+ end
47
47
 
48
- # Given an output string from the ogrinfo command, returns
49
- # the vector dataset name.
50
- # @return [String] vector dataset name
51
- def vector_name
52
- match = /(?<=Layer name:\s).*?(?=\n)/.match(doc)
53
- match ? match[0] : ''
54
- end
48
+ # Given an output string from the ogrinfo command, returns
49
+ # the vector dataset name.
50
+ # @return [String] vector dataset name
51
+ def vector_name
52
+ match = /(?<=Layer name:\s).*?(?=\n)/.match(doc)
53
+ match ? match[0] : ''
54
+ end
55
55
 
56
- # Given an output string from the ogrinfo command, returns
57
- # the ogr driver used to read dataset.
58
- # @return [String] ogr driver name
59
- def driver_name
60
- match = /(?<=driver\s`).*?(?=')/.match(doc)
61
- match ? match[0] : ''
62
- end
56
+ # Given an output string from the ogrinfo command, returns
57
+ # the ogr driver used to read dataset.
58
+ # @return [String] ogr driver name
59
+ def driver_name
60
+ match = /(?<=driver\s`).*?(?=')/.match(doc)
61
+ match ? match[0] : ''
62
+ end
63
63
 
64
- # Given an output string from the ogrinfo command, returns
65
- # the vector geometry type.
66
- # @return [String] vector geom
67
- def vector_geom
68
- match = /(?<=Geometry:\s).*?(?=\n)/.match(doc)
69
- geom = match ? match[0] : ''
70
- # Transform OGR-style 'Line String' into GeoJSON 'Line'
71
- geom == 'Line String' ? 'Line' : geom
72
- end
64
+ # Given an output string from the ogrinfo command, returns
65
+ # the vector geometry type.
66
+ # @return [String] vector geom
67
+ def vector_geom
68
+ match = /(?<=Geometry:\s).*?(?=\n)/.match(doc)
69
+ geom = match ? match[0] : ''
70
+ # Transform OGR-style 'Line String' into GeoJSON 'Line'
71
+ geom == 'Line String' ? 'Line' : geom
72
+ end
73
73
 
74
- # Given an output string from the ogrinfo command, returns
75
- # the vector bounding box.
76
- # @return [Hash] vector bounds
77
- def vector_bounds
78
- match = /(?<=Extent:\s).*?(?=\n)/.match(doc)
79
- extent = match ? match[0] : ''
74
+ # Given an output string from the ogrinfo command, returns
75
+ # the vector bounding box.
76
+ # @return [Hash] vector bounds
77
+ def vector_bounds
78
+ match = /(?<=Extent:\s).*?(?=\n)/.match(doc)
79
+ extent = match ? match[0] : ''
80
80
 
81
- # remove parens and spaces, split into array, and assign elements to variables
82
- w, s, e, n = extent.delete(' ').gsub(')-(', ',').delete('(').delete(')').split(',')
83
- { north: n.to_f, east: e.to_f, south: s.to_f, west: w.to_f }
84
- end
81
+ # remove parens and spaces, split into array, and assign elements to variables
82
+ w, s, e, n = extent.delete(' ').gsub(')-(', ',').delete('(').delete(')').split(',')
83
+ { north: n.to_f, east: e.to_f, south: s.to_f, west: w.to_f }
84
+ end
85
85
  end
86
86
  end
87
87
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  module GeoWorks
3
3
  module Derivatives
4
- VERSION = "0.5.0"
4
+ VERSION = "0.6.0"
5
5
  end
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geo_works-derivatives
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eliot Jordan
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-11-08 00:00:00.000000000 Z
11
+ date: 2022-04-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hydra-derivatives
@@ -70,16 +70,16 @@ dependencies:
70
70
  name: bundler
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: '1.16'
75
+ version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - "~>"
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
- version: '1.16'
82
+ version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: coveralls
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry-byebug
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: rake
99
113
  requirement: !ruby/object:Gem::Requirement
@@ -129,14 +143,16 @@ executables: []
129
143
  extensions: []
130
144
  extra_rdoc_files: []
131
145
  files:
146
+ - ".circleci/config.yml"
132
147
  - ".gitignore"
133
148
  - ".rspec"
134
149
  - ".rubocop.yml"
135
- - ".travis.yml"
150
+ - ".tool-versions"
136
151
  - Gemfile
137
152
  - LICENSE.txt
138
153
  - README.md
139
154
  - Rakefile
155
+ - bin/ci_simple_tiles_install.sh
140
156
  - bin/console
141
157
  - bin/setup
142
158
  - config/simpler_tiles.yml
@@ -166,7 +182,7 @@ files:
166
182
  homepage: https://github.com/pulibrary/geo_works-derivatives
167
183
  licenses: []
168
184
  metadata: {}
169
- post_install_message:
185
+ post_install_message:
170
186
  rdoc_options: []
171
187
  require_paths:
172
188
  - lib
@@ -181,8 +197,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
181
197
  - !ruby/object:Gem::Version
182
198
  version: '0'
183
199
  requirements: []
184
- rubygems_version: 3.0.3
185
- signing_key:
200
+ rubygems_version: 3.1.6
201
+ signing_key:
186
202
  specification_version: 4
187
203
  summary: Geospatial derivative generation
188
204
  test_files: []
data/.travis.yml DELETED
@@ -1,21 +0,0 @@
1
- sudo: true
2
- language: ruby
3
- rvm:
4
- - 2.4.5
5
- addons:
6
- apt:
7
- packages:
8
- - libgdal1i
9
- - libgdal-dev
10
- - gdal-bin
11
- - libcairo2-dev
12
- - libpango1.0-dev
13
- before_install:
14
- - git clone https://github.com/propublica/simple-tiles.git
15
- - cd simple-tiles
16
- - ./configure && make
17
- - sudo make install
18
- - cd ..
19
- - gem install bundler -v 1.16.1
20
- before_script:
21
- - gdalinfo --version