xy2lonlat
function lonlat2xy(xy::Vector{<:Real}, t_srs_=nothing; t_srs=nothing, s_srs=prj4WGS84) vec(lonlat2xy(reshape(xy[:],1,length(xy)), t_srs_; t_srs=t_srs, s_srs=s_srs)) end lonlat2xy(x::Real, y::Real, t_srs_=nothing; t_srs=nothing, s_srs=prj4WGS84) = lonlat2xy([x y], t_srs_; t_srs=t_srs, s_srs=s_srs)
function lonlat2xy(xy::Matrix{T}, t_srs_=nothing; t_srs=nothing, s_srs=prj4WGS84) where {T <: Real} (t_srs_ !== nothing) && (t_srs = t_srs_) isa(s_srs, Int) && (s_srs = epsg2wkt(s_srs)) isa(t_srs, Int) && (t_srs = epsg2wkt(t_srs)) (t_srs === nothing) && error(“Must specify at least the target referencing system.”) opts = (size(xy,2) == 2) ? [“-s_srs”, s_srs, “-t_srs”, t_srs, “-overwrite”] : [“-s_srs”, s_srs, “-t_srs”, t_srs, “-overwrite”, “-dim”, “XYZ”] D = ogr2ogr(xy, opts) return D.data # Return only the array because that’s what was sent in end
lonlat2xy(D::GMTdataset, t_srs_=nothing; t_srs=nothing, s_srs=prj4WGS84) = lonlat2xy([D], t_srs_; t_srs=t_srs, s_srs=s_srs) function lonlat2xy(D::Vector{<:GMTdataset{T,2}}, t_srs_=nothing; t_srs=nothing, s_srs=prj4WGS84) where {T<:Real} (t_srs_ !== nothing) && (t_srs = t_srs_) isa(t_srs, Int) && (t_srs = epsg2wkt(t_srs)) isa(s_srs, Int) && (s_srs = epsg2wkt(s_srs))
(D[1].proj4 == "" && D[1].wkt == "" && t_srs === nothing) && error("No projection information whatsoever on the input data.")
if (t_srs != "") _t_srs = t_srs
else _t_srs = (D[1].proj4 != "") ? D[1].proj4 : D[1].wkt
end
opts = (size(D[1].data,2) == 2) ? ["-s_srs", s_srs, "-t_srs", t_srs, "-overwrite"] :
["-s_srs", s_srs, "-t_srs", t_srs, "-overwrite", "-dim", "XYZ"]
r = ogr2ogr(D, opts)
# For some bloody reason if we don't do this and call gdalwarp after, we get a "gdalwarp returned a NULL pointer." error
(length(D) > 1) && ogr2ogr([0.0 0], ["-s_srs", "+proj=lonlat", "-t_srs", "+proj=lonlat", "-overwrite"])
return r
end
—————————————————————————————————
““” xy2lonlat(xy::Matrix{<:Real}, s_srs=““; s_srs=”“, t_srs=”+proj=longlat +datum=WGS84”) or
xy2lonlat(D::GMTdataset, s_srs=""; s_srs="", t_srs="+proj=longlat +datum=WGS84")
Computes the inverse projection from XY to LonLat in the given projection. The output is assumed to be in WGS84. If that isn’t right, pass the appropriate projection info via the t_srs option (PROJ4, WKT, EPSG).
Parameters
xy: The input data. It can be a Matrix, or a GMTdataset (or vector of it)s_srs: The data projection system. This can be a PROJ4, a WKT string or EPSG codet_srs: The target SRS. If the default is not satisfactory, provide a new projection info (PROJ4, WKT, EPSG)
Returns
A Matrix if input is a Matrix or a GMTdadaset if input had that type