ArchGDAL.jl icon indicating copy to clipboard operation
ArchGDAL.jl copied to clipboard

Enable the use of ArchGDAL.ISpatialRef in reproject

Open felixcremer opened this issue 2 years ago • 8 comments

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

felixcremer avatar Nov 29 '23 13:11 felixcremer

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

rafaqz avatar Nov 29 '23 14:11 rafaqz

So I will pose the question here again after i had it in #434. What is the Intention of having the ISpatialRef when for Reprojection we use GeoFormatTypes. Wouldn't it be more useful if instead of ISpatialRef we obtain actual GeoFormatTypes?

toihr avatar Aug 13 '24 11:08 toihr

ISpatialRef is a wrapper for the internal GDAL object OGRSpatialReferenceH. It needs to exist because its what GDAL uses internally:

https://github.com/yeesian/ArchGDAL.jl/blob/4b40fe857503ec2ef8bc431919d8d31bcec7cba5/src/types.jl#L214-L222

Its not very useful outside of GDAL/ArchGDAL because its not a known format. But reproject and other ArchGDAL methods should accept it.

rafaqz avatar Aug 14 '24 07:08 rafaqz

Oh I see, that makes a lot of sense. I didn't look into the types.jl otherwise i would have figured this out probably.

If you are not working on this I could try to spin up a fork which does allow this, later.

toihr avatar Aug 14 '24 11:08 toihr

Its very likely you are the most motivated person to do it :)

rafaqz avatar Aug 15 '24 12:08 rafaqz