/usr/include/osgEarth/SpatialReference is in libosgearth-dev 2.5.0+dfsg-2+b2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 | /* -*-c++-*- */
/* osgEarth - Dynamic map generation toolkit for OpenSceneGraph
* Copyright 2008-2013 Pelican Mapping
* http://osgearth.org
*
* osgEarth is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
#ifndef OSGEARTH_SPATIAL_REFERENCE_H
#define OSGEARTH_SPATIAL_REFERENCE_H 1
#include <osgEarth/Common>
#include <osgEarth/Units>
#include <osgEarth/VerticalDatum>
#include <osg/CoordinateSystemNode>
#include <osg/Vec3>
#include <OpenThreads/ReentrantMutex>
namespace osgEarth
{
//Definitions for the mercator extent
const double MERC_MINX = -20037508.34278925;
const double MERC_MINY = -20037508.34278925;
const double MERC_MAXX = 20037508.34278925;
const double MERC_MAXY = 20037508.34278925;
const double MERC_WIDTH = MERC_MAXX - MERC_MINX;
const double MERC_HEIGHT = MERC_MAXY - MERC_MINY;
class OSGEARTH_EXPORT GeoLocator;
/**
* SpatialReference holds information describing the reference ellipsoid/datum
* and the projection of geospatial data.
*/
class OSGEARTH_EXPORT SpatialReference : public osg::Referenced
{
public:
/**
* Creates an SRS from two intialization strings; the first for the horizontal datum and
* the second for the vertical datum. If you omit the vertical datum, it will default to
* the geodetic datum for the ellipsoid.
*/
static SpatialReference* create( const std::string& init, const std::string& vinit ="" );
static SpatialReference* get ( const std::string& init, const std::string& vinit ="" ) { return create(init,vinit); }
/**
* Attempts to create a spatial reference def from a pre-existing CSN, returning
* NULL if there is not enough information.
*/
static SpatialReference* create( osg::CoordinateSystemNode* csn );
/**
* Creates an SRS around a pre-existing OGR spatial reference handle. The new
* SpatialReference object takes ownership of the handle.
*
* @param xferOwnership
* If true, the SpatialReference object is responsible for releasing the handle
* upon destruction.
*/
static SpatialReference* createFromHandle( void* ogrHandle, bool xferOwnership =false );
public: // Basic transformations.
/**
* Transform a single point from this SRS to another SRS.
* Returns true if the transformation succeeded.
*/
virtual bool transform(
const osg::Vec3d& input,
const SpatialReference* outputSRS,
osg::Vec3d& output) const;
/**
* Transform a collection of points from this SRS to another SRS.
* Returns true if ALL transforms succeeded, false if at least one failed.
*/
virtual bool transform(
std::vector<osg::Vec3d>& input,
const SpatialReference* outputSRS ) const;
/**
* Transform a 2D point directly. (Convenience function)
*/
bool transform2D(
double x,
double y,
const SpatialReference* outputSRS,
double& out_x,
double& out_y ) const;
public: // Units transformations.
/**
* Transforms a distance from the base units of this SRS to the base units of
* another. If one of the SRS's is geographic (i.e. has angular units), the
* conversion will assume that the corresponding distance is measured at the
* equator.
*/
double transformUnits(
double distance,
const SpatialReference* outputSRS,
double latitude =0.0) const;
public: // World transformations.
/**
* Transforms a point from this SRS into "world" coordinates. This normalizes
* the Z coordinate (according to the vertical datum) and converts to ECEF
* if necessary.
*/
bool transformToWorld(
const osg::Vec3d& input,
osg::Vec3d& out_world ) const;
/**
* Transforms a point from the "world" coordinate system into this spatial
* reference.
* @param world
* World point to transform
* @param out_local
* Output coords in local (SRS) coords
* @param worldIsGeocentric
* Whether the incoming world coordinates are ECEF/geocentric coords
* @param out_geodeticZ
* (optional) Outputs the geodetic (HAE) Z if applicable
*/
bool transformFromWorld(
const osg::Vec3d& world,
osg::Vec3d& out_local,
double* out_geodeticZ =0L ) const;
public: // extent transformations.
/**
* Transforms a spatial extent to another SRS. The transformed extent will
* actually be the minimum bounding axis-aligned rectangle that would hold
* the source extent.
*/
virtual bool transformExtentToMBR(
const SpatialReference* to_srs,
double& in_out_xmin,
double& in_out_ymin,
double& in_out_xmax,
double& in_out_ymax ) const;
virtual bool transformExtentPoints(
const SpatialReference* to_srs,
double in_xmin, double in_ymin,
double in_xmax, double in_ymax,
double* x, double* y,
unsigned numx, unsigned numy ) const;
public: // properties
typedef std::pair<std::string,std::string> Key;
/** True if this is a geographic SRS (lat/long/msl) */
virtual bool isGeographic() const;
/** True if this is a geodetic SRS (lat/long/hae) */
virtual bool isGeodetic() const;
/** True if this is a projected SRS (i.e. local coordinate system) */
virtual bool isProjected() const;
/** True if this is an ECEF system (geocentric/meters) */
virtual bool isECEF() const;
/** Tests whether this SRS represents a Mercator projection. */
bool isMercator() const;
/** Tests whether this SRS represents a Spherical Mercator pseudo-projection. */
bool isSphericalMercator() const;
/** Tests whether this SRS represents a polar sterographic projection. */
bool isNorthPolar() const;
bool isSouthPolar() const;
/** Tests whether this SRS is user-defined; i.e. whether it is other than a
well-known SRS. (i.e. whether the SRS is unsupported by GDAL) */
virtual bool isUserDefined() const;
/** Tests whether coordinates in this SRS form a contiguous space. A non-contiguous
SRS is one in which adjacent coordinates may not necessarily represent
adjacent map locations. */
virtual bool isContiguous() const;
/** Tests whether this SRS is a Unified Cube projection (osgEarth-internal) */
virtual bool isCube() const;
/** Tests whether this SRS is a Local Tangent Plane projection (osgEarth-internal) */
virtual bool isLTP() const { return _is_ltp; }
/** Whether this is a geographic plate carre SRS */
virtual bool isPlateCarre() const { return _is_plate_carre; }
/** Gets the readable name of this SRS. */
const std::string& getName() const;
/** Gets the underlying reference ellipsoid of this SRS */
const osg::EllipsoidModel* getEllipsoid() const;
/** Gets the WKT string */
const std::string& getWKT() const;
/** Gets the initialization type (PROJ4, WKT, etc.) */
const std::string& getInitType() const;
/** Gets the initialization key. */
const Key& getKey() const;
/** Gets the initialization string for the horizontal datum */
const std::string& getHorizInitString() const;
/** Gets the initialization string for the vertical datum */
const std::string& getVertInitString() const;
/** Gets the datum identifier of this SRS (or empty string if not available) */
const std::string& getDatumName() const;
/** Gets the base units of data in this SRS */
const Units& getUnits() const;
/** Whether the two SRS are completely equivalent. */
virtual bool isEquivalentTo( const SpatialReference* rhs ) const;
/** Whether the two SRS are horizonally equivalent (ignoring the vertical datums) */
bool isHorizEquivalentTo( const SpatialReference* rhs ) const;
/** Whether this SRS has the same vertical datum as another. */
bool isVertEquivalentTo( const SpatialReference* rhs ) const;
/** Gets a reference to this SRS's underlying geographic SRS. */
const SpatialReference* getGeographicSRS() const;
/** Gets a reference to this SRS's underlying geodetic SRS. This is the same as the
geographic SRS [see getGeographicSRS()] but with a geodetic vertical datum (in
which Z is expressed as height above the geodetic ellipsoid). */
const SpatialReference* getGeodeticSRS() const;
/** Gets the ECEF reference system associated with this SRS' ellipsoid. */
const SpatialReference* getECEF() const;
/** Gets the vertical datum. If null, this SRS uses a default geodetic vertical datum */
const VerticalDatum* getVerticalDatum() const;
/** Creates a localizer matrix based on a point in this SRS. */
bool createLocalToWorld( const osg::Vec3d& point, osg::Matrixd& out_local2world ) const;
/** Create a de-localizer matrix based on a point in this SRS. */
bool createWorldToLocal( const osg::Vec3d& point, osg::Matrix& out_world2local ) const;
/** Creates and returns a local trangent plane SRS at the given reference location.
The reference location is expressed in this object's SRS, but it tangent to
the globe at getGeographicSRS(). LTP units are in meters. */
const SpatialReference* createTangentPlaneSRS( const osg::Vec3d& refPos ) const;
/** Creates a transverse mercator projection centered at the specified longitude. */
const SpatialReference* createTransMercFromLongitude( const Angular& lon ) const;
/** Creates a UTM (universal transverse mercator) projection in the UTM zone
containing the specified longitude. NOTE: this is slightly faster than using
basic tmerc (transverse mercator) above. */
const SpatialReference* createUTMFromLonLat( const Angle& lon, const Angle& lat ) const;
/** Creates a copy of this SRS, but flags the new SRS so that it will operate in
Plate Carre mode for the purposes of world coordinate conversion. The SRS is
otherwise mathematically equivalent to its vanilla counterpart. */
const SpatialReference* createPlateCarreGeographicSRS() const;
/** Creates a new CSN based on this spatial reference. */
osg::CoordinateSystemNode* createCoordinateSystemNode() const;
/** Populates the provided CSN with information from this SRS. */
bool populateCoordinateSystemNode( osg::CoordinateSystemNode* csn ) const;
/**
* Creates a new Locator object based on this spatial reference.
*
* @param xmin, ymin, xmax, ymax
* Extents of the tile for which to create a locator. These should
* be in degrees for a geographic/geocentric scene.
* @param plate_carre
* Set this to true for the special case in which you are using a
* geographic SRS with a PROJECTED map (like flat-earth lat/long).
*/
virtual GeoLocator* createLocator(
double xmin, double ymin, double xmax, double ymax,
bool plate_carre =false ) const;
/**
* Gets the underlying OGRLayerH that this SpatialReference owns.
* Don't use this unless you know what you're doing.
*/
void* getHandle() const { return _handle;}
protected:
virtual ~SpatialReference();
protected:
SpatialReference( void* handle, const std::string& type );
SpatialReference( void* handle, bool ownsHandle =true );
void init();
bool _initialized;
void* _handle;
bool _owns_handle;
bool _is_geographic;
bool _is_mercator;
bool _is_spherical_mercator;
bool _is_north_polar, _is_south_polar;
bool _is_cube;
bool _is_contiguous;
bool _is_user_defined;
bool _is_ltp;
bool _is_plate_carre;
bool _is_ecef;
unsigned _ellipsoidId;
std::string _name;
Key _key;
std::string _wkt;
std::string _proj4;
std::string _init_type;
std::string _datum;
Units _units;
osg::ref_ptr<osg::EllipsoidModel> _ellipsoid;
osg::ref_ptr<SpatialReference> _geo_srs;
osg::ref_ptr<SpatialReference> _geodetic_srs; // _geo_srs with a NULL vdatum.
osg::ref_ptr<SpatialReference> _ecef_srs;
osg::ref_ptr<VerticalDatum> _vdatum;
typedef std::map<std::string,void*> TransformHandleCache;
TransformHandleCache _transformHandleCache;
// user can override these methods in a subclass to perform custom functionality; must
// call the superclass version.
virtual void _init();
virtual bool _isEquivalentTo( const SpatialReference* srs, bool considerVDatum =true ) const;
virtual bool preTransform(std::vector<osg::Vec3d>&) const { return true; }
virtual bool postTransform(std::vector<osg::Vec3d>&) const { return true; }
bool transformXYPointArrays(
double* x,
double* y,
unsigned numPoints,
const SpatialReference* out_srs) const;
bool transformZ(
std::vector<osg::Vec3d>& points,
const SpatialReference* outputSRS,
bool pointsAreGeodetic) const;
typedef std::map<Key, osg::ref_ptr<SpatialReference> > SRSCache;
static SRSCache& getSRSCache();
private:
static SpatialReference* create( const Key& key, bool useCache );
static SpatialReference* createFromWKT(
const std::string& wkt,
const std::string& name ="" );
static SpatialReference* createFromPROJ4(
const std::string& proj4,
const std::string& name = "" );
static SpatialReference* createCube();
SpatialReference* fixWKT();
};
}
#endif // OSGEARTH_SPATIAL_REFERENCE_H
|