bool visitPoint( GeoPoint& p ) { bool ok = true; // pull it out of the source reference frame: p.set( p * src_rf ); // reproject it: if ( handle ) ok = OCTTransform( handle, 1, &p.x(), &p.y(), &p.z() ) != 0; // push it into the new reference frame: p.set( p * to_srs->getReferenceFrame() ); p = p.getDim() == 2? GeoPoint( p.x(), p.y(), to_srs ) : GeoPoint( p.x(), p.y(), p.z(), to_srs ); return ok; }
bool MapInfo::worldPointToMapPoint( const osg::Vec3d& input, GeoPoint& output ) const { osg::Vec3d temp; bool ok = _profile->getSRS()->transformFromWorld(input, temp); if ( ok ) output.set(_profile->getSRS(), temp, ALTMODE_ABSOLUTE); return ok; }
bool OGR_SpatialReference::transformInPlace( GeoPoint& input ) const { if ( !handle || !input.isValid() ) { osgGIS::notify( osg::WARN ) << "Spatial reference or input point is invalid" << std::endl; return false; } OGR_SpatialReference* input_sr = (OGR_SpatialReference*)input.getSRS(); if ( !input_sr ) { osgGIS::notify( osg::WARN ) << "SpatialReference: input point has no SRS" << std::endl; return false; } // first check whether the input point is geocentric - and if so, pre-convert it to geographic: if ( input_sr->isGeocentric() ) { input.set( input * input_sr->getInverseReferenceFrame() ); osg::Vec3d temp = input_sr->getEllipsoid().geocentricToLatLong( input ); input = GeoPoint( temp, input_sr->getGeographicSRS() ); input_sr = static_cast<OGR_SpatialReference*>( input.getSRS() ); } osg::Vec3d input_vec = input; bool crs_equiv = false; bool mat_equiv = false; testEquivalence( input_sr, /*out*/crs_equiv, /*out*/mat_equiv ); // pull it out of its source frame: if ( !mat_equiv ) { input.set( input * input_sr->inv_ref_frame ); } bool result = false; if ( !crs_equiv ) { OGR_SCOPE_LOCK(); //TODO: some kind of per-thread cache void* xform_handle = OCTNewCoordinateTransformation( input_sr->handle, this->handle ); if ( !xform_handle ) { osgGIS::notify( osg::WARN ) << "Spatial Reference: SRS xform not possible" << std::endl << " From => " << input_sr->getWKT() << std::endl << " To => " << this->getWKT() << std::endl; return false; } //TODO: figure out why xforming GEOCS x=-180 to another GEOCS doesn't work if ( OCTTransform( xform_handle, 1, &input.x(), &input.y(), &input.z() ) ) { result = true; } else { osgGIS::notify( osg::WARN ) << "Spatial Reference: Failed to xform a point from " << input_sr->getName() << " to " << this->getName() << std::endl; } OCTDestroyCoordinateTransformation( xform_handle ); } else { result = true; } // put it into the new ref frame: if ( !mat_equiv ) { input.set( input * ref_frame ); } if ( result == true ) { applyTo( input ); } return result; }