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

Consistent factories for GeoJSON and OGC API Features clients #155

Closed
navispatial opened this issue Sep 5, 2022 · 2 comments
Closed

Consistent factories for GeoJSON and OGC API Features clients #155

navispatial opened this issue Sep 5, 2022 · 2 comments
Labels
🌎 geodata Related to the code package "geodata" enhancement New feature or request refactoring

Comments

@navispatial
Copy link
Member

Currently client instances created using factory functions.

GeoJSON client:

/// A client for accessing a `GeoJSON` data resource at [location] via http(s)
/// conforming to [format].
///
/// The required [location] should refer to a web resource containing GeoJSON
/// compliant data.
///
/// When given the optional [client] is used for http requests, otherwise the
/// default client of the `package:http/http.dart` package is used.
///
/// When given [headers] are injected to http requests (however some can be
/// overridden by the feature source implementation).
///
/// When [format] is not given, then [GeoJSON] with default settings is used as
/// a default. Note that currently only GeoJSON is supported, but it's possible
/// to inject another format implementation (or with custom configuration) to
/// the default one.
BasicFeatureSource geoJsonHttpClient({
  required Uri location,
  http.Client? client,
  Map<String, String>? headers,
  TextReaderFormat<FeatureContent> format = GeoJSON.feature,
});

OGC API Features client:

/// A client for accessing `OGC API Features` compliant sources via http(s)
/// conforming to [format].
///
/// The required [endpoint] should refer to a base url of a feature service.
///
/// When given the optional [client] is used for http requests, otherwise the
/// default client of the `package:http/http.dart` package is used.
///
/// When given [headers] are injected to http requests (however some can be
/// overridden by the feature service implementation).
///
/// When [format] is not given, then [GeoJSON] with default settings is used as
/// a default. Note that currently only GeoJSON is supported, but it's possible
/// to inject another format implementation (or with custom configuration) to
/// the default one.
OGCFeatureService ogcApiFeaturesHttpClient({
  required Uri endpoint,
  http.Client? client,
  Map<String, String>? headers,
  TextReaderFormat<FeatureContent> format = GeoJSON.feature,
});

Another refers to an API endpoint by location, and another by endpoint. Choose one of these to be consistent.

Also consider similar factories as encoders / decoder on formats provider by geobase package:

GeoJsonClient.http(....);
GeoJsonClient.local(....); 
OGCAPI.features(....)
@navispatial navispatial added enhancement New feature or request 🌎 geodata Related to the code package "geodata" refactoring labels Sep 5, 2022
@navispatial
Copy link
Member Author

Also there should be convenient helper methods to map generic Feature and FeatureCollection objects (GeoJSON data model) to domain specific data models.

@navispatial
Copy link
Member Author

Implemented in geodata 0.11.0-dev.0.

The final implementation with small changes from plans above.

GeoJSON Features client:

/// A class with static factory methods to create feature sources conforming to
/// the GeoJSON format.
class GeoJSONFeatures {
  /// A client for accessing a `GeoJSON` data resource at [location] via http(s)
  /// conforming to [format].
  ///
  /// The required [location] should refer to a web resource containing GeoJSON
  /// compliant data.
  ///
  /// When given the optional [client] is used for http requests, otherwise the
  /// default client of the `package:http/http.dart` package is used.
  ///
  /// When given [headers] are injected to http requests (however some can be
  /// overridden by the feature source implementation).
  ///
  /// When [format] is not given, then [GeoJSON] with default settings is used
  /// as a default. Note that currently only GeoJSON is supported, but it's
  /// possible to inject another format implementation (or with custom
  /// configuration) to the default one.
  static BasicFeatureSource http({
    required Uri location,
    Client? client,
    Map<String, String>? headers,
    TextReaderFormat<FeatureContent> format = GeoJSON.feature,
  });

  /// A client for accessing a `GeoJSON` feature collection from any [source];
  ///
  /// The source function returns a future that fetches data from a file, a web
  /// resource or other sources. Contents must be GeoJSON compliant data.
  ///
  /// When [format] is not given, then [GeoJSON] with default settings is used
  /// as a default. Note that currently only GeoJSON is supported, but it's
  /// possible to inject another format implementation (or with custom
  /// configuration) to the default one.
  static BasicFeatureSource any(
    Future<String> Function() source, {
    TextReaderFormat<FeatureContent> format = GeoJSON.feature,
  });
}

OGC API Features client:

/// A class with static factory methods to create feature sources conforming to
/// the OGC API Features standard.
class OGCAPIFeatures {
  /// A client for accessing `OGC API Features` compliant sources via http(s)
  /// conforming to [format].
  ///
  /// The required [endpoint] should refer to a base url of a feature service.
  ///
  /// When given the optional [client] is used for http requests, otherwise the
  /// default client of the `package:http/http.dart` package is used.
  ///
  /// When given [headers] are injected to http requests (however some can be
  /// overridden by the feature service implementation).
  ///
  /// When [format] is not given, then [GeoJSON] with default settings is used
  /// as a default. Note that currently only GeoJSON is supported, but it's
  /// possible to inject another format implementation (or with custom
  /// configuration) to the default one.
  static OGCFeatureService http({
    required Uri endpoint,
    Client? client,
    Map<String, String>? headers,
    TextReaderFormat<FeatureContent> format = GeoJSON.feature,
  });
}

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 refactoring
Projects
None yet
Development

No branches or pull requests

1 participant