Skip to content
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

Implement crstrait. #140

Merged
merged 5 commits into from
Jul 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,9 @@
"""
length(geom) = length(geomtrait(geom), geom)


# Surface

"""
area(geom) -> Number

Expand All @@ -226,6 +228,7 @@
"""
area(geom) = area(geomtrait(geom), geom)


"""
centroid(geom) -> Point

Expand All @@ -235,6 +238,7 @@
"""
centroid(geom) = centroid(geomtrait(geom), geom)


"""
pointonsurface(geom) -> Point

Expand All @@ -243,6 +247,7 @@
"""
pointonsurface(geom) = pointonsurface(geomtrait(geom), geom)


"""
boundary(geom) -> Curve

Expand All @@ -251,7 +256,9 @@
"""
boundary(geom) = boundary(geomtrait(geom), geom)


# Polygon/Triangle

"""
nring(geom) -> Integer

Expand Down Expand Up @@ -670,3 +677,12 @@
Convert `geom` into Well Known Binary (WKB) representation, such as `000000000140000000000000004010000000000000`.
"""
asbinary(geom) = asbinary(geomtrait(geom), geom)

"""
crstrait(geom) -> AbstractCRSTrait

Retrieves the type of the Coordinate Reference System for the given `geom`.
Defaults to retrieving from `crs(geom)` and to `UnknownTrait` if not implemented.

"""
crstrait(geom) = UnknownTrait()

Check warning on line 688 in src/interface.jl

View check run for this annotation

Codecov / codecov/patch

src/interface.jl#L688

Added line #L688 was not covered by tests
20 changes: 20 additions & 0 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,26 @@
"A FeatureCollectionTrait holds objects of `FeatureTrait`"
struct FeatureCollectionTrait <: AbstractFeatureCollectionTrait end

"Supertype for all coordinate reference system traits"
abstract type AbstractCRSTrait end

"An AbstractProjectedTrait for all projected coordinate reference systems"
evetion marked this conversation as resolved.
Show resolved Hide resolved
abstract type AbstractProjectedTrait <: AbstractCRSTrait end
"An AbstractGeographicTrait for all geographic coordinate reference systems"
abstract type AbstractGeographicTrait <: AbstractCRSTrait end

"An ProjectedTrait for all projected coordinate reference systems"
rafaqz marked this conversation as resolved.
Show resolved Hide resolved
struct ProjectedTrait <: AbstractProjectedTrait end
"An GeographicTrait for all geographic coordinate reference systems"
struct GeographicTrait <: AbstractGeographicTrait end
"An UnknownTrait for all unknown (assumed projected) coordinate reference systems"
struct UnknownTrait <: AbstractProjectedTrait
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this inherit from AbstractCRStrait?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we assume projected anyway then dispatch can just be on AbstractProjectedTrait right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I assume you implement GeometryOps with Abstractprojected and catch both.

function UnknownTrait()
Base.depwarn("It is unknown whether your geometry is projected or geographic. Please implement `crstrait` for your geometry.", :UnknownTrait)
new()

Check warning on line 112 in src/types.jl

View check run for this annotation

Codecov / codecov/patch

src/types.jl#L110-L112

Added lines #L110 - L112 were not covered by tests
end
end

"An AbstractRasterTrait for all rasters"
abstract type AbstractRasterTrait <: AbstractTrait end
struct RasterTrait <: AbstractRasterTrait end
Loading