bool VerticalDatum::transform(const VerticalDatum* from, const VerticalDatum* to, double lat_deg, double lon_deg, double& in_out_z) { if ( from == to ) return true; if ( from ) { in_out_z = from->msl2hae( lat_deg, lon_deg, in_out_z ); } Units fromUnits = from ? from->getUnits() : Units::METERS; Units toUnits = to ? to->getUnits() : Units::METERS; in_out_z = fromUnits.convertTo(toUnits, in_out_z); if ( to ) { in_out_z = to->hae2msl( lat_deg, lon_deg, in_out_z ); } return true; }
bool SpatialReference::transformZ(std::vector<osg::Vec3d>& points, const SpatialReference* outputSRS, bool pointsAreLatLong) const { const VerticalDatum* outVDatum = outputSRS->getVerticalDatum(); // same vdatum, no xformation necessary. if ( _vdatum.get() == outVDatum ) return true; Units inUnits = _vdatum.valid() ? _vdatum->getUnits() : Units::METERS; Units outUnits = outVDatum ? outVDatum->getUnits() : inUnits; if ( isGeographic() || pointsAreLatLong ) { for( unsigned i=0; i<points.size(); ++i ) { if ( _vdatum.valid() ) { // to HAE: points[i].z() = _vdatum->msl2hae( points[i].y(), points[i].x(), points[i].z() ); } // do the units conversion: points[i].z() = inUnits.convertTo(outUnits, points[i].z()); if ( outVDatum ) { // to MSL: points[i].z() = outVDatum->hae2msl( points[i].y(), points[i].x(), points[i].z() ); } } } else // need to xform input points { // copy the points and convert them to geographic coordinates (lat/long with the same Z): std::vector<osg::Vec3d> geopoints(points); transform( geopoints, getGeographicSRS() ); for( unsigned i=0; i<geopoints.size(); ++i ) { if ( _vdatum.valid() ) { // to HAE: points[i].z() = _vdatum->msl2hae( geopoints[i].y(), geopoints[i].x(), points[i].z() ); } // do the units conversion: points[i].z() = inUnits.convertTo(outUnits, points[i].z()); if ( outVDatum ) { // to MSL: points[i].z() = outVDatum->hae2msl( geopoints[i].y(), geopoints[i].x(), points[i].z() ); } } } return true; }