Skip to content

Commit

Permalink
Point2 to point
Browse files Browse the repository at this point in the history
  • Loading branch information
natgeo-wong committed Sep 27, 2024
1 parent e230bfc commit 5198382
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 39 deletions.
32 changes: 19 additions & 13 deletions docs/src/api/isin.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
# API for Is it in a GeoRegion?
# API for Is it in/on a GeoRegion?

```@docs
in(
Point :: Point2{<:Real},
geo :: GeoRegion;
tlon :: Real = 0,
tlat :: Real = 0,
throw :: Bool = false
)
in(
cgeo :: GeoRegion,
geo :: RectRegion;
Point :: Point{<:Real},
geo :: GeoRegion;
throw :: Bool = false
)
in(
cgeo :: GeoRegion,
geo :: Union{TiltRegion,PolyRegion};
n :: Int = 100,
cgeo :: GeoRegion,
geo :: GeoRegion;
n :: Int = 100,
throw :: Bool = false,
verbose :: Bool = false
)
on(
Point :: Point{<:Real},
geo :: GeoRegion;
throw :: Bool = false
)
on(
cgeo :: GeoRegion,
geo :: GeoRegion;
n :: Int = 100,
throw :: Bool = false,
verbose :: Bool = false
)
```
8 changes: 7 additions & 1 deletion docs/src/basics/properties/isequal.md
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
# Are the GeoRegions Equivalent?
# Comparing GeoRegions

Now, suppose we have two different GeoRegions, we have constructed several different ways of defining equivalence:

## 1. Are two GeoRegions Equivalent

If you want to check that two GeoRegions are exactly the same, we can use the `==` or `isequal()` functions
6 changes: 3 additions & 3 deletions src/georegions/define.jl
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ function RectRegion(
lon,lat = rect2shape(N,S,E,W)
geo = RectRegion{ST,FT}(
ID, pID, name, joinpath(path,"rectlist.txt"),
[N, S, E, W], Point2.(lon,lat), Polygon(Point2.(lon,lat)),
[N, S, E, W], Point.(lon,lat), Polygon(Point.(lon,lat)),
is180, is360
)

Expand Down Expand Up @@ -227,7 +227,7 @@ function TiltRegion(
lon,lat = tilt2shape(X,Y,ΔX,ΔY,θ)
geo = TiltRegion{ST,FT}(
ID, pID, name, joinpath(path,"tiltlist.txt"),
[N, S, E, W], Point2.(lon,lat), Polygon(Point2.(lon,lat)), [X, Y, ΔX, ΔY, θ],
[N, S, E, W], Point.(lon,lat), Polygon(Point.(lon,lat)), [X, Y, ΔX, ΔY, θ],
is180, is360
)

Expand Down Expand Up @@ -342,7 +342,7 @@ function PolyRegion(
is180,is360 = checkbounds(N,S,E,W)
geo = PolyRegion{ST,FT}(
ID, pID, name, joinpath(path,"polylist.txt"),
[N, S, E, W], Point2.(lon,lat), Polygon(Point2.(lon,lat)),
[N, S, E, W], Point.(lon,lat), Polygon(Point.(lon,lat)),
is180, is360
)

Expand Down
6 changes: 3 additions & 3 deletions src/georegions/get.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function getrectregion(

return RectRegion{ST,FT}(
ID, pID, name, fID,
[N, S, E, W], Point2.(lon,lat), Polygon(Point2.(lon,lat)),
[N, S, E, W], Point.(lon,lat), Polygon(Point.(lon,lat)),
is180, is360
)

Expand Down Expand Up @@ -65,7 +65,7 @@ function gettiltregion(

return TiltRegion{ST,FT}(
ID, pID, name, fID,
[N, S, E, W], Point2.(lon,lat), Polygon(Point2.(lon,lat)), [X, Y, ΔX, ΔY, θ],
[N, S, E, W], Point.(lon,lat), Polygon(Point.(lon,lat)), [X, Y, ΔX, ΔY, θ],
is180, is360
)

Expand Down Expand Up @@ -93,7 +93,7 @@ function getpolyregion(

return PolyRegion{ST,FT}(
ID, pID, name, fID,
[N, S, E, W], Point2.(lon,lat), Polygon(Point2.(lon,lat)),
[N, S, E, W], Point.(lon,lat), Polygon(Point.(lon,lat)),
is180, is360
)

Expand Down
18 changes: 9 additions & 9 deletions src/isin/isin.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
in(
point :: Point2{<:Real},
point :: Point{<:Real},
geo :: GeoRegion;
throw :: Bool = false
) -> Bool
Expand All @@ -9,15 +9,15 @@ Check if a geographical point `point` is within a GeoRegion defined by `geo`.
Arguments
=========
- `point` : A geographical point of Type `Point2`. Pass `Point2(plon,plat)`, where `plon` and `plat` are the longitude and latitudes of the point.
- `point` : A geographical point of Type `Point`. Pass `Point(plon,plat)`, where `plon` and `plat` are the longitude and latitudes of the point.
- `geo` : The GeoRegion struct container
Keyword Arguments
=================
- `throw` : If `true`, then if `point` is not within `geo`, an error is thrown and the program stops running.
"""
function Base.in(
point :: Point2{<:Real},
point :: Point{<:Real},
geo :: GeoRegion;
throw :: Bool = false
)
Expand All @@ -33,20 +33,20 @@ function Base.in(
while plon < -180; plon += 360 end

isin = !iszero(sum([
within(Point2(plon ,plat),geo.geometry),
within(Point2(plon+360,plat),geo.geometry),
within(Point2(plon-360,plat),geo.geometry)
within(Point(plon ,plat),geo.geometry),
within(Point(plon+360,plat),geo.geometry),
within(Point(plon-360,plat),geo.geometry)
]))

if !isin
if throw
error("$(modulelog()) - The requested coordinates $(Point2(plon,plat)) are not within the specified region boundaries.")
error("$(modulelog()) - The requested coordinates $(Point(plon,plat)) are not within the specified region boundaries.")
else
return false
end
else
if throw
@info "$(modulelog()) - The requested coordinates $(Point2(plon,plat)) are within the specified region boundaries."
@info "$(modulelog()) - The requested coordinates $(Point(plon,plat)) are within the specified region boundaries."
end
return true
end
Expand Down Expand Up @@ -84,7 +84,7 @@ function Base.in(
if verbose; @info "$(modulelog()) - Performing a check to determine if the $(cgeo.name) GeoRegion ($(cgeo.ID)) is inside the $(geo.name) GeoRegion ($(geo.ID))" end

lon,lat = coordinates(cgeo,n=n)
isin = sum(.!in.(Point2.(lon,lat),[geo],n=n));
isin = sum(.!in.(Point.(lon,lat),[geo],n=n));

if iszero(isin)

Expand Down
20 changes: 10 additions & 10 deletions src/isin/ison.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
on(
point :: Point2{<:Real},
point :: Point{<:Real},
geo :: GeoRegion;
throw :: Bool = false
) -> Bool
Expand All @@ -9,15 +9,15 @@ Check if a geographical point `point` is on the boundary of a shape of a GeoRegi
Arguments
=========
- `point` : A geographical point of Type `Point2`. Pass `Point2(plon,plat)`, where `plon` and `plat` are the longitude and latitudes of the point.
- `point` : A geographical point of Type `Point`. Pass `Point(plon,plat)`, where `plon` and `plat` are the longitude and latitudes of the point.
- `geo` : The GeoRegion struct container
Keyword Arguments
=================
- `throw` : If `true`, then if `point` is not within `geo`, an error is thrown and the program stops running.
"""
function on(
point :: Point2{<:Real},
point :: Point{<:Real},
geo :: GeoRegion;
throw :: Bool = false
)
Expand All @@ -33,20 +33,20 @@ function on(
while plon < -180; plon += 360 end

isin = !iszero(sum([
touches(Point2(plon ,plat),geo.geometry),
touches(Point2(plon+360,plat),geo.geometry),
touches(Point2(plon-360,plat),geo.geometry)
touches(Point(plon ,plat),geo.geometry),
touches(Point(plon+360,plat),geo.geometry),
touches(Point(plon-360,plat),geo.geometry)
]))

if !isin
if throw
error("$(modulelog()) - The requested coordinates $(Point2(plon,plat)) are not on the region perimeter.")
error("$(modulelog()) - The requested coordinates $(Point(plon,plat)) are not on the region perimeter.")
else
return false
end
else
if throw
@info "$(modulelog()) - The requested coordinates $(Point2(plon,plat)) are on the region perimeter."
@info "$(modulelog()) - The requested coordinates $(Point(plon,plat)) are on the region perimeter."
end
return true
end
Expand Down Expand Up @@ -85,9 +85,9 @@ function on(

lon1,lat1 = coordinates(geo1,n=n)
lon2,lat2 = coordinates(geo2,n=n)
isin = sum(.!on.(Point2.(lon1,lat1),[geo2])) + sum(.!on.(Point2.(lon2,lat2),[geo1]))
isin = sum(.!on.(Point.(lon1,lat1),[geo2])) + sum(.!on.(Point.(lon2,lat2),[geo1]))

# @info lon1,lat1,Point2.(lon1,lat1)
# @info lon1,lat1,Point.(lon1,lat1)

if iszero(isin)

Expand Down

0 comments on commit 5198382

Please sign in to comment.