Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Can anyone point me to a C++ class for representing coordinates that automatically handles projection transforms? What I'm thinking of is something that would allow me to create vars that incorporate a projection and have appropriate geographic operators such that comparisons make sense even when the coordinates are in different projections. Using template notation (though I can't figure out how to template on a projection)

Coord < SRID:1234> point1 (x1, y1); Coord < SRID:5678> point2 (x2, y2);

if (point1.east(point2)) ... // true if point1 is east of point2

or

point2 = point1 // This operation assigns the coordinates of point1 to point2, 
using the coordinate system of point2 (in this case SRID::5678).
share|improve this question
add comment

3 Answers 3

Try to look at Proj.4 library.

You can reproject you points to common coordinate system and then perform the comparison.

Try to create some wrapper class that will perform automate reprojection to common CS and then compare coordinates.

share|improve this answer
    
Not to be overly critical, but this answer is not useful at all. The whole point this question asks is how to write the wrapper class in a clever way. I'm already familiar with the Proj.4 library. The question is how to create a clean C++ wrapper, or better yet, find someone who also already done it. –  Llaves May 16 '12 at 15:44
add comment

I recently wrote a mini wrapper for our OpenGL 3D map engine. Under the hood, the wrapper uses Proj.4. However, I simply use convenience methods for for common conversions (e.g. WGS84 <-> projection used by map).

I'd consider a template based approach to automate conversion as bad software design decision for a few reasons. It adds unnecessary types and introduces complexity to what should be a simple class or struct. And also it would mean that a coordinate must know how to convert itself - I'd say this is bad design, similar as if a "POJO" (data object) knew how to map data from the database (which should ather be the responsibility of the data mapper to transfer db data to the object). And also, your coordinate adds coupling to some sort of projection library.

So, I'd just use a conversion library or at most add a small wrapper for convenience to transform between different datums.

share|improve this answer
add comment

If you want to support comparing points on different datums you have a lot of work ahead; there are often multiple "paths" between datums and it is often the case that the correct path is context dependent.

That being said, CS-MAP (C API) will do its best to pick a path between datums - if you aren't picky it will probably do something acceptable.

And many CS-MAP coordinate systems are tagged with EPSG #s, so you could look up the name associated with a given number.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.