stac 0.1.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +6 -0
- data/CHANGELOG.md +18 -0
- data/GETTING_STARTED.md +384 -0
- data/Gemfile.lock +48 -37
- data/README.md +16 -57
- data/Rakefile +62 -4
- data/Steepfile +2 -0
- data/lib/stac/asset.rb +7 -1
- data/lib/stac/catalog.rb +81 -9
- data/lib/stac/collection.rb +43 -9
- data/lib/stac/common_metadata.rb +162 -0
- data/lib/stac/errors.rb +2 -5
- data/lib/stac/extension.rb +34 -0
- data/lib/stac/extensions/electro_optical.rb +67 -0
- data/lib/stac/extensions/projection.rb +42 -0
- data/lib/stac/extensions/scientific_citation.rb +84 -0
- data/lib/stac/extensions/view_geometry.rb +38 -0
- data/lib/stac/extent.rb +39 -31
- data/lib/stac/file_writer.rb +31 -0
- data/lib/stac/hash_like.rb +74 -0
- data/lib/stac/item.rb +58 -22
- data/lib/stac/link.rb +50 -14
- data/lib/stac/object_resolver.rb +14 -20
- data/lib/stac/properties.rb +6 -1
- data/lib/stac/provider.rb +5 -1
- data/lib/stac/{default_http_client.rb → simple_http_client.rb} +9 -4
- data/lib/stac/stac_object.rb +142 -31
- data/lib/stac/version.rb +1 -1
- data/lib/stac.rb +18 -2
- data/sig/stac/asset.rbs +3 -3
- data/sig/stac/catalog.rbs +29 -5
- data/sig/stac/collection.rbs +13 -5
- data/sig/stac/common_metadata.rbs +34 -0
- data/sig/stac/errors.rbs +1 -4
- data/sig/stac/extension.rbs +12 -0
- data/sig/stac/extensions/electro_optical.rbs +40 -0
- data/sig/stac/extensions/projection.rbs +32 -0
- data/sig/stac/extensions/scientific_citation.rbs +38 -0
- data/sig/stac/extensions/view_geometry.rbs +22 -0
- data/sig/stac/extent.rbs +13 -16
- data/sig/stac/file_writer.rbs +13 -0
- data/sig/stac/hash_like.rbs +13 -0
- data/sig/stac/item.rbs +17 -7
- data/sig/stac/link.rbs +21 -12
- data/sig/stac/object_resolver.rbs +5 -9
- data/sig/stac/properties.rbs +3 -3
- data/sig/stac/provider.rbs +2 -3
- data/sig/stac/{default_http_client.rbs → simple_http_client.rbs} +5 -2
- data/sig/stac/stac_object.rbs +34 -11
- data/sig/stac.rbs +7 -1
- data/stac.gemspec +1 -1
- metadata +26 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 63e6934e16a8ff0f70fb3e7c9770d84b2a69b423b2ec00e21a217562a1a22438
|
4
|
+
data.tar.gz: 92dba6bb4fe3ce5a8952cd7b9a5ef3de35d7accf9d35ca7a10469b62596e6b5d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cd77e8737745c7cbe084fb43f654db060605891385d3494a263523e16d997a9a96913d4bd72fcee488036102c6dc98595fbb9973a04138f066531ca351095705
|
7
|
+
data.tar.gz: efe10bba8bc91a59b74ee5b04b2d5f0d1cee86d7b47c49c920ffb456b48b32770fa436d2cf756b076986245fc720143e9c6304016008d9bfdcdbf0f62602cb64
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,23 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.3.0] - 2022-12-16
|
4
|
+
|
5
|
+
- Add extension modules from the current stable extensions (`ElectroOptical`, `Projection`, `ScientificCitation` and `ViewGeometry`).
|
6
|
+
- Make `STACObject` extend extension modules from `stac_extensions` value automatically.
|
7
|
+
- Introduce `HashLike` module and make STAC Object classes include it.
|
8
|
+
- Fix a bug that `Catalog#all_items` returns only direct children's items.
|
9
|
+
- Improve documentation.
|
10
|
+
- Add methods `#add_child` and `#add_item` to `STAC::Catalog`
|
11
|
+
- Add `STAC::Catalog#export`
|
12
|
+
|
13
|
+
## [0.2.0] - 2022-11-02
|
14
|
+
|
15
|
+
- Add `STAC::CommonMetadata` and make `Asset` and `Properties` include it.
|
16
|
+
- Make `http_client` instance variable of `STACObject` instead of class instance variable of `ObjectResolver`.
|
17
|
+
- Change `DefaultHTTPClient#get` return type: String => Hash (parsed JSON).
|
18
|
+
- Rename `DefaultHTTPClient` => `SimpleHTTPClient`.
|
19
|
+
- Enable to change the default HTTP client via `STAC.default_http_client`.
|
20
|
+
|
3
21
|
## [0.1.0] - 2022-10-09
|
4
22
|
|
5
23
|
- Initial release
|
data/GETTING_STARTED.md
ADDED
@@ -0,0 +1,384 @@
|
|
1
|
+
# Getting Started
|
2
|
+
|
3
|
+
- [Reading STAC Objects](#reading-stac-objects)
|
4
|
+
- [STAC Object Classes](#stac-object-classes)
|
5
|
+
- [STAC::Catalog](#staccatalog)
|
6
|
+
- [Crawling Catalog Links](#crawling-catalog-links)
|
7
|
+
- [Exporting Catalog](#exporting-catalog)
|
8
|
+
- [STAC::Collection](#staccollection)
|
9
|
+
- [STAC::Item](#stacitem)
|
10
|
+
- [Common Metadata](#common-metadata)
|
11
|
+
- [Extensions](#extensions)
|
12
|
+
- [Adding Extensions](#adding-extensions)
|
13
|
+
- [Using Custom HTTP Client](#using-custom-http-client)
|
14
|
+
|
15
|
+
## Reading STAC Objects
|
16
|
+
|
17
|
+
You can read any STAC objects from URL by `STAC.from_url`:
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
catalog = STAC.from_url('https://raw.githubusercontent.com/radiantearth/stac-spec/master/examples/catalog.json')
|
21
|
+
catalog.class #=> STAC::Catalog
|
22
|
+
catalog.type #=> "Catalog"
|
23
|
+
|
24
|
+
collection = STAC.from_url('https://raw.githubusercontent.com/radiantearth/stac-spec/master/examples/collection.json')
|
25
|
+
collection.class #=> STAC::Collection
|
26
|
+
collection.type #=> "Collection"
|
27
|
+
|
28
|
+
item = STAC.from_item('https://raw.githubusercontent.com/radiantearth/stac-spec/master/examples/core-item.json')
|
29
|
+
item.class #=> STAC::Item
|
30
|
+
item.type #=> "Feature"
|
31
|
+
```
|
32
|
+
|
33
|
+
Also, from a local file by `STAC.from_file`:
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
catalog = STAC.from_file('/path/to/local/catalog.json')
|
37
|
+
collection = STAC.from_file('/path/to/local/collection.json')
|
38
|
+
item = STAC.from_file('/path/to/local/item.json')
|
39
|
+
```
|
40
|
+
|
41
|
+
## STAC Object Classes
|
42
|
+
|
43
|
+
There are 3 core STAC object classes: `STAC::Catalog`, `STAC::Collection`, and `STAC::Item`.
|
44
|
+
|
45
|
+
They have a class method `from_hash(hash)`, which returns its instance converted from the given Hash.
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
catalog = STAC::Catalog.from_hash(
|
49
|
+
{
|
50
|
+
'stac_version' => '1.0.0',
|
51
|
+
'type' => 'Catalog',
|
52
|
+
'id' => '20201211_223832_CS2',
|
53
|
+
'description' => 'A simple catalog example',
|
54
|
+
'links' => [],
|
55
|
+
}
|
56
|
+
)
|
57
|
+
```
|
58
|
+
|
59
|
+
And they have the following instance methods in common:
|
60
|
+
|
61
|
+
- `extra: -> Hash[String, untyped]` returns extra fields that do not belong to the core specification like STAC extensions fields
|
62
|
+
- `to_h: -> Hash[String, untyped]`
|
63
|
+
- `to_json: -> String`
|
64
|
+
- `deep_dup: -> self` returns a deep copy of self.
|
65
|
+
- `stac_extensions: -> Array[String]`
|
66
|
+
- `add_extension: (String extension_id) -> self | (Module extension) -> self` (see [Extensions](#extensions))
|
67
|
+
- `links: -> Array[STAC::Link]`
|
68
|
+
- `find_link: (rel: String, ?type: String?) -> STAC::Link?`
|
69
|
+
- `add_link: (rel: String, href: String, ?type: String?, ?title: String?) -> self`
|
70
|
+
|
71
|
+
Followings are shorthand methods for core links:
|
72
|
+
|
73
|
+
- `self_href: -> String?` returns rel="self" link's href value
|
74
|
+
- `self_href=: (String absolute_href) -> void` adds rel="self" link with the given href
|
75
|
+
- `root: -> Catalog?` returns rel="root" link as a catalog object
|
76
|
+
- `root=: (Catalog? catalog) -> void` overwrites rel="root" link
|
77
|
+
- `parent: -> Catalog?` returns rel="parent" link as a catalog object
|
78
|
+
- `parent=: (Catalog? catalog) -> void` overwrites rel="parent" link
|
79
|
+
|
80
|
+
### STAC::Catalog
|
81
|
+
|
82
|
+
`STAC::Catalog` has the following attributes:
|
83
|
+
|
84
|
+
- `attr_accessor id: String`
|
85
|
+
- `attr_accessor description: String`
|
86
|
+
- `attr_accessor title: String?`
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
catalog.id = 'awesome_catalog'
|
90
|
+
catalog.id #=> "awesome_catalog"
|
91
|
+
```
|
92
|
+
|
93
|
+
See [STAC Catalog Specification](https://github.com/radiantearth/stac-spec/blob/master/catalog-spec/catalog-spec.md) for the details.
|
94
|
+
|
95
|
+
#### Crawling Catalog Links
|
96
|
+
|
97
|
+
`STAC::Catalog` also has methods to crawl its `links`:
|
98
|
+
|
99
|
+
- `children: -> Enumerator::Lazy[STAC::Catalog, void]` returns catalog/collection objects from rel="child" links
|
100
|
+
- `collections: -> Enumerator::Lazy[STAC::Collection, void]` filters only collections from #children
|
101
|
+
- `all_collections: -> Enumerator::Lazy[STAC::Collection, void]` returns all collections from the catalog and its children recursively
|
102
|
+
- `items: -> Enumerator::Lazy[STAC::Item, void]` returns item objects from rel="items" links
|
103
|
+
- `all_items: -> Enumerator::Lazy[STAC::Item, void]` returns all items from the catalog and its children recursively
|
104
|
+
- `find_child: (String id, ?recursive: bool) -> STAC::Catalog?`
|
105
|
+
- `find_item: (String id, ?recursive: bool) -> STAC::Item?`
|
106
|
+
|
107
|
+
Note that the first 5 methods return [`Enumerator::Lazy`](https://rubyapi.org/3.1/o/enumerator/lazy).
|
108
|
+
This is to prevent making a large number of HTTP requests when calling the methods.
|
109
|
+
|
110
|
+
```ruby
|
111
|
+
catalog.collections.each do |collection|
|
112
|
+
puts collection.id
|
113
|
+
end
|
114
|
+
collection = catalog.find_child('awesome_collection')
|
115
|
+
|
116
|
+
catalog.all_items.first(100).each do |item|
|
117
|
+
puts item.id
|
118
|
+
end
|
119
|
+
item = catalog.find_item('awesome_item', recursive: true)
|
120
|
+
```
|
121
|
+
|
122
|
+
#### Exporting Catalog
|
123
|
+
|
124
|
+
Furthermore, `STAC::Catalog` has methods to create a new static STAC catalog:
|
125
|
+
|
126
|
+
- `add_child: (Catalog catalog, ?href: String, ?title: String?) -> self`
|
127
|
+
- `add_item: (Item item, ?href: String, ?title: String?) -> self`
|
128
|
+
- `export: (?String? dest_dir) -> void`
|
129
|
+
|
130
|
+
```ruby
|
131
|
+
catalog = STAC::Catalog.new(id: 'root', description: 'The root catalog')
|
132
|
+
catalog.self_href = 'https://example.com/catalog.json'
|
133
|
+
catalog.root = catalog
|
134
|
+
|
135
|
+
item = STAC::Item.from_hash(
|
136
|
+
{
|
137
|
+
'stac_version' => '1.0.0',
|
138
|
+
'type' => 'Feature',
|
139
|
+
'id' => 'item',
|
140
|
+
'geometry' => nil,
|
141
|
+
'properties' => {
|
142
|
+
'datetime' => Time.now.iso8601
|
143
|
+
},
|
144
|
+
'links' => [],
|
145
|
+
'assets' => {}
|
146
|
+
}
|
147
|
+
)
|
148
|
+
|
149
|
+
# Add rel="item" link to catalog with href="#{item.id}.json" (based on best practice).
|
150
|
+
# And add rel="self", rel="root", and rel="parent" links to item.
|
151
|
+
catalog.add_item(item)
|
152
|
+
|
153
|
+
item.links.each { |l| puts "#{l.rel}: #{l.href}" }
|
154
|
+
# self: https://example.com/item.json
|
155
|
+
# root: https://example.com/catalog.json
|
156
|
+
# parent: https://example.com/catalog.json
|
157
|
+
|
158
|
+
sub_catalog = STAC::Catalog.new(id: 'sub-catalog', description: 'The sub catalog')
|
159
|
+
|
160
|
+
# Add rel="child" link to catalog with href="#{catalog.id}/catalog.json".
|
161
|
+
# Also add rel="self", rel="root", and rel="parent" links to sub-catalog.
|
162
|
+
catalog.add_child(sub_catalog)
|
163
|
+
|
164
|
+
sub_catalog.add_item(item.deep_dup.update(id: 'sub-item'))
|
165
|
+
sub_catalog.links.each { |l| puts "#{l.rel}: #{l.href}" }
|
166
|
+
# self: https://example.com/sub-catalog/catalog.json
|
167
|
+
# root: https://example.com/catalog.json
|
168
|
+
# parent: https://example.com/catalog.json
|
169
|
+
# item: https://example.com/sub-catalog/sub-item.json
|
170
|
+
|
171
|
+
catalog.links.each { |l| puts "#{l.rel}: #{l.href}" }
|
172
|
+
# self: https://example.com/catalog.json
|
173
|
+
# root: https://example.com/catalog.json
|
174
|
+
# item: https://example.com/item.json
|
175
|
+
# child: https://example.com/sub-catalog/catalog.json
|
176
|
+
|
177
|
+
# Exports the catalog and its children/item recursively to the given directory.
|
178
|
+
catalog.export('path/to/dest')
|
179
|
+
|
180
|
+
# $ tree path/to/dest
|
181
|
+
# path/to/dest
|
182
|
+
# ├── catalog.json
|
183
|
+
# ├── item.json
|
184
|
+
# └── sub-catalog
|
185
|
+
# ├── catalog.json
|
186
|
+
# └── sub-item.json
|
187
|
+
```
|
188
|
+
|
189
|
+
### STAC::Collection
|
190
|
+
|
191
|
+
`STAC::Collection` inherits `STAC::Catalog`.
|
192
|
+
|
193
|
+
The followings are `STAC::Collection` specific attributes:
|
194
|
+
|
195
|
+
- `attr_accessor license: String`
|
196
|
+
- `attr_accessor extent: STAC::Extent`
|
197
|
+
- `attr_accessor keywords: Array[String]?`
|
198
|
+
- `attr_accessor providers: Array[STAC::Provider]?`
|
199
|
+
- `attr_accessor summaries: Hash[String, untyped]?`
|
200
|
+
- `attr_reader assets: Hash[String, STAC::Asset]?`
|
201
|
+
|
202
|
+
To add an asset, use:
|
203
|
+
|
204
|
+
- `add_asset: (key: String, href: String, ?title: String?, ?description: String?, ?type: String?, ?roles: Array[String]?) -> self`
|
205
|
+
|
206
|
+
`STAC::Extent`, `STAC::Provider`, and `STAC::Asset` provide accessors for the corresponding object's fields.
|
207
|
+
|
208
|
+
```ruby
|
209
|
+
collection.extent.spatial.bbox = [-180, -90, 180, 90]
|
210
|
+
collection.extent.spatial.bbox #=> [-180, -90, 180, 90]
|
211
|
+
collection.extent.temporal.interval = ['2022-12-01T00:00:00Z', null]
|
212
|
+
collection.extent.temporal.interval #=> ["2022-12-01T00:00:00Z", null]
|
213
|
+
|
214
|
+
collection.providers << STAC::Provider.new(name: 'sankichi92')
|
215
|
+
collection.providers.last.name #=> "sankichi92"
|
216
|
+
```
|
217
|
+
|
218
|
+
See [STAC Collection Specification](https://github.com/radiantearth/stac-spec/blob/master/collection-spec/collection-spec.md) for the details.
|
219
|
+
|
220
|
+
### STAC::Item
|
221
|
+
|
222
|
+
`STAC::Item` has the following attributes:
|
223
|
+
|
224
|
+
- `attr_accessor id: String`
|
225
|
+
- `attr_reader properties: STAC::Properties`
|
226
|
+
- `attr_reader assets: Hash[String, STAC::Asset]`
|
227
|
+
- `attr_accessor geometry: Hash[String, untyped]?`
|
228
|
+
- `attr_accessor bbox: Array[Numeric]?`
|
229
|
+
- `attr_accessor collection_id: String?`
|
230
|
+
|
231
|
+
And has the following methods:
|
232
|
+
|
233
|
+
- `add_asset: (key: String, href: String, ?title: String?, ?description: String?, ?type: String?, ?roles: Array[String]?) -> self`
|
234
|
+
- `collection: -> Collection?` returns a rel="collection" link as a collection object
|
235
|
+
- `collection=: (Collection collection) -> void` overwrites rel="collection" link and collection_id attribute
|
236
|
+
|
237
|
+
See [STAC Item Specification](https://github.com/radiantearth/stac-spec/blob/master/collection-spec/collection-spec.md) for the details.
|
238
|
+
|
239
|
+
#### Common Metadata
|
240
|
+
|
241
|
+
`STAC::Properties` and `STAC::Asset` includes `STAC::CommonMetadata`, which provides read/write methods for [STAC Common Metadata](https://github.com/radiantearth/stac-spec/blob/master/item-spec/common-metadata.md) fields:
|
242
|
+
|
243
|
+
- `title: -> String?`
|
244
|
+
- `title=: (String) -> void`
|
245
|
+
- `description: -> String?`
|
246
|
+
- `description=: (String) -> void`
|
247
|
+
- `created: -> Time?`
|
248
|
+
- `created=: (Time | String) -> void`
|
249
|
+
- `updated: -> Time?`
|
250
|
+
- `updated=: (Time | String) -> void`
|
251
|
+
- `start_datetime: -> Time?`
|
252
|
+
- `start_datetime=: (Time | String) -> void`
|
253
|
+
- `end_datetime: -> Time?`
|
254
|
+
- `end_datetime=: (Time | String) -> void`
|
255
|
+
- `datetime_range: -> Range[Time]?` returns a range from #start_datetime to #end_datetime
|
256
|
+
- `datetime_range=: (Range[Time]) -> void` sets #start_datetime and #end_datetime by the given range
|
257
|
+
- `license: -> String?`
|
258
|
+
- `license=: (String) -> void`
|
259
|
+
- `providers: -> Array[Provider]`
|
260
|
+
- `providers=: (Array[Provider | Hash[String, untyped]]) -> void`
|
261
|
+
- `platform: -> String?`
|
262
|
+
- `platform=: (String) -> void`
|
263
|
+
- `instruments: -> Array[String]?`
|
264
|
+
- `instruments=: (Array[String]) -> void`
|
265
|
+
- `constellation: -> String?`
|
266
|
+
- `constellation=: (String) -> void`
|
267
|
+
- `mission: -> String?`
|
268
|
+
- `mission=: (String) -> void`
|
269
|
+
- `gsd: -> Numeric`
|
270
|
+
- `gsd=: (Numeric) -> void`
|
271
|
+
|
272
|
+
These methods are shorthand accessors of `#extra` hash:
|
273
|
+
|
274
|
+
```ruby
|
275
|
+
item.properties.extra #=> {}
|
276
|
+
item.properties.title = 'Awesome Item' # same as `item.properties.extra['title'] = 'Awesome Item'`
|
277
|
+
item.properties.title #=> "Awesome Item"
|
278
|
+
item.properties.extra #=> {"title"=>"Awesome Item"}
|
279
|
+
```
|
280
|
+
|
281
|
+
## Extensions
|
282
|
+
|
283
|
+
When an extension is added to a STAC object, methods corresponding to the extension will be added **dynamically** by [`Object#extend`](https://rubyapi.org/3.1/o/object#method-i-extend).
|
284
|
+
|
285
|
+
These methods are also shorthand accessors of `extra` hash same as `STAC::CommonMetadata`.
|
286
|
+
|
287
|
+
```ruby
|
288
|
+
item.stac_extensions #=> []
|
289
|
+
item.properties.extra #=> {}
|
290
|
+
item.properties.eo_cloud_cover #=> raises NoMethodError
|
291
|
+
|
292
|
+
item.add_extension('https://stac-extensions.github.io/eo/v1.0.0/schema.json')
|
293
|
+
# same as `item.add_extension(STAC::Extensions::ElectroOptical)`
|
294
|
+
|
295
|
+
item.stac_extensions #=> ["https://stac-extensions.github.io/eo/v1.0.0/schema.json"]
|
296
|
+
item.properties.eo_cloud_cover = 1.2
|
297
|
+
item.properties.eo_cloud_cover #=> 1.2
|
298
|
+
item.properties.extra #=> {"eo:cloud_cover"=>1.2}
|
299
|
+
|
300
|
+
# item.properties extends STAC::Extensions::ElectroOptical::Properties
|
301
|
+
item.properties.is_a?(STAC::Extensions::ElectroOptical::Properties) #=> true
|
302
|
+
```
|
303
|
+
|
304
|
+
Currently, only 4 stable extensions have been implemented:
|
305
|
+
|
306
|
+
```ruby
|
307
|
+
puts STAC::STACObject.extendables
|
308
|
+
# STAC::Extensions::ElectroOptical
|
309
|
+
# STAC::Extensions::Projection
|
310
|
+
# STAC::Extensions::ScientificCitation
|
311
|
+
# STAC::Extensions::ViewGeometry
|
312
|
+
```
|
313
|
+
|
314
|
+
### Adding Extensions
|
315
|
+
|
316
|
+
You can add custom extensions.
|
317
|
+
|
318
|
+
Extension modules must extend `STAC::Extension` and set `identifier` and `scope`.
|
319
|
+
And you must register it by `STAC::STACObject.add_extendable(extension_module)`.
|
320
|
+
|
321
|
+
```ruby
|
322
|
+
module MyExtension
|
323
|
+
extend STAC::Extension
|
324
|
+
|
325
|
+
identifier 'https://sankichi92.github.io/my_extension/v1.0.0/schema.json'
|
326
|
+
scope STAC::Item, STAC::Collection
|
327
|
+
end
|
328
|
+
|
329
|
+
STAC::STACObject.add_extendable(MyExtension)
|
330
|
+
```
|
331
|
+
|
332
|
+
Then you can add methods to `STAC::Properties`, `STAC::Asset`, and `STAC::Collection` by defining modules with corresponding names **under the extension namespace**:
|
333
|
+
|
334
|
+
```ruby
|
335
|
+
module MyExtension
|
336
|
+
module Properties
|
337
|
+
def my_field
|
338
|
+
extra['my:field']
|
339
|
+
end
|
340
|
+
|
341
|
+
def my_field(val)
|
342
|
+
extra['my:field'] = val
|
343
|
+
end
|
344
|
+
end
|
345
|
+
|
346
|
+
module Asset
|
347
|
+
include Properties
|
348
|
+
end
|
349
|
+
end
|
350
|
+
```
|
351
|
+
|
352
|
+
See [`lib/stac/extensions`](https://github.com/sankichi92/stac-ruby/tree/main/lib/stac/extensions) for examples.
|
353
|
+
|
354
|
+
## Using Custom HTTP Client
|
355
|
+
|
356
|
+
Custom HTTP client class must implement `get: (URI | String url) -> Hash[String, untyped]`, which returns response JSON as a Hash:
|
357
|
+
|
358
|
+
```ruby
|
359
|
+
class MyHTTPClient
|
360
|
+
def get(url)
|
361
|
+
# ...
|
362
|
+
end
|
363
|
+
end
|
364
|
+
```
|
365
|
+
|
366
|
+
You can pass the custom HTTP client to `STAC.from_url` for a specific STAC object instance:
|
367
|
+
|
368
|
+
```ruby
|
369
|
+
catalog = STAC.from_url('https://example.com/catalog.json', http_client: MyHTTPClient.new)
|
370
|
+
```
|
371
|
+
|
372
|
+
Or you can set it as the global default by `STAC.default_http_client=`:
|
373
|
+
|
374
|
+
```ruby
|
375
|
+
STAC.default_http_client = MyHTTPClient.new
|
376
|
+
```
|
377
|
+
|
378
|
+
If you want to only add custom HTTP headers, you can use `STAC::SimpleHTTPClient`:
|
379
|
+
|
380
|
+
```ruby
|
381
|
+
http_client = STAC::SimpleHTTPClient.new({ 'X-Foo' => 'Bar' })
|
382
|
+
catalog = STAC.from_url('https://example.com/catalog.json', http_client:)
|
383
|
+
STAC.default_http_client = http_client
|
384
|
+
```
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
stac (0.
|
4
|
+
stac (0.3.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
@@ -17,84 +17,95 @@ GEM
|
|
17
17
|
concurrent-ruby (1.1.10)
|
18
18
|
crack (0.4.5)
|
19
19
|
rexml
|
20
|
-
|
21
|
-
|
20
|
+
csv (3.2.6)
|
21
|
+
debug (1.7.0)
|
22
|
+
irb (>= 1.5.0)
|
22
23
|
reline (>= 0.3.1)
|
23
24
|
diff-lcs (1.5.0)
|
24
25
|
ffi (1.15.5)
|
26
|
+
fileutils (1.7.0)
|
25
27
|
hashdiff (1.0.1)
|
26
28
|
i18n (1.12.0)
|
27
29
|
concurrent-ruby (~> 1.0)
|
28
|
-
io-console (0.
|
29
|
-
irb (1.
|
30
|
+
io-console (0.6.0)
|
31
|
+
irb (1.6.1)
|
30
32
|
reline (>= 0.3.0)
|
31
|
-
json (2.6.
|
32
|
-
language_server-protocol (3.17.0.
|
33
|
+
json (2.6.3)
|
34
|
+
language_server-protocol (3.17.0.2)
|
33
35
|
listen (3.7.1)
|
34
36
|
rb-fsevent (~> 0.10, >= 0.10.3)
|
35
37
|
rb-inotify (~> 0.9, >= 0.9.10)
|
38
|
+
logger (1.5.3)
|
36
39
|
minitest (5.16.3)
|
37
40
|
parallel (1.22.1)
|
38
|
-
parser (3.1.
|
41
|
+
parser (3.1.3.0)
|
39
42
|
ast (~> 2.4.1)
|
40
|
-
prettier_print (
|
41
|
-
public_suffix (5.0.
|
43
|
+
prettier_print (1.1.0)
|
44
|
+
public_suffix (5.0.1)
|
42
45
|
rainbow (3.1.1)
|
43
46
|
rake (13.0.6)
|
44
47
|
rb-fsevent (0.11.2)
|
45
48
|
rb-inotify (0.10.1)
|
46
49
|
ffi (~> 1.0)
|
47
|
-
rbs (2.
|
48
|
-
regexp_parser (2.6.
|
49
|
-
reline (0.3.
|
50
|
+
rbs (2.8.1)
|
51
|
+
regexp_parser (2.6.1)
|
52
|
+
reline (0.3.2)
|
50
53
|
io-console (~> 0.5)
|
51
54
|
rexml (3.2.5)
|
52
|
-
rspec (3.
|
53
|
-
rspec-core (~> 3.
|
54
|
-
rspec-expectations (~> 3.
|
55
|
-
rspec-mocks (~> 3.
|
56
|
-
rspec-core (3.
|
57
|
-
rspec-support (~> 3.
|
58
|
-
rspec-expectations (3.
|
55
|
+
rspec (3.12.0)
|
56
|
+
rspec-core (~> 3.12.0)
|
57
|
+
rspec-expectations (~> 3.12.0)
|
58
|
+
rspec-mocks (~> 3.12.0)
|
59
|
+
rspec-core (3.12.0)
|
60
|
+
rspec-support (~> 3.12.0)
|
61
|
+
rspec-expectations (3.12.1)
|
59
62
|
diff-lcs (>= 1.2.0, < 2.0)
|
60
|
-
rspec-support (~> 3.
|
61
|
-
rspec-mocks (3.
|
63
|
+
rspec-support (~> 3.12.0)
|
64
|
+
rspec-mocks (3.12.1)
|
62
65
|
diff-lcs (>= 1.2.0, < 2.0)
|
63
|
-
rspec-support (~> 3.
|
64
|
-
rspec-support (3.
|
65
|
-
rubocop (1.
|
66
|
+
rspec-support (~> 3.12.0)
|
67
|
+
rspec-support (3.12.0)
|
68
|
+
rubocop (1.40.0)
|
66
69
|
json (~> 2.3)
|
67
70
|
parallel (~> 1.10)
|
68
71
|
parser (>= 3.1.2.1)
|
69
72
|
rainbow (>= 2.2.2, < 4.0)
|
70
73
|
regexp_parser (>= 1.8, < 3.0)
|
71
74
|
rexml (>= 3.2.5, < 4.0)
|
72
|
-
rubocop-ast (>= 1.
|
75
|
+
rubocop-ast (>= 1.23.0, < 2.0)
|
73
76
|
ruby-progressbar (~> 1.7)
|
74
77
|
unicode-display_width (>= 1.4.0, < 3.0)
|
75
|
-
rubocop-ast (1.
|
78
|
+
rubocop-ast (1.24.0)
|
76
79
|
parser (>= 3.1.1.0)
|
77
80
|
rubocop-rake (0.6.0)
|
78
81
|
rubocop (~> 1.0)
|
79
|
-
rubocop-rspec (2.
|
82
|
+
rubocop-rspec (2.16.0)
|
80
83
|
rubocop (~> 1.33)
|
81
|
-
ruby-lsp (0.3.
|
84
|
+
ruby-lsp (0.3.7)
|
82
85
|
language_server-protocol (~> 3.17.0)
|
83
86
|
sorbet-runtime
|
84
|
-
syntax_tree (>=
|
87
|
+
syntax_tree (>= 4.0.2, < 5.0.0)
|
85
88
|
ruby-progressbar (1.11.0)
|
86
|
-
|
87
|
-
|
89
|
+
securerandom (0.2.2)
|
90
|
+
sorbet-runtime (0.5.10594)
|
91
|
+
steep (1.3.0)
|
88
92
|
activesupport (>= 5.1)
|
93
|
+
csv (>= 3.0.9)
|
94
|
+
fileutils (>= 1.1.0)
|
95
|
+
json (>= 2.1.0)
|
89
96
|
language_server-protocol (>= 3.15, < 4.0)
|
90
97
|
listen (~> 3.0)
|
98
|
+
logger (>= 1.3.0)
|
91
99
|
parallel (>= 1.0.0)
|
92
100
|
parser (>= 3.1)
|
93
101
|
rainbow (>= 2.2.2, < 4.0)
|
94
|
-
rbs (>= 2.
|
102
|
+
rbs (>= 2.8.0)
|
103
|
+
securerandom (>= 0.1)
|
104
|
+
strscan (>= 1.0.0)
|
95
105
|
terminal-table (>= 2, < 4)
|
96
|
-
|
97
|
-
|
106
|
+
strscan (3.0.5)
|
107
|
+
syntax_tree (4.3.0)
|
108
|
+
prettier_print (>= 1.0.2)
|
98
109
|
terminal-table (3.0.2)
|
99
110
|
unicode-display_width (>= 1.1.1, < 3)
|
100
111
|
tzinfo (2.0.5)
|
@@ -106,7 +117,7 @@ GEM
|
|
106
117
|
hashdiff (>= 0.4.0, < 2.0.0)
|
107
118
|
|
108
119
|
PLATFORMS
|
109
|
-
x86_64-darwin-
|
120
|
+
x86_64-darwin-22
|
110
121
|
x86_64-linux
|
111
122
|
|
112
123
|
DEPENDENCIES
|
@@ -123,4 +134,4 @@ DEPENDENCIES
|
|
123
134
|
webmock
|
124
135
|
|
125
136
|
BUNDLED WITH
|
126
|
-
2.3.
|
137
|
+
2.3.26
|
data/README.md
CHANGED
@@ -1,8 +1,20 @@
|
|
1
1
|
# stac-ruby
|
2
2
|
|
3
|
-
A Ruby library for working with [SpatioTemporal Asset Catalog (STAC)](https://stacspec.org/)
|
3
|
+
A Ruby library for working with [SpatioTemporal Asset Catalog (STAC)](https://stacspec.org/).\
|
4
|
+
See [satc-client-ruby](https://github.com/sankichi92/stac-client-ruby) for [STAC API](https://github.com/radiantearth/stac-api-spec) client.
|
4
5
|
|
5
|
-
This gem's implementation refers to [
|
6
|
+
This gem's implementation refers to [PySTAC](https://github.com/stac-utils/pystac).
|
7
|
+
|
8
|
+
### STAC Spec Version Support
|
9
|
+
|
10
|
+
v1.0.0
|
11
|
+
|
12
|
+
### STAC Extensions Support
|
13
|
+
|
14
|
+
- [Electro-Optical](https://github.com/stac-extensions/eo) v1.0.0
|
15
|
+
- [Projection](https://github.com/stac-extensions/projection) v1.0.0
|
16
|
+
- [Scientific Citation](https://github.com/stac-extensions/scientific) v1.0.0
|
17
|
+
- [View Geometry](https://github.com/stac-extensions/view) v1.0.0
|
6
18
|
|
7
19
|
## Installation
|
8
20
|
|
@@ -14,62 +26,9 @@ If bundler is not being used to manage dependencies, install the gem by executin
|
|
14
26
|
|
15
27
|
$ gem install stac
|
16
28
|
|
17
|
-
##
|
18
|
-
|
19
|
-
```ruby
|
20
|
-
require 'stac'
|
21
|
-
|
22
|
-
# Reading a Catalog
|
23
|
-
# ================
|
24
|
-
|
25
|
-
# Read the example catalog.
|
26
|
-
catalog = STAC.from_url('https://raw.githubusercontent.com/radiantearth/stac-spec/master/examples/catalog.json')
|
27
|
-
|
28
|
-
# Print some basic metadata.
|
29
|
-
puts "ID: #{catalog.id}"
|
30
|
-
puts "Title: #{catalog.title}"
|
31
|
-
puts "Description: #{catalog.description}"
|
32
|
-
|
33
|
-
# Crawling Child Catalogs/Collections
|
34
|
-
# ================
|
35
|
-
|
36
|
-
# List Collections in the Catalog.
|
37
|
-
puts 'Collections IDs:'
|
38
|
-
catalog.collections.each do |collection|
|
39
|
-
puts "- #{collection.id}"
|
40
|
-
end
|
41
|
-
|
42
|
-
# Get a child Catalog or Collection by ID.
|
43
|
-
_collection = catalog.find_child('extensions-collection')
|
44
|
-
|
45
|
-
# Crawling Items
|
46
|
-
# ================
|
47
|
-
|
48
|
-
# List all items associated with the Catalog recursively.
|
49
|
-
puts 'Item IDs:'
|
50
|
-
catalog.all_items.each do |item|
|
51
|
-
puts "- #{item.id}"
|
52
|
-
end
|
53
|
-
|
54
|
-
# Item Metadata
|
55
|
-
# ================
|
56
|
-
|
57
|
-
# Get an Item by ID.
|
58
|
-
item = catalog.find_item('proj-example', recursive: true)
|
59
|
-
|
60
|
-
# Print core Item metadeata.
|
61
|
-
puts 'geometry:'
|
62
|
-
p item.geometry
|
63
|
-
puts 'bbox:'
|
64
|
-
p item.bbox
|
65
|
-
puts 'datetime:'
|
66
|
-
p item.datetime
|
67
|
-
puts 'collection_id:'
|
68
|
-
p item.collection_id
|
29
|
+
## Getting Started
|
69
30
|
|
70
|
-
|
71
|
-
_collection = item.collection
|
72
|
-
```
|
31
|
+
[GETTING_STARTED.md](GETTING_STARTED.md)
|
73
32
|
|
74
33
|
## Documentation
|
75
34
|
|