search_geometry_iowa 0.0.2

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: faf2219f8a06e9886aacb28a89ad61eeddef1e1c
4
+ data.tar.gz: b4f59528e72633cca335eb4d8573b2828108450a
5
+ SHA512:
6
+ metadata.gz: 7b5a5b953f20bfd8ed6016971d452c5708225a3b35e9b8829a6bcfece0f2120c0bf5eef2d1ecb8cc06edc17a29ddbc2c2831b234eccf706c9a74855c3db785c2
7
+ data.tar.gz: 9cf2f78375c4c988cf15aeab845ab8e7c0e94d6091244716fa1340e3efc68190608d624fdbbe4620fc643528e59baf2e6f05ab8159e3fd8197642f58b175144d
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in search_geometry_iowa.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 JoseLuis Torres
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # SearchGeometryIowa
2
+
3
+ Search by Tier, Range and Section
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'search_geometry_iowa'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install search_geometry_iowa
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( https://github.com/[my-github-username]/search_geometry_iowa/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rspec/core/rake_task'
4
+
5
+ #Bundler::GemHelper.install_tasks
6
+
7
+ # RSpec::Core::RakeTask.new(:spec) do |rspec|
8
+ # rspec.rspec_opts = ['--backtrace']
9
+ # end
10
+ RSpec::Core::RakeTask.new('spec')
11
+
12
+
13
+ task :default => :spec
@@ -0,0 +1,40 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://devgis.mmp360.com/geoserver/ows?cql_filter=(township%20=%20'T91N'%20AND%20range%20=%20'R46W'AND%20section%20=%205)&outputFormat=text/javascript&request=GetFeature&service=WFS&srsName=EPSG:4326&typeName=plss:plss&version=1.0.0
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept-Encoding:
11
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
+ Accept:
13
+ - "*/*"
14
+ User-Agent:
15
+ - Ruby
16
+ Host:
17
+ - devgis.mmp360.com
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Content-Disposition:
24
+ - inline; filename=geoserver-GetFeature.text
25
+ Content-Type:
26
+ - text/javascript
27
+ Date:
28
+ - Fri, 08 Aug 2014 17:21:34 GMT
29
+ Server:
30
+ - Apache-Coyote/1.1
31
+ Content-Length:
32
+ - '384'
33
+ Connection:
34
+ - keep-alive
35
+ body:
36
+ encoding: UTF-8
37
+ string: parseResponse({"type":"FeatureCollection","features":[{"type":"Feature","id":"plss.42104","geometry":{"type":"MultiPolygon","coordinates":[[[[-96.31150561080953,42.73501417583397],[-96.29194211482496,42.735011497289676],[-96.29194211482496,42.735011497289676],[-96.29177634216329,42.72123064593823],[-96.29177634216329,42.72123064593823],[-96.31149179582005,42.721129927640824],[-96.31149179582005,42.721129927640824],[-96.31150561080953,42.73501417583397]]]]},"geometry_name":"wkb_geometry","properties":{"area":2474110,"perimeter":6293.415,"township":"T91N","range":"R46W","section":5,"plss":"75","plss_":468,"plss_id":467,"shape_length":6289.52642942885,"shape_area":2471643.57875305}}],"crs":{"type":"EPSG","properties":{"code":"4326"}}})
38
+ http_version:
39
+ recorded_at: Fri, 08 Aug 2014 17:21:32 GMT
40
+ recorded_with: VCR 2.9.2
data/geoserver.yml ADDED
@@ -0,0 +1,2 @@
1
+ test:
2
+ url: https://devgis.mmp360.com
data/lib/.DS_Store ADDED
Binary file
@@ -0,0 +1,52 @@
1
+ require 'nokogiri'
2
+
3
+ class Searcher
4
+ attr_accessor :tier, :range, :section
5
+
6
+ def initialize(tier, range, section)
7
+ @tier = sanitize_str tier
8
+ @range = sanitize_str range
9
+ @section = sanitize_str section
10
+ raise 'Invalid parameters' unless valid_params?
11
+ end
12
+
13
+ def sanitize_str(str)
14
+ str.to_s.upcase
15
+ end
16
+
17
+ def geo_server_url
18
+ GEOSERVER[:url]
19
+ end
20
+
21
+ def valid_params?
22
+ return false if @tier.nil? || @range.nil?
23
+ return true if match_me(@tier, 'T', 'N|S') && match_me(@range, 'R', 'W|E')
24
+ false
25
+ end
26
+
27
+ def match_me(str, first_letter, last_letter)
28
+ str.match(/#{first_letter}[0-9]{1,2}(#{last_letter})/)
29
+ end
30
+
31
+ def get_response
32
+ call_url(format_url)
33
+ end
34
+
35
+ def format_url
36
+ url = "/geoserver/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=plss:plss"
37
+ url = url + "&cql_filter=(township%20=%20%27#{@tier}%27"
38
+ url = url + "%20AND%20range%20=%20%27#{@range}%27AND%20section%20=%20#{@section})"
39
+ geo_server_url + url + "&outputFormat=text/javascript&srsName=EPSG:4326"
40
+ end
41
+
42
+ def call_url(url)
43
+ Net::HTTP.get(URI.parse(url))
44
+ end
45
+
46
+ # @TODO remove to a libtool may be
47
+ def transform_to_multipolygon(response)
48
+ response.gsub!(/(\[){3}(.*)(\]){3}/, "[#{response.match(/(\[){3}(.*)(\]){3}/)}]")
49
+ response.gsub!(/Polygon/, 'MultiPolygon')
50
+ response
51
+ end
52
+ end
@@ -0,0 +1,3 @@
1
+ module SearchGeometryIowa
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,7 @@
1
+ require "search_geometry_iowa/version"
2
+
3
+ module SearchGeometryIowa
4
+ def by_tier_and_range(args)
5
+ Searcher.new(args[:tier], args[:range], args[:section]).get_response
6
+ end
7
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'search_geometry_iowa/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "search_geometry_iowa"
8
+ spec.version = SearchGeometryIowa::VERSION
9
+ spec.authors = ["JoseLuis Torres"]
10
+ spec.email = ["jl@joseluistorres.me"]
11
+ spec.summary = %q{Make searches by Range, Tier and Section}
12
+ spec.description = %q{Shared library to search through the GeoServer by Range, Tier and Section}
13
+ spec.homepage = "https://github.com/joseluistorres/search_geometry_iowa"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake", '~> 10.3.2'
23
+ spec.add_development_dependency 'rspec', '~> 2.13'
24
+ spec.add_development_dependency 'vcr', '~> 2.9.2'
25
+ spec.add_development_dependency 'webmock', '~> 1.18.0'
26
+ spec.add_dependency 'nokogiri', '~> 1.6.2'
27
+
28
+ end
@@ -0,0 +1,30 @@
1
+ require "spec_helper"
2
+ require 'search_geometry_iowa/searcher'
3
+
4
+ describe Searcher, :vcr_on do
5
+ let(:search) { Searcher.new('T91N','R46W', 5) }
6
+ let(:invalid_search) { Searcher.new(1, nil, 5) }
7
+
8
+ it "should get the geoserver URL" do
9
+ expect(search.geo_server_url).to eq("https://devgis.mmp360.com")
10
+ end
11
+
12
+ it "should return true if have valid params" do
13
+ expect(search.valid_params?).to eq(true)
14
+ end
15
+
16
+ it "should rise an exception if params are invalid" do
17
+ expect { invalid_search }.to raise_error(RuntimeError)
18
+ end
19
+
20
+ it "should get a correct URL" do
21
+ expect(search.format_url).to eq("https://devgis.mmp360.com/geoserver/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=plss:plss&cql_filter=(township%20=%20%27T91N%27%20AND%20range%20=%20%27R46W%27AND%20section%20=%205)&outputFormat=text/javascript&srsName=EPSG:4326")
22
+ end
23
+
24
+ it "should get correct response from geoserver" do
25
+ VCR.use_cassette('searches') do
26
+ expect(search.get_response).to match(/\{\"type\"\:\"MultiPolygon\"\,\"coordinates\"\:(\[){4}/)
27
+ end
28
+ end
29
+
30
+ end
@@ -0,0 +1,23 @@
1
+ require 'rubygems'
2
+ require 'webmock/rspec'
3
+ require 'vcr'
4
+ require 'yaml'
5
+
6
+ config_path = 'geoserver.yml'
7
+ hash_geo = YAML.load_file(config_path)['test']
8
+ GEOSERVER = Hash[hash_geo.map{|(k,v)| [k.to_sym,v]}]
9
+
10
+ VCR.configure do |c|
11
+ c.cassette_library_dir = 'fixtures/vcr_cassettes'
12
+ c.hook_into :webmock
13
+ c.allow_http_connections_when_no_cassette = true
14
+ end
15
+ VCR.turn_off! # turn off VCR by default
16
+
17
+ RSpec.configure do |config|
18
+
19
+ config.before(:all, :vcr_on) do
20
+ VCR.turn_on!
21
+ end
22
+
23
+ end
metadata ADDED
@@ -0,0 +1,146 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: search_geometry_iowa
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - JoseLuis Torres
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-08 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.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
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.3.2
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 10.3.2
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.13'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.13'
55
+ - !ruby/object:Gem::Dependency
56
+ name: vcr
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 2.9.2
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 2.9.2
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 1.18.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 1.18.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: nokogiri
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 1.6.2
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 1.6.2
97
+ description: Shared library to search through the GeoServer by Range, Tier and Section
98
+ email:
99
+ - jl@joseluistorres.me
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - Gemfile
107
+ - LICENSE.txt
108
+ - README.md
109
+ - Rakefile
110
+ - fixtures/vcr_cassettes/searches.yml
111
+ - geoserver.yml
112
+ - lib/.DS_Store
113
+ - lib/search_geometry_iowa.rb
114
+ - lib/search_geometry_iowa/searcher.rb
115
+ - lib/search_geometry_iowa/version.rb
116
+ - search_geometry_iowa.gemspec
117
+ - spec/searcher_spec.rb
118
+ - spec/spec_helper.rb
119
+ homepage: https://github.com/joseluistorres/search_geometry_iowa
120
+ licenses:
121
+ - MIT
122
+ metadata: {}
123
+ post_install_message:
124
+ rdoc_options: []
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ requirements: []
138
+ rubyforge_project:
139
+ rubygems_version: 2.2.2
140
+ signing_key:
141
+ specification_version: 4
142
+ summary: Make searches by Range, Tier and Section
143
+ test_files:
144
+ - spec/searcher_spec.rb
145
+ - spec/spec_helper.rb
146
+ has_rdoc: