Skip to content

Commit

Permalink
feat(geodata): consistent factories for GeoJSON and OGC API Features …
Browse files Browse the repository at this point in the history
…clients #155
  • Loading branch information
navispatial committed Nov 15, 2022
1 parent 390f63a commit 3775c1e
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 40 deletions.
9 changes: 9 additions & 0 deletions dart/geodata/CHANGELOG.md
@@ -1,3 +1,12 @@
## 0.11.0

[geodata version 0.11.0 #162](https://github.com/navibyte/geospatial/issues/162)

Under development, current pre-release: 0.11.0-dev.0

🧩 Features:
* [Consistent factories for GeoJSON and OGC API Features clients #155](https://github.com/navibyte/geospatial/issues/155)

## 0.10.1

📚 Small documentation updates. Also a link to the [Geospatial demos for Dart](https://github.com/navibyte/geospatial_demos) repository.
Expand Down
4 changes: 2 additions & 2 deletions dart/geodata/example/geodata_example.dart
Expand Up @@ -115,7 +115,7 @@ Future<void> main(List<String> args) async {
print('Reading web resource at: $location');

// GeoJSON client for a data source
final source = geoJsonHttpClient(location: location);
final source = GeoJSONFeatures.http(location: location);
switch (operation) {
case 'items':
// get actual data, a single feature or features
Expand All @@ -135,7 +135,7 @@ Future<void> main(List<String> args) async {
final endpoint = Uri.parse(baseURL);

// OGC API Features client (the service provides both meta and items)
final service = ogcApiFeaturesHttpClient(endpoint: endpoint);
final service = OGCAPIFeatures.http(endpoint: endpoint);

switch (operation) {
case 'meta':
Expand Down
4 changes: 2 additions & 2 deletions dart/geodata/example/geojson_example.dart
Expand Up @@ -19,7 +19,7 @@ Future<void> main(List<String> args) async {
// read GeoJSON for earthquakes from web using HTTP(S)
print('GeoJSON features from HTTP');
await _readFeatures(
geoJsonHttpClient(
GeoJSONFeatures.http(
location: Uri.parse(
'https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/'
'2.5_day.geojson',
Expand All @@ -31,7 +31,7 @@ Future<void> main(List<String> args) async {
print('');
print('GeoJSON features from file');
await _readFeatures(
geoJsonFutureClient(
GeoJSONFeatures.any(
() async => File('test/usgs/summary/2.5_day.geojson').readAsString(),
),
);
Expand Down
Expand Up @@ -6,32 +6,74 @@

import 'package:geobase/vector.dart';
import 'package:geobase/vector_data.dart';
import 'package:http/http.dart' as http;
import 'package:http/http.dart' as _http;

import '/src/common/paged.dart';
import '/src/common/service.dart';
import '/src/core/features.dart';
import '/src/utils/features.dart';

/// 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,
_http.Client? client,
Map<String, String>? headers,
TextReaderFormat<FeatureContent> format = GeoJSON.feature,
}) =>
_GeoJSONFeatureSource(
location,
adapter: FeatureHttpAdapter(
client: client,
headers: headers,
),
format: format,
);

/// 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,
}) =>
_GeoJSONFeatureSource(
source,
format: format,
);
}

/// 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.
/// See [GeoJSONFeatures.http].
@Deprecated('Use GeoJSONFeature.http instead.')
BasicFeatureSource geoJsonHttpClient({
required Uri location,
http.Client? client,
_http.Client? client,
Map<String, String>? headers,
TextReaderFormat<FeatureContent> format = GeoJSON.feature,
}) =>
Expand All @@ -46,13 +88,8 @@ BasicFeatureSource geoJsonHttpClient({

/// A client for accessing a `GeoJSON` feature collection from [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.
/// See [GeoJSONFeatures.any].
@Deprecated('Use GeoJSONFeature.any instead.')
BasicFeatureSource geoJsonFutureClient(
Future<String> Function() source, {
TextReaderFormat<FeatureContent> format = GeoJSON.feature,
Expand Down
Expand Up @@ -8,7 +8,7 @@ import 'package:geobase/coordinates.dart';
import 'package:geobase/meta.dart';
import 'package:geobase/vector.dart';
import 'package:geobase/vector_data.dart';
import 'package:http/http.dart' as http;
import 'package:http/http.dart' as _http;

import '/src/common/links.dart';
import '/src/common/paged.dart';
Expand All @@ -17,24 +17,48 @@ import '/src/core/data.dart';
import '/src/ogcapi_features/model.dart';
import '/src/utils/features.dart';

/// 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,
_http.Client? client,
Map<String, String>? headers,
TextReaderFormat<FeatureContent> format = GeoJSON.feature,
}) =>
_OGCFeatureClientHttp(
endpoint,
adapter: FeatureHttpAdapter(
client: client,
headers: headers,
),
format: format,
);
}

/// 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.
/// See [OGCAPIFeatures.http].
@Deprecated('Use GeoJSONFeature.http instead.')
OGCFeatureService ogcApiFeaturesHttpClient({
required Uri endpoint,
http.Client? client,
_http.Client? client,
Map<String, String>? headers,
TextReaderFormat<FeatureContent> format = GeoJSON.feature,
}) =>
Expand Down

0 comments on commit 3775c1e

Please sign in to comment.