-
Notifications
You must be signed in to change notification settings - Fork 36
[Feature] Envelope #215
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
Open
NithyaNN3
wants to merge
9
commits into
dartclub:main
Choose a base branch
from
deanpapas:feature-envelope-final
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
[Feature] Envelope #215
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
2130d94
added envelope files with one test case
NithyaNN3 fc6e189
made some fixes
NithyaNN3 e3ef341
added linestring test case for envelope
NithyaNN3 f51824b
envelope line and point tests
NithyaNN3 59a90db
added envelope tests for multiline, polygon, multipolygon
NithyaNN3 5d94b7a
added envelope test for feature collection
NithyaNN3 6857977
added example files for envelope geometries
NithyaNN3 4e24d2b
PR review changes
NithyaNN3 14554c4
test change
NithyaNN3 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,4 @@ | ||
library turf_envelope; | ||
|
||
export 'package:geotypes/geotypes.dart'; | ||
export "src/envelope.dart"; |
This file contains hidden or 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,10 @@ | ||
import '../helpers.dart'; | ||
|
||
import '../bbox.dart'; | ||
import '../bbox_polygon.dart'; | ||
|
||
|
||
|
||
NithyaNN3 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Feature<Polygon> envelope(GeoJSONObject geojson) { | ||
return bboxPolygon(bbox(geojson)); | ||
} |
This file contains hidden or 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 hidden or 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,198 @@ | ||
import 'package:turf/turf.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
void main() { | ||
final point = Feature<Point>( | ||
geometry: Point(coordinates: Position.named(lat: 102.0, lng: 0.5))); | ||
|
||
final line = Feature<LineString>( | ||
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), | ||
]) | ||
); | ||
|
||
final poly = Feature<Polygon>( | ||
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), | ||
], | ||
])); | ||
NithyaNN3 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
final multiLine = Feature<MultiLineString>( | ||
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<MultiPolygon>( | ||
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: [point, line, poly, multiLine, multiPoly]); | ||
|
||
test("envelope for point", () { | ||
// Point | ||
final pointEnvelope = envelope(point); | ||
expect( | ||
pointEnvelope, | ||
equals(Feature<Polygon>( | ||
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", | ||
); | ||
}); | ||
|
||
test("envelope for linestring", () { | ||
// LineString | ||
final lineEnvelope = envelope(line); | ||
|
||
// Directly use the expected envelope in the expect call | ||
expect( | ||
lineEnvelope, | ||
equals(Feature<Polygon>( | ||
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", | ||
); | ||
}); | ||
|
||
test("envelope for polygon", () { | ||
// Point | ||
final polyEnvelope = envelope(poly); | ||
expect( | ||
polyEnvelope, | ||
equals(Feature<Polygon>( | ||
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<Polygon>( | ||
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<Polygon>( | ||
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", | ||
); | ||
}); | ||
|
||
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<Polygon>( | ||
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", | ||
); | ||
}); | ||
} |
This file contains hidden or 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,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" | ||
} | ||
} | ||
] | ||
} |
This file contains hidden or 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,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" | ||
} | ||
} | ||
] | ||
} |
This file contains hidden or 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,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" | ||
} | ||
} | ||
] | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.