diff --git a/.github/workflows/dart-pub-publish-on-pr.yml b/.github/workflows/dart-pub-publish-on-pr.yml index 8a112eed..dbce0b12 100644 --- a/.github/workflows/dart-pub-publish-on-pr.yml +++ b/.github/workflows/dart-pub-publish-on-pr.yml @@ -27,9 +27,5 @@ jobs: run: dart analyze if: always() - - name: Run build_runner - run: dart run build_runner build --delete-conflicting-outputs - if: always() - - name: Preview publish package (dry-run) run: dart pub publish --dry-run diff --git a/.github/workflows/dart-pub-publish.yml b/.github/workflows/dart-pub-publish.yml index 6bd5db7f..77a70b78 100644 --- a/.github/workflows/dart-pub-publish.yml +++ b/.github/workflows/dart-pub-publish.yml @@ -26,10 +26,6 @@ jobs: - name: Analyze project source run: dart analyze if: always() - - - name: Run build_runner - run: dart run build_runner build --delete-conflicting-outputs - if: always() - name: Setup credentials env: diff --git a/.github/workflows/dart-unit-tests-on-pr.yml b/.github/workflows/dart-unit-tests-on-pr.yml index 10e4a4f5..b6ca9dd0 100644 --- a/.github/workflows/dart-unit-tests-on-pr.yml +++ b/.github/workflows/dart-unit-tests-on-pr.yml @@ -27,10 +27,6 @@ jobs: run: dart analyze if: always() - - name: Run build_runner - run: dart run build_runner build --delete-conflicting-outputs - if: always() - - name: Run tests with coverage enabled run: dart test --coverage=./coverage if: always() diff --git a/.github/workflows/dart-unit-tests.yml b/.github/workflows/dart-unit-tests.yml index 47784bbd..1206f668 100644 --- a/.github/workflows/dart-unit-tests.yml +++ b/.github/workflows/dart-unit-tests.yml @@ -6,18 +6,13 @@ on: jobs: test: - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - os: [ubuntu-latest, macos-latest, windows-latest] - sdk: [stable] + runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - uses: dart-lang/setup-dart@v1 with: - sdk: ${{ matrix.sdk }} + sdk: stable - name: Print Dart SDK version run: dart --version @@ -32,10 +27,6 @@ jobs: run: dart analyze if: always() - - name: Run build_runner - run: dart run build_runner build --delete-conflicting-outputs - if: always() - - name: Run tests run: dart test if: always() diff --git a/lib/src/geojson.dart b/lib/src/geojson.dart index c967e74f..24af095f 100644 --- a/lib/src/geojson.dart +++ b/lib/src/geojson.dart @@ -1,732 +1 @@ -import 'package:json_annotation/json_annotation.dart'; - -part 'geojson.g.dart'; - -@JsonEnum(alwaysCreate: true) -enum GeoJSONObjectType { - @JsonValue('Point') - point, - @JsonValue('MultiPoint') - multiPoint, - @JsonValue('LineString') - lineString, - @JsonValue('MultiLineString') - multiLineString, - @JsonValue('Polygon') - polygon, - @JsonValue('MultiPolygon') - multiPolygon, - @JsonValue('GeometryCollection') - geometryCollection, - @JsonValue('Feature') - feature, - @JsonValue('FeatureCollection') - featureCollection, -} - -abstract class GeoJSONObject { - final GeoJSONObjectType type; - BBox? bbox; - - GeoJSONObject.withType(this.type, {this.bbox}); - - Map serialize(Map map) => { - 'type': _$GeoJSONObjectTypeEnumMap[type], - ...map, - }; - - static GeoJSONObject fromJson(Map json) { - GeoJSONObjectType decoded = json['type'] is GeoJSONObjectType - ? json['type'] - : $enumDecode(_$GeoJSONObjectTypeEnumMap, json['type']); - switch (decoded) { - case GeoJSONObjectType.point: - return Point.fromJson(json); - case GeoJSONObjectType.multiPoint: - return MultiPoint.fromJson(json); - case GeoJSONObjectType.lineString: - return LineString.fromJson(json); - case GeoJSONObjectType.multiLineString: - return MultiLineString.fromJson(json); - case GeoJSONObjectType.polygon: - return Polygon.fromJson(json); - case GeoJSONObjectType.multiPolygon: - return MultiPolygon.fromJson(json); - case GeoJSONObjectType.geometryCollection: - return GeometryCollection.fromJson(json); - case GeoJSONObjectType.feature: - return Feature.fromJson(json); - case GeoJSONObjectType.featureCollection: - return FeatureCollection.fromJson(json); - } - } - - Map toJson(); - - GeoJSONObject clone(); -} - -/// Coordinate types, following https://tools.ietf.org/html/rfc7946#section-4 -abstract class CoordinateType implements Iterable { - final List _items; - - CoordinateType(List list) : _items = List.of(list, growable: false); - - @override - num get first => _items.first; - - @override - num get last => _items.last; - - @override - int get length => _items.length; - - num? operator [](int index) => _items[index]; - - void operator []=(int index, num value) => _items[index] = value; - - @override - bool any(bool Function(num element) test) => _items.any(test); - - @override - List cast() => _items.cast(); - - @override - bool contains(Object? element) => _items.contains(element); - - @override - num elementAt(int index) => _items.elementAt(index); - - @override - bool every(bool Function(num element) test) => _items.every(test); - - @override - Iterable expand(Iterable Function(num element) f) => - _items.expand(f); - - @override - num firstWhere(bool Function(num element) test, {num Function()? orElse}) => - _items.firstWhere(test); - - @override - T fold(T initialValue, T Function(T previousValue, num element) combine) => - _items.fold(initialValue, combine); - - @override - Iterable followedBy(Iterable other) => _items.followedBy(other); - - @override - void forEach(void Function(num element) f) => _items.forEach(f); - - @override - bool get isEmpty => _items.isEmpty; - - @override - bool get isNotEmpty => _items.isNotEmpty; - - @override - Iterator get iterator => _items.iterator; - - @override - String join([String separator = '']) => _items.join(separator); - - @override - num lastWhere(bool Function(num element) test, {num Function()? orElse}) => - _items.lastWhere(test, orElse: orElse); - - @override - Iterable map(T Function(num e) f) => _items.map(f); - - @override - num reduce(num Function(num value, num element) combine) => - _items.reduce(combine); - - @override - num get single => _items.single; - - @override - num singleWhere(bool Function(num element) test, {num Function()? orElse}) => - _items.singleWhere(test, orElse: orElse); - - @override - Iterable skip(int count) => _items.skip(count); - - @override - Iterable skipWhile(bool Function(num value) test) => - _items.skipWhile(test); - - @override - Iterable take(int count) => _items.take(count); - - @override - Iterable takeWhile(bool Function(num value) test) => - _items.takeWhile(test); - - @override - List toList({bool growable = true}) => _items; - - @override - Set toSet() => _items.toSet(); - - @override - Iterable where(bool Function(num element) test) => _items.where(test); - - @override - Iterable whereType() => _items.whereType(); - - List toJson() => _items; - - CoordinateType clone(); - - CoordinateType toSigned(); - - bool get isSigned; - - num _untilSigned(num val, limit) { - if (val > limit) { - return _untilSigned(val - 360, limit); - } else { - return val; - } - } -} - -// Position, as specified here https://tools.ietf.org/html/rfc7946#section-3.1.1 -/// Please make sure, you arrange your parameters like this: -/// 1. Longitude, 2. Latitude, 3. Altitude (optional) -class Position extends CoordinateType { - Position(num lng, num lat, [num? alt]) - : super([ - lng, - lat, - if (alt != null) alt, - ]); - - Position.named({required num lat, required num lng, num? alt}) - : super([ - lng, - lat, - if (alt != null) alt, - ]); - - /// Position.of([, , ]) - Position.of(super.list) : assert(list.length >= 2 && list.length <= 3); - - factory Position.fromJson(List list) => Position.of(list); - - Position operator +(Position p) => Position.of([ - lng + p.lng, - lat + p.lat, - if (alt != null && p.alt != null) alt! + p.alt! - ]); - - Position operator -(Position p) => Position.of([ - lng - p.lng, - lat - p.lat, - if (alt != null && p.alt != null) alt! - p.alt!, - ]); - - num dotProduct(Position p) => - (lng * p.lng) + - (lat * p.lat) + - (alt != null && p.alt != null ? (alt! * p.alt!) : 0); - - Position crossProduct(Position p) { - if (alt != null && p.alt != null) { - return Position( - lat * p.alt! - alt! * p.lat, - alt! * p.lng - lng * p.alt!, - lng * p.lat - lat * p.lng, - ); - } - throw Exception('Cross product only implemented for 3 dimensions'); - } - - Position operator *(Position p) => crossProduct(p); - - num get lng => _items[0]; - - num get lat => _items[1]; - - num? get alt => length == 3 ? _items[2] : null; - - @override - bool get isSigned => lng <= 180 && lat <= 90; - - @override - Position toSigned() => Position.named( - lng: _untilSigned(lng, 180), - lat: _untilSigned(lat, 90), - alt: alt, - ); - - @override - Position clone() => Position.of(_items); - - @override - int get hashCode => Object.hashAll(_items); - - @override - bool operator ==(Object other) => other is Position - ? lng == other.lng && lat == other.lat && alt == other.alt - : false; -} - -// Bounding box, as specified here https://tools.ietf.org/html/rfc7946#section-5 -/// Please make sure, you arrange your parameters like this: -/// Longitude 1, Latitude 1, Altitude 1 (optional), Longitude 2, Latitude 2, Altitude 2 (optional) -/// You can either specify 4 or 6 parameters -/// If you are using the default constructor with two dimensional positions (lng + lat only), please use the constructor like this: -/// `BBox(lng1, lat1, lng2, lat2);` -class BBox extends CoordinateType { - BBox( - /// longitude 1 - num lng1, - - /// latitude 1 - num lat1, - - /// longitude 2 for 2 dim. positions; altitude 1 for 3 dim. positions - num alt1, - - /// latitude 2 for 2 dim. positions; longitude 2 for 3 dim. positions - num lng2, [ - /// latitude 2 for 3 dim. positions - num? lat2, - - /// altitude 2 for 3 dim. positions - num? alt2, - ]) : super([ - lng1, - lat1, - alt1, - lng2, - if (lat2 != null) lat2, - if (alt2 != null) alt2, - ]); - - BBox.named({ - required num lng1, - required num lat1, - num? alt1, - required num lng2, - required num lat2, - num? alt2, - }) : super([ - lng1, - lat1, - if (alt1 != null) alt1, - lng2, - lat2, - if (alt2 != null) alt2, - ]); - - /// Position.of([, , ]) - BBox.of(super.list) : assert(list.length == 4 || list.length == 6); - - factory BBox.fromJson(List list) => BBox.of(list); - - bool get _is3D => length == 6; - - num get lng1 => _items[0]; - - num get lat1 => _items[1]; - - num? get alt1 => _is3D ? _items[2] : null; - - num get lng2 => _items[_is3D ? 3 : 2]; - - num get lat2 => _items[_is3D ? 4 : 3]; - - num? get alt2 => _is3D ? _items[5] : null; - - BBox copyWith({ - num? lng1, - num? lat1, - num? alt1, - num? lat2, - num? lng2, - num? alt2, - }) => - BBox.named( - lng1: lng1 ?? this.lng1, - lat1: lat1 ?? this.lat1, - alt1: alt1 ?? this.alt1, - lng2: lng2 ?? this.lng2, - lat2: lat2 ?? this.lat2, - alt2: alt2 ?? this.alt2, - ); - - @override - BBox clone() => BBox.of(_items); - - @override - bool get isSigned => lng1 <= 180 && lng2 <= 180 && lat1 <= 90 && lat2 <= 90; - - @override - BBox toSigned() => BBox.named( - alt1: alt1, - alt2: alt2, - lat1: _untilSigned(lat1, 90), - lat2: _untilSigned(lat2, 90), - lng1: _untilSigned(lng1, 180), - lng2: _untilSigned(lng2, 180), - ); - - @override - int get hashCode => Object.hashAll(_items); - - @override - bool operator ==(Object other) => other is BBox - ? lng1 == other.lng1 && - lat1 == other.lat1 && - alt1 == other.alt1 && - lng2 == other.lng2 && - lat2 == other.lat2 && - alt2 == other.alt2 - : false; -} - -abstract class GeometryObject extends GeoJSONObject { - GeometryObject.withType(super.type, {super.bbox}) : super.withType(); - - static GeometryObject deserialize(Map json) { - return json['type'] == 'GeometryCollection' || - json['type'] == GeoJSONObjectType.geometryCollection - ? GeometryCollection.fromJson(json) - : GeometryType.deserialize(json); - } -} - -abstract class GeometryType extends GeometryObject { - T coordinates; - - GeometryType.withType(this.coordinates, GeoJSONObjectType type, {BBox? bbox}) - : super.withType(type, bbox: bbox); - - static GeometryType deserialize(Map json) { - GeoJSONObjectType decoded = json['type'] is GeoJSONObjectType - ? json['type'] - : $enumDecode(_$GeoJSONObjectTypeEnumMap, json['type']); - switch (decoded) { - case GeoJSONObjectType.point: - return Point.fromJson(json); - case GeoJSONObjectType.multiPoint: - return MultiPoint.fromJson(json); - case GeoJSONObjectType.lineString: - return LineString.fromJson(json); - case GeoJSONObjectType.multiLineString: - return MultiLineString.fromJson(json); - case GeoJSONObjectType.polygon: - return Polygon.fromJson(json); - case GeoJSONObjectType.multiPolygon: - return MultiPolygon.fromJson(json); - case GeoJSONObjectType.geometryCollection: - throw Exception( - 'This implementation does not support nested GeometryCollections'); - default: - throw Exception('${json['type']} is not a valid GeoJSON type'); - } - } - - @override - GeometryType clone(); -} - -/// Point, as specified here https://tools.ietf.org/html/rfc7946#section-3.1.2 -@JsonSerializable(explicitToJson: true) -class Point extends GeometryType { - Point({BBox? bbox, required Position coordinates}) - : super.withType(coordinates, GeoJSONObjectType.point, bbox: bbox); - - factory Point.fromJson(Map json) => _$PointFromJson(json); - - @override - Map toJson() => super.serialize(_$PointToJson(this)); - - @override - Point clone() => Point(coordinates: coordinates.clone(), bbox: bbox?.clone()); - - @override - int get hashCode => Object.hashAll([ - type, - ...coordinates, - if (bbox != null) ...bbox!, - ]); - - @override - bool operator ==(Object other) => - other is Point ? coordinates == other.coordinates : false; -} - -/// MultiPoint, as specified here https://tools.ietf.org/html/rfc7946#section-3.1.3 -@JsonSerializable(explicitToJson: true) -class MultiPoint extends GeometryType> { - MultiPoint({BBox? bbox, List coordinates = const []}) - : super.withType(coordinates, GeoJSONObjectType.multiPoint, bbox: bbox); - - factory MultiPoint.fromJson(Map json) => - _$MultiPointFromJson(json); - - MultiPoint.fromPoints({BBox? bbox, required List points}) - : assert(points.length >= 2), - super.withType(points.map((e) => e.coordinates).toList(), - GeoJSONObjectType.multiPoint, - bbox: bbox); - - @override - Map toJson() => super.serialize(_$MultiPointToJson(this)); - - @override - MultiPoint clone() => MultiPoint( - coordinates: coordinates.map((e) => e.clone()).toList(), - bbox: bbox?.clone(), - ); -} - -/// LineString, as specified here https://tools.ietf.org/html/rfc7946#section-3.1.4 -@JsonSerializable(explicitToJson: true) -class LineString extends GeometryType> { - LineString({BBox? bbox, List coordinates = const []}) - : super.withType(coordinates, GeoJSONObjectType.lineString, bbox: bbox); - - factory LineString.fromJson(Map json) => - _$LineStringFromJson(json); - - LineString.fromPoints({BBox? bbox, required List points}) - : assert(points.length >= 2), - super.withType(points.map((e) => e.coordinates).toList(), - GeoJSONObjectType.lineString, - bbox: bbox); - - @override - Map toJson() => super.serialize(_$LineStringToJson(this)); - - @override - LineString clone() => LineString( - coordinates: coordinates.map((e) => e.clone()).toList(), - bbox: bbox?.clone()); -} - -/// MultiLineString, as specified here https://tools.ietf.org/html/rfc7946#section-3.1.5 -@JsonSerializable(explicitToJson: true) -class MultiLineString extends GeometryType>> { - MultiLineString({BBox? bbox, List> coordinates = const []}) - : super.withType(coordinates, GeoJSONObjectType.multiLineString, - bbox: bbox); - - factory MultiLineString.fromJson(Map json) => - _$MultiLineStringFromJson(json); - - MultiLineString.fromLineStrings( - {BBox? bbox, required List lineStrings}) - : assert(lineStrings.length >= 2), - super.withType(lineStrings.map((e) => e.coordinates).toList(), - GeoJSONObjectType.multiLineString, - bbox: bbox); - - @override - Map toJson() => - super.serialize(_$MultiLineStringToJson(this)); - - @override - MultiLineString clone() => MultiLineString( - coordinates: - coordinates.map((e) => e.map((e) => e.clone()).toList()).toList(), - bbox: bbox?.clone(), - ); -} - -/// Polygon, as specified here https://tools.ietf.org/html/rfc7946#section-3.1.6 -@JsonSerializable(explicitToJson: true) -class Polygon extends GeometryType>> { - Polygon({BBox? bbox, List> coordinates = const []}) - : super.withType(coordinates, GeoJSONObjectType.polygon, bbox: bbox); - - factory Polygon.fromJson(Map json) => - _$PolygonFromJson(json); - - Polygon.fromPoints({BBox? bbox, required List> points}) - : assert(points.expand((list) => list).length >= 3), - super.withType( - points.map((e) => e.map((e) => e.coordinates).toList()).toList(), - GeoJSONObjectType.polygon, - bbox: bbox); - - @override - Map toJson() => super.serialize(_$PolygonToJson(this)); - - @override - Polygon clone() => Polygon( - coordinates: - coordinates.map((e) => e.map((e) => e.clone()).toList()).toList(), - bbox: bbox?.clone(), - ); -} - -/// MultiPolygon, as specified here https://tools.ietf.org/html/rfc7946#section-3.1.7 -@JsonSerializable(explicitToJson: true) -class MultiPolygon extends GeometryType>>> { - MultiPolygon({BBox? bbox, List>> coordinates = const []}) - : super.withType(coordinates, GeoJSONObjectType.multiPolygon, bbox: bbox); - - factory MultiPolygon.fromJson(Map json) => - _$MultiPolygonFromJson(json); - - MultiPolygon.fromPolygons({BBox? bbox, required List polygons}) - : assert(polygons.length >= 2), - super.withType(polygons.map((e) => e.coordinates).toList(), - GeoJSONObjectType.multiPolygon, - bbox: bbox); - - @override - Map toJson() => super.serialize(_$MultiPolygonToJson(this)); - - @override - MultiPolygon clone() => MultiPolygon( - coordinates: coordinates - .map((e) => e.map((e) => e.map((e) => e.clone()).toList()).toList()) - .toList(), - bbox: bbox?.clone(), - ); -} - -/// GeometryCollection, as specified here https://tools.ietf.org/html/rfc7946#section-3.1.8 -@JsonSerializable(explicitToJson: true, createFactory: false) -class GeometryCollection extends GeometryObject { - List geometries; - - GeometryCollection({BBox? bbox, this.geometries = const []}) - : super.withType(GeoJSONObjectType.geometryCollection, bbox: bbox); - - factory GeometryCollection.fromJson(Map json) => - GeometryCollection( - bbox: json['bbox'] == null - ? null - : BBox.fromJson( - (json['bbox'] as List).map((e) => e as num).toList(), - ), - geometries: (json['geometries'] as List?) - ?.map((e) => GeometryType.deserialize(e)) - .toList() ?? - const [], - ); - - @override - Map toJson() => - super.serialize(_$GeometryCollectionToJson(this)); - - @override - GeometryCollection clone() => GeometryCollection( - geometries: geometries.map((e) => e.clone()).toList(), - bbox: bbox?.clone(), - ); -} - -/// Feature, as specified here https://tools.ietf.org/html/rfc7946#section-3.2 -class Feature extends GeoJSONObject { - dynamic id; - Map? properties; - T? geometry; - Map fields; - - Feature({ - BBox? bbox, - this.id, - this.properties = const {}, - this.geometry, - this.fields = const {}, - }) : super.withType(GeoJSONObjectType.feature, bbox: bbox); - - factory Feature.fromJson(Map json) => Feature( - id: json['id'], - geometry: json['geometry'] == null - ? null - : GeometryObject.deserialize(json['geometry']) as T, - properties: json['properties'], - bbox: json['bbox'] == null - ? null - : BBox.fromJson( - (json['bbox'] as List).map((e) => e as num).toList()), - fields: Map.fromEntries( - json.entries.where( - (el) => - el.key != 'geometry' && - el.key != 'properties' && - el.key != 'id', - ), - ), - ); - - dynamic operator [](String key) { - switch (key) { - case 'id': - return id; - case 'properties': - return properties; - case 'geometry': - return geometry; - case 'type': - return type; - case 'bbox': - return bbox; - default: - return fields[key]; - } - } - - @override - int get hashCode => Object.hash(type, id); - - @override - bool operator ==(Object other) => other is Feature ? id == other.id : false; - - @override - Map toJson() => super.serialize({ - 'id': id, - 'geometry': geometry!.toJson(), - 'properties': properties, - ...fields, - }); - - @override - Feature clone() => Feature( - geometry: geometry?.clone() as T?, - bbox: bbox?.clone(), - fields: Map.of(fields), - properties: Map.of(properties ?? {}), - id: id, - ); -} - -/// FeatureCollection, as specified here https://tools.ietf.org/html/rfc7946#section-3.3 -class FeatureCollection extends GeoJSONObject { - List> features; - - FeatureCollection({BBox? bbox, this.features = const []}) - : super.withType(GeoJSONObjectType.featureCollection, bbox: bbox); - - factory FeatureCollection.fromJson(Map json) => - FeatureCollection( - bbox: json['bbox'] == null - ? null - : BBox.fromJson( - (json['bbox'] as List).map((e) => e as num).toList()), - features: (json['features'] as List?) - ?.map((e) => Feature.fromJson(e as Map)) - .toList() ?? - const [], - ); - - @override - Map toJson() => super.serialize({ - 'features': features.map((e) => e.toJson()).toList(), - 'bbox': bbox?.toJson(), - }); - - @override - FeatureCollection clone() => FeatureCollection( - features: features.map((e) => e.clone()).toList(), - bbox: bbox?.clone(), - ); -} +export 'package:geotypes/geotypes.dart'; diff --git a/lib/src/geojson.g.dart b/lib/src/geojson.g.dart deleted file mode 100644 index 7a07462c..00000000 --- a/lib/src/geojson.g.dart +++ /dev/null @@ -1,144 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'geojson.dart'; - -// ************************************************************************** -// JsonSerializableGenerator -// ************************************************************************** - -Point _$PointFromJson(Map json) => Point( - bbox: json['bbox'] == null - ? null - : BBox.fromJson( - (json['bbox'] as List).map((e) => e as num).toList()), - coordinates: Position.fromJson( - (json['coordinates'] as List).map((e) => e as num).toList()), - ); - -Map _$PointToJson(Point instance) => { - 'bbox': instance.bbox?.toJson(), - 'coordinates': instance.coordinates.toJson(), - }; - -MultiPoint _$MultiPointFromJson(Map json) => MultiPoint( - bbox: json['bbox'] == null - ? null - : BBox.fromJson( - (json['bbox'] as List).map((e) => e as num).toList()), - coordinates: (json['coordinates'] as List?) - ?.map((e) => Position.fromJson( - (e as List).map((e) => e as num).toList())) - .toList() ?? - const [], - ); - -Map _$MultiPointToJson(MultiPoint instance) => - { - 'bbox': instance.bbox?.toJson(), - 'coordinates': instance.coordinates.map((e) => e.toJson()).toList(), - }; - -LineString _$LineStringFromJson(Map json) => LineString( - bbox: json['bbox'] == null - ? null - : BBox.fromJson( - (json['bbox'] as List).map((e) => e as num).toList()), - coordinates: (json['coordinates'] as List?) - ?.map((e) => Position.fromJson( - (e as List).map((e) => e as num).toList())) - .toList() ?? - const [], - ); - -Map _$LineStringToJson(LineString instance) => - { - 'bbox': instance.bbox?.toJson(), - 'coordinates': instance.coordinates.map((e) => e.toJson()).toList(), - }; - -MultiLineString _$MultiLineStringFromJson(Map json) => - MultiLineString( - bbox: json['bbox'] == null - ? null - : BBox.fromJson( - (json['bbox'] as List).map((e) => e as num).toList()), - coordinates: (json['coordinates'] as List?) - ?.map((e) => (e as List) - .map((e) => Position.fromJson( - (e as List).map((e) => e as num).toList())) - .toList()) - .toList() ?? - const [], - ); - -Map _$MultiLineStringToJson(MultiLineString instance) => - { - 'bbox': instance.bbox?.toJson(), - 'coordinates': instance.coordinates - .map((e) => e.map((e) => e.toJson()).toList()) - .toList(), - }; - -Polygon _$PolygonFromJson(Map json) => Polygon( - bbox: json['bbox'] == null - ? null - : BBox.fromJson( - (json['bbox'] as List).map((e) => e as num).toList()), - coordinates: (json['coordinates'] as List?) - ?.map((e) => (e as List) - .map((e) => Position.fromJson( - (e as List).map((e) => e as num).toList())) - .toList()) - .toList() ?? - const [], - ); - -Map _$PolygonToJson(Polygon instance) => { - 'bbox': instance.bbox?.toJson(), - 'coordinates': instance.coordinates - .map((e) => e.map((e) => e.toJson()).toList()) - .toList(), - }; - -MultiPolygon _$MultiPolygonFromJson(Map json) => MultiPolygon( - bbox: json['bbox'] == null - ? null - : BBox.fromJson( - (json['bbox'] as List).map((e) => e as num).toList()), - coordinates: (json['coordinates'] as List?) - ?.map((e) => (e as List) - .map((e) => (e as List) - .map((e) => Position.fromJson( - (e as List).map((e) => e as num).toList())) - .toList()) - .toList()) - .toList() ?? - const [], - ); - -Map _$MultiPolygonToJson(MultiPolygon instance) => - { - 'bbox': instance.bbox?.toJson(), - 'coordinates': instance.coordinates - .map((e) => e.map((e) => e.map((e) => e.toJson()).toList()).toList()) - .toList(), - }; - -Map _$GeometryCollectionToJson(GeometryCollection instance) => - { - 'type': _$GeoJSONObjectTypeEnumMap[instance.type]!, - 'bbox': instance.bbox?.toJson(), - 'geometries': instance.geometries.map((e) => e.toJson()).toList(), - }; - -const _$GeoJSONObjectTypeEnumMap = { - GeoJSONObjectType.point: 'Point', - GeoJSONObjectType.multiPoint: 'MultiPoint', - GeoJSONObjectType.lineString: 'LineString', - GeoJSONObjectType.multiLineString: 'MultiLineString', - GeoJSONObjectType.polygon: 'Polygon', - GeoJSONObjectType.multiPolygon: 'MultiPolygon', - GeoJSONObjectType.geometryCollection: 'GeometryCollection', - GeoJSONObjectType.feature: 'Feature', - GeoJSONObjectType.featureCollection: 'FeatureCollection', -}; diff --git a/lib/turf.dart b/lib/turf.dart index cee47a0e..952f5b8b 100644 --- a/lib/turf.dart +++ b/lib/turf.dart @@ -1,5 +1,6 @@ library turf; +export 'package:geotypes/geotypes.dart'; export 'src/along.dart'; export 'src/area.dart'; export 'src/bbox.dart'; @@ -8,7 +9,6 @@ export 'src/center.dart'; export 'src/centroid.dart'; export 'src/destination.dart'; export 'src/distance.dart'; -export 'src/geojson.dart'; export 'src/helpers.dart'; export 'src/length.dart'; export 'src/midpoint.dart'; diff --git a/pubspec.yaml b/pubspec.yaml index 5099bcdc..58f7a6e9 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -7,7 +7,7 @@ homepage: https://github.com/dartclub/turf_dart repository: https://github.com/dartclub/turf_dart dependencies: - json_annotation: ^4.8.1 + geotypes: ^0.0.2 turf_equality: ^0.1.0 turf_pip: ^0.0.2 rbush: ^1.1.1 @@ -16,7 +16,6 @@ dependencies: dev_dependencies: lints: ^3.0.0 test: ^1.24.3 - json_serializable: ^6.7.0 build_runner: ^2.4.5 analyzer: ^6.4.0 benchmark: ^0.3.0