-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: Geo format type wrappers and generic methods (#97)
* add convert methods and reproject for GeoFormatTypes * bump geoformattypes version * bugfix tests * move conversions to convert.jl * update convert * tweaks to finish PR * test importCRS * bump GeoFormatTypes version to 0.3 * clean up docs
- Loading branch information
Showing
11 changed files
with
395 additions
and
164 deletions.
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
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,64 @@ | ||
# This file contains friendly type-pyracy on `convert` for GeoFormatTypes.jl types | ||
|
||
""" | ||
convert(::Type{<:AbstractGeometry}, mode::Geom source::GeoFormat) | ||
Convert a GeoFromat object to Geometry, then to the target format. | ||
The Geom trait is needed to separate out convert for CRS for WellKnownText | ||
and GML, which may contain both. | ||
""" | ||
Base.convert(target::Type{<:GFT.GeoFormat}, mode::Union{GFT.FormatMode,Type{GFT.FormatMode}}, | ||
source::GFT.GeoFormat) = | ||
convert(target, convert(AbstractGeometry, source)) | ||
|
||
""" | ||
convert(::Type{<:AbstractGeometry}, source::GeoFormat) | ||
Convert `GeoFormat` geometry data to an ArchGDAL `Geometry` type | ||
""" | ||
Base.convert(::Type{<:AbstractGeometry}, source::GFT.AbstractWellKnownText) = | ||
fromWKT(GFT.val(source)) | ||
Base.convert(::Type{<:AbstractGeometry}, source::GFT.WellKnownBinary) = | ||
fromWKB(GFT.val(source)) | ||
Base.convert(::Type{<:AbstractGeometry}, source::GFT.GeoJSON) = | ||
fromJSON(GFT.val(source)) | ||
Base.convert(::Type{<:AbstractGeometry}, source::GFT.GML) = | ||
fromGML(GFT.val(source)) | ||
|
||
""" | ||
convert(::Type{<:AbstractGeometry}, source::GeoFormat) | ||
Convert `AbstractGeometry` data to any gemoetry `GeoFormat` | ||
""" | ||
Base.convert(::Type{<:GFT.AbstractWellKnownText}, source::AbstractGeometry) = | ||
GFT.WellKnownText(GFT.Geom(), toWKT(source)) | ||
Base.convert(::Type{<:GFT.WellKnownBinary}, source::AbstractGeometry) = | ||
GFT.WellKnownBinary(GFT.Geom(), toWKB(source)) | ||
Base.convert(::Type{<:GFT.GeoJSON}, source::AbstractGeometry) = | ||
GFT.GeoJSON(toJSON(source)) | ||
Base.convert(::Type{<:GFT.GML}, source::AbstractGeometry) = | ||
GFT.GML(GFT.Geom(), toGML(source)) | ||
Base.convert(::Type{<:GFT.KML}, source::AbstractGeometry) = | ||
GFT.KML(toKML(source)) | ||
|
||
|
||
""" | ||
convert(target::Type{GeoFormat}, mode::CRS, source::GeoFormat) | ||
Convert `GeoFormat` crs data to another another `GeoFormat` crs type. | ||
""" | ||
Base.convert(target::Type{<:GFT.GeoFormat}, mode::Union{GFT.CRS,Type{GFT.CRS}}, | ||
source::GFT.GeoFormat) = | ||
unsafe_convertcrs(target, importCRS(source)) | ||
|
||
unsafe_convertcrs(::Type{<:GFT.CoordSys}, crsref) = | ||
GFT.CoordSys(toMICoordSys(crsref)) | ||
unsafe_convertcrs(::Type{<:GFT.ProjString}, crsref) = | ||
GFT.ProjString(toPROJ4(crsref)) | ||
unsafe_convertcrs(::Type{<:GFT.WellKnownText}, crsref) = | ||
GFT.WellKnownText(GFT.CRS(), toWKT(crsref)) | ||
unsafe_convertcrs(::Type{<:GFT.ESRIWellKnownText}, crsref) = | ||
GFT.ESRIWellKnownText(GFT.CRS(), toWKT(morphtoESRI!(crsref))) | ||
unsafe_convertcrs(::Type{<:GFT.GML}, crsref) = | ||
GFT.GML(toXML(crsref)) | ||
|
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
|
||
""" | ||
fromWKB(data) | ||
|
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,30 @@ | ||
using Test | ||
import ArchGDAL; const AG = ArchGDAL | ||
import GeoFormatTypes; const GFT = GeoFormatTypes | ||
|
||
# Tests high level convert methods | ||
|
||
@testset "convert point format" begin | ||
point = AG.createpoint(100, 70) | ||
json = convert(GFT.GeoJSON, point) | ||
kml = convert(GFT.KML, point) | ||
gml = convert(GFT.GML, point) | ||
wkb = convert(GFT.WellKnownBinary, point) | ||
wkt = convert(GFT.WellKnownText, point) | ||
@test json.val == AG.toJSON(point) | ||
@test kml.val == AG.toKML(point) | ||
@test gml.val == AG.toGML(point) | ||
@test wkb.val == AG.toWKB(point) | ||
@test wkt.val == AG.toWKT(point) | ||
@test convert(GFT.GeoJSON, json) == convert(GFT.GeoJSON, wkb) == | ||
convert(GFT.GeoJSON, wkt) == convert(GFT.GeoJSON, gml) == json | ||
@test convert(GFT.KML, gml) == convert(GFT.KML, wkt) | ||
end | ||
|
||
@testset "convert crs format" begin | ||
proj4326 = GFT.ProjString("+proj=longlat +datum=WGS84 +no_defs") | ||
@test convert(GFT.ProjString, GFT.CRS(), | ||
convert(GFT.WellKnownText, GFT.CRS(), | ||
convert(GFT.ESRIWellKnownText, GFT.CRS(), | ||
GFT.EPSG(4326)))) == proj4326 | ||
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
Oops, something went wrong.