osgEarth 2.1.1
|
Public Member Functions | |
WFSFeatureSource (const WFSFeatureOptions &options) | |
virtual | ~WFSFeatureSource () |
void | initialize (const std::string &referenceURI) |
const FeatureProfile * | createFeatureProfile () |
void | saveResponse (HTTPResponse &response, const std::string &filename) |
std::string | getExtensionForMimeType (const std::string &mime) |
void | getFeatures (HTTPResponse &response, FeatureList &features) |
std::string | createURL (const Symbology::Query &query) |
FeatureCursor * | createFeatureCursor (const Symbology::Query &query) |
virtual bool | deleteFeature (FeatureID fid) |
virtual int | getFeatureCount () const |
virtual bool | insertFeature (Feature *feature) |
virtual Feature * | getFeature (FeatureID fid) |
virtual bool | isWritable () const |
virtual const FeatureSchema & | getSchema () const |
virtual osgEarth::Symbology::Geometry::Type | getGeometryType () const |
Private Attributes | |
const WFSFeatureOptions | _options |
osg::ref_ptr< WFSCapabilities > | _capabilities |
FeatureSchema | _schema |
A FeatureSource that reads features from a WFS layer
This FeatureSource does NOT support styling.
Definition at line 93 of file FeatureSourceWFS.cpp.
WFSFeatureSource::WFSFeatureSource | ( | const WFSFeatureOptions & | options | ) | [inline] |
Definition at line 96 of file FeatureSourceWFS.cpp.
: FeatureSource( options ), _options( options ) { }
virtual WFSFeatureSource::~WFSFeatureSource | ( | ) | [inline, virtual] |
Destruct the object, cleaning up and OGR handles.
Definition at line 102 of file FeatureSourceWFS.cpp.
{ }
FeatureCursor* WFSFeatureSource::createFeatureCursor | ( | const Symbology::Query & | query | ) | [inline, virtual] |
Creates a cursor that iterates over all the features corresponding to the specified query.
Caller takes ownership of the returned object.
Implements osgEarth::Features::FeatureSource.
Definition at line 282 of file FeatureSourceWFS.cpp.
{ std::string url = createURL( query ); OE_DEBUG << LC << "URL: " << url << std::endl; HTTPResponse response = HTTPClient::get(url); FeatureList features; if (response.isOK()) { getFeatures(response, features); std::string data = response.getPartAsString(0); } else { OE_INFO << "Error getting url " << url << std::endl; } return new FeatureListCursor( features ); }
const FeatureProfile* WFSFeatureSource::createFeatureProfile | ( | ) | [inline, virtual] |
Called once at startup to create the profile for this feature set. Successful profile creation implies that the datasource opened succesfully.
Implements osgEarth::Features::FeatureSource.
Definition at line 134 of file FeatureSourceWFS.cpp.
{ FeatureProfile* result = NULL; if (_capabilities.valid()) { //Find the feature type by name osg::ref_ptr< WFSFeatureType > featureType = _capabilities->getFeatureTypeByName( _options.typeName().get() ); if (featureType.valid()) { if (featureType->getExtent().isValid()) { result = new FeatureProfile(featureType->getExtent()); if (featureType->getTiled()) { result->setTiled( true ); result->setFirstLevel( featureType->getFirstLevel() ); result->setMaxLevel( featureType->getMaxLevel() ); result->setProfile( osgEarth::Profile::create(osgEarth::SpatialReference::create("epsg:4326"), featureType->getExtent().xMin(), featureType->getExtent().yMin(), featureType->getExtent().xMax(), featureType->getExtent().yMax(), 0, 1, 1) ); } } } } if (!result) { result = new FeatureProfile(GeoExtent(SpatialReference::create( "epsg:4326" ), -180, -90, 180, 90)); } return result; }
std::string WFSFeatureSource::createURL | ( | const Symbology::Query & | query | ) | [inline] |
Definition at line 252 of file FeatureSourceWFS.cpp.
{ std::stringstream buf; buf << _options.url()->full() << "?SERVICE=WFS&VERSION=1.0.0&REQUEST=getfeature"; buf << "&TYPENAME=" << _options.typeName().get(); std::string outputFormat = "geojson"; if (_options.outputFormat().isSet()) outputFormat = _options.outputFormat().get(); buf << "&OUTPUTFORMAT=" << outputFormat; if (_options.maxFeatures().isSet()) { buf << "&MAXFEATURES=" << _options.maxFeatures().get(); } if (query.tileKey().isSet()) { buf << "&Z=" << query.tileKey().get().getLevelOfDetail() << "&X=" << query.tileKey().get().getTileX() << "&Y=" << query.tileKey().get().getTileY(); } else if (query.bounds().isSet()) { buf << "&BBOX=" << query.bounds().get().xMin() << "," << query.bounds().get().yMin() << "," << query.bounds().get().xMax() << "," << query.bounds().get().yMax(); } return buf.str(); }
virtual bool WFSFeatureSource::deleteFeature | ( | FeatureID | fid | ) | [inline, virtual] |
Deletes the feature with the given FID
Reimplemented from osgEarth::Features::FeatureSource.
Definition at line 300 of file FeatureSourceWFS.cpp.
{ return false; }
std::string WFSFeatureSource::getExtensionForMimeType | ( | const std::string & | mime | ) | [inline] |
Definition at line 182 of file FeatureSourceWFS.cpp.
{ //OGR is particular sometimes about the extension of files when it's reading them so it's good to have //the temp file have an appropriate extension if ((mime.compare("text/xml") == 0) || (mime.compare("text/xml; subtype=gml/2.1.2") == 0) || (mime.compare("text/xml; subtype=gml/3.1.1") == 0) ) { return ".xml"; } else if ((mime.compare("application/json") == 0) || (mime.compare("json") == 0) || (mime.compare("application/x-javascript") == 0) || (mime.compare("text/javascript") == 0) || (mime.compare("text/x-javascript") == 0) || (mime.compare("text/x-json") == 0) ) { return ".json"; } return ""; }
Gets the Feature with the given FID
Reimplemented from osgEarth::Features::FeatureSource.
Definition at line 320 of file FeatureSourceWFS.cpp.
{
return 0;
}
virtual int WFSFeatureSource::getFeatureCount | ( | ) | const [inline, virtual] |
Gets the number of features in this FeatureSource
Reimplemented from osgEarth::Features::FeatureSource.
Definition at line 305 of file FeatureSourceWFS.cpp.
{
return -1;
}
void WFSFeatureSource::getFeatures | ( | HTTPResponse & | response, |
FeatureList & | features | ||
) | [inline] |
Definition at line 207 of file FeatureSourceWFS.cpp.
{ //OE_NOTICE << "mimetype=" << response.getMimeType() << std::endl; //TODO: Handle more than just geojson... std::string ext = getExtensionForMimeType(response.getMimeType()); //Save the response to a temp file std::string tmpPath = getTempPath(); std::string name = getTempName(tmpPath, ext); saveResponse(response, name ); //OE_NOTICE << "Saving to " << name << std::endl; //OGRDataSourceH ds = OGROpen(name.c_str(), FALSE, &driver); OGRDataSourceH ds = OGROpen(name.c_str(), FALSE, NULL); if (!ds) { OE_NOTICE << "Error opening data with contents " << std::endl << response.getPartAsString(0) << std::endl; } OGRLayerH layer = OGR_DS_GetLayer(ds, 0); //Read all the features if (layer) { OGR_L_ResetReading(layer); OGRFeatureH feat_handle; while ((feat_handle = OGR_L_GetNextFeature( layer )) != NULL) { if ( feat_handle ) { Feature* f = OgrUtils::createFeature( feat_handle ); if ( f ) { features.push_back( f ); } OGR_F_Destroy( feat_handle ); } } } //Destroy the datasource OGR_DS_Destroy( ds ); //Remove the temporary file remove( name.c_str() ); }
virtual osgEarth::Symbology::Geometry::Type WFSFeatureSource::getGeometryType | ( | ) | const [inline, virtual] |
Gets the Geometry type of the FeatureSource
Reimplemented from osgEarth::Features::FeatureSource.
Definition at line 336 of file FeatureSourceWFS.cpp.
{
return Geometry::TYPE_UNKNOWN;
}
virtual const FeatureSchema& WFSFeatureSource::getSchema | ( | ) | const [inline, virtual] |
Gets the FeatureSchema for this FeatureSource. If the schema doesn't publish a source, this might be empty.
Reimplemented from osgEarth::Features::FeatureSource.
Definition at line 330 of file FeatureSourceWFS.cpp.
{ //TODO: Populate the schema from the DescribeFeatureType call return _schema; }
void WFSFeatureSource::initialize | ( | const std::string & | referenceURI | ) | [inline, virtual] |
Initialize the FeatureSource. The profile should be computed and set here using setProfile()
Implements osgEarth::Features::FeatureSource.
Definition at line 107 of file FeatureSourceWFS.cpp.
{ char sep = _options.url()->full().find_first_of('?') == std::string::npos? '?' : '&'; std::string capUrl; if ( capUrl.empty() ) { capUrl = _options.url()->full() + sep + "SERVICE=WFS&VERSION=1.0.0&REQUEST=GetCapabilities"; } _capabilities = WFSCapabilitiesReader::read( capUrl, 0L ); if ( !_capabilities.valid() ) { OE_WARN << "[osgEarth::WFS] Unable to read WFS GetCapabilities." << std::endl; //return; } else { OE_NOTICE << "[osgEarth::WFS] Got capabilities from " << capUrl << std::endl; } }
virtual bool WFSFeatureSource::insertFeature | ( | Feature * | feature | ) | [inline, virtual] |
Inserts the given feature into the FeatureSource
Reimplemented from osgEarth::Features::FeatureSource.
Definition at line 310 of file FeatureSourceWFS.cpp.
{ return false; }
virtual bool WFSFeatureSource::isWritable | ( | ) | const [inline, virtual] |
Whether this FeatureSource supports inserting and deleting features
Reimplemented from osgEarth::Features::FeatureSource.
Definition at line 325 of file FeatureSourceWFS.cpp.
{ return false; }
void WFSFeatureSource::saveResponse | ( | HTTPResponse & | response, |
const std::string & | filename | ||
) | [inline] |
Definition at line 165 of file FeatureSourceWFS.cpp.
{ std::ofstream fout; fout.open(filename.c_str(), std::ios::out | std::ios::binary); std::istream& input_stream = response.getPartStream(0); input_stream.seekg (0, std::ios::end); int length = input_stream.tellg(); input_stream.seekg (0, std::ios::beg); char *buffer = new char[length]; input_stream.read(buffer, length); fout.write(buffer, length); delete[] buffer; fout.close(); }
osg::ref_ptr< WFSCapabilities > WFSFeatureSource::_capabilities [private] |
Definition at line 345 of file FeatureSourceWFS.cpp.
const WFSFeatureOptions WFSFeatureSource::_options [private] |
Reimplemented from osgEarth::Features::FeatureSource.
Definition at line 344 of file FeatureSourceWFS.cpp.
FeatureSchema WFSFeatureSource::_schema [private] |
Definition at line 346 of file FeatureSourceWFS.cpp.