yeesian / ArchGDAL.jl

A high level API for GDAL - Geospatial Data Abstraction Library
https://yeesian.github.io/ArchGDAL.jl/stable/
Other
137 stars 25 forks source link

Enable the use of ArchGDAL.ISpatialRef in reproject #403

Open felixcremer opened 6 months ago

felixcremer commented 6 months ago

When I have a geometry in a specific CRS I can get the crs information via ArchGDAL.getspatialref(geom) but then I can't use this crs for the reprojection. It would be good to be able to use the crs that I get from ArchGDAL in the relevant ArchGDAL functions.

I can get the projstring via ArchGDAL.toProj4 but then to use it in the reproject call I have to wrap it in the ProjString type.

julia> deu = GADM.get("DEU", depth=0)
(geom = ArchGDAL.IGeometry{ArchGDAL.wkbMultiPolygon}[Geometry: MULTIPOLYGON (((7.98642063100016 47.5555305480001, ... 02)))], GID_0 = ["DEU"], COUNTRY = ["Germany"])

julia> crs = ArchGDAL.getspatialref(deu.geom[1])
Spatial Reference System: +proj=longlat +datum=WGS84 +no_defs
# This works: but could be made easier
julia> projdeu = ArchGDAL.reproject(only(deu.geom), ProjString(ArchGDAL.toPROJ4(crs)), ProjString(newproj))

Geometry: MULTIPOLYGON (((17.199717191748 -0.16543096960377, ... 47)))
julia> projdeu = ArchGDAL.reproject(only(deu.geom), crs, ProjString(newproj))
ERROR: MethodError: no method matching reproject(::ArchGDAL.IGeometry{ArchGDAL.wkbMultiPolygon}, ::ArchGDAL.ISpatialRef, ::ProjString)

Closest candidates are:
  reproject(::ArchGDAL.AbstractGeometry, ::GeoFormat, ::GeoFormat; kwargs...)
   @ ArchGDAL ~/Documents/NFDI4Earth/deliverables/D2.5_1-5_Overview_DC_tech/dev/ArchGDAL/src/spatialref.jl:155
  reproject(::T, ::GeoFormat, ::Nothing; kwargs...) where T
   @ ArchGDAL ~/Documents/NFDI4Earth/deliverables/D2.5_1-5_Overview_DC_tech/dev/ArchGDAL/src/spatialref.jl:100
  reproject(::Union{Tuple{var"#s244", var"#s244"} where var"#s244"<:Number, Tuple{var"#s243", var"#s243", var"#s243"} where var"#s243"<:Number, AbstractVector{<:Number}}, ::GeoFormat, ::GeoFormat; kwargs...)
   @ ArchGDAL ~/Documents/NFDI4Earth/deliverables/D2.5_1-5_Overview_DC_tech/dev/ArchGDAL/src/spatialref.jl:114
  ...

Stacktrace:
 [1] top-level scope
   @ REPL[160]:1
rafaqz commented 6 months ago

I think I just never thought to add that, rather than intentionally leaving it out. But sounds like it would be good to have.