LatLonAlt to screen coords for mercator projection

classic Classic list List threaded Threaded
6 messages Options
Blanky Blanky
Reply | Threaded
Open this post in threaded view
|

LatLonAlt to screen coords for mercator projection

Hello,

I'm trying to mimic the behavior of this post:

https://blog.csdn.net/yang_sen_/article/details/84564583

In this post, the poster used the following function:

osg::Vec3d LonLatAltToWorld(const osg::Vec3d lonLatAlt){
        osg::Vec3d world;
        osg::EllipsoidModel* em = new osg::EllipsoidModel();
        em->convertLatLongHeightToXYZ(osg::DegreesToRadians(lonLatAlt.y()), osg::DegreesToRadians(lonLatAlt.x()), lonLatAlt.z(), world.x(), world.y(), world.z());
        return world;
}

This will work for the 3D earth only. The issue is that I do not want to use an ellipsoid model for my mercator projection. Unluckily osg has this functionality built in, but only for a spherical ellipsoid model. I need something similar to the above convertLatLonHeightToXYZ but for a mercator projection. I'm not quite sure what I need to do to get this working. Does anyone have a clue?

The reason I need this, is because I'm rewriting the osgEarth MapMeasureTool to cross a treadmilled mercator projection correctly over the dateline and I need to know if the initial point is currently in the left, center, or right matrix transform that holds a copy of the osgEarth MapNode. If the user pans during the measureEventHandler, I need to know if the start and end point are in different matrix transforms. It's easy for me to know where the end point is located because I have the event adapter's getX() and getY() functions. However, I need to essentially get the x and y screen coords of the initial point's Lat/Lon after panning or moving the map around in a mercator projection. The above link actually does work for the 3D map quite well if anyone need that information.

Thanks for any assistance.

- Banky
gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|

Re: LatLonAlt to screen coords for mercator projection

Use the SpatialReference class to transform between projections.

const SpatialReference* latlong = SpatialReference::get("wgs84");
const SpatialReference* mercator = SpatialReference::get("spherical-mercator");

Then use one of the transform* methods, like:

latlong->transform(input, mercator, output);
Glenn Waldron / Pelican Mapping
Blanky Blanky
Reply | Threaded
Open this post in threaded view
|

Re: LatLonAlt to screen coords for mercator projection

So do I even want to bother using the ellipsoidal model at all and its convertXYZToLatLongAlt? I'm not getting the right numbers at all when I do that like I do on the 3D earth.
gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|

Re: LatLonAlt to screen coords for mercator projection

No. The "XYZ" in theose methods refers to ECEF coordinates which is a 3D Cartesian coordinate system...not what you want.
Glenn Waldron / Pelican Mapping
Blanky Blanky
Reply | Threaded
Open this post in threaded view
|

Re: LatLonAlt to screen coords for mercator projection

Ahhh okay, so I needed just a worldToScreen of the mercator coordinates essentially. That was a lot more trivial than I expected. Thanks for pointing that out Glenn!
gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|

Re: LatLonAlt to screen coords for mercator projection

Right.

For posterity: in osgEarth-speak, "World" coordinates refers to the actual OpenGL model coordinates in the scene.

For a projected map, World coordinates and Map coordinates are the same. In a geocentric (globe) map, Map coordinates are lat/long, but World coordinates are ECEF.
Glenn Waldron / Pelican Mapping