osgEarth 2.1.1
Public Member Functions | Private Member Functions | Private Attributes

WCS11Source Class Reference

#include <WCS11Source.h>

Inheritance diagram for WCS11Source:
Collaboration diagram for WCS11Source:

List of all members.

Public Member Functions

 WCS11Source (const TileSourceOptions &opt)
osg::Image * createImage (const TileKey &key, ProgressCallback *progress=0)
osg::HeightField * createHeightField (const TileKey &key, ProgressCallback *progress=0)
std::string getExtension () const
void initialize (const std::string &referenceURI, const Profile *overrideProfile)

Private Member Functions

HTTPRequest createRequest (const TileKey &key) const

Private Attributes

const WCSOptions _options
std::string _covFormat
std::string _osgFormat

Detailed Description

Definition at line 35 of file WCS11Source.h.


Constructor & Destructor Documentation

WCS11Source::WCS11Source ( const TileSourceOptions opt)

Definition at line 32 of file WCS11Source.cpp.

                                                           :
TileSource( options ),
_options(options)
{
    _covFormat = _options.format().value();
    
    if ( _covFormat.empty() )
        _covFormat = "image/GeoTIFF";

    _osgFormat = "tif";
}

Here is the call graph for this function:


Member Function Documentation

osg::HeightField * WCS11Source::createHeightField ( const TileKey key,
ProgressCallback progress = 0 
) [virtual]

Creates a heightfield for the given TileKey The returned object is new and is the responsibility of the caller.

Reimplemented from osgEarth::TileSource.

Definition at line 113 of file WCS11Source.cpp.

{
    osg::HeightField* field = NULL;

    osg::ref_ptr<osg::Image> image = createImage( key, progress );
    if ( image.valid() )
    {        
        ImageToHeightFieldConverter conv;
        conv.setRemoveNoDataValues( true );
        field = conv.convert( image.get() );
    }

    return field;
}

Here is the call graph for this function:

osg::Image * WCS11Source::createImage ( const TileKey key,
ProgressCallback progress = 0 
) [virtual]

Creates an image for the given TileKey. The returned object is new and is the responsibility of the caller.

Implements osgEarth::TileSource.

Definition at line 67 of file WCS11Source.cpp.

{
    HTTPRequest request = createRequest( key );

    OE_INFO << "[osgEarth::WCS1.1] Key=" << key.str() << " URL = " << request.getURL() << std::endl;

    double lon0,lat0,lon1,lat1;
    key.getExtent().getBounds( lon0, lat0, lon1, lat1 );

    // download the data
    HTTPResponse response = HTTPClient::get( request, 0L, progress ); //getOptions(), progress );
    if ( !response.isOK() )
    {
        OE_WARN << "[osgEarth::WCS1.1] WARNING: HTTP request failed" << std::endl;
        return NULL;
    }

    //TODO:  Make WCS driver use progress callback
    unsigned int part_num = response.getNumParts() > 1? 1 : 0;
    std::istream& input_stream = response.getPartStream( part_num );

    //TODO: un-hard-code TIFFs
    osgDB::ReaderWriter* reader = osgDB::Registry::instance()->getReaderWriterForExtension( "tiff" );

    if ( !reader )
    {
        OE_NOTICE << "[osgEarth::WCS1.1] WARNING: no reader for \"tiff\"" << std::endl;
        return NULL;
    }

    osgDB::ReaderWriter::ReadResult result = reader->readImage( input_stream ); //, getOptions() );
    if ( !result.success() )
    {
        OE_NOTICE << "[osgEarth::WCS1.1] WARNING: readImage() failed for Reader " << reader->getName() << std::endl;
        return NULL;
    }

    osg::Image* image = result.getImage();
    //OE_NOTICE << "Returned grid is " << image->s() << "x" << image->t() << std::endl;
    if ( image ) image->ref();
    return image;
}

Here is the call graph for this function:

Here is the caller graph for this function:

HTTPRequest WCS11Source::createRequest ( const TileKey key) const [private]

Definition at line 147 of file WCS11Source.cpp.

{
    std::stringstream buf;

    double lon_min, lat_min, lon_max, lat_max;
    key.getExtent().getBounds( lon_min, lat_min, lon_max, lat_max );

    int lon_samples = _options.tileSize().value();
    int lat_samples = _options.tileSize().value();
    double lon_interval = (lon_max-lon_min)/(double)(lon_samples-1);
    double lat_interval = (lat_max-lat_min)/(double)(lat_samples-1);

    HTTPRequest req( _options.url()->full() );

    req.addParameter( "SERVICE",    "WCS" );
    req.addParameter( "VERSION",    "1.1.0" );
    req.addParameter( "REQUEST",    "GetCoverage" );
    req.addParameter( "IDENTIFIER", _options.identifier().value() );
    req.addParameter( "FORMAT",     _covFormat );

    req.addParameter( "GridBaseCRS", "urn:ogc:def:crs:EPSG::4326" );
    req.addParameter( "GridCS",      "urn:ogc:def:crs:EPSG::4326" );
    req.addParameter( "GridType",    "urn:ogc:def:method:WCS:1.1:2dGridIn2dCrs" );

    // IMPORTANT NOTE:
    //   For WCS1.1+, the BOUNDINGBOX for geographic CRS's (like WGS84) are expressed
    //   at minlat,minlon,maxlat,maxlon instead of the usual minx,miny,maxx,maxy.
    //   So we will somehow need to figure out whether the CRS is geographic.
    //
    // MORE IMPORTANT NOTE:
    //   ESRI's ArcGIS WCS Server doesn't obey the above rule. Their server expects
    //   minx,miny,maxx,maxy no matter what ...

    // Hack to guess whether it's an ArcGIS Server:
    buf.str("");

    //bool use_legacy_geog_bbox_encoding = _url.find( "/MapServer/WCSServer" ) != std::string::npos;
    //if ( use_legacy_geog_bbox_encoding )
    //    buf << lon_min << "," << lat_min << "," << lon_max << "," << lat_max;
    //else
    //    buf << lat_min << "," << lon_min << "," << lat_max << "," << lon_max;
    //buf << ",urn:ogc:def:crs:EPSG::4326";

    double halfLon = lon_interval/2.0;
    double halfLat = lat_interval/2.0;

    //We need to shift the bounding box out by half a pixel in all directions so that the center of the edge pixels lie on
    //the edge of this TileKey's extents.  Doing this makes neighboring tiles have the same elevation values so there is no need
    //to run the tile edge normalization code.
    buf << lon_min - halfLon << "," << lat_min - halfLat << "," << lon_max + halfLon << "," << lat_max + halfLat << ",EPSG:4326";
        std::string bufStr;
        bufStr = buf.str();
    req.addParameter( "BOUNDINGBOX", bufStr );

    double originX = lon_min;
    double originY = lat_max;

    buf.str("");
    buf << originX << "," << originY; 
        bufStr = buf.str();
    req.addParameter( "GridOrigin", bufStr );
    
    buf.str("");
    buf << lon_interval << "," << lat_interval;   // note: top-down
    //buf << lon_interval << "," << lat_interval;
        bufStr = buf.str();
    req.addParameter( "GridOffsets", bufStr );

    if ( !_options.rangeSubset()->empty() )
        req.addParameter( "RangeSubset", _options.rangeSubset().value() );

    return req;
}

Here is the call graph for this function:

Here is the caller graph for this function:

std::string WCS11Source::getExtension ( ) const [virtual]

Gets the preferred extension for this TileSource

Reimplemented from osgEarth::TileSource.

Definition at line 60 of file WCS11Source.cpp.

{
    return "tif";
}
void WCS11Source::initialize ( const std::string &  referenceURI,
const Profile overrideProfile 
) [virtual]

Initialize the TileSource. The profile should be computed and set here using setProfile()

Implements osgEarth::TileSource.

Definition at line 45 of file WCS11Source.cpp.

{
        if (overrideProfile)
        {
                setProfile( overrideProfile );
        }
        else
        {
                //TODO: once we read GetCapabilities.. this will change..
                setProfile(osgEarth::Registry::instance()->getGlobalGeodeticProfile());
        }
}

Here is the call graph for this function:


Member Data Documentation

std::string WCS11Source::_covFormat [private]

Definition at line 55 of file WCS11Source.h.

Reimplemented from osgEarth::TileSource.

Definition at line 54 of file WCS11Source.h.

std::string WCS11Source::_osgFormat [private]

Definition at line 55 of file WCS11Source.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines