From 2130d9449dc57708c49e7ef37d68ee2cc011f684 Mon Sep 17 00:00:00 2001 From: NithyaNN3 Date: Fri, 28 Mar 2025 16:31:03 +1100 Subject: [PATCH 1/9] added envelope files with one test case --- lib/envelope.dart | 4 ++ lib/src/envelope.dart | 10 +++ lib/turf.dart | 1 + test/components/envelope_test.dart | 102 +++++++++++++++++++++++++++++ 4 files changed, 117 insertions(+) create mode 100644 lib/envelope.dart create mode 100644 lib/src/envelope.dart create mode 100644 test/components/envelope_test.dart diff --git a/lib/envelope.dart b/lib/envelope.dart new file mode 100644 index 00000000..6fb4c636 --- /dev/null +++ b/lib/envelope.dart @@ -0,0 +1,4 @@ +library turf_envelope; + +export 'package:geotypes/geotypes.dart'; +export "src/envelope.dart"; \ No newline at end of file diff --git a/lib/src/envelope.dart b/lib/src/envelope.dart new file mode 100644 index 00000000..4da07aec --- /dev/null +++ b/lib/src/envelope.dart @@ -0,0 +1,10 @@ +import '../helpers.dart'; + +import '../bbox.dart'; +import '../bbox_polygon.dart'; + + + +num? envelope(GeoJSONObject geojson) { + return bboxPolygon(bbox(geojson)); +} \ No newline at end of file diff --git a/lib/turf.dart b/lib/turf.dart index 482694bb..795a35ee 100644 --- a/lib/turf.dart +++ b/lib/turf.dart @@ -13,6 +13,7 @@ export 'clean_coords.dart'; export 'clusters.dart'; export 'destination.dart'; export 'distance.dart'; +export 'envelope.dart'; export 'explode.dart'; export 'extensions.dart'; export 'helpers.dart'; diff --git a/test/components/envelope_test.dart b/test/components/envelope_test.dart new file mode 100644 index 00000000..429269d0 --- /dev/null +++ b/test/components/envelope_test.dart @@ -0,0 +1,102 @@ +import 'package:test/test.dart'; +import 'package:turf/envelope.dart;' + +void main() { + final pt = Feature( + geometry: Point(coordinates: Position.named(lat: 102.0, lng: 0.5))); +// final line = Feature( +// geometry: LineString(coordinates: [ +// Position.named(lat: 102.0, lng: -10.0), +// Position.named(lat: 103.0, lng: 1.0), +// Position.named(lat: 104.0, lng: 0.0), +// Position.named(lat: 130.0, lng: 4.0), +// ])); +// final poly = Feature( +// geometry: Polygon(coordinates: [ +// [ +// Position.named(lat: 101.0, lng: 0.0), +// Position.named(lat: 101.0, lng: 1.0), +// Position.named(lat: 100.0, lng: 1.0), +// Position.named(lat: 100.0, lng: 0.0), +// Position.named(lat: 101.0, lng: 0.0), +// ], +// ])); +// final multiLine = Feature( +// geometry: MultiLineString(coordinates: [ +// [ +// Position.named(lat: 100.0, lng: 0.0), +// Position.named(lat: 101.0, lng: 1.0), +// ], +// [ +// Position.named(lat: 102.0, lng: 2.0), +// Position.named(lat: 103.0, lng: 3.0), +// ], +// ])); +// final multiPoly = Feature( +// geometry: MultiPolygon(coordinates: [ +// [ +// [ +// Position.named(lat: 102.0, lng: 2.0), +// Position.named(lat: 103.0, lng: 2.0), +// Position.named(lat: 103.0, lng: 3.0), +// Position.named(lat: 102.0, lng: 3.0), +// Position.named(lat: 102.0, lng: 2.0), +// ], +// ], +// [ +// [ +// Position.named(lat: 100.0, lng: 0.0), +// Position.named(lat: 101.0, lng: 0.0), +// Position.named(lat: 101.0, lng: 1.0), +// Position.named(lat: 100.0, lng: 1.0), +// Position.named(lat: 100.0, lng: 0.0), +// ], +// [ +// Position.named(lat: 100.2, lng: 0.2), +// Position.named(lat: 100.8, lng: 0.2), +// Position.named(lat: 100.8, lng: 0.8), +// Position.named(lat: 100.2, lng: 0.8), +// Position.named(lat: 100.2, lng: 0.2), +// ], +// ], +// ])); + final fc = + // FeatureCollection(features: [pt, line, poly, multiLine, multiPoly]); + FeatureCollection(features: [pt]); + + test("bbox", () { + // // FeatureCollection + // final fcBBox = bbox(fc); + // expect(fcBBox, equals([-10, 100, 4, 130]), reason: "featureCollection"); + + // Point + final ptEnvelope = envelope(pt); + expect(ptEnvelope, equals([[0.5, 102.0], [0.5, 102.0], [0.5, 102.0], [0.5, 102.0]]), reason: "point"); + + // // // Line + // final lineBBox = bbox(line); + // expect(lineBBox, equals([-10, 102, 4, 130]), reason: "lineString"); + + // // // Polygon + // final polyExtent = bbox(poly); + // expect(polyExtent, equals([0, 100, 1, 101]), reason: "polygon"); + + // // // MultiLineString + // final multiLineBBox = bbox(multiLine); + // expect(multiLineBBox, equals([0, 100, 3, 103]), reason: "multiLineString"); + + // // // MultiPolygon + // final multiPolyBBox = bbox(multiPoly); + // expect(multiPolyBBox, equals([0, 100, 3, 103]), reason: "multiPolygon"); + + // final pt2 = Feature( + // geometry: Point(coordinates: Position.named(lat: 102.0, lng: 0.5)), + // bbox: bbox(Feature( + // geometry: Point(coordinates: Position.named(lat: 0, lng: 0)))), + // ); + // expect(bbox(pt2), equals([0, 0, 0, 0]), + // reason: "uses built-in bbox by default"); + // expect(bbox(pt2, recompute: true), [0.5, 102, 0.5, 102], + // reason: "recomputes bbox with recompute option"); + }); +} \ No newline at end of file From fc6e189a77b89b1e8aecf9a301c5a98acb842f24 Mon Sep 17 00:00:00 2001 From: NithyaNN3 Date: Fri, 28 Mar 2025 23:26:18 +1100 Subject: [PATCH 2/9] made some fixes --- lib/src/envelope.dart | 2 +- test/components/envelope_test.dart | 112 ++++++----------------------- 2 files changed, 21 insertions(+), 93 deletions(-) diff --git a/lib/src/envelope.dart b/lib/src/envelope.dart index 4da07aec..16b9a699 100644 --- a/lib/src/envelope.dart +++ b/lib/src/envelope.dart @@ -5,6 +5,6 @@ import '../bbox_polygon.dart'; -num? envelope(GeoJSONObject geojson) { +Feature envelope(GeoJSONObject geojson) { return bboxPolygon(bbox(geojson)); } \ No newline at end of file diff --git a/test/components/envelope_test.dart b/test/components/envelope_test.dart index 429269d0..d4ce9442 100644 --- a/test/components/envelope_test.dart +++ b/test/components/envelope_test.dart @@ -1,102 +1,30 @@ +import 'package:turf/turf.dart'; import 'package:test/test.dart'; -import 'package:turf/envelope.dart;' void main() { final pt = Feature( geometry: Point(coordinates: Position.named(lat: 102.0, lng: 0.5))); -// final line = Feature( -// geometry: LineString(coordinates: [ -// Position.named(lat: 102.0, lng: -10.0), -// Position.named(lat: 103.0, lng: 1.0), -// Position.named(lat: 104.0, lng: 0.0), -// Position.named(lat: 130.0, lng: 4.0), -// ])); -// final poly = Feature( -// geometry: Polygon(coordinates: [ -// [ -// Position.named(lat: 101.0, lng: 0.0), -// Position.named(lat: 101.0, lng: 1.0), -// Position.named(lat: 100.0, lng: 1.0), -// Position.named(lat: 100.0, lng: 0.0), -// Position.named(lat: 101.0, lng: 0.0), -// ], -// ])); -// final multiLine = Feature( -// geometry: MultiLineString(coordinates: [ -// [ -// Position.named(lat: 100.0, lng: 0.0), -// Position.named(lat: 101.0, lng: 1.0), -// ], -// [ -// Position.named(lat: 102.0, lng: 2.0), -// Position.named(lat: 103.0, lng: 3.0), -// ], -// ])); -// final multiPoly = Feature( -// geometry: MultiPolygon(coordinates: [ -// [ -// [ -// Position.named(lat: 102.0, lng: 2.0), -// Position.named(lat: 103.0, lng: 2.0), -// Position.named(lat: 103.0, lng: 3.0), -// Position.named(lat: 102.0, lng: 3.0), -// Position.named(lat: 102.0, lng: 2.0), -// ], -// ], -// [ -// [ -// Position.named(lat: 100.0, lng: 0.0), -// Position.named(lat: 101.0, lng: 0.0), -// Position.named(lat: 101.0, lng: 1.0), -// Position.named(lat: 100.0, lng: 1.0), -// Position.named(lat: 100.0, lng: 0.0), -// ], -// [ -// Position.named(lat: 100.2, lng: 0.2), -// Position.named(lat: 100.8, lng: 0.2), -// Position.named(lat: 100.8, lng: 0.8), -// Position.named(lat: 100.2, lng: 0.8), -// Position.named(lat: 100.2, lng: 0.2), -// ], -// ], -// ])); - final fc = - // FeatureCollection(features: [pt, line, poly, multiLine, multiPoly]); - FeatureCollection(features: [pt]); - - test("bbox", () { - // // FeatureCollection - // final fcBBox = bbox(fc); - // expect(fcBBox, equals([-10, 100, 4, 130]), reason: "featureCollection"); + test("envelope", () { // Point final ptEnvelope = envelope(pt); - expect(ptEnvelope, equals([[0.5, 102.0], [0.5, 102.0], [0.5, 102.0], [0.5, 102.0]]), reason: "point"); - - // // // Line - // final lineBBox = bbox(line); - // expect(lineBBox, equals([-10, 102, 4, 130]), reason: "lineString"); - - // // // Polygon - // final polyExtent = bbox(poly); - // expect(polyExtent, equals([0, 100, 1, 101]), reason: "polygon"); - - // // // MultiLineString - // final multiLineBBox = bbox(multiLine); - // expect(multiLineBBox, equals([0, 100, 3, 103]), reason: "multiLineString"); - - // // // MultiPolygon - // final multiPolyBBox = bbox(multiPoly); - // expect(multiPolyBBox, equals([0, 100, 3, 103]), reason: "multiPolygon"); - - // final pt2 = Feature( - // geometry: Point(coordinates: Position.named(lat: 102.0, lng: 0.5)), - // bbox: bbox(Feature( - // geometry: Point(coordinates: Position.named(lat: 0, lng: 0)))), - // ); - // expect(bbox(pt2), equals([0, 0, 0, 0]), - // reason: "uses built-in bbox by default"); - // expect(bbox(pt2, recompute: true), [0.5, 102, 0.5, 102], - // reason: "recomputes bbox with recompute option"); + expect( + ptEnvelope, + equals(Feature( + geometry: Polygon(coordinates: [ + [ + Position.named(lat: 102.0, lng: 0.5), + Position.named(lat: 102.0, lng: 0.5), + Position.named(lat: 102.0, lng: 0.5), + Position.named(lat: 102.0, lng: 0.5), + Position.named(lat: 102.0, lng: 0.5), + ] + ]) + )), + reason: "point", + ); + + // Print ptEnvelope here inside the test + print(ptEnvelope); }); } \ No newline at end of file From e3ef34120dca87e94c1609c6c27434900de167eb Mon Sep 17 00:00:00 2001 From: NithyaNN3 Date: Fri, 28 Mar 2025 23:55:41 +1100 Subject: [PATCH 3/9] added linestring test case for envelope --- test/components/envelope_test.dart | 41 +++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/test/components/envelope_test.dart b/test/components/envelope_test.dart index d4ce9442..5f27a449 100644 --- a/test/components/envelope_test.dart +++ b/test/components/envelope_test.dart @@ -2,14 +2,22 @@ import 'package:turf/turf.dart'; import 'package:test/test.dart'; void main() { - final pt = Feature( + final point = Feature( geometry: Point(coordinates: Position.named(lat: 102.0, lng: 0.5))); - test("envelope", () { + final line = Feature( + geometry: LineString(coordinates: [ + Position.named(lat: 102.0, lng: 0.5), + Position.named(lat: 103.0, lng: 1.5), + Position.named(lat: 104.0, lng: 2.5), + ]) + ); + + test("envelope for point", () { // Point - final ptEnvelope = envelope(pt); + final pointEnvelope = envelope(point); expect( - ptEnvelope, + pointEnvelope, equals(Feature( geometry: Polygon(coordinates: [ [ @@ -23,8 +31,27 @@ void main() { )), reason: "point", ); - - // Print ptEnvelope here inside the test - print(ptEnvelope); + }); + + test("envelope for linestring", () { + // LineString + final lineEnvelope = envelope(line); + + // Directly use the expected envelope in the expect call + expect( + lineEnvelope, + equals(Feature( + geometry: Polygon(coordinates: [ + [ + Position.named(lat: 102.0, lng: 0.5), + Position.named(lat: 104.0, lng: 0.5), + Position.named(lat: 104.0, lng: 2.5), + Position.named(lat: 102.0, lng: 2.5), + Position.named(lat: 102.0, lng: 0.5), + ] + ]), + )), + reason: "LineString", + ); }); } \ No newline at end of file From f51824b5da506fb7b5429e7bd24b527a90c210a2 Mon Sep 17 00:00:00 2001 From: NithyaNN3 Date: Thu, 3 Apr 2025 00:39:09 +1100 Subject: [PATCH 4/9] envelope line and point tests --- test/components/envelope_test.dart | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/components/envelope_test.dart b/test/components/envelope_test.dart index 5f27a449..6dd6523a 100644 --- a/test/components/envelope_test.dart +++ b/test/components/envelope_test.dart @@ -54,4 +54,6 @@ void main() { reason: "LineString", ); }); + + } \ No newline at end of file From 59a90db773f46517bb37d1da2331be48e7304a91 Mon Sep 17 00:00:00 2001 From: NithyaNN3 Date: Thu, 3 Apr 2025 01:02:57 +1100 Subject: [PATCH 5/9] added envelope tests for multiline, polygon, multipolygon --- test/components/envelope_test.dart | 116 ++++++++++++++++++++++++++++- 1 file changed, 115 insertions(+), 1 deletion(-) diff --git a/test/components/envelope_test.dart b/test/components/envelope_test.dart index 6dd6523a..65779014 100644 --- a/test/components/envelope_test.dart +++ b/test/components/envelope_test.dart @@ -13,6 +13,58 @@ void main() { ]) ); + final poly = Feature( + geometry: Polygon(coordinates: [ + [ + Position.named(lat: 101.0, lng: 0.0), + Position.named(lat: 101.0, lng: 1.0), + Position.named(lat: 100.0, lng: 1.0), + Position.named(lat: 100.0, lng: 0.0), + Position.named(lat: 101.0, lng: 0.0), + ], + ])); + + final multiLine = Feature( + geometry: MultiLineString(coordinates: [ + [ + Position.named(lat: 100.0, lng: 0.0), + Position.named(lat: 101.0, lng: 1.0), + ], + [ + Position.named(lat: 102.0, lng: 2.0), + Position.named(lat: 103.0, lng: 3.0), + ], + ])); + + final multiPoly = Feature( + geometry: MultiPolygon(coordinates: [ + [ + [ + Position.named(lat: 102.0, lng: 2.0), + Position.named(lat: 103.0, lng: 2.0), + Position.named(lat: 103.0, lng: 3.0), + Position.named(lat: 102.0, lng: 3.0), + Position.named(lat: 102.0, lng: 2.0), + ], + ], + [ + [ + Position.named(lat: 100.0, lng: 0.0), + Position.named(lat: 101.0, lng: 0.0), + Position.named(lat: 101.0, lng: 1.0), + Position.named(lat: 100.0, lng: 1.0), + Position.named(lat: 100.0, lng: 0.0), + ], + [ + Position.named(lat: 100.2, lng: 0.2), + Position.named(lat: 100.8, lng: 0.2), + Position.named(lat: 100.8, lng: 0.8), + Position.named(lat: 100.2, lng: 0.8), + Position.named(lat: 100.2, lng: 0.2), + ], + ], + ])); + test("envelope for point", () { // Point final pointEnvelope = envelope(point); @@ -55,5 +107,67 @@ void main() { ); }); - + test("envelope for polygon", () { + // Point + final polyEnvelope = envelope(poly); + expect( + polyEnvelope, + equals(Feature( + geometry: Polygon(coordinates: [ + [ + Position.named(lat: 100.0, lng: 0.0), + Position.named(lat: 101.0, lng: 0.0), + Position.named(lat: 101.0, lng: 1.0), + Position.named(lat: 100.0, lng: 1.0), + Position.named(lat: 100.0, lng: 0.0), + ] + ]) + )), + reason: "polygon", + ); + }); + + test("envelope for multilinestring", () { + // MultiLineString + final multiLineEnvelope = envelope(multiLine); + + // Directly use the expected envelope in the expect call + expect( + multiLineEnvelope, + equals(Feature( + geometry: Polygon(coordinates: [ + [ + Position.named(lat: 100.0, lng: 0.0), + Position.named(lat: 103.0, lng: 0.0), + Position.named(lat: 103.0, lng: 3.0), + Position.named(lat: 100.0, lng: 3.0), + Position.named(lat: 100.0, lng: 0.0), + ] + ]), + )), + reason: "MultiLineString", + ); + }); + + test("envelope for multipolygon", () { + // MultiPolygon + final multiPolyEnvelope = envelope(multiPoly); + + // Directly use the expected envelope in the expect call + expect( + multiPolyEnvelope, + equals(Feature( + geometry: Polygon(coordinates: [ + [ + Position.named(lat: 100.0, lng: 0.0), + Position.named(lat: 103.0, lng: 0.0), + Position.named(lat: 103.0, lng: 3.0), + Position.named(lat: 100.0, lng: 3.0), + Position.named(lat: 100.0, lng: 0.0), + ] + ]), + )), + reason: "MultiPolygon", + ); + }); } \ No newline at end of file From 5d94b7a894e875209a918b994d0253a7d3a5c359 Mon Sep 17 00:00:00 2001 From: NithyaNN3 Date: Thu, 3 Apr 2025 01:23:22 +1100 Subject: [PATCH 6/9] added envelope test for feature collection --- test/components/envelope_test.dart | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test/components/envelope_test.dart b/test/components/envelope_test.dart index 65779014..03318e9e 100644 --- a/test/components/envelope_test.dart +++ b/test/components/envelope_test.dart @@ -65,6 +65,9 @@ void main() { ], ])); + final fc = + FeatureCollection(features: [point, line, poly, multiLine, multiPoly]); + test("envelope for point", () { // Point final pointEnvelope = envelope(point); @@ -170,4 +173,26 @@ void main() { reason: "MultiPolygon", ); }); + + test("envelope for featureCollection", () { + final fcEnvelope = envelope(fc); + + // The envelope should be a polygon that represents the minimum bounding rectangle + // containing all features in the collection + expect( + fcEnvelope, + equals(Feature( + geometry: Polygon(coordinates: [ + [ + Position.named(lat: 100.0, lng: 0.0), + Position.named(lat: 104.0, lng: 0.0), + Position.named(lat: 104.0, lng: 3.0), + Position.named(lat: 100.0, lng: 3.0), + Position.named(lat: 100.0, lng: 0.0), + ] + ]), + )), + reason: "FeatureCollection", + ); + }); } \ No newline at end of file From 6857977cfcd2bd27f1255df3d3ad340e91fd2ca0 Mon Sep 17 00:00:00 2001 From: NithyaNN3 Date: Thu, 3 Apr 2025 02:13:43 +1100 Subject: [PATCH 7/9] added example files for envelope geometries --- .../examples/envelope/geometryCollection.json | 57 +++++++++++++++++++ test/examples/envelope/lineString.geojson | 36 ++++++++++++ .../examples/envelope/multiLineString.geojson | 42 ++++++++++++++ test/examples/envelope/multiPoint.geojson | 38 +++++++++++++ test/examples/envelope/multiPolygon.geojson | 52 +++++++++++++++++ test/examples/envelope/point.geojson | 33 +++++++++++ test/examples/envelope/polygon.geojson | 48 ++++++++++++++++ 7 files changed, 306 insertions(+) create mode 100644 test/examples/envelope/geometryCollection.json create mode 100644 test/examples/envelope/lineString.geojson create mode 100644 test/examples/envelope/multiLineString.geojson create mode 100644 test/examples/envelope/multiPoint.geojson create mode 100644 test/examples/envelope/multiPolygon.geojson create mode 100644 test/examples/envelope/point.geojson create mode 100644 test/examples/envelope/polygon.geojson diff --git a/test/examples/envelope/geometryCollection.json b/test/examples/envelope/geometryCollection.json new file mode 100644 index 00000000..96d9abb7 --- /dev/null +++ b/test/examples/envelope/geometryCollection.json @@ -0,0 +1,57 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "geometry": { + "type": "GeometryCollection", + "geometries": [ + { + "type": "Point", + "coordinates": [100.0, 0.0] + }, + { + "type": "LineString", + "coordinates": [ + [100.0, 0.0], + [101.0, 1.0] + ] + }, + { + "type": "Polygon", + "coordinates": [ + [ + [101.0, 0.0], + [102.0, 0.0], + [102.0, 1.0], + [101.0, 1.0], + [101.0, 0.0] + ] + ] + } + ] + }, + "properties": { + "name": "GeometryCollection" + } + }, + { + "type": "Feature", + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [100.0, 0.0], + [102.0, 0.0], + [102.0, 1.0], + [100.0, 1.0], + [100.0, 0.0] + ] + ] + }, + "properties": { + "name": "GeometryCollection Envelope" + } + } + ] +} \ No newline at end of file diff --git a/test/examples/envelope/lineString.geojson b/test/examples/envelope/lineString.geojson new file mode 100644 index 00000000..6119ff0d --- /dev/null +++ b/test/examples/envelope/lineString.geojson @@ -0,0 +1,36 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "geometry": { + "type": "LineString", + "coordinates": [ + [100.0, 0.0], + [101.0, 1.0] + ] + }, + "properties": { + "name": "LineString" + } + }, + { + "type": "Feature", + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [100.0, 0.0], + [101.0, 0.0], + [101.0, 1.0], + [100.0, 1.0], + [100.0, 0.0] + ] + ] + }, + "properties": { + "name": "LineString Envelope" + } + } + ] +} \ No newline at end of file diff --git a/test/examples/envelope/multiLineString.geojson b/test/examples/envelope/multiLineString.geojson new file mode 100644 index 00000000..1ce24d68 --- /dev/null +++ b/test/examples/envelope/multiLineString.geojson @@ -0,0 +1,42 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "geometry": { + "type": "MultiLineString", + "coordinates": [ + [ + [100.0, 0.0], + [101.0, 1.0] + ], + [ + [102.0, 2.0], + [103.0, 3.0] + ] + ] + }, + "properties": { + "name": "MultiLineString" + } + }, + { + "type": "Feature", + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [100.0, 0.0], + [103.0, 0.0], + [103.0, 3.0], + [100.0, 3.0], + [100.0, 0.0] + ] + ] + }, + "properties": { + "name": "MultiLineString Envelope" + } + } + ] +} \ No newline at end of file diff --git a/test/examples/envelope/multiPoint.geojson b/test/examples/envelope/multiPoint.geojson new file mode 100644 index 00000000..ff40d4c7 --- /dev/null +++ b/test/examples/envelope/multiPoint.geojson @@ -0,0 +1,38 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "geometry": { + "type": "MultiPoint", + "coordinates": [ + [100.0, 0.0], + [101.0, 0.0], + [101.0, 1.0], + [100.0, 1.0] + ] + }, + "properties": { + "name": "MultiPoint" + } + }, + { + "type": "Feature", + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [100.0, 0.0], + [101.0, 0.0], + [101.0, 1.0], + [100.0, 1.0], + [100.0, 0.0] + ] + ] + }, + "properties": { + "name": "MultiPoint Envelope" + } + } + ] +} \ No newline at end of file diff --git a/test/examples/envelope/multiPolygon.geojson b/test/examples/envelope/multiPolygon.geojson new file mode 100644 index 00000000..313251f1 --- /dev/null +++ b/test/examples/envelope/multiPolygon.geojson @@ -0,0 +1,52 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "geometry": { + "type": "MultiPolygon", + "coordinates": [ + [ + [ + [100.0, 0.0], + [101.0, 0.0], + [101.0, 1.0], + [100.0, 1.0], + [100.0, 0.0] + ] + ], + [ + [ + [102.0, 2.0], + [103.0, 2.0], + [103.0, 3.0], + [102.0, 3.0], + [102.0, 2.0] + ] + ] + ] + }, + "properties": { + "name": "MultiPolygon" + } + }, + { + "type": "Feature", + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [100.0, 0.0], + [103.0, 0.0], + [103.0, 3.0], + [100.0, 3.0], + [100.0, 0.0] + ] + ] + }, + "properties": { + "name": "MultiPolygon Envelope" + } + } + ] +} \ No newline at end of file diff --git a/test/examples/envelope/point.geojson b/test/examples/envelope/point.geojson new file mode 100644 index 00000000..2c927866 --- /dev/null +++ b/test/examples/envelope/point.geojson @@ -0,0 +1,33 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "geometry": { + "type": "Point", + "coordinates": [102.0, 0.5] + }, + "properties": { + "name": "Point" + } + }, + { + "type": "Feature", + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [102.0, 0.5], + [102.1, 0.5], + [102.1, 0.6], + [102.0, 0.6], + [102.0, 0.5] + ] + ] + }, + "properties": { + "name": "Point Envelope" + } + } + ] +} \ No newline at end of file diff --git a/test/examples/envelope/polygon.geojson b/test/examples/envelope/polygon.geojson new file mode 100644 index 00000000..908edee1 --- /dev/null +++ b/test/examples/envelope/polygon.geojson @@ -0,0 +1,48 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [100.0, 0.0], + [101.0, 0.0], + [101.0, 1.0], + [100.0, 1.0], + [100.0, 0.0] + ], + [ + [100.2, 0.2], + [100.8, 0.2], + [100.8, 0.8], + [100.2, 0.8], + [100.2, 0.2] + ] + ] + }, + "properties": { + "name": "Polygon" + } + }, + { + "type": "Feature", + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [100.0, 0.0], + [101.0, 0.0], + [101.0, 1.0], + [100.0, 1.0], + [100.0, 0.0] + ] + ] + }, + "properties": { + "name": "Polygon Envelope" + } + } + ] +} \ No newline at end of file From 4e24d2b6c8109c8826906d91f873447e8816bfb6 Mon Sep 17 00:00:00 2001 From: NithyaNN3 Date: Tue, 29 Apr 2025 23:10:44 +1000 Subject: [PATCH 8/9] PR review changes --- lib/src/envelope.dart | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/src/envelope.dart b/lib/src/envelope.dart index 16b9a699..66e46b77 100644 --- a/lib/src/envelope.dart +++ b/lib/src/envelope.dart @@ -1,10 +1,10 @@ -import '../helpers.dart'; - -import '../bbox.dart'; -import '../bbox_polygon.dart'; +import 'package:turf/helpers.dart'; +import 'package:turf/bbox.dart'; +import 'package:turf/bbox_polygon.dart'; +// Returns a rectangular Polygon (envelope) that fully contains the given GeoJSON object. Feature envelope(GeoJSONObject geojson) { return bboxPolygon(bbox(geojson)); } \ No newline at end of file From 14554c49ed866318a451ce5fd970b33735b02f1e Mon Sep 17 00:00:00 2001 From: NithyaNN3 Date: Tue, 29 Apr 2025 23:20:06 +1000 Subject: [PATCH 9/9] test change --- test/components/envelope_test.dart | 93 ++++++++++++++++-------------- 1 file changed, 50 insertions(+), 43 deletions(-) diff --git a/test/components/envelope_test.dart b/test/components/envelope_test.dart index 03318e9e..8694acc8 100644 --- a/test/components/envelope_test.dart +++ b/test/components/envelope_test.dart @@ -10,60 +10,67 @@ void main() { Position.named(lat: 102.0, lng: 0.5), Position.named(lat: 103.0, lng: 1.5), Position.named(lat: 104.0, lng: 2.5), - ]) + ], + ), ); final poly = Feature( geometry: Polygon(coordinates: [ - [ - Position.named(lat: 101.0, lng: 0.0), - Position.named(lat: 101.0, lng: 1.0), - Position.named(lat: 100.0, lng: 1.0), - Position.named(lat: 100.0, lng: 0.0), - Position.named(lat: 101.0, lng: 0.0), - ], - ])); + [ + Position.named(lat: 101.0, lng: 0.0), + Position.named(lat: 101.0, lng: 1.0), + Position.named(lat: 100.0, lng: 1.0), + Position.named(lat: 100.0, lng: 0.0), + Position.named(lat: 101.0, lng: 0.0), + ], + ], + ), + ); final multiLine = Feature( geometry: MultiLineString(coordinates: [ - [ - Position.named(lat: 100.0, lng: 0.0), - Position.named(lat: 101.0, lng: 1.0), - ], - [ - Position.named(lat: 102.0, lng: 2.0), - Position.named(lat: 103.0, lng: 3.0), - ], - ])); + [ + Position.named(lat: 100.0, lng: 0.0), + Position.named(lat: 101.0, lng: 1.0), + ], + [ + Position.named(lat: 102.0, lng: 2.0), + Position.named(lat: 103.0, lng: 3.0), + ], + ], + ), + ); final multiPoly = Feature( geometry: MultiPolygon(coordinates: [ - [ - [ - Position.named(lat: 102.0, lng: 2.0), - Position.named(lat: 103.0, lng: 2.0), - Position.named(lat: 103.0, lng: 3.0), - Position.named(lat: 102.0, lng: 3.0), - Position.named(lat: 102.0, lng: 2.0), - ], - ], - [ - [ - Position.named(lat: 100.0, lng: 0.0), - Position.named(lat: 101.0, lng: 0.0), - Position.named(lat: 101.0, lng: 1.0), - Position.named(lat: 100.0, lng: 1.0), - Position.named(lat: 100.0, lng: 0.0), - ], - [ - Position.named(lat: 100.2, lng: 0.2), - Position.named(lat: 100.8, lng: 0.2), - Position.named(lat: 100.8, lng: 0.8), - Position.named(lat: 100.2, lng: 0.8), - Position.named(lat: 100.2, lng: 0.2), + [ + [ + Position.named(lat: 102.0, lng: 2.0), + Position.named(lat: 103.0, lng: 2.0), + Position.named(lat: 103.0, lng: 3.0), + Position.named(lat: 102.0, lng: 3.0), + Position.named(lat: 102.0, lng: 2.0), + ], + ], + [ + [ + Position.named(lat: 100.0, lng: 0.0), + Position.named(lat: 101.0, lng: 0.0), + Position.named(lat: 101.0, lng: 1.0), + Position.named(lat: 100.0, lng: 1.0), + Position.named(lat: 100.0, lng: 0.0), + ], + [ + Position.named(lat: 100.2, lng: 0.2), + Position.named(lat: 100.8, lng: 0.2), + Position.named(lat: 100.8, lng: 0.8), + Position.named(lat: 100.2, lng: 0.8), + Position.named(lat: 100.2, lng: 0.2), + ], + ], ], - ], - ])); + ), + ); final fc = FeatureCollection(features: [point, line, poly, multiLine, multiPoly]);