sos-core 0.1.3
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 +7 -0
- data/lib/board_of_directors/boss.rb +66 -0
- data/lib/board_of_directors/factory/factory.rb +70 -0
- data/lib/board_of_directors/factory/hashMerge.rb +71 -0
- data/lib/employees/fes.rb +7 -0
- data/lib/employees/fes/comparisonOps/propertyIsBetween.rb +32 -0
- data/lib/employees/fes/comparisonOps/propertyIsEqualTo.rb +10 -0
- data/lib/employees/fes/comparisonOps/propertyIsGreaterThan.rb +10 -0
- data/lib/employees/fes/comparisonOps/propertyIsGreaterThanOrEqualTo.rb +10 -0
- data/lib/employees/fes/comparisonOps/propertyIsLessThan.rb +10 -0
- data/lib/employees/fes/comparisonOps/propertyIsLessThanOrEqualTo.rb +10 -0
- data/lib/employees/fes/comparisonOps/propertyIsLike.rb +10 -0
- data/lib/employees/fes/comparisonOps/propertyIsNil.rb +10 -0
- data/lib/employees/fes/comparisonOps/propertyIsNotEqualTo.rb +10 -0
- data/lib/employees/fes/comparisonOps/propertyIsNull.rb +10 -0
- data/lib/employees/fes/expression/function.rb +9 -0
- data/lib/employees/fes/expression/literal.rb +7 -0
- data/lib/employees/fes/expression/valueReference.rb +9 -0
- data/lib/employees/fes/extensionOps/extensionOps.rb +6 -0
- data/lib/employees/fes/logicOps/and.rb +9 -0
- data/lib/employees/fes/logicOps/not.rb +10 -0
- data/lib/employees/fes/logicOps/or.rb +9 -0
- data/lib/employees/fes/spatialOps/bbox.rb +10 -0
- data/lib/employees/fes/spatialOps/beyond.rb +10 -0
- data/lib/employees/fes/spatialOps/contains.rb +10 -0
- data/lib/employees/fes/spatialOps/crosses.rb +10 -0
- data/lib/employees/fes/spatialOps/dWithin.rb +10 -0
- data/lib/employees/fes/spatialOps/disjoint.rb +10 -0
- data/lib/employees/fes/spatialOps/equals.rb +9 -0
- data/lib/employees/fes/spatialOps/intersects.rb +10 -0
- data/lib/employees/fes/spatialOps/touches.rb +10 -0
- data/lib/employees/fes/spatialOps/withIn.rb +9 -0
- data/lib/employees/fes/temporalOps/after.rb +9 -0
- data/lib/employees/fes/temporalOps/anyInteracts.rb +10 -0
- data/lib/employees/fes/temporalOps/before.rb +9 -0
- data/lib/employees/fes/temporalOps/begins.rb +9 -0
- data/lib/employees/fes/temporalOps/begunBy.rb +9 -0
- data/lib/employees/fes/temporalOps/during.rb +9 -0
- data/lib/employees/fes/temporalOps/endedBy.rb +9 -0
- data/lib/employees/fes/temporalOps/ends.rb +9 -0
- data/lib/employees/fes/temporalOps/meets.rb +9 -0
- data/lib/employees/fes/temporalOps/metBy.rb +9 -0
- data/lib/employees/fes/temporalOps/overlappedBy.rb +10 -0
- data/lib/employees/fes/temporalOps/tContains.rb +9 -0
- data/lib/employees/fes/temporalOps/tOverlaps.rb +10 -0
- data/lib/employees/fes/temporalOps/tequals.rb +9 -0
- data/lib/employees/gml.rb +2 -0
- data/lib/employees/gml/begin.rb +5 -0
- data/lib/employees/gml/end.rb +5 -0
- data/lib/employees/gml/envelope.rb +9 -0
- data/lib/employees/gml/exterior.rb +5 -0
- data/lib/employees/gml/linearRing.rb +9 -0
- data/lib/employees/gml/lowerCorner.rb +5 -0
- data/lib/employees/gml/polygon.rb +9 -0
- data/lib/employees/gml/posList.rb +5 -0
- data/lib/employees/gml/timeInstant.rb +9 -0
- data/lib/employees/gml/timePeriod.rb +33 -0
- data/lib/employees/gml/timePosition.rb +6 -0
- data/lib/employees/gml/upperCorner.rb +5 -0
- data/lib/employees/man.rb +1 -0
- data/lib/employees/mankind/complicated.rb +55 -0
- data/lib/employees/mankind/people.rb +58 -0
- data/lib/employees/mankind/simple.rb +16 -0
- data/lib/employees/sos.rb +2 -0
- data/lib/employees/sos/offering.rb +22 -0
- data/lib/employees/sos/temporalFilter.rb +5 -0
- data/lib/sos-core.rb +35 -0
- data/lib/sos-helper.rb +21 -0
- data/lib/sos_helper/capability.rb +65 -0
- data/lib/sos_helper/getObservation.xml +11 -0
- data/lib/sos_helper/node.rb +30 -0
- data/lib/sos_helper/observation.rb +77 -0
- data/lib/sos_helper/offering.rb +49 -0
- data/lib/sos_helper/xmlRequest.rb +54 -0
- metadata +117 -0
@@ -0,0 +1,58 @@
|
|
1
|
+
class People
|
2
|
+
def initialize(tasks=nil)
|
3
|
+
@tasks = tasks.to_a
|
4
|
+
@attributes = ""
|
5
|
+
end
|
6
|
+
|
7
|
+
def do(tasks)
|
8
|
+
|
9
|
+
end
|
10
|
+
|
11
|
+
def typeOf(task, args={})
|
12
|
+
raise ArgumentError "Set check type" if args == {}
|
13
|
+
type = args[:is] || args[:is_not]
|
14
|
+
return task.class == type if not args[:is].nil?
|
15
|
+
return task.class != type if not args[:is_not].nil?
|
16
|
+
end
|
17
|
+
|
18
|
+
def inspect
|
19
|
+
tag
|
20
|
+
end
|
21
|
+
|
22
|
+
def inject(task)
|
23
|
+
task if typeOf task, is: String
|
24
|
+
end
|
25
|
+
|
26
|
+
def tag(value=nil)
|
27
|
+
"<#{namespace}#{tag_name}>#{value.to_s}</#{namespace}#{tag_name}> "
|
28
|
+
end
|
29
|
+
|
30
|
+
def tag_name
|
31
|
+
uncapitalize self.class.to_s
|
32
|
+
end
|
33
|
+
|
34
|
+
def uncapitalize(name)
|
35
|
+
name = name.dup
|
36
|
+
name[0] = name[0].downcase;
|
37
|
+
name
|
38
|
+
end
|
39
|
+
|
40
|
+
def capitalize(name)
|
41
|
+
name = name.dup
|
42
|
+
name[0] = name[0].upcase;
|
43
|
+
name
|
44
|
+
end
|
45
|
+
|
46
|
+
def attributes(attrs)
|
47
|
+
attrs.each { |k, v| @attributes += " #{namespace}" + k.to_s + "=\"" + v.to_a[0] + "\"" }
|
48
|
+
end
|
49
|
+
|
50
|
+
def class_name
|
51
|
+
self.class.to_s
|
52
|
+
end
|
53
|
+
|
54
|
+
def namespace
|
55
|
+
nil
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require_relative 'people.rb'
|
2
|
+
|
3
|
+
class Simple < People
|
4
|
+
def do(tasks)
|
5
|
+
raise ArgumentError, "It must be Array in the hash" unless tasks.is_a? Array
|
6
|
+
|
7
|
+
tasks = tasks.to_a.map do |task|
|
8
|
+
tag inject task
|
9
|
+
end
|
10
|
+
tasks.join " "
|
11
|
+
end
|
12
|
+
|
13
|
+
def namespace
|
14
|
+
"sos:"
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class Offering < Simple
|
2
|
+
|
3
|
+
end
|
4
|
+
|
5
|
+
class Procedure < Simple
|
6
|
+
|
7
|
+
end
|
8
|
+
|
9
|
+
class ObservedProperty < Simple
|
10
|
+
|
11
|
+
end
|
12
|
+
|
13
|
+
class FeatureOfInterest < Simple
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
class ResponseFormat < Simple
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
# a = Procedure.new()
|
22
|
+
# p a.do ["1", "2", "3", "4", "5"]
|
data/lib/sos-core.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require_relative 'sos-helper.rb'
|
2
|
+
|
3
|
+
class SOS
|
4
|
+
|
5
|
+
def initialize(url, args={})
|
6
|
+
# request to http://cgis.csrsr.ncu.edu.tw:8080/swcb-sos-new/service
|
7
|
+
@request = XmlRequest.new(url)
|
8
|
+
@capabilities = getCapabilities
|
9
|
+
@observations, @gc, @go = nil
|
10
|
+
end
|
11
|
+
|
12
|
+
def allowedValue
|
13
|
+
@allowedValue ||= checkAllowedValues
|
14
|
+
end
|
15
|
+
|
16
|
+
def getCapabilities(query={})
|
17
|
+
@gc = SOSHelper::GetCapability.new(request: @request)
|
18
|
+
@capabilities = @gc.send
|
19
|
+
end
|
20
|
+
|
21
|
+
def checkAllowedValues
|
22
|
+
@gc.checkAllowedValues
|
23
|
+
end
|
24
|
+
|
25
|
+
def getObservations(condition={})
|
26
|
+
@go = SOSHelper::GetObservation.new(request: @request)
|
27
|
+
filter condition unless condition == {}
|
28
|
+
@go
|
29
|
+
end
|
30
|
+
|
31
|
+
def offering
|
32
|
+
@offerings = @offerings || @capabilities.xpath("//sos:Contents//swes:offering").map { |node| Offering.new(node) } unless @capabilities.nil?
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
data/lib/sos-helper.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'set'
|
2
|
+
require 'nokogiri'
|
3
|
+
Dir[ File.dirname(__FILE__) + "/employees/*.rb"].each {|file| require file }
|
4
|
+
require_relative 'board_of_directors/factory/factory.rb'
|
5
|
+
require_relative 'board_of_directors/boss.rb'
|
6
|
+
Dir[ File.dirname(__FILE__) + "/sos_helper/*.rb"].each {|file| require file }
|
7
|
+
|
8
|
+
module SOSHelper
|
9
|
+
Dir[ File.dirname(__FILE__) + "/sos_helper/*.rb"]
|
10
|
+
Urls = ["http://cgis.csrsr.ncu.edu.tw:8080/swcb-sos-new/service",
|
11
|
+
"http://cgis.csrsr.ncu.edu.tw:8080/epa-sos/service",
|
12
|
+
"http://cgis.csrsr.ncu.edu.tw:8080/epa-aqx-sos/service"].freeze
|
13
|
+
|
14
|
+
Relics = ["offering","observedProperty",
|
15
|
+
"featureOfInterest",
|
16
|
+
"procedure", "spatialFilter",
|
17
|
+
"temporalFilter", "responseFormat"].freeze
|
18
|
+
|
19
|
+
ObservationRequest = File.open(File.dirname(__FILE__) + '/sos_helper/getObservation.xml') { |f| Nokogiri::XML(f) }.freeze
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module SOSHelper
|
2
|
+
class GetCapability
|
3
|
+
|
4
|
+
def initialize(args={})
|
5
|
+
@request = args[:request]
|
6
|
+
@url = args[:url]
|
7
|
+
@query = {}
|
8
|
+
@allowedValue = {}
|
9
|
+
@capabilities = nil
|
10
|
+
end
|
11
|
+
|
12
|
+
def send(query={})
|
13
|
+
query[:service] = query[:service] || "SOS"
|
14
|
+
query[:request] = query[:request] || "GetCapabilities"
|
15
|
+
@capabilities = request.get(query) { |str| next Nokogiri::XML(str) }
|
16
|
+
end
|
17
|
+
|
18
|
+
def checkAllowedValues(capabilities=nil)
|
19
|
+
|
20
|
+
@allowedValue = check Relics
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def dig(operation, type="Value")
|
26
|
+
@capabilities.xpath("//ows:Operation[@name='GetObservation']//ows:Parameter[@name='#{operation}']//ows:#{type}")
|
27
|
+
end
|
28
|
+
|
29
|
+
def request
|
30
|
+
@request ||= XmlRequest.new(@url)
|
31
|
+
end
|
32
|
+
|
33
|
+
def check(relics)
|
34
|
+
backpack = {}
|
35
|
+
|
36
|
+
relics.each do |relic|
|
37
|
+
level = checkLevelOf relic
|
38
|
+
|
39
|
+
backpack[ relic.to_sym ] = adventure level, relic
|
40
|
+
end
|
41
|
+
|
42
|
+
backpack
|
43
|
+
end
|
44
|
+
|
45
|
+
def adventure(level, relic)
|
46
|
+
if level == "normal"
|
47
|
+
(dig relic).map { |treasure| normal treasure }
|
48
|
+
else
|
49
|
+
(dig relic, "Range").map { |treasure| complex treasure}
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def checkLevelOf(condition)
|
54
|
+
!(condition.include? "Filter") ? "normal" : "complex"
|
55
|
+
end
|
56
|
+
|
57
|
+
def normal(tag)
|
58
|
+
tag.text
|
59
|
+
end
|
60
|
+
|
61
|
+
def complex(tag)
|
62
|
+
[tag.xpath(".//ows:MinimumValue").text, tag.xpath(".//ows:MaximumValue").text]
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<sos:GetObservation
|
3
|
+
xmlns:sos="http://www.opengis.net/sos/2.0"
|
4
|
+
xmlns:fes="http://www.opengis.net/fes/2.0"
|
5
|
+
xmlns:gml="http://www.opengis.net/gml/3.2"
|
6
|
+
xmlns:swe="http://www.opengis.net/swe/2.0"
|
7
|
+
xmlns:xlink="http://www.w3.org/1999/xlink"
|
8
|
+
xmlns:swes="http://www.opengis.net/swes/2.0"
|
9
|
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" service="SOS" version="2.0.0" xsi:schemaLocation="http://www.opengis.net/sos/2.0 http://schemas.opengis.net/sos/2.0/sos.xsd">
|
10
|
+
|
11
|
+
</sos:GetObservation>
|
@@ -0,0 +1,30 @@
|
|
1
|
+
class Node
|
2
|
+
NAMESPACE = { id: "swes:identifier",
|
3
|
+
procedure: "swes:procedure",
|
4
|
+
observableProperty: "swes:observableProperty",
|
5
|
+
observedArea: "sos:observedArea",
|
6
|
+
envelope: "gml:Envelope",
|
7
|
+
lowerCorner: "gml:lowerCorner",
|
8
|
+
upperCorner: "gml:upperCorner",
|
9
|
+
timePeriod: "gml:TimePeriod",
|
10
|
+
phenomenonTime: "sos:phenomenonTime",
|
11
|
+
begin: "gml:beginPosition",
|
12
|
+
end: "gml:endPosition",
|
13
|
+
resultTime: "sos:resultTime"}
|
14
|
+
|
15
|
+
def initialize(node)
|
16
|
+
@node = node.dup
|
17
|
+
end
|
18
|
+
|
19
|
+
def [](name)
|
20
|
+
Node.new @node.xpath(".//#{NAMESPACE[name]}")
|
21
|
+
end
|
22
|
+
|
23
|
+
def method_missing(name)
|
24
|
+
@node.send(name)
|
25
|
+
end
|
26
|
+
|
27
|
+
def inspect
|
28
|
+
self.to_s
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
module SOSHelper
|
2
|
+
|
3
|
+
class Observation
|
4
|
+
def initialize(args)
|
5
|
+
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
# GetObservation just focus on two things:
|
10
|
+
# filter conditions into hash
|
11
|
+
# send the conditions to specific @request
|
12
|
+
class GetObservation
|
13
|
+
|
14
|
+
def initialize(args={})
|
15
|
+
@request = args[:request]
|
16
|
+
@xml = ObservationRequest.dup
|
17
|
+
@request_body = nil
|
18
|
+
@body = ""
|
19
|
+
end
|
20
|
+
|
21
|
+
# Without preset Conditions is Okay
|
22
|
+
def send(body=nil, &block)
|
23
|
+
raise RuntimeError, 'Need to set request' if @request.nil?
|
24
|
+
@body = condition.transform @xml if body.nil?
|
25
|
+
@request.post(@body, &block) if block_given?
|
26
|
+
end
|
27
|
+
|
28
|
+
def body(body=nil)
|
29
|
+
@body = body
|
30
|
+
end
|
31
|
+
|
32
|
+
# filter() => no argument to return @condtion
|
33
|
+
# filter({:condition => "value"}) => extend @condition
|
34
|
+
def filter(custom={})
|
35
|
+
raise ArgumentError, 'Filters need to be hash' unless custom.is_a? Hash
|
36
|
+
return condition.to_s if custom == {}
|
37
|
+
condition.merge! custom
|
38
|
+
|
39
|
+
self
|
40
|
+
end
|
41
|
+
|
42
|
+
def inspect
|
43
|
+
"<GetObservation 0x#{self.__id__} @condition= #{condition}>"
|
44
|
+
end
|
45
|
+
|
46
|
+
def condition
|
47
|
+
@condition ||= Factory.new()
|
48
|
+
end
|
49
|
+
|
50
|
+
def offering(text)
|
51
|
+
filter({offering: text})
|
52
|
+
end
|
53
|
+
|
54
|
+
def procedure(text)
|
55
|
+
filter({procedure: text})
|
56
|
+
end
|
57
|
+
|
58
|
+
def observedProperty(text)
|
59
|
+
filter({observedProperty: text})
|
60
|
+
end
|
61
|
+
|
62
|
+
def temporalFilter(id, range)
|
63
|
+
filter({ temporalFilter: {
|
64
|
+
during: {
|
65
|
+
valueReference: "phenomenonTime",
|
66
|
+
timePeriod: { attributes: { id: id }, range: range } }
|
67
|
+
}
|
68
|
+
})
|
69
|
+
end
|
70
|
+
|
71
|
+
def responseFormat(text)
|
72
|
+
filter({responseFormat: text})
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require_relative 'node'
|
2
|
+
|
3
|
+
module SOSHelper
|
4
|
+
class Offering
|
5
|
+
ATRRIBUTES = [ :identifier, :procedure, :observableProperty, :observedArea, :resultTime, :phenomenonTime, :node ]
|
6
|
+
ATRRIBUTES.each { |t| attr_reader t }
|
7
|
+
|
8
|
+
def initialize(xml_offer)
|
9
|
+
@node = Node.new xml_offer
|
10
|
+
@id, @procedure = getText(:id), getText(:procedure)
|
11
|
+
@observableProperty = getList(:observableProperty)
|
12
|
+
@observedArea = getHash(:observedArea, [:lowerCorner, :upperCorner])
|
13
|
+
@phenomenonTime = getHash(:phenomenonTime, [:begin, :end])
|
14
|
+
@resultTime = getHash(:resultTime, [:begin, :end])
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
def getText(name)
|
19
|
+
@node[name].text
|
20
|
+
end
|
21
|
+
|
22
|
+
def getList(name)
|
23
|
+
@node[name].children.map { |node| node.text }
|
24
|
+
end
|
25
|
+
|
26
|
+
def getHash(name, scope=[])
|
27
|
+
hash = {}
|
28
|
+
scope.each { |s| hash.store(s, @node[name][s].text )} unless scope.empty?
|
29
|
+
hash
|
30
|
+
end
|
31
|
+
|
32
|
+
def to_json
|
33
|
+
{ "identifier": @id,
|
34
|
+
"procedure": @procedure,
|
35
|
+
"observableProperty": @observableProperty,
|
36
|
+
"observedArea": @observedArea,
|
37
|
+
"phenomenonTime": @phenomenonTime,
|
38
|
+
"resultTime": @resultTime }
|
39
|
+
end
|
40
|
+
|
41
|
+
def to_s
|
42
|
+
to_json.to_s
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
# p a.node.inspect
|
49
|
+
# p a.to_json
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require "uri"
|
2
|
+
require "net/http"
|
3
|
+
require "json"
|
4
|
+
|
5
|
+
# To send get or post request with custom payload.
|
6
|
+
#
|
7
|
+
# Usage:
|
8
|
+
# => hello = XmlRequest.new( uri )
|
9
|
+
# => hello.get({service: "SOS", request: "GetCapabilities"})
|
10
|
+
#
|
11
|
+
class XmlRequest
|
12
|
+
|
13
|
+
attr_accessor :uri, :packet, :post
|
14
|
+
|
15
|
+
def initialize(url)
|
16
|
+
@uri = url
|
17
|
+
@packet = Net::HTTP.new(uri.host, uri.port)
|
18
|
+
@query = nil
|
19
|
+
end
|
20
|
+
|
21
|
+
def post(body=nil, &block)
|
22
|
+
@post = Net::HTTP::Post.new(uri.path)
|
23
|
+
@post["Content-type"] = "application/xml"
|
24
|
+
@post.body = body
|
25
|
+
# File.new("./request/request-tmp", "w").write body.dup
|
26
|
+
p body, "packet sending, it may take times to get response..."
|
27
|
+
@res = send @post
|
28
|
+
@result = yield @res.body if block_given?
|
29
|
+
end
|
30
|
+
|
31
|
+
def get(query={}, &block)
|
32
|
+
fullPath = path_combine query
|
33
|
+
@get = Net::HTTP::Get.new(fullPath)
|
34
|
+
@res = send @get
|
35
|
+
@result = yield @res.body if block_given?
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def uri
|
41
|
+
URI(@uri)
|
42
|
+
end
|
43
|
+
|
44
|
+
def path_combine(query={})
|
45
|
+
params = URI.encode_www_form(query)
|
46
|
+
[uri.path, params].join('?')
|
47
|
+
end
|
48
|
+
|
49
|
+
def send(action)
|
50
|
+
@packet.request( action )
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|