Projected map and positioning problem

classic Classic list List threaded Threaded
3 messages Options
DizL DizL
Reply | Threaded
Open this post in threaded view
|

Projected map and positioning problem

This post was updated on .
Hi,

Here is my earth file:

<map name="ArcGIS Online" type="projected" version="2">
       
    <image name="arcgis-world-imagery" driver="arcgis" opacity = "1.0">
        <url>http://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer</url>
        <profile>spherical-mercator</profile>
        <cache_policy usage="read_write"/>
    </image> 

    <options>
        <cache type="filesystem">
            <path>Cache</path>
        </cache>
    </options>

</map>

In code I add circleNode:

    osgEarth::Symbology::Style circleStyle2;
    circleStyle2.getOrCreateSymbol<osgEarth::Symbology::LineSymbol>()->stroke()->color() = osg::Vec4f(1, 0, 1, 1);
    circleStyle2.getOrCreateSymbol<osgEarth::Symbology::LineSymbol>()->stroke()->width() = 4.0f;

    const osgEarth::SpatialReference* geoSRS = osgEarth::Registry::instance()->getGlobalGeodeticProfile()->getSRS();    
    CircleNode* circle2 = new CircleNode(mapNode, GeoPoint(geoSRS, 21.0754, 52.1559, 0.0, ALTMODE_ABSOLUTE),10000.0, circleStyle2);
    rootNode->addChild(circle2);

and I also add second 'geometry' but in the other way:

    const osgEarth::SpatialReference* geoSRS = osgEarth::Registry::instance()->getGlobalGeodeticProfile()->getSRS();    

     osgEarth::GeoPoint geoPoint( geoSRS , 21.0754, 52.1559, osgEarth::AltitudeMode::ALTMODE_ABSOLUTE);
     osg::Vec3d pnt;
     geoPoint.toWorld(pnt);

     osg::PositionAttitudeTransform *triangleNode = new osg::PositionAttitudeTransform();
     triangleNode ->setPosition(pnt);

    osg::Geometry* triangle = createTriangle(6.0, color, 3);
    osg::Geode* triangleGeode= new osg::Geode;
    triangleGeode->getOrCreateStateSet()->setAttributeAndModes(new osg::LineWidth(2.f));
    triangleGeode->addDrawable(triangle);

    osg::AutoTransform* at = new osg::AutoTransform();
    at->setAutoScaleToScreen(true);
    at->setAutoRotateMode(osg::AutoTransform::ROTATE_TO_SCREEN);
    at->addChild(triangleGeode);

    triangleNode ->addChild(at);

    rootNode->addChild(triangleNode);

I also have output about positions of both GeoPoints x(),y() and worldPos x(),y(),z() which are thse same

21.0754 52.1559 3.65897e+06 1.41008e+06 5.01346e+06
21.0754 52.1559 3.65897e+06 1.41008e+06 5.01346e+06

but the problem is, that only circleNode is in a right place, triangleNode is somewhere above Africa :/

When I change type of map from projected to geocentric, everything is ok :|

Any help?

regards,

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

Re: Projected map and positioning problem

DizL,

Your map is in the Mercator projection. But, the GeoPoint::toWorld() function doesn't know that :) So when you call GeoPoint::toWorld on a point with a geographic SRS, the resulting XYZ is in geocentric space. That would be fine for round earth, but not for Mercator.

So in this case you need to transform your GeoPoint into the map's SRS before calling toWorld:

  geoPoint.transformInPlace(mapNode->getMapSRS());

One more piece of advice: Instead of getting your geoSRS from the registry, get it directly from the mapNode's SRS. Then you will get correct datum correlation:

  geoSRS = mapNode->getMapSRS()->getGeographicSRS();

Hope this helps!
Glenn Waldron / Pelican Mapping
DizL DizL
Reply | Threaded
Open this post in threaded view
|

Re: Projected map and positioning problem

Thanks Glenn!!

It works :)

regards,
DizL