-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(geobase): define TemporalRefSys and TemporalRefSysResolver basic…
… implementations #196 BREAKING CHANGE: meta classes changes type of trs parameter
- Loading branch information
1 parent
fb4bcd7
commit d5362a0
Showing
8 changed files
with
149 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
dart/geobase/lib/src/coordinates/reference/temporal_ref_sys.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// Copyright (c) 2020-2023 Navibyte (https://navibyte.com). All rights reserved. | ||
// Use of this source code is governed by a “BSD-3-Clause”-style license that is | ||
// specified in the LICENSE file. | ||
// | ||
// Docs: https://github.com/navibyte/geospatial | ||
|
||
import 'package:meta/meta.dart'; | ||
|
||
import 'temporal_ref_sys_resolver.dart'; | ||
|
||
/// Metadata about a temporal coordinate reference system (TRS) identified and | ||
/// specified by [id]. | ||
@immutable | ||
class TemporalRefSys { | ||
/// Metadata about a temporal coordinate reference system (TRS) identified and | ||
/// specified by [id]. | ||
/// | ||
/// No normalization of identifiers is done. | ||
/// | ||
/// See also [TemporalRefSys.normalized]. | ||
const TemporalRefSys.id(this.id); | ||
|
||
/// Metadata about a temporal coordinate reference system (TRS) identified and | ||
/// specified by the normalized identifier of [id]. | ||
/// | ||
/// Normalization: `TemporalRefSysResolver.registry.normalizeId(id)`. | ||
/// | ||
/// The default implementation returns [id] unmodified (however when necessary | ||
/// a custom logic can be registered for [TemporalRefSysResolver]). | ||
TemporalRefSys.normalized(String id) | ||
: id = TemporalRefSysResolver.registry.normalizeId(id); | ||
|
||
/// The temporal coordinate reference system (TRS) identifier. | ||
/// | ||
/// The identifier is authorative, it identifies a well known or referenced | ||
/// specification that defines properties for a temporal coordinate reference | ||
/// system. | ||
/// | ||
/// Examples: | ||
/// * `http://www.opengis.net/def/uom/ISO-8601/0/Gregorian`: dates or | ||
/// timestamps are in the Gregorian calendar and conform to | ||
/// [RFC 3339](https://www.rfc-editor.org/rfc/rfc3339.html). | ||
final String id; | ||
|
||
/// The temporal coordinate reference system resolved in this order: | ||
/// 1. [temporalRefSys] if it's non-null | ||
/// 2. otherwise `TemporalRefSys.normalized(trs)` if [trs] is non-null | ||
/// 3. otherwise `TemporalRefSys.gregorian` | ||
factory TemporalRefSys.from({ | ||
TemporalRefSys? temporalRefSys, | ||
String? trs, | ||
}) => | ||
temporalRefSys ?? | ||
(trs != null ? TemporalRefSys.normalized(trs) : gregorian); | ||
|
||
/// The temporal coordinate reference system identified by | ||
/// 'http://www.opengis.net/def/uom/ISO-8601/0/Gregorian'. | ||
/// | ||
/// References temporal coordinates, dates or timestamps, that are in the | ||
/// Gregorian calendar and conform to | ||
/// [RFC 3339](https://www.rfc-editor.org/rfc/rfc3339.html). | ||
static const TemporalRefSys gregorian = | ||
TemporalRefSys.id('http://www.opengis.net/def/uom/ISO-8601/0/Gregorian'); | ||
|
||
@override | ||
String toString() => id; | ||
|
||
@override | ||
bool operator ==(Object other) => other is TemporalRefSys && id == other.id; | ||
|
||
@override | ||
int get hashCode => id.hashCode; | ||
} |
50 changes: 50 additions & 0 deletions
50
dart/geobase/lib/src/coordinates/reference/temporal_ref_sys_resolver.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright (c) 2020-2023 Navibyte (https://navibyte.com). All rights reserved. | ||
// Use of this source code is governed by a “BSD-3-Clause”-style license that is | ||
// specified in the LICENSE file. | ||
// | ||
// Docs: https://github.com/navibyte/geospatial | ||
|
||
// NOTE: implement normalization for the template | ||
// `http://www.opengis.net/def/uom/{authority}/{version}/{code}`. | ||
|
||
/// An abstract class for resolving temporal coordinate reference system | ||
/// information. | ||
/// | ||
/// A resolver can be accessed using [registry] that is initially instantiated | ||
/// with the basic default implementation. It be customized by registering a | ||
/// custom instance using [register]). | ||
/// | ||
/// NOTE: The current version of this resolver class provides only the method | ||
/// [normalizeId]. In future other methods might be added. | ||
abstract class TemporalRefSysResolver { | ||
const TemporalRefSysResolver._(); | ||
|
||
/// Normalizes the temporal coordinate reference system identifier. | ||
/// | ||
/// The normalization logic depends on the resolver of [registry]. | ||
String normalizeId(String id); | ||
|
||
/// The current instance of [TemporalRefSysResolver], initially instantiated | ||
/// with the basic default implementation. | ||
/// | ||
/// Currently the basic default implemention returns identifiers unmodified. | ||
/// | ||
/// NOTE: In future the basic implementation is going to be extended to | ||
/// support also other identifier and more wide normalization logic. | ||
static TemporalRefSysResolver registry = const _BasicTemporalRefSysRegistry(); | ||
|
||
/// Registers a custom instance of [TemporalRefSysResolver], available at | ||
/// static [registry] after calling this. | ||
// ignore: use_setters_to_change_properties | ||
static void register(TemporalRefSysResolver resolver) => | ||
TemporalRefSysResolver.registry = resolver; | ||
} | ||
|
||
class _BasicTemporalRefSysRegistry implements TemporalRefSysResolver { | ||
const _BasicTemporalRefSysRegistry(); | ||
|
||
@override | ||
String normalizeId(String id) { | ||
return id; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters