embulk-formatter-geojson 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +6 -0
- data/.ruby-version +1 -0
- data/Gemfile +2 -0
- data/LICENSE.txt +21 -0
- data/README.md +31 -0
- data/Rakefile +3 -0
- data/embulk-formatter-geojson.gemspec +20 -0
- data/lib/embulk/formatter/geojson.rb +84 -0
- metadata +94 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1c808a33eecd22735f21cbc2977756caa7a841a9
|
4
|
+
data.tar.gz: b7beb7b6e8b2e0942e49a4feb78b4d2d5bc456d1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cd84202ad4c9814fd5e891af6330b91802731cada56d8b2c7a2277172cb11c7036ada4dd3d8b706e280c16b1b8844076d68803c2af08f9c936afb5d12f71eb7b
|
7
|
+
data.tar.gz: 6006476a8ecc4983e02187068228d964529382150039fc2ba606a4c09490f8072957c1b98a3a5a2355c13ba848210525b056b6631b8933e6c9abe4eb8f4d998e
|
data/.gitignore
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
jruby-9.0.4.0
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
|
2
|
+
MIT License
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
a copy of this software and associated documentation files (the
|
6
|
+
"Software"), to deal in the Software without restriction, including
|
7
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Geojson formatter plugin for Embulk
|
2
|
+
|
3
|
+
Geojson formatter based on given `.geojson` template file.
|
4
|
+
This plugin inject properties passed from input to template `.geojson` file.
|
5
|
+
|
6
|
+
## Overview
|
7
|
+
|
8
|
+
* **Plugin type**: formatter
|
9
|
+
|
10
|
+
## Configuration
|
11
|
+
|
12
|
+
- **template_file**: template geojson file path (integer, required)
|
13
|
+
- **encoding**: output file encoding (string, default: `"UTF-8"`)
|
14
|
+
- **identifier**: which identifies corresponding feature in geojson file (string, default: `id`)
|
15
|
+
|
16
|
+
## Example
|
17
|
+
|
18
|
+
```yaml
|
19
|
+
out:
|
20
|
+
type: file
|
21
|
+
formatter:
|
22
|
+
type: geojson
|
23
|
+
template_file: /path/to/template.geojson
|
24
|
+
identifier: "identifier"
|
25
|
+
```
|
26
|
+
|
27
|
+
## Build
|
28
|
+
|
29
|
+
```
|
30
|
+
$ rake
|
31
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
|
2
|
+
Gem::Specification.new do |spec|
|
3
|
+
spec.name = "embulk-formatter-geojson"
|
4
|
+
spec.version = "0.1.0"
|
5
|
+
spec.authors = ["lewuathe"]
|
6
|
+
spec.summary = "Geojson formatter plugin for Embulk"
|
7
|
+
spec.description = "Formats Geojson files for other file output plugins."
|
8
|
+
spec.email = ["lewuathe@me.com"]
|
9
|
+
spec.licenses = ["MIT"]
|
10
|
+
spec.homepage = "https://github.com/lewuathe/embulk-formatter-geojson"
|
11
|
+
|
12
|
+
spec.files = `git ls-files`.split("\n") + Dir["classpath/*.jar"]
|
13
|
+
spec.test_files = spec.files.grep(%r{^(test|spec)/})
|
14
|
+
spec.require_paths = ["lib"]
|
15
|
+
|
16
|
+
#spec.add_dependency 'YOUR_GEM_DEPENDENCY', ['~> YOUR_GEM_DEPENDENCY_VERSION']
|
17
|
+
spec.add_development_dependency 'embulk', ['>= 0.8.6']
|
18
|
+
spec.add_development_dependency 'bundler', ['>= 1.10.6']
|
19
|
+
spec.add_development_dependency 'rake', ['>= 10.0']
|
20
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module Embulk
|
4
|
+
module Formatter
|
5
|
+
|
6
|
+
class Geojson < FormatterPlugin
|
7
|
+
Plugin.register_formatter("geojson", self)
|
8
|
+
|
9
|
+
def self.transaction(config, schema, &control)
|
10
|
+
# configuration code:
|
11
|
+
task = {
|
12
|
+
"template_file" => config.param("template_file", :string), # required
|
13
|
+
"encoding" => config.param("encoding", :string, default: 'UTF-8'),
|
14
|
+
"identifier" => config.param("identifier", :string, default: 'id')
|
15
|
+
}
|
16
|
+
|
17
|
+
yield(task)
|
18
|
+
end
|
19
|
+
|
20
|
+
def init
|
21
|
+
# initialization code:
|
22
|
+
@template_file = task['template_file']
|
23
|
+
@encoding = task['encoding']
|
24
|
+
@identifier = task['identifier']
|
25
|
+
|
26
|
+
@template_json = JSON.parse(File.read(@template_file))
|
27
|
+
@features = @template_json["features"]
|
28
|
+
# your data
|
29
|
+
@current_file == nil
|
30
|
+
@current_file_size = 0
|
31
|
+
|
32
|
+
@is_first_row = true
|
33
|
+
end
|
34
|
+
|
35
|
+
def close
|
36
|
+
end
|
37
|
+
|
38
|
+
def add(page)
|
39
|
+
# output code:
|
40
|
+
page.each do |record|
|
41
|
+
if @current_file == nil
|
42
|
+
@current_file = file_output.next_file
|
43
|
+
@current_file.write '{"type": "FeatureCollection", "features": ['.encode(@encoding)
|
44
|
+
@current_file_size = 0
|
45
|
+
@is_first_row = true
|
46
|
+
elsif @current_file_size > 32 * 1024 * 1024
|
47
|
+
@current_file.write ']}'.encode(@encoding)
|
48
|
+
@current_file = file_output.next_file
|
49
|
+
@current_file.write '{"type": "FeatureCollection", "features": ['.encode(@encoding)
|
50
|
+
@current_file_size = 0
|
51
|
+
@is_first_row = true
|
52
|
+
end
|
53
|
+
|
54
|
+
schema = page.schema.map { |s| s.name }
|
55
|
+
record_hash = Hash[schema.zip record]
|
56
|
+
|
57
|
+
feature = @features.select do |f|
|
58
|
+
f["properties"][@identifier].to_s == record_hash[@identifier]
|
59
|
+
end
|
60
|
+
|
61
|
+
raise "Invalid identifier" unless feature.length <= 1
|
62
|
+
|
63
|
+
if feature.length == 1
|
64
|
+
if @is_first_row
|
65
|
+
@is_first_row = false
|
66
|
+
else
|
67
|
+
@current_file.write ','.encode(@encoding)
|
68
|
+
end
|
69
|
+
feature[0]["properties"] = feature[0]["properties"].merge(record_hash)
|
70
|
+
@current_file.write JSON.dump(feature[0]).encode(@encoding)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def finish
|
76
|
+
if @current_file != nil
|
77
|
+
@current_file.write ']}'.encode(@encoding)
|
78
|
+
end
|
79
|
+
file_output.finish
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
end
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: embulk-formatter-geojson
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- lewuathe
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-03-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - ">="
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: 0.8.6
|
19
|
+
name: embulk
|
20
|
+
prerelease: false
|
21
|
+
type: :development
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.8.6
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.10.6
|
33
|
+
name: bundler
|
34
|
+
prerelease: false
|
35
|
+
type: :development
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.10.6
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '10.0'
|
47
|
+
name: rake
|
48
|
+
prerelease: false
|
49
|
+
type: :development
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
description: Formats Geojson files for other file output plugins.
|
56
|
+
email:
|
57
|
+
- lewuathe@me.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".ruby-version"
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- embulk-formatter-geojson.gemspec
|
69
|
+
- lib/embulk/formatter/geojson.rb
|
70
|
+
homepage: https://github.com/lewuathe/embulk-formatter-geojson
|
71
|
+
licenses:
|
72
|
+
- MIT
|
73
|
+
metadata: {}
|
74
|
+
post_install_message:
|
75
|
+
rdoc_options: []
|
76
|
+
require_paths:
|
77
|
+
- lib
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
requirements: []
|
89
|
+
rubyforge_project:
|
90
|
+
rubygems_version: 2.4.8
|
91
|
+
signing_key:
|
92
|
+
specification_version: 4
|
93
|
+
summary: Geojson formatter plugin for Embulk
|
94
|
+
test_files: []
|