/** Called once at startup to create the profile for this feature set. Successful profile creation implies that the datasource opened succesfully. */ const FeatureProfile* createFeatureProfile() { 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; }
/** Called once at startup to create the profile for this feature set. Successful profile creation implies that the datasource opened succesfully. */ const FeatureProfile* createFeatureProfile() { FeatureProfile* result = NULL; if (_layerValid) { result = new FeatureProfile(_layer._extent); result->setTiled( true ); result->setFirstLevel( _layer._firstLevel); result->setMaxLevel( _layer._maxLevel); result->setProfile( osgEarth::Profile::create(osgEarth::SpatialReference::create("epsg:4326"), _layer._extent.xMin(), _layer._extent.yMin(), _layer._extent.xMax(), _layer._extent.yMax(), 1, 1) ); } return result; }
/** Called once at startup to create the profile for this feature set. Successful profile creation implies that the datasource opened succesfully. */ const FeatureProfile* createFeatureProfile() { FeatureProfile* result = NULL; if (_layerValid) { result = new FeatureProfile(_layer.getExtent()); result->setTiled( true ); result->setFirstLevel( _layer.getFirstLevel()); result->setMaxLevel( _layer.getMaxLevel()); result->setProfile( osgEarth::Profile::create(_layer.getSRS(), _layer.getExtent().xMin(), _layer.getExtent().yMin(), _layer.getExtent().xMax(), _layer.getExtent().yMax(), 1, 1) ); } return result; }
/** Called once at startup to create the profile for this feature set. Successful profile creation implies that the datasource opened succesfully. */ const FeatureProfile* createFeatureProfile() { const Profile* wgs84 = Registry::instance()->getGlobalGeodeticProfile(); //GeoExtent extent(wgs84->getSRS(), -180, -90, 0, 90); GeoExtent extent(wgs84->getSRS(), -180, -90, 180, 90); FeatureProfile* profile = new FeatureProfile( extent ); profile->setProfile( Profile::create("wgs84", extent.xMin(), extent.yMin(), extent.xMax(), extent.yMax(), "", 1, 1) ); unsigned int level = *_options.level(); profile->setFirstLevel(level); profile->setMaxLevel(level); profile->setTiled(true); return profile; }
/** Called once at startup to create the profile for this feature set. Successful profile creation implies that the datasource opened succesfully. */ const FeatureProfile* createFeatureProfile() { if ( !_featureProfile.valid() ) { static Threading::Mutex s_mutex; Threading::ScopedMutexLock lock(s_mutex); if ( !_featureProfile.valid() ) { FeatureProfile* result = 0L; 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()); bool disableTiling = _options.disableTiling().isSetTo(true); if (featureType->getTiled() && !disableTiling) { 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(), 1, 1) ); } } } } if (!result) { result = new FeatureProfile(GeoExtent(SpatialReference::create( "epsg:4326" ), -180, -90, 180, 90)); } _featureProfile = result; } } if ( _featureProfile.valid() && _options.geoInterp().isSet() ) { _featureProfile->geoInterp() = _options.geoInterp().get(); } return _featureProfile.get(); }
//override Status initialize(const osgDB::Options* readOptions) { _dbOptions = Registry::cloneOrCreateOptions(readOptions); // Establish the feature profile. const Profile* wgs84 = Registry::instance()->getGlobalGeodeticProfile(); GeoExtent extent(wgs84->getSRS(), -180, -90, 180, 90); FeatureProfile* profile = new FeatureProfile( extent ); profile->setProfile( Profile::create("wgs84", extent.xMin(), extent.yMin(), extent.xMax(), extent.yMax(), "", 1, 1) ); unsigned int level = _options.level().get(); profile->setFirstLevel(level); profile->setMaxLevel(level); profile->setTiled(true); setFeatureProfile(profile); return Status::OK(); }
v8::Handle<v8::Value> JSFeatureProfile::PropertyCallback(v8::Local<v8::String> name, const v8::AccessorInfo& info) { FeatureProfile* profile = V8Util::UnwrapObject<FeatureProfile>(info.Holder()); v8::String::Utf8Value utf8_value(name); std::string prop(*utf8_value); if (!profile || prop.empty()) return v8::Handle<v8::Value>(); if (prop == "extent") return JSGeoExtent::WrapGeoExtent(const_cast<osgEarth::GeoExtent*>(&profile->getExtent())); if (prop == "srs") return JSSpatialReference::WrapSpatialReference(const_cast<osgEarth::SpatialReference*>(profile->getSRS())); return v8::Handle<v8::Value>(); }
/** Called once at startup to create the profile for this feature set. Successful profile creation implies that the datasource opened succesfully. */ const FeatureProfile* createFeatureProfile() { const osgEarth::Profile* profile = osgEarth::Registry::instance()->getSphericalMercatorProfile(); FeatureProfile* result = new FeatureProfile(profile->getExtent()); result->setTiled(true); std::string minLevelStr, maxLevelStr; if (getMetaData("minzoom", minLevelStr) && getMetaData("maxzoom", maxLevelStr)) { _minLevel = as<int>(minLevelStr, 0); _maxLevel = as<int>(maxLevelStr, 0); OE_NOTICE << LC << "Got levels from metadata " << _minLevel << ", " << _maxLevel << std::endl; } else { computeLevels(); OE_NOTICE << LC << "Got levels from database " << _minLevel << ", " << _maxLevel << std::endl; } result->setFirstLevel(_minLevel); result->setMaxLevel(_maxLevel); result->setProfile(profile); result->geoInterp() = osgEarth::GEOINTERP_GREAT_CIRCLE; return result; }
bool getFeatures( const std::string& buffer, const std::string& mimeType, FeatureList& features ) { OGR_SCOPED_LOCK; bool json = isJSON( mimeType ); bool gml = isGML( mimeType ); // find the right driver for the given mime type OGRSFDriverH ogrDriver = json ? OGRGetDriverByName( "GeoJSON" ) : gml ? OGRGetDriverByName( "GML" ) : 0L; // fail if we can't find an appropriate OGR driver: if ( !ogrDriver ) { OE_WARN << LC << "Error reading WFS response; cannot grok content-type \"" << mimeType << "\"" << std::endl; return false; } std::string tmpName; OGRDataSourceH ds = 0; //GML needs to be saved to a temp file to load from disk. GeoJSON can be loaded directly from memory if (gml) { std::string ext = getExtensionForMimeType( mimeType ); //Save the response to a temp file std::string tmpPath = getTempPath(); tmpName = getTempName(tmpPath, ext); saveResponse(buffer, tmpName ); ds = OGROpen( tmpName.c_str(), FALSE, &ogrDriver ); } else if (json) { //Open GeoJSON directly from memory ds = OGROpen( buffer.c_str(), FALSE, &ogrDriver ); } if ( !ds ) { OE_WARN << LC << "Error reading WFS response" << std::endl; return false; } // read the feature data. OGRLayerH layer = OGR_DS_GetLayer(ds, 0); if ( layer ) { FeatureProfile* fp = getFeatureProfile(); const SpatialReference* srs = fp ? fp->getSRS() : 0L; OGR_L_ResetReading(layer); OGRFeatureH feat_handle; while ((feat_handle = OGR_L_GetNextFeature( layer )) != NULL) { if ( feat_handle ) { osg::ref_ptr<Feature> f = OgrUtils::createFeature( feat_handle, srs ); if ( f.valid() && !isBlacklisted(f->getFID()) ) { features.push_back( f.release() ); } OGR_F_Destroy( feat_handle ); } } } // Destroy the datasource OGR_DS_Destroy( ds ); //Delete the temp file if one was created if (!tmpName.empty()) { remove( tmpName.c_str() ); } return true; }
/** Called once at startup to create the profile for this feature set. Successful profile creation implies that the datasource opened succesfully. */ const FeatureProfile* createFeatureProfile() { if ( !_featureProfile.valid() ) { static Threading::Mutex s_mutex; Threading::ScopedMutexLock lock(s_mutex); if ( !_featureProfile.valid() ) { FeatureProfile* result = 0L; _typeName = _options.typeName().get(); if (_capabilities.valid()) { osg::ref_ptr< WFSFeatureType > featureType; if (_options.title().isSet()) { if (_options.typeName().isSet()) { OE_NOTICE << LC << "Both typename and title specified - using title \"" << _options.title().value() << "\"" << std::endl; } featureType = _capabilities->getFeatureTypeByTitle(_options.title().get()); if (featureType) { _typeName = featureType->getName(); OE_INFO << LC << "Matched title \"" << _options.title().value() << "\" to feature type \"" << _typeName << "\"" << std::endl; } else { OE_WARN << LC << "Could not find coverage with title \"" << _options.title().value() << "\"" << std::endl; } } else { featureType = _capabilities->getFeatureTypeByName(_options.typeName().get()); } //Find the feature type by name if (featureType.valid()) { if (featureType->getExtent().isValid()) { result = new FeatureProfile(featureType->getExtent()); bool disableTiling = _options.disableTiling().isSet() && *_options.disableTiling(); if (featureType->getTiled() && !disableTiling) { 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(), 1, 1) ); } } } } if (!result) { result = new FeatureProfile(GeoExtent(SpatialReference::create( "epsg:4326" ), -180, -90, 180, 90)); } _featureProfile = result; } } return _featureProfile.get(); }
/** Called once at startup to create the profile for this feature set. Successful profile creation implies that the datasource opened succesfully. */ const FeatureProfile* createFeatureProfile() { FeatureProfile* result = 0L; // see if we have a custom profile. osg::ref_ptr<const Profile> profile; if ( _options.profile().isSet() ) { profile = Profile::create( *_options.profile() ); } if ( _geometry.valid() ) { // if the user specified explicit geometry, use that and the calculated // extent of the geometry to derive a profile. GeoExtent ex; if ( profile.valid() ) { //ex = profile->getExtent(); ex = GeoExtent(profile->getSRS(), _geometry->getBounds()); } if ( !ex.isValid() ) { // default to WGS84 Lat/Long ex = osgEarth::Registry::instance()->getGlobalGeodeticProfile()->getExtent(); } result = new FeatureProfile( ex ); } else if ( !_source.empty() ) { // otherwise, assume we're loading from the URL: OGR_SCOPED_LOCK; // load up the driver, defaulting to shapefile if unspecified. std::string driverName = _options.ogrDriver().value(); if ( driverName.empty() ) driverName = "ESRI Shapefile"; _ogrDriverHandle = OGRGetDriverByName( driverName.c_str() ); // attempt to open the dataset: int openMode = _options.openWrite().isSet() && _options.openWrite().value() ? 1 : 0; _dsHandle = OGROpen( _source.c_str(), openMode, &_ogrDriverHandle ); if ( _dsHandle ) { if (openMode == 1) _writable = true; _layerHandle = openLayer(_dsHandle, _options.layer().value()); if ( _layerHandle ) { GeoExtent extent; // if the user provided a profile, user that: if ( profile.valid() ) { result = new FeatureProfile( profile->getExtent() ); } else { // extract the SRS and Extent: OGRSpatialReferenceH srHandle = OGR_L_GetSpatialRef( _layerHandle ); if ( srHandle ) { osg::ref_ptr<SpatialReference> srs = SpatialReference::createFromHandle( srHandle, false ); if ( srs.valid() ) { // extract the full extent of the layer: OGREnvelope env; if ( OGR_L_GetExtent( _layerHandle, &env, 1 ) == OGRERR_NONE ) { GeoExtent extent( srs.get(), env.MinX, env.MinY, env.MaxX, env.MaxY ); if ( extent.isValid() ) { // got enough info to make the profile! result = new FeatureProfile( extent ); } else { OE_WARN << LC << "Extent returned from OGR was invalid.\n"; } } } } } // assuming we successfully opened the layer, build a spatial index if requested. if ( _options.buildSpatialIndex() == true ) { if ( (_options.forceRebuildSpatialIndex() == true) || (OGR_L_TestCapability(_layerHandle, OLCFastSpatialFilter) == 0) ) { OE_INFO << LC << "Building spatial index for " << getName() << std::endl; std::stringstream buf; const char* name = OGR_FD_GetName( OGR_L_GetLayerDefn( _layerHandle ) ); buf << "CREATE SPATIAL INDEX ON " << name; std::string bufStr; bufStr = buf.str(); OE_DEBUG << LC << "SQL: " << bufStr << std::endl; OGR_DS_ExecuteSQL( _dsHandle, bufStr.c_str(), 0L, 0L ); } else { OE_INFO << LC << "Use existing spatial index for " << getName() << std::endl; } } //Get the feature count _featureCount = OGR_L_GetFeatureCount( _layerHandle, 1 ); initSchema(); OGRwkbGeometryType wkbType = OGR_FD_GetGeomType( OGR_L_GetLayerDefn( _layerHandle ) ); if ( wkbType == wkbPolygon || wkbType == wkbPolygon25D ) { _geometryType = Geometry::TYPE_POLYGON; } else if ( wkbType == wkbLineString || wkbType == wkbLineString25D ) { _geometryType = Geometry::TYPE_LINESTRING; } else if ( wkbType == wkbLinearRing ) { _geometryType = Geometry::TYPE_RING; } else if ( wkbType == wkbPoint || wkbType == wkbPoint25D ) { _geometryType = Geometry::TYPE_POINTSET; } else if ( wkbType == wkbGeometryCollection || wkbType == wkbGeometryCollection25D || wkbType == wkbMultiPoint || wkbType == wkbMultiPoint25D || wkbType == wkbMultiLineString || wkbType == wkbMultiLineString25D || wkbType == wkbMultiPolygon || wkbType == wkbMultiPolygon25D ) { _geometryType = Geometry::TYPE_MULTI; } } } else { OE_INFO << LC << "failed to open dataset at \"" << _source << "\" error " << CPLGetLastErrorMsg() << std::endl; } } else { OE_INFO << LC << "Feature Source: no valid source data available" << std::endl; } if ( result ) { if ( _options.geoInterp().isSet() ) { result->geoInterp() = _options.geoInterp().get(); } } return result; }
//override Status initialize(const osgDB::Options* readOptions) { // make a local copy of the read options. _readOptions = Registry::cloneOrCreateOptions(readOptions); FeatureProfile* fp = 0L; // Try to read the TFS metadata: _layerValid = TFSReaderWriter::read(_options.url().get(), _readOptions.get(), _layer); if (_layerValid) { OE_INFO << LC << "Read layer TFS " << _layer.getTitle() << " " << _layer.getAbstract() << " " << _layer.getFirstLevel() << " " << _layer.getMaxLevel() << " " << _layer.getExtent().toString() << std::endl; fp = new FeatureProfile(_layer.getExtent()); fp->setTiled( true ); fp->setFirstLevel( _layer.getFirstLevel()); fp->setMaxLevel( _layer.getMaxLevel()); fp->setProfile( osgEarth::Profile::create(_layer.getSRS(), _layer.getExtent().xMin(), _layer.getExtent().yMin(), _layer.getExtent().xMax(), _layer.getExtent().yMax(), 1, 1) ); if ( _options.geoInterp().isSet() ) fp->geoInterp() = _options.geoInterp().get(); } else { // Try to get the results from the settings instead if ( !_options.profile().isSet()) { return Status::Error(Status::ConfigurationError, "TFS driver requires an explicit profile"); } if (!_options.minLevel().isSet() || !_options.maxLevel().isSet()) { return Status::Error(Status::ConfigurationError, "TFS driver requires a min and max level"); } osg::ref_ptr<const Profile> profile = Profile::create( *_options.profile() ); fp = new FeatureProfile(profile->getExtent()); fp->setTiled( true ); fp->setFirstLevel( *_options.minLevel() ); fp->setMaxLevel( *_options.maxLevel() ); fp->setProfile( profile.get() ); if ( _options.geoInterp().isSet() ) fp->geoInterp() = _options.geoInterp().get(); } setFeatureProfile(fp); return Status::OK(); }