diff --git a/coverage.go b/coverage.go index db27b2f..cdad5c9 100644 --- a/coverage.go +++ b/coverage.go @@ -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 diff --git a/edr.go b/edr.go index 4b1a07c..5fab2b7 100644 --- a/edr.go +++ b/edr.go @@ -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. @@ -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. diff --git a/edr_live_test.go b/edr_live_test.go index 0acc4f1..da114d6 100644 --- a/edr_live_test.go +++ b/edr_live_test.go @@ -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, diff --git a/main.go b/main.go index 6ffd4dc..c5ae6f5 100644 --- a/main.go +++ b/main.go @@ -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) diff --git a/samples/conformance-declaration.json b/samples/conformance-declaration.json index 3befe08..ff16204 100644 --- a/samples/conformance-declaration.json +++ b/samples/conformance-declaration.json @@ -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" ] }