/
oamcatalogresult.go
108 lines (93 loc) · 4.38 KB
/
oamcatalogresult.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
///////////////////////////////////////////////////////////////////////////////
//
// The MIT License (MIT)
// Copyright (c) 2018 Tom Kralidis
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
//
///////////////////////////////////////////////////////////////////////////////
package parsers
import (
"time"
"github.com/go-spatial/geocatalogo/metadata"
)
// properties provides OAM Catalog Result properties
type properties struct {
Sensor string `json:"sensor"`
Thumbnail string `json:"thumbnail"`
TMS string `json:"tms"`
WTMS string `json:"wtms"`
}
// OAMCatalogResult provides an OAM Catalog Result
type OAMCatalogResult struct {
Identifier string `json:"_id"`
Uuid string `json:"uuid"`
Version int `json:"__v"`
Title string `json:"title"`
Projection string `json:"projection"`
Gsd int `json:"gsd"`
Filesize int `json:"file_size"`
AcquisitionStart *time.Time `json:"acquisition_start"`
AcquisitionEnd *time.Time `json:"acquisition_end"`
Platform string `json:"platform"`
Provider string `json:"provider"`
Contact string `json:"contact"`
MetaUri string `json:"meta_uri"`
Properties properties `json:"properties"`
Bbox [4]float64 `json:"bbox"`
}
// OAMCatalogResults provides OAM Catalog Results
type OAMCatalogResults struct {
Result []OAMCatalogResult `json:"results"`
}
// ParseOAMCatalogResult parses CSWRecord
func ParseOAMCatalogResult(result OAMCatalogResult) (metadata.Record, error) {
metadataRecord := metadata.Record{}
metadataRecord.Type = "Feature"
metadataRecord.Identifier = result.Identifier
metadataRecord.Properties.Type = "dataset"
metadataRecord.Properties.Title = result.Title
metadataRecord.Geometry.Type = "Polygon"
metadataRecord.Properties.Contacts = append(metadataRecord.Properties.Contacts, metadata.Contact{Value: result.Provider})
metadataRecord.Properties.Contacts = append(metadataRecord.Properties.Contacts, metadata.Contact{Value: result.Contact})
mpi := metadata.ProductInfo{}
mpi.Collection = "openaerialmap"
mpi.Platform = result.Platform
mpi.SensorIdentifier = result.Properties.Sensor
mpi.AcquisitionDate = result.AcquisitionStart
metadataRecord.Properties.ProductInfo = &mpi
metadataRecord.Links = append(metadataRecord.Links, metadata.Link{URL: result.Uuid})
metadataRecord.Links = append(metadataRecord.Links, metadata.Link{URL: result.Properties.Thumbnail, Protocol: "WWW:LINK"})
metadataRecord.Links = append(metadataRecord.Links, metadata.Link{URL: result.Properties.TMS, Protocol: "OSGeo:TMS"})
metadataRecord.Links = append(metadataRecord.Links, metadata.Link{URL: result.Properties.WTMS, Protocol: "OGC:WMTS"})
metadataRecord.Links = append(metadataRecord.Links, metadata.Link{URL: result.MetaUri, Protocol: "WWW:LINK"})
var bbox = [][][2]float64{{
{result.Bbox[0], result.Bbox[1]},
{result.Bbox[0], result.Bbox[3]},
{result.Bbox[2], result.Bbox[3]},
{result.Bbox[2], result.Bbox[1]},
{result.Bbox[0], result.Bbox[1]},
}}
metadataRecord.Geometry.Coordinates = bbox
metadataRecord.BoundingBox = metadataRecord.Geometry.Bounds()
metadataRecord.Properties.Geocatalogo.Typename = "oam:meta"
metadataRecord.Properties.Geocatalogo.Schema = "https://api.openaerialmap.org/meta"
metadataRecord.Properties.Geocatalogo.Source = "local"
return metadataRecord, nil
}