skra-geo 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +111 -0
- data/Rakefile +6 -0
- data/lib/skra/geo.rb +64 -0
- data/lib/skra/geo/version.rb +5 -0
- data/skra-geo.gemspec +26 -0
- data/spec/skra/geo_spec.rb +52 -0
- data/spec/spec_helper.rb +2 -0
- metadata +115 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 54539d0fd651a0e9ecda8eb8af3f47bbfdce0f72
|
4
|
+
data.tar.gz: 046db7317d618107fc75ecc9d7179fa79b0bea32
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4b7f51c3ef2f7b022dd46c1b6196f790d7a77be1b1bc35495cb578f00c5b94af224af2aefd437b802bf9a2f399414ba89cbfe83a2ff95c523218b99f819c9ba8
|
7
|
+
data.tar.gz: ec334d91375ee1c875781e36fced7958535f6bb3003bb8625c557465f71e909a9a8390cbb2f74778ffdf81c65168fb7b8ff869dc227bbb2b5c8eab91cfc74013
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Aitor García
|
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,111 @@
|
|
1
|
+
# Skra::Geo
|
2
|
+
|
3
|
+
Skra::Geo is a thin ruby wrapper to query WFS API of the [Icelandic National Registry](http://www.skra.is) Geoserver.
|
4
|
+
Its main goal is to provide easy access to geo information of every parcel in Iceland, thus making trivial the implementation
|
5
|
+
of features like geolocation.
|
6
|
+
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
gem 'skra-geo'
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install skra-geo
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
> bundle console
|
26
|
+
>> Skra::Geo.landnr(100404) # Looking up by landnr (Parcel ID)
|
27
|
+
[
|
28
|
+
{"type"=>"Feature", "id"=>"VSTADF.fid-51fadf5a_144745fbcac_-1eb7", "geometry"=>{"type"=… data skipped …4)", "HUSMERKING"=>"13"}},
|
29
|
+
{"type"=>"Feature", "id"=>"VSTADF.fid-51fadf5a_144745fbcac_-1eb6", "geometry"=>{"type"=… data skipped …4)", "HUSMERKING"=>"1"}}
|
30
|
+
]
|
31
|
+
```
|
32
|
+
|
33
|
+
Althought landnr (Parcel ID) is one the most usual ids for querying the server, it's also possible to query the server by different properties:
|
34
|
+
|
35
|
+
* Looking up by heinum (Property ID)
|
36
|
+
```ruby
|
37
|
+
>> Skra::Geo.heinum(1008773) # Looking up by heinum (Property ID)
|
38
|
+
```
|
39
|
+
|
40
|
+
* Looking up by street name
|
41
|
+
```ruby
|
42
|
+
>> Skra::Geo.street('Holtsgata') # All streets in Iceland with that name
|
43
|
+
>> Skra::Geo.street('Holtsgata', 13) # All buildings No. 13 in Holtsgata streets in Iceland
|
44
|
+
>> Skra::Geo.street('Holtsgata', 13, 101) # Building No. 13 in Holtsgata streets in postcode 101 (Reykjavík)
|
45
|
+
>> Skra::Geo.street('Holtsgötu', 13, 101, {:dative => true}) # dative version of the name street (useful in icelandic)
|
46
|
+
```
|
47
|
+
|
48
|
+
* Or even more freely by any property using the ```Skra::Geo#query``` method
|
49
|
+
```ruby
|
50
|
+
>> Skra::Geo.query([{:name => :POSTNR, :value => 101}]) # All features in postcode 101
|
51
|
+
```
|
52
|
+
|
53
|
+
## Data
|
54
|
+
|
55
|
+
A feature returned by the server will have the following structure:
|
56
|
+
```json
|
57
|
+
[
|
58
|
+
{
|
59
|
+
"type": "Feature",
|
60
|
+
"id": "VSTADF.fid-51fadf5a_144745ff88d_-259b",
|
61
|
+
"geometry": {
|
62
|
+
"type": "Point",
|
63
|
+
"coordinates": [
|
64
|
+
356227.738636364,
|
65
|
+
408530.288636364
|
66
|
+
]
|
67
|
+
},
|
68
|
+
"geometry_name": "HNIT",
|
69
|
+
"properties": {
|
70
|
+
"HNITNUM": 10019748,
|
71
|
+
"SVFNR": "0000",
|
72
|
+
"LANDNR": 100404,
|
73
|
+
"HEINUM": 1008773,
|
74
|
+
"MATSNR": null,
|
75
|
+
"POSTNR": 101,
|
76
|
+
"HEITI_NF": "Holtsgata",
|
77
|
+
"HEITI_TGF": "Holtsgötu",
|
78
|
+
"HUSNR": 13,
|
79
|
+
"BOKST": null,
|
80
|
+
"VIDSK": null,
|
81
|
+
"SERHEITI": null,
|
82
|
+
"DAGS_INN": "2007-09-07",
|
83
|
+
"DAGS_LEIDR": "2010-01-08",
|
84
|
+
"GAGNA_EIGN": "Fasteignaskrá Íslands",
|
85
|
+
"TEGHNIT": 0,
|
86
|
+
"YFIRFARID": 0,
|
87
|
+
"YFIRF_HEITI": null,
|
88
|
+
"ATH": null,
|
89
|
+
"NAKV_XY": null,
|
90
|
+
"NOTNR": 956,
|
91
|
+
"LM_HEIMILISFANG": "Holtsgata 13 (100404)",
|
92
|
+
"VEF_BIRTING": "Holtsgata 13 (100404)",
|
93
|
+
"HUSMERKING": "13"
|
94
|
+
}
|
95
|
+
}
|
96
|
+
]
|
97
|
+
```
|
98
|
+
|
99
|
+
Geometry coordinates are returned in [ISNET93](https://is.wikipedia.org/wiki/ISNET93) and they usually need conversion to something more standard (like [WGS84](https://en.wikipedia.org/wiki/World_Geodetic_System)) to be used.
|
100
|
+
|
101
|
+
## Contributing
|
102
|
+
|
103
|
+
1. Fork it ( http://github.com/<my-github-username>/skra-geo/fork )
|
104
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
105
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
106
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
107
|
+
5. Create new Pull Request
|
108
|
+
|
109
|
+
## Kudos
|
110
|
+
|
111
|
+
This library was extracted from the work made by [Linking Paths](http://www.linkingpaths.com) during the first hackathon organized by [Open Knowledge Foundation Iceland](https://www.facebook.com/OKFNis). Documentation on the actual functionaly of the server was researched from [geoserver.org](http://docs.geoserver.org/stable/en/user/services/wfs/reference.html#operations) and previous work on the python library [fasteignamat-functions](https://github.com/pallih/fasteignamat-functions) was checked as reference.
|
data/Rakefile
ADDED
data/lib/skra/geo.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
require "httparty"
|
2
|
+
|
3
|
+
require "skra/geo/version"
|
4
|
+
|
5
|
+
module Skra
|
6
|
+
module Geo
|
7
|
+
include HTTParty
|
8
|
+
base_uri 'geo.skra.is'
|
9
|
+
def self.defaults
|
10
|
+
{
|
11
|
+
:service => :wfs,
|
12
|
+
:version => "1.1.0",
|
13
|
+
:request => 'GetFeature',
|
14
|
+
:typename => 'fasteignaskra:VSTADF',
|
15
|
+
:outputformat => 'json'
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.query(filter, options={})
|
20
|
+
get_features(filter, options)
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.heinum(id, options={})
|
24
|
+
get_features([{:name => :HEINUM, :value => id}], options)
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.landnr(id, options={})
|
28
|
+
get_features([{:name => :LANDNR, :value => id}], options)
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.street(name, number=nil, postcode=nil, options={})
|
32
|
+
property = options.delete(:dative) ? :HEITI_TGF : :HEITI_NF
|
33
|
+
filter = [
|
34
|
+
{:name => property, :value => name}
|
35
|
+
]
|
36
|
+
filter << {:name => :HUSNR, :value => number} if number
|
37
|
+
filter << {:name => :POSTNR, :value => postcode} if postcode
|
38
|
+
get_features(filter, options)
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
protected
|
43
|
+
|
44
|
+
def self.get_features(filter, options)
|
45
|
+
query = defaults.merge(options)
|
46
|
+
wfs_filter = build_wfs_filter(filter)
|
47
|
+
response = post('/geoserver/wfs', { :query => query.merge(wfs_filter) })
|
48
|
+
query[:outputformat] == 'json' ? response["features"] : response
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.build_wfs_filter(properties=[])
|
52
|
+
conditions = properties.map do |condition|
|
53
|
+
<<-eos
|
54
|
+
<PropertyIsLike wildCard="*" singleChar="#" escapeChar="!">
|
55
|
+
<PropertyName>fasteignaskra:#{condition[:name]}</PropertyName>
|
56
|
+
<Literal>#{condition[:value]}</Literal>
|
57
|
+
</PropertyIsLike>
|
58
|
+
eos
|
59
|
+
end.join
|
60
|
+
conditions = "<And>#{conditions}</And>" if properties.size > 1
|
61
|
+
properties.size > 0 ? { :filter => "<Filter>#{conditions}</Filter>" } : {}
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
data/skra-geo.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'skra/geo/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "skra-geo"
|
8
|
+
spec.version = Skra::Geo::VERSION
|
9
|
+
spec.authors = ["Aitor García"]
|
10
|
+
spec.email = ["aitor@linkingpaths.com"]
|
11
|
+
spec.summary = %q{Skra::Geo is a thin ruby wrapper to query WFS API of the [Icelandic National Registry](http://www.skra.is) Geoserver.}
|
12
|
+
spec.homepage = "https://github.com/linkingpaths/skra-geo"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
21
|
+
spec.add_development_dependency "rake"
|
22
|
+
spec.add_development_dependency "rspec"
|
23
|
+
|
24
|
+
spec.add_dependency('httparty', [">= 0.13.0"])
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Skra::Geo do
|
4
|
+
it 'should have a version number' do
|
5
|
+
Skra::Geo::VERSION.should_not be_nil
|
6
|
+
end
|
7
|
+
|
8
|
+
|
9
|
+
describe "search based on landnr" do
|
10
|
+
it "should return the feature for that landnr (Parcel ID)" do
|
11
|
+
results = Skra::Geo.landnr(100404)
|
12
|
+
results[0]["properties"]["LANDNR"].should == 100404
|
13
|
+
results[0]["properties"]["HEITI_NF"].should == "Holtsgata"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "search based on heinum" do
|
18
|
+
it "should return the feature for that heinum (Property ID)" do
|
19
|
+
results = Skra::Geo.heinum(1008773)
|
20
|
+
results.size.should == 1
|
21
|
+
results[0]["properties"]["HEINUM"].should == 1008773
|
22
|
+
results[0]["properties"]["HEITI_NF"].should == "Holtsgata"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "search based on a street" do
|
27
|
+
|
28
|
+
it "should return features for all streets in Iceland with that name" do
|
29
|
+
results = Skra::Geo.street('Holtsgata')
|
30
|
+
results.size.should > 1
|
31
|
+
results.map{|result| result["properties"]["POSTNR"]}.should include(101)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should return features for all streets in Iceland using a name in dative" do
|
35
|
+
results = Skra::Geo.street('Holtsgötu', nil, nil, {:dative => true})
|
36
|
+
results.size.should > 1
|
37
|
+
results.map{|result| result["properties"]["POSTNR"]}.should include(101)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should return features for a given street+number" do
|
41
|
+
results = Skra::Geo.street('Holtsgata', 13)
|
42
|
+
results.size.should > 1
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should return features for a given street+number+postcode" do
|
46
|
+
results = Skra::Geo.street('Holtsgata', 13, 101)
|
47
|
+
results.size.should == 1
|
48
|
+
results[0]["properties"]["HEINUM"].should == 1008773
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: skra-geo
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Aitor García
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-02-27 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.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
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: httparty
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.13.0
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.13.0
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- aitor@linkingpaths.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- ".travis.yml"
|
79
|
+
- Gemfile
|
80
|
+
- LICENSE.txt
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- lib/skra/geo.rb
|
84
|
+
- lib/skra/geo/version.rb
|
85
|
+
- skra-geo.gemspec
|
86
|
+
- spec/skra/geo_spec.rb
|
87
|
+
- spec/spec_helper.rb
|
88
|
+
homepage: https://github.com/linkingpaths/skra-geo
|
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: '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.2.0
|
109
|
+
signing_key:
|
110
|
+
specification_version: 4
|
111
|
+
summary: Skra::Geo is a thin ruby wrapper to query WFS API of the [Icelandic National
|
112
|
+
Registry](http://www.skra.is) Geoserver.
|
113
|
+
test_files:
|
114
|
+
- spec/skra/geo_spec.rb
|
115
|
+
- spec/spec_helper.rb
|