-
Notifications
You must be signed in to change notification settings - Fork 5
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
Check the dimensions of child geoms when rebuilding #239
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
48e1eed
Core: check the dimensions of child geoms when rebuilding
asinghvi17 ed9ff1d
add `forcexy`
asinghvi17 6c664d6
Merge branch 'as/usecore' into as/checkdims
asinghvi17 d260517
Check only the first geom
asinghvi17 9a9fde4
Add a test for 2D to 3D
asinghvi17 c5d2ec0
Add forcexy, forcexyz
asinghvi17 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#= | ||
# Force dimensions (xy, xyz) | ||
|
||
These functions force the geometry to be 2D or 3D. They work on any geometry, vector of geometries, feature collection, or table! | ||
|
||
They're implemented by `apply` pretty simply. | ||
=# | ||
|
||
export forcexy, forcexyz | ||
|
||
""" | ||
forcexy(geom) | ||
|
||
Force the geometry to be 2D. Works on any geometry, vector of geometries, feature collection, or table! | ||
""" | ||
function forcexy(geom) | ||
return apply(GI.PointTrait(), geom) do point | ||
(GI.x(point), GI.y(point)) | ||
end | ||
end | ||
|
||
""" | ||
forcexyz(geom, z = 0) | ||
|
||
Force the geometry to be 3D. Works on any geometry, vector of geometries, feature collection, or table! | ||
|
||
The `z` parameter is the default z value - if a point has no z value, it will be set to this value. | ||
If it does, then the z value will be kept. | ||
""" | ||
function forcexyz(geom, z = 0) | ||
return apply(GI.PointTrait(), geom) do point | ||
x, y = GI.x(point), GI.y(point) | ||
z = GI.is3d(geom) ? GI.z(point) : z | ||
(x, y, z) | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import GeometryOps as GO | ||
import GeoInterface as GI | ||
using ..TestHelpers | ||
|
||
using Test | ||
|
||
geom = GI.Polygon([GI.LinearRing([(1, 2), (3, 4), (5, 6), (1, 2)]), | ||
GI.LinearRing([(3, 4), (5, 6), (6, 7), (3, 4)])]) | ||
|
||
@testset_implementations "force dimensions" begin | ||
|
||
# Test forcexy on 3D geometry | ||
geom3d = GO.transform($geom) do p | ||
(GI.x(p), GI.y(p), 1.0) | ||
end | ||
@test GI.is3d(geom3d) | ||
geom2d = GO.forcexy(geom3d) | ||
@test !GI.is3d(geom2d) | ||
@test GO.equals(geom2d, geom) | ||
|
||
# Test forcexyz with default z | ||
geom3d_default = GO.forcexyz($geom) | ||
@test GI.is3d(geom3d_default) | ||
points3d = collect(GO.flatten(GI.PointTrait, geom3d_default)) | ||
@test all(p -> GI.z(p) == 0, points3d) | ||
|
||
# Test forcexyz with custom z | ||
geom3d_custom = GO.forcexyz($geom, 5.0) | ||
@test GI.is3d(geom3d_custom) | ||
points3d_custom = collect(GO.flatten(GI.PointTrait, geom3d_custom)) | ||
@test all(p -> GI.z(p) == 5.0, points3d_custom) | ||
|
||
# Test forcexyz preserves existing z values | ||
@test GO.equals(GO.forcexyz(geom3d), geom3d) | ||
end |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.