osgEarth 2.1.1
|
00001 /* -*-c++-*- */ 00002 /* osgEarth - Dynamic map generation toolkit for OpenSceneGraph 00003 * Copyright 2008-2010 Pelican Mapping 00004 * http://osgearth.org 00005 * 00006 * osgEarth is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU Lesser General Public License as published by 00008 * the Free Software Foundation; either version 2 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public License 00017 * along with this program. If not, see <http://www.gnu.org/licenses/> 00018 */ 00019 #ifndef OSGEARTH_DRIVER_OGR_FEATURE_SOURCE_OPTIONS 00020 #define OSGEARTH_DRIVER_OGR_FEATURE_SOURCE_OPTIONS 1 00021 00022 #include <osgEarth/Common> 00023 #include <osgEarthFeatures/FeatureSource> 00024 00025 namespace osgEarth { namespace Drivers 00026 { 00027 using namespace osgEarth; 00028 using namespace osgEarth::Features; 00029 00030 class OGRFeatureOptions : public FeatureSourceOptions // NO EXPORT; header only 00031 { 00032 public: 00033 optional<URI>& url() { return _url; } 00034 const optional<URI>& url() const { return _url; } 00035 00036 optional<std::string>& connection() { return _connection; } 00037 const optional<std::string>& connection() const { return _connection; } 00038 00039 optional<std::string>& ogrDriver() { return _ogrDriver; } 00040 const optional<std::string>& ogrDriver() const { return _ogrDriver; } 00041 00042 optional<bool>& buildSpatialIndex() { return _buildSpatialIndex; } 00043 const optional<bool>& buildSpatialIndex() const { return _buildSpatialIndex; } 00044 00045 optional<Config>& geometryConfig() { return _geometryConf; } 00046 const optional<Config>& geometryConfig() const { return _geometryConf; } 00047 00048 optional<std::string>& geometryUrl() { return _geometryUrl; } 00049 const optional<std::string>& geometryUrl() const { return _geometryUrl; } 00050 00051 // does not serialize 00052 osg::ref_ptr<Symbology::Geometry>& geometry() { return _geometry; } 00053 const osg::ref_ptr<Symbology::Geometry>& geometry() const { return _geometry; } 00054 00055 public: 00056 OGRFeatureOptions( const ConfigOptions& opt =ConfigOptions() ) : FeatureSourceOptions( opt ) { 00057 setDriver( "ogr" ); 00058 fromConfig( _conf ); 00059 } 00060 00061 public: 00062 Config getConfig() const { 00063 Config conf = FeatureSourceOptions::getConfig(); 00064 conf.updateIfSet( "url", _url ); 00065 conf.updateIfSet( "connection", _connection ); 00066 conf.updateIfSet( "ogr_driver", _ogrDriver ); 00067 conf.updateIfSet( "build_spatial_index", _buildSpatialIndex ); 00068 conf.updateIfSet( "geometry", _geometryConf ); 00069 conf.updateIfSet( "geometry_url", _geometryUrl ); 00070 conf.updateNonSerializable( "OGRFeatureOptions::geometry", _geometry.get() ); 00071 return conf; 00072 } 00073 00074 protected: 00075 void mergeConfig( const Config& conf ) { 00076 FeatureSourceOptions::mergeConfig( conf ); 00077 fromConfig( conf ); 00078 } 00079 00080 private: 00081 void fromConfig( const Config& conf ) { 00082 conf.getIfSet( "url", _url ); 00083 conf.getIfSet( "connection", _connection ); 00084 conf.getIfSet( "ogr_driver", _ogrDriver ); 00085 conf.getIfSet( "build_spatial_index", _buildSpatialIndex ); 00086 conf.getIfSet( "geometry", _geometryConf ); 00087 conf.getIfSet( "geometry_url", _geometryUrl ); 00088 _geometry = conf.getNonSerializable<Symbology::Geometry>( "OGRFeatureOptions::geometry" ); 00089 } 00090 00091 optional<URI> _url; 00092 optional<std::string> _connection; 00093 optional<std::string> _ogrDriver; 00094 optional<bool> _buildSpatialIndex; 00095 optional<Config> _geometryConf; 00096 optional<Config> _geometryProfileConf; 00097 optional<std::string> _geometryUrl; 00098 osg::ref_ptr<Symbology::Geometry> _geometry; 00099 }; 00100 00101 } } // namespace osgEarth::Drivers 00102 00103 #endif // OSGEARTH_DRIVER_OGR_FEATURE_SOURCE_OPTIONS 00104