Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check conformance classes known by OGC API Features #169

Closed
navispatial opened this issue Mar 15, 2023 · 1 comment
Closed

Check conformance classes known by OGC API Features #169

navispatial opened this issue Mar 15, 2023 · 1 comment
Labels
🌎 geodata Related to the code package "geodata" enhancement New feature or request

Comments

@navispatial
Copy link
Member

navispatial commented Mar 15, 2023

The OGC API Features standard defines that a server should announce conformance classes supported by an API instance in /conformance resource.

A JSON response by a compliant server could be for example:

{
    "conformsTo": [
        "http://www.opengis.net/spec/ogcapi-common-1/1.0/conf/core",
        "http://www.opengis.net/spec/ogcapi-common-2/1.0/conf/collections",
        "http://www.opengis.net/spec/ogcapi-features-1/1.0/conf/core",
        "http://www.opengis.net/spec/ogcapi-features-1/1.0/req/oas30",
        "http://www.opengis.net/spec/ogcapi-features-1/1.0/conf/html",
        "http://www.opengis.net/spec/ogcapi-features-1/1.0/conf/geojson",
        "http://www.opengis.net/spec/ogcapi-features-4/1.0/conf/create-replace-delete"
    ]
}

See also official example by OGC.

Currently conformance classes could be checked by code like:

  // create an OGC API Features client
  final client = OGCAPIFeatures.http(endpoint: Uri.parse('https://example.org/api'));

  // conformance classes (text ids) informs the capabilities of the service
  final conformance = await client.conformance();

  // the service should be compliant with OGC API Features - Part 1 and GeoJSON
  const c1 = 'http://www.opengis.net/spec/ogcapi-features-1/1.0/conf/core';
  const c2 = 'http://www.opengis.net/spec/ogcapi-features-1/1.0/conf/geojson';
  if (conformance.contains(c1) && conformance.contains(c2)) {
    print('The service is compliant with OGC API Features, Part 1 - Core and GeoJSON');
  }

However a client code would have to know text identifiers, which is quite inconvenient.

The check should be something like this:

  if (conformance.conformsToFeaturesCore(geoJson: true)) {
    print('The service is compliant with OGC API Features, Part 1 - Core and GeoJSON');
  }
@navispatial navispatial added enhancement New feature or request 🌐 geobase Related to the code package "geobase" 🌎 geodata Related to the code package "geodata" and removed 🌐 geobase Related to the code package "geobase" labels Mar 15, 2023
navispatial added a commit that referenced this issue Jul 5, 2023
BREAKING CHANGE: type of conformance from service changed
@navispatial
Copy link
Member Author

Implemented by 2535da0

A new class OGCFeatureConformance was introduced:

import 'package:equatable/equatable.dart';
import 'package:meta/meta.dart';

/// A wrapper for conformance classes for a OGC API Features compliant service.
///
/// See [OGC API Features](https://github.com/opengeospatial/ogcapi-features).
///
/// This class can be used to check conformance classes for:
/// * `OGC API - Features - Part 1: Core`
/// * `OGC API - Features - Part 2: Coordinate Reference Systems by Reference`
@immutable
class OGCFeatureConformance extends Equatable {
  /// Conformance classes a service is conforming to.
  final Iterable<String> classes;

  /// Creates a wrapper for conformance classes a service is conforming to.
  const OGCFeatureConformance(this.classes);

  /// Check whether a service conforms to `OGC API - Features - Part 1: Core`
  ///
  /// Optionally also check whether it supports [openAPI30Class],
  /// [htmlClass], [geoJSONClass], [gmlSF0] and/or [gmlSF2].
  bool conformsToCore({
    bool? openAPI30,
    bool? html,
    bool? geoJSON,
    bool? gmlSF0,
    bool? gmlSF2,
  }) {
    var isCore = false;
    var isOpenAPI30 = false;
    var isHTML = false;
    var isGeoJSON = false;
    var isGMLSF0 = false;
    var isGMLSF2 = false;

    for (final id in classes) {
      if (!isCore && id == coreClass) {
        isCore = true;
      }
      if (!isOpenAPI30 && id == openAPI30Class) {
        isOpenAPI30 = true;
      }
      if (!isHTML && id == htmlClass) {
        isHTML = true;
      }
      if (!isGeoJSON && id == geoJSONClass) {
        isGeoJSON = true;
      }
      if (!isGMLSF0 && id == gmlSF0Class) {
        isGMLSF0 = true;
      }
      if (!isGMLSF2 && id == gmlSF2Class) {
        isGMLSF2 = true;
      }
    }

    return isCore &&
        (openAPI30 == null || isOpenAPI30 == openAPI30) &&
        (html == null || isHTML == html) &&
        (geoJSON == null || isGeoJSON == geoJSON) &&
        (gmlSF0 == null || isGMLSF0 == gmlSF0) &&
        (gmlSF2 == null || isGMLSF2 == gmlSF2);
  }

  /// Check whether a service conforms to
  /// `OGC API - Features - Part 2: Coordinate Reference Systems by Reference`.
  bool conformsToCrs() => classes.contains(crsClass);

  @override
  List<Object?> get props => [classes];

  static const coreClass =
      'http://www.opengis.net/spec/ogcapi-features-1/1.0/conf/core';

  static const openAPI30Class =
      'http://www.opengis.net/spec/ogcapi-features-1/1.0/conf/oas30';

  static const htmlClass =
      'http://www.opengis.net/spec/ogcapi-features-1/1.0/conf/html';

  static const geoJSONClass =
      'http://www.opengis.net/spec/ogcapi-features-1/1.0/conf/geojson';

  static const gmlSF0Class =
      'http://www.opengis.net/spec/ogcapi-features-1/1.0/conf/gmlsf0';

  static const gmlSF2Class =
      'http://www.opengis.net/spec/ogcapi-features-1/1.0/conf/gmlsf2';

  static const crsClass =
      'http://www.opengis.net/spec/ogcapi-features-2/1.0/conf/crs';
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🌎 geodata Related to the code package "geodata" enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant