logstash-filter-wkt_to_geojson 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
+ SHA1:
3
+ metadata.gz: 6326cc532ab5c75899ca81cbe55e3eacfd53a0e9
4
+ data.tar.gz: 9f5dc359b1c01e7898c977b69abe23d086838df0
5
+ SHA512:
6
+ metadata.gz: 62ea8fbedea795d2f709dec737e628ef56f9000e150740371e7b7a9f6cf5624de722d003e69cf7717c51109b54aa0d0d8ede156402f30d78188f54d9112149d8
7
+ data.tar.gz: 6cf0359fbd6c6050c0796a6eaa510dcfad841e34f5a2a45afabca8fce460943e516dce9aed8d77cd5f7b972652c82ab90e8bc05032b5a259b64f3bf1d460e057
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'http://rubygems.org'
2
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,11 @@
1
+ Licensed under the Apache License, Version 2.0 (the "License");
2
+ you may not use this file except in compliance with the License.
3
+ You may obtain a copy of the License at
4
+
5
+ http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ Unless required by applicable law or agreed to in writing, software
8
+ distributed under the License is distributed on an "AS IS" BASIS,
9
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ See the License for the specific language governing permissions and
11
+ limitations under the License.
@@ -0,0 +1,40 @@
1
+ # encoding: utf-8
2
+ require "logstash/filters/base"
3
+ require "logstash/namespace"
4
+ require "rgeo"
5
+ require "rgeo-geojson"
6
+ require "json"
7
+
8
+ class LogStash::Filters::WktToGeojson < LogStash::Filters::Base
9
+
10
+ config_name "wkt_to_geojson"
11
+
12
+ config :field, :validate => :string, :required => true
13
+ config :target, :validate => :string, :default => 'geo_json'
14
+ config :tag_on_parse_failure, :validate => :array, :default => [ '_wkt_parse_failure' ]
15
+
16
+ public
17
+ def register
18
+ @parser = RGeo::WKRep::WKTParser.new()
19
+ @encoder = RGeo::GeoJSON.coder()
20
+ end # def register
21
+
22
+ public
23
+ def filter(event)
24
+
25
+ wkt = event.get(@field)
26
+
27
+ begin
28
+ geo = @parser.parse(wkt)
29
+ json = @encoder.encode(geo)
30
+ event.set(@target, json.to_json)
31
+ rescue Exception => e
32
+ @logger.error('WKT Parse Error',
33
+ :wkt => wkt, :exception => e)
34
+ @tag_on_parse_failure.each { |tag| event.tag(tag) }
35
+ end
36
+
37
+ # filter_matched should go in the last line of our successful code
38
+ filter_matched(event)
39
+ end # def filter
40
+ end # class LogStash::Filters::WktToGeojson
@@ -0,0 +1,25 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'logstash-filter-wkt_to_geojson'
3
+ s.version = '0.1.0'
4
+ s.licenses = ['Apache-2.0']
5
+ s.summary = 'Converts WKT geography shapes to GeoJSON.'
6
+ s.homepage = 'https://kalmas.net'
7
+ s.authors = ['kalmas']
8
+ s.email = 'kylealmas@gmail.com'
9
+ s.require_paths = ['lib']
10
+
11
+ # Files
12
+ s.files = Dir['lib/**/*','spec/**/*','vendor/**/*','*.gemspec','*.md','CONTRIBUTORS','Gemfile','LICENSE','NOTICE.TXT']
13
+ # Tests
14
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
15
+
16
+ # Special flag to let us know this is actually a logstash plugin
17
+ s.metadata = { "logstash_plugin" => "true", "logstash_group" => "filter" }
18
+
19
+ s.add_runtime_dependency 'rgeo', '0.6.0'
20
+ s.add_runtime_dependency 'rgeo-geojson', '0.4.3'
21
+
22
+ # Gem dependencies
23
+ s.add_runtime_dependency "logstash-core-plugin-api", ">= 1.60", "<= 2.99"
24
+ s.add_development_dependency 'logstash-devutils'
25
+ end
@@ -0,0 +1,87 @@
1
+ # encoding: utf-8
2
+ require_relative '../spec_helper'
3
+ require "logstash/filters/wkt_to_geojson"
4
+
5
+ describe LogStash::Filters::WktToGeojson do
6
+ describe "Convert WKT to GeoJSON" do
7
+ let(:config) do <<-CONFIG
8
+ filter {
9
+ wkt_to_geojson {
10
+ field => "geometry"
11
+ }
12
+ }
13
+ CONFIG
14
+ end
15
+
16
+ sample("geometry" => "POLYGON ((0.0 0.0, 5.0 0.0, 5.0 5.0, 0.0 5.0, 0.0 0.0), (2.0 2.0, 2.0 3.0, 3.0 3.0, 3.0 2.0, 2.0 2.0))") do
17
+ expect(subject.get('geo_json')).to eq("{\"type\":\"Polygon\",\"coordinates\":[[[0.0,0.0],[5.0,0.0],[5.0,5.0],[0.0,5.0],[0.0,0.0]],[[2.0,2.0],[2.0,3.0],[3.0,3.0],[3.0,2.0],[2.0,2.0]]]}")
18
+ end
19
+ end
20
+
21
+ describe "Write to target field" do
22
+ let(:config) do <<-CONFIG
23
+ filter {
24
+ wkt_to_geojson {
25
+ field => "geometry"
26
+ target => "geoff_jason"
27
+ }
28
+ }
29
+ CONFIG
30
+ end
31
+
32
+ sample("geometry" => "GeometryCollection(Point(3 5), LineString(-2 0, -3 -4))") do
33
+ expect(subject.get('geoff_jason')).to eq("{\"type\":\"GeometryCollection\",\"geometries\":[{\"type\":\"Point\",\"coordinates\":[3.0,5.0]},{\"type\":\"LineString\",\"coordinates\":[[-2.0,0.0],[-3.0,-4.0]]}]}")
34
+ expect(subject.get('geometry')).to eq("GeometryCollection(Point(3 5), LineString(-2 0, -3 -4))")
35
+ end
36
+ end
37
+
38
+ describe "Handle invalid input" do
39
+ let(:config) do <<-CONFIG
40
+ filter {
41
+ wkt_to_geojson {
42
+ field => "geometry"
43
+ }
44
+ }
45
+ CONFIG
46
+ end
47
+
48
+ sample("geometry" => "MULTIPOLYGON (((40, 20, 45, 40)))") do
49
+ expect(subject).to_not include("geo_json")
50
+ expect(subject.get('geometry')).to eq("MULTIPOLYGON (((40, 20, 45, 40)))")
51
+ expect(subject.get('tags')).to include('_wkt_parse_failure')
52
+ end
53
+ end
54
+
55
+ describe "Handle nil input" do
56
+ let(:config) do <<-CONFIG
57
+ filter {
58
+ wkt_to_geojson {
59
+ field => "geometry"
60
+ tag_on_parse_failure => [ "oppsie" ]
61
+ }
62
+ }
63
+ CONFIG
64
+ end
65
+
66
+ sample("geometry" => nil) do
67
+ expect(subject).to_not include("geo_json")
68
+ expect(subject.get('geometry')).to eq(nil)
69
+ expect(subject.get('tags')).to include('oppsie')
70
+ end
71
+ end
72
+
73
+ describe "Handle absent field" do
74
+ let(:config) do <<-CONFIG
75
+ filter {
76
+ wkt_to_geojson {
77
+ field => "not_a_field"
78
+ }
79
+ }
80
+ CONFIG
81
+ end
82
+
83
+ sample("geometry" => "GeometryCollection(Point(3 5), LineString(-2 0, -3 -4))") do
84
+ expect(subject).to_not include("geo_json")
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,2 @@
1
+ # encoding: utf-8
2
+ require "logstash/devutils/rspec/spec_helper"
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-filter-wkt_to_geojson
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - kalmas
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-07-03 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.6.0
19
+ name: rgeo
20
+ prerelease: false
21
+ type: :runtime
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.6.0
27
+ - !ruby/object:Gem::Dependency
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - '='
31
+ - !ruby/object:Gem::Version
32
+ version: 0.4.3
33
+ name: rgeo-geojson
34
+ prerelease: false
35
+ type: :runtime
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 0.4.3
41
+ - !ruby/object:Gem::Dependency
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '1.60'
47
+ - - "<="
48
+ - !ruby/object:Gem::Version
49
+ version: '2.99'
50
+ name: logstash-core-plugin-api
51
+ prerelease: false
52
+ type: :runtime
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '1.60'
58
+ - - "<="
59
+ - !ruby/object:Gem::Version
60
+ version: '2.99'
61
+ - !ruby/object:Gem::Dependency
62
+ requirement: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ name: logstash-devutils
68
+ prerelease: false
69
+ type: :development
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ description:
76
+ email: kylealmas@gmail.com
77
+ executables: []
78
+ extensions: []
79
+ extra_rdoc_files: []
80
+ files:
81
+ - Gemfile
82
+ - LICENSE
83
+ - lib/logstash/filters/wkt_to_geojson.rb
84
+ - logstash-filter-wkt_to_geojson.gemspec
85
+ - spec/filters/wkt_to_geojson_spec.rb
86
+ - spec/spec_helper.rb
87
+ homepage: https://kalmas.net
88
+ licenses:
89
+ - Apache-2.0
90
+ metadata:
91
+ logstash_plugin: 'true'
92
+ logstash_group: filter
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 2.6.8
110
+ signing_key:
111
+ specification_version: 4
112
+ summary: Converts WKT geography shapes to GeoJSON.
113
+ test_files:
114
+ - spec/filters/wkt_to_geojson_spec.rb
115
+ - spec/spec_helper.rb