2
/* osgEarth - Dynamic map generation toolkit for OpenSceneGraph
3
* Copyright 2008-2010 Pelican Mapping
6
* osgEarth is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU Lesser General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU Lesser General Public License for more details.
16
* You should have received a copy of the GNU Lesser General Public License
17
* along with this program. If not, see <http://www.gnu.org/licenses/>
19
#ifndef OSGEARTH_GEODATA_H
20
#define OSGEARTH_GEODATA_H 1
22
#include <osg/Referenced>
25
#include <osgTerrain/Locator>
26
#include <osgEarth/Common>
27
#include <osgEarth/SpatialReference>
28
#include <osgEarth/VerticalSpatialReference>
29
#include <osgEarth/HeightFieldUtils>
30
#include <osgEarth/Units>
35
* An "anonymous" bounding extent (i.e., no geo reference information)
37
class OSGEARTH_EXPORT Bounds : public osg::BoundingBoxImpl<osg::Vec3d>
41
Bounds(double xmin, double ymin, double xmax, double ymax );
44
double height() const;
46
bool contains(double x, double y ) const;
47
Bounds unionWith(const Bounds& rhs) const;
48
void expandBy( double x, double y );
49
void expandBy( double x, double y, double z );
50
void expandBy( const Bounds& rhs );
51
osg::Vec2d center2d() const;
55
* A georeferenced extent. A bounding box that is aligned with a
56
* spatial reference's coordinate system.
58
* TODO: this class needs better integrated support for geographic extents
59
* that cross the date line.
61
class OSGEARTH_EXPORT GeoExtent
64
/** Default ctor creates an "invalid" extent */
67
/** Contructs a valid extent */
69
const SpatialReference* srs,
70
double xmin = FLT_MAX, double ymin = FLT_MAX,
71
double xmax = -FLT_MAX, double ymax = -FLT_MAX );
74
GeoExtent( const GeoExtent& rhs );
76
/** create from Bounds object */
77
GeoExtent( const SpatialReference* srs, const Bounds& bounds );
79
bool operator == ( const GeoExtent& rhs ) const;
80
bool operator != ( const GeoExtent& rhs ) const;
82
/** Gets the spatial reference system underlying this extent. */
83
const SpatialReference* getSRS() const;
85
double xMin() const { return _xmin; }
86
double& xMin() { return _xmin; }
87
double yMin() const { return _ymin; }
88
double& yMin() { return _ymin; }
89
double xMax() const { return _xmax; }
90
double& xMax() { return _xmax; }
91
double yMax() const { return _ymax; }
92
double& yMax() { return _ymax; }
95
double height() const;
97
void getCentroid( double& out_x, double& out_y ) const;
100
* Returns true is that extent is in a Geographic (lat/long) SRS that spans
101
* the international date line.
103
bool crossesDateLine() const;
106
* Returns the raw bounds in a single function call
108
void getBounds(double &xmin, double &ymin, double &xmax, double &ymax) const;
110
/** True if this object defines a real, valid extent with positive area */
111
bool isValid() const;
112
bool defined() const { return isValid(); }
115
* If this extent crosses the international date line, populates two extents, one for
116
* each side, and returns true. Otherwise returns false and leaves the reference
117
* parameters untouched.
119
bool splitAcrossDateLine( GeoExtent& first, GeoExtent& second ) const;
122
* Returns this extent transformed into another spatial reference.
124
GeoExtent transform( const SpatialReference* to_srs ) const;
127
* Returns true if the specified point falls within the bounds of the extent.
130
* Coordinates to test
132
* SRS of input x and y coordinates; if null, the method assumes x and y
133
* are in the same SRS as this object.
135
bool contains(double x, double y, const SpatialReference* xy_srs =0L) const;
138
* Returns TRUE if this extent intersects another extent.
140
bool intersects( const GeoExtent& rhs ) const;
142
/** Direct access to the anonymous bounding box */
143
Bounds bounds() const;
146
* Grow this extent to include the specified point (which is assumed to be
147
* in the extent's SRS.
149
void expandToInclude( double x, double y );
152
* Grow this extent to include the specified GeoExtent (which is assumed to be
153
* in the extent's SRS.
155
void expandToInclude( const GeoExtent& rhs );
158
* Intersect this extent with another extent in the same SRS and return the
161
GeoExtent intersectionSameSRS( const GeoExtent& rhs ) const;
164
* Returns a human-readable string containing the extent data (without the SRS)
166
std::string toString() const;
169
*Inflates this GeoExtent by the given ratios
171
void scale(double x_scale, double y_scale);
174
* Expands the extent by x and y.
176
void expand( double x, double y );
179
*Gets the area of this GeoExtent
184
static GeoExtent INVALID;
187
osg::ref_ptr<const SpatialReference> _srs;
188
double _xmin, _ymin, _xmax, _ymax;
192
* A geospatial area with tile data LOD extents
194
class OSGEARTH_EXPORT DataExtent : public GeoExtent
197
DataExtent(const GeoExtent& extent, unsigned int minLevel, unsigned int maxLevel);
199
/** The minimum LOD of the extent */
200
unsigned int getMinLevel() const;
202
/** The maximum LOD of the extent */
203
unsigned int getMaxLevel() const;
206
unsigned int _minLevel;
207
unsigned int _maxLevel;
210
typedef std::vector< DataExtent > DataExtentList;
214
* A georeferenced image; i.e. an osg::Image and an associated GeoExtent with SRS.
216
class OSGEARTH_EXPORT GeoImage
219
/** Construct an empty (invalid) geoimage. */
223
* Constructs a new goereferenced image.
225
GeoImage( osg::Image* image, const GeoExtent& extent );
227
static GeoImage INVALID;
231
* True if this is a valid geo image.
233
bool valid() const { return _image.valid(); }
236
* Gets a pointer to the underlying OSG image.
238
osg::Image* getImage() const;
241
* Gets the geospatial extent of the image.
243
const GeoExtent& getExtent() const;
246
* Shortcut to get the spatial reference system describing
247
* the projection of the image.
249
const SpatialReference* getSRS() const;
252
* Crops the image to a new geospatial extent.
255
* New extent to which to crop the image.
257
* If "exact" is true, the output image will have exactly the extents requested;
258
* this process may require resampling and will therefore be more expensive. If
259
* "exact" is false, we do a simple crop of the image that is rounded to the nearest
260
* pixel. The resulting extent will be close but usually not exactly what was
261
* requested - however, this method is faster.
262
* @param width, height
263
* New pixel size for the output image. By default, the method will automatically
264
* calculate a new pixel size.
267
const GeoExtent& extent,
269
unsigned int width = 0,
270
unsigned int height = 0) const;
273
* Warps the image into a new spatial reference system.
276
* SRS into which to warp the image.
278
* Supply this extent if you wish to warp AND crop the image in one step. This is
279
* faster than calling reproject() and then crop().
280
* @param width, height
281
* New pixel size for the output image. Be default, the method will automatically
282
* calculate a new pixel size.
285
const SpatialReference* to_srs,
286
const GeoExtent* to_extent = 0,
287
unsigned int width = 0,
288
unsigned int height = 0) const;
291
* Adds a one-pixel transparent border around an image.
293
GeoImage addTransparentBorder(
294
bool leftBorder=true,
295
bool rightBorder=true,
296
bool bottomBorder=true,
297
bool topBorder=true);
300
* Returns the underlying OSG image and releases the reference pointer.
302
osg::Image* takeImage();
305
* Gets the units per pixel of this geoimage
307
double getUnitsPerPixel() const;
310
osg::ref_ptr<osg::Image> _image;
314
typedef std::vector<GeoImage> GeoImageVector;
317
* A georeferenced heightfield.
319
class OSGEARTH_EXPORT GeoHeightField
322
/** Constructs an empty (invalid) heightfield. */
326
* Constructs a new georeferenced heightfield.
329
osg::HeightField* heightField,
330
const GeoExtent& extent,
331
const VerticalSpatialReference* vsrs);
333
static GeoHeightField INVALID;
336
* True if this is a valid heightfield.
338
bool valid() const { return _heightField.valid(); }
341
* Gets the elevation value at a specified point.
344
* Spatial reference of the query coordinates. (If you pass in NULL, the method
345
* will assume that the SRS is equivalent to that of the GeoHeightField. Be sure
346
* this is case of you will get incorrect results.)
348
* Coordinates at which to query the elevation value.
350
* Interpolation method for the elevation query.
352
* Convert the output elevation value to this VSRS (NULL to ignore)
353
* @param out_elevation
354
* Output: the elevation value
356
* True if the elevation query was succesful; false if not (e.g. if the query
357
* fell outside the geospatial extent of the heightfield)
360
const SpatialReference* inputSRS,
362
ElevationInterpolation interp,
363
const VerticalSpatialReference* outputVSRS,
364
float& out_elevation ) const;
367
* Subsamples the heightfield, returning a new heightfield corresponding to
368
* the destEx extent. The destEx must be a smaller, inset area of sourceEx.
370
GeoHeightField createSubSample( const GeoExtent& destEx, ElevationInterpolation interpolation) const;
373
* Gets the geospatial extent of the heightfield.
375
const GeoExtent& getExtent() const;
378
* Gets a pointer to the underlying OSG heightfield.
380
const osg::HeightField* getHeightField() const;
381
osg::HeightField* getHeightField();
384
* Gets a pointer to the underlying OSG heightfield, and releases the internal reference.
386
osg::HeightField* takeHeightField();
389
osg::ref_ptr<osg::HeightField> _heightField;
391
osg::ref_ptr<const VerticalSpatialReference> _vsrs;
394
typedef std::vector<GeoHeightField> GeoHeightFieldVector;
398
* A representation of the surface of the earth based on a grid of
399
* height values that are relative to a reference ellipsoid.
401
class OSGEARTH_EXPORT Geoid : public osg::Referenced
406
/** Gets the readable name of this geoid. */
407
void setName( const std::string& value );
408
const std::string& getName() const { return _name; }
410
/** Sets the underlying heightfield data */
411
void setHeightField( const GeoHeightField& hf );
413
/** Queries to geoid for the height offset at the specified coordinates. */
415
double lat_deg, double lon_deg,
416
const ElevationInterpolation& interp =INTERP_BILINEAR) const;
418
/** The linear units in which height values are expressed. */
419
const Units& getUnits() const { return _units; }
420
void setUnits( const Units& value );
422
/** Whether this is a valid object to use */
423
bool isValid() const { return _valid; }
425
/** True if two geoids are mathmatically equivalent. */
426
bool isEquivalentTo( const Geoid& rhs ) const;
438
#endif // OSGEARTH_GEODATA_H