JuliaGeo / Proj.jl

Julia wrapper for the PROJ cartographic projections library
MIT License
48 stars 9 forks source link

Comparing two projections #13

Closed mauro3 closed 7 years ago

mauro3 commented 7 years ago

Would it be possible to add comparison of two projections? Currently:

julia> Proj4.Projection("+proj=utm +zone=32")==Proj4.Projection("+proj=utm +zone=32")
false

julia> Proj4.Projection("+proj=utm +zone=32")==Proj4.Projection("+zone=32 +proj=utm")
false

as it uses the fall-back in Base to ===.

Comparing the string(...) works for the first of above examples but fails on the second.

c42f commented 7 years ago

A very good question. Unfortunately I don't think the underlying proj.4 library supports this, otherwise we could just hook up the associated function.

Comparison based on strings is not reliable either - at least not without heroic efforts. As you pointed out, two different strings may represent the same projection. Actually argument ordering is just one of many complicated ways that two apparently different strings could be equivalent.

So I don't think there's any good way to do this, short of heroic efforts implementing comparison logic which should belong in the underlying C library.

c42f commented 7 years ago

I had a quick poke around in the C library again, there's been a few changes lately, but I'm still not sure this can be done. I'd love to be wrong - please reopen the issue if you've got any ideas. The proj.4 C source code itself doesn't look promising: there's this comment inside the top of pj_transform:

/************************************************************************/
/*                            pj_transform()                            */
/*                                                                      */
/*      Currently this function doesn't recognise if two projections    */
/*      are identical (to short circuit reprojection) because it is     */
/*      difficult to compare PJ structures (since there are some        */
/*      projection specific components).                                */
/************************************************************************/
mauro3 commented 7 years ago

Thanks for your digging! I'll just use the string comparison and if that is a false negative do some extra identity transformations.

c42f commented 7 years ago

That sounds like an excellent idea if you're trying to make the transformation of a large number of points more efficient.