cartograss 0.0.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
+ SHA1:
3
+ metadata.gz: 1be2ae76673df3767e91e76cd83285c62d14d45c
4
+ data.tar.gz: f09dacdfbb2d2b8793d1ab16360c2c8c04baf323
5
+ SHA512:
6
+ metadata.gz: 9b80f79ab47916598dcc84ba50fcd80c04350fb15efb555bac1fd111c66798e2d3ba7af1728617063da8deaef958201a35ba8fd8aeb16be95e11f21f76197f45
7
+ data.tar.gz: 286be244d15151d1ad0d4186e7e3645b311ff47532aead6091afd424b9fa7d97e6a6624c1685036b5bc1a0f846caf374f2e91f2e4132a24f3f5b5b1e60076dd1
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.10.6
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in cartograss.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Javier Goizueta
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,75 @@
1
+ # CartoGrass
2
+
3
+ Import and Export [CARTO](http://carto.com) datasets as GRASS GIS maps.
4
+
5
+ Works with GRASS 7.x and only with vector geometry.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'cartograss'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install cartograss
22
+
23
+ ## Usage
24
+
25
+ You'll need a [CARTO engine](https://carto.com/engine/) account
26
+ (that is, one with an authorized API KEY).
27
+
28
+ This example fetches some data from your CARTO account, then processes it in GRASS and
29
+ sends the results back to CARTO so they can be visualized in web maps.
30
+
31
+ ```ruby
32
+ require 'cartograss'
33
+
34
+ grass_config = {
35
+ # ...
36
+ }
37
+
38
+ GrassGis.session grass_config do
39
+ extend CartoGrass
40
+
41
+ # Bring-in a dataset from CARTO.
42
+ # It is automatically reprojected for the current locations
43
+ carto_import(
44
+ user: 'carto_username',
45
+ api_key: 'secret_api_key',
46
+ dataset: 'mydataset'
47
+ )
48
+
49
+ # ... process mydataset with GRASS tools ...
50
+
51
+ # Now save the changed dataset back to CARTO.
52
+ carto_export(
53
+ user: 'carto_username',
54
+ api_key: 'secret_api_key',
55
+ input: 'mydataset',
56
+ dataset: 'mydataset'
57
+ )
58
+ end
59
+
60
+ ```
61
+
62
+ ## Development
63
+
64
+ 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.
65
+
66
+ 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).
67
+
68
+ ## Contributing
69
+
70
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/cartograss. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
71
+
72
+
73
+ ## License
74
+
75
+ 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 "cartograss"
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/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,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'cartograss/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "cartograss"
8
+ spec.version = CartoGrass::VERSION
9
+ spec.authors = ["Javier Goizueta"]
10
+ spec.email = ["jgoizueta@gmail.com"]
11
+
12
+ spec.summary = %q{Use CARTO datasets in GRASS GIS}
13
+ spec.description = %q{GRASS functions to import/export CARTO datasets}
14
+ spec.homepage = "https://gitlab.com/jgoizueta/cartograss"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.10"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "minitest"
25
+
26
+ spec.required_ruby_version = '>= 2.0'
27
+
28
+ spec.add_dependency 'grassgis', '~> 0.5'
29
+ end
data/lib/cartograss.rb ADDED
@@ -0,0 +1,112 @@
1
+ require "cartograss/version"
2
+
3
+ module CartoGrass
4
+ def carto_import(user:, dataset:, api_key:)
5
+ with_api_key api_key do
6
+ if epsg4326?
7
+ v.in.ogr(
8
+ '-o',
9
+ input: "#{CARTO_OGR}:#{user} tables=#{dataset}",
10
+ layer: dataset,
11
+ output: dataset
12
+ )
13
+ else
14
+ v.import(
15
+ input: "#{CARTO_OGR}:#{user} tables=#{dataset}",
16
+ layer: dataset,
17
+ output: dataset,
18
+ epsg: 4326
19
+ )
20
+ end
21
+ end
22
+ end
23
+
24
+ def carto_export(user:, api_key:, input:, dataset:, overwrite: false)
25
+ if epsg4326?
26
+ carto_export_4326 user: user, api_key: api_key, input: input, dataset: dataset, overwrite: overwrite
27
+ else
28
+ projected = self
29
+ GrassGis.session(configuration.merge(CARTO_TMP_4326)) do
30
+ v.proj(
31
+ '--overwrite',
32
+ location: projected.configuration[:location],
33
+ mapset: projected.configuration[:mapset],
34
+ input: input
35
+ )
36
+ extend CartoGrass
37
+ carto_export_4326 user: user, api_key: api_key, input: input, dataset: dataset, overwrite: true
38
+ end
39
+
40
+ # GrassGis.session(configuration.merge(CARTO_TMP_4326)) do |carto_tmp|
41
+ # carto_tmp.v.proj(
42
+ # '--overwrite',
43
+ # location: configuration[:location],
44
+ # mapset: configuration[:mapset],
45
+ # input: input
46
+ # )
47
+ # carto_tmp.extend CartoGrass
48
+ # carto_tmp.send :carto_export_4326, user: user, api_key: api_key, input: input, dataset: dataset, overwrite: overwrite
49
+ # end
50
+ end
51
+ end
52
+
53
+ private
54
+
55
+ CARTO_OGR = 'CartoDB'
56
+ CARTO_TMP_4326 = {
57
+ location: 'carto_tmp',
58
+ mapset: 'maps_4326',
59
+ create: {
60
+ epsg: 4326,
61
+ limits: [-180.0, 0.0, 180.0, 90.0]
62
+ }
63
+ }
64
+
65
+ def epsg4326?
66
+ g.proj '-g'
67
+ proj = shell_to_hash
68
+ proj['epsg'] == '4326' ||
69
+ proj['ellps'] == 'wgs84' && proj['proj'] == 'll' && proj['unit'] == 'degrees'
70
+ end
71
+
72
+ def with_api_key(api_key)
73
+ api_key_var = "#{CARTO_OGR.upcase}_API_KEY"
74
+ begin
75
+ ENV[api_key_var] = api_key
76
+ yield
77
+ ensure
78
+ ENV.delete api_key_var
79
+ end
80
+ end
81
+
82
+ def carto_export_4326(user:, api_key:, input:, dataset:, overwrite: false)
83
+ with_api_key api_key do
84
+ if overwrite
85
+ v.out.ogr(
86
+ '--overwrite',
87
+ format: CARTO_OGR,
88
+ input: input,
89
+ output: "#{CARTO_OGR}:#{user} tables=#{dataset}",
90
+ output_layer: dataset
91
+ )
92
+ else
93
+ # first create layer to avoid problem reading all layers
94
+ v.out.ogr(
95
+ '-n',
96
+ format: CARTO_OGR,
97
+ input: input,
98
+ output: "#{CARTO_OGR}:#{user}",
99
+ output_layer: dataset
100
+ )
101
+ # now overwrite it:
102
+ v.out.ogr(
103
+ '--overwrite',
104
+ format: CARTO_OGR,
105
+ input: input,
106
+ output: "#{CARTO_OGR}:#{user} tables=#{dataset}",
107
+ output_layer: dataset
108
+ )
109
+ end
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,3 @@
1
+ module CartoGrass
2
+ VERSION = "0.0.0"
3
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cartograss
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Javier Goizueta
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-12-30 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: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: grassgis
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.5'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.5'
69
+ description: GRASS functions to import/export CARTO datasets
70
+ email:
71
+ - jgoizueta@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".travis.yml"
78
+ - CODE_OF_CONDUCT.md
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - bin/console
84
+ - bin/setup
85
+ - cartograss.gemspec
86
+ - lib/cartograss.rb
87
+ - lib/cartograss/version.rb
88
+ homepage: https://gitlab.com/jgoizueta/cartograss
89
+ licenses:
90
+ - MIT
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '2.0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.4.5.1
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: Use CARTO datasets in GRASS GIS
112
+ test_files: []