Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions coverage.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,19 @@ const (
mediaCovJSON = "application/vnd.cov+json"
mediaSchema = "application/schema+json"
coverageItems = "coverage"
// mediaCovJSONEDR is the spelling of CoverageJSON that EDR 1.1
// (/req/covjson/content) names, the same document as mediaCovJSON
mediaCovJSONEDR = "application/prs.coverage+json"
)

// coverageEncodings are the encodings a coverage is written in, each with the
// SQL function writing it, in the order a client stating no preference gets
// them: GeoTIFF first, the type the collection's coverage link states.
// CoverageJSON is answered in either spelling, the one the client names.
var coverageEncodings = []struct{ media, fn string }{
{mediaGeoTIFF, "asTIFF"},
{mediaCovJSON, "asCoverageJSON"},
{mediaCovJSONEDR, "asCoverageJSON"},
}

// coverageSource is what the registry records of a raster collection: its
Expand Down
30 changes: 23 additions & 7 deletions edr.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,17 @@ import (
"strings"
)

// The conformance class of EDR the tier declares: the core, which
// /req/core/conformance names. The class queries of 1.1 holds eight queries, each
// one a server MAY answer, and the tier answers six; the class covjson of 1.1
// names CoverageJSON application/prs.coverage+json, where the tier writes
// application/vnd.cov+json, the type OGC CoverageJSON (OGC 21-069r2) defines.
const edrConformance = "http://www.opengis.net/spec/ogcapi-edr-1/1.1/conf/core"
// The conformance classes of EDR the tier declares: the core, which
// /req/core/conformance names, and covjson, whose /req/covjson/content names
// CoverageJSON application/prs.coverage+json: an answer is written in that
// spelling where the client names it, and otherwise as
// application/vnd.cov+json, the type OGC CoverageJSON (OGC 21-069r2) defines
// (#edrMedia). The class queries of 1.1 holds eight queries, each one a server
// MAY answer, and the tier answers six.
const (
edrConformance = "http://www.opengis.net/spec/ogcapi-edr-1/1.1/conf/core"
edrCovJSONConformance = "http://www.opengis.net/spec/ogcapi-edr-1/1.1/conf/covjson"
)

// The queries a raster collection answers, with the WKT geometry each reads
// from coords; cube reads a bbox and no coords.
Expand Down Expand Up @@ -129,12 +134,23 @@ func edrQuery(query string) http.HandlerFunc {
httpErr(w, errStatus(err, 400), err.Error())
return
}
w.Header().Set("Content-Type", mediaCovJSON)
w.Header().Set("Content-Type", edrMedia(r.Header.Get("Accept")))
w.WriteHeader(200)
w.Write(data)
}
}

// edrMedia answers the spelling of CoverageJSON an EDR answer is written in,
// negotiated as #negotiateCoverage negotiates a coverage: the one the client's
// Accept names, application/vnd.cov+json, the type OGC CoverageJSON (OGC
// 21-069r2) states, wherever it names neither.
func edrMedia(accept string) string {
if media, _ := negotiateCoverage(accept); media == mediaCovJSONEDR {
return mediaCovJSONEDR
}
return mediaCovJSON
}

// edrCoords checks that coords is WKT of the geometry type a query reads, in
// CRS84, refusing it as #parseCoverageRequest refuses a bbox it cannot read;
// a trajectory reads a LINESTRINGM.
Expand Down
32 changes: 30 additions & 2 deletions edr_live_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,36 @@ func TestLiveRasterEDRQueries(t *testing.T) {
}
}
rec = atsDo(t, mux, "GET", "/conformance", "")
if !strings.Contains(rec.Body.String(), edrConformance) {
t.Errorf("the conformance declaration does not name %s", edrConformance)
for _, c := range []string{edrConformance, edrCovJSONConformance} {
if !strings.Contains(rec.Body.String(), c) {
t.Errorf("the conformance declaration does not name %s", c)
}
}

// CoverageJSON is written in the spelling the client names: EDR 1.1's
// application/prs.coverage+json, which /req/covjson/content states, or
// application/vnd.cov+json, OGC CoverageJSON's, which is also the answer
// to a client naming neither, alike on an EDR query and on /coverage.
position := "/collections/cov/position?coords=POINT(0.5%201)&datetime=2024-01-15T00:00:00Z"
coverage := "/collections/cov/coverage?datetime=2024-01-15T00:00:00Z"
for _, c := range []struct{ path, accept, want string }{
{position, mediaCovJSONEDR, mediaCovJSONEDR},
{position, mediaCovJSON, mediaCovJSON},
{position, "", mediaCovJSON},
{position, "*/*", mediaCovJSON},
{position, mediaCovJSON + ", " + mediaCovJSONEDR, mediaCovJSON},
{coverage, mediaCovJSONEDR, mediaCovJSONEDR},
{coverage, mediaCovJSON, mediaCovJSON},
} {
rec := coverageGet(t, c.path, c.accept)
if rec.Code != 200 || rec.Header().Get("Content-Type") != c.want {
t.Errorf("%s with Accept %q answered %d as %s, want 200 as %s", c.path, c.accept, rec.Code,
rec.Header().Get("Content-Type"), c.want)
continue
}
if domain, _, _ := edrCoverage(t, rec.Body.String()); domain == "" {
t.Errorf("%s with Accept %q answered no CoverageJSON domain: %s", c.path, c.accept, rec.Body.String())
}
}

// The instances are the two periods, January and February, in time order,
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ func conformsTo() []string {
classes := append([]string{
confMFCommon, confMFCollection, confMovingFeatures, confCQuery, confCommonCore, confCommonLanding,
confCommonCollections,
}, append(coverageConformance, edrConformance)...)
}, append(coverageConformance, edrConformance, edrCovJSONConformance)...)
var out []string
for _, c := range classes {
out = append(out, c)
Expand Down
3 changes: 2 additions & 1 deletion samples/conformance-declaration.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"http://www.opengis.net/spec/ogcapi-coverages-1/1.0/conf/geotiff",
"https://www.opengis.net/spec/ogcapi-coverages-1/1.0/conf/coveragejson",
"http://www.opengis.net/spec/ogcapi-coverages-1/1.0/conf/coveragejson",
"http://www.opengis.net/spec/ogcapi-edr-1/1.1/conf/core"
"http://www.opengis.net/spec/ogcapi-edr-1/1.1/conf/core",
"http://www.opengis.net/spec/ogcapi-edr-1/1.1/conf/covjson"
]
}