osgEarth 2.1.1

/home/cube/sources/osgearth/src/osgEarthSymbology/Query.cpp

Go to the documentation of this file.
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 #include <osgEarthSymbology/Query>
00020 
00021 using namespace osgEarth;
00022 using namespace osgEarth::Symbology;
00023 
00024 Query::Query( const Config& conf )
00025 {
00026     mergeConfig( conf );
00027 }
00028 
00029 void
00030 Query::mergeConfig( const Config& conf )
00031 {
00032     if ( !conf.getIfSet( "expr", _expression ) )
00033         if ( !conf.getIfSet( "where", _expression ) )
00034             if ( !conf.getIfSet( "sql", _expression ) )
00035                 conf.getIfSet( "expression", _expression );
00036 
00037     Config b = conf.child( "extent" );
00038     if( !b.empty() )
00039     {
00040         _bounds = Bounds(
00041             b.value<double>( "xmin", 0.0 ),
00042             b.value<double>( "ymin", 0.0 ),
00043             b.value<double>( "xmax", 0.0 ),
00044             b.value<double>( "ymax", 0.0 ) );
00045     }
00046 }
00047 
00048 Config
00049 Query::getConfig() const
00050 {
00051     Config conf( "query" );
00052     conf.addIfSet( "expr", _expression );
00053     if ( _bounds.isSet() ) {
00054         Config bc( "extent" );
00055         bc.add( "xmin", toString(_bounds->xMin()) );
00056         bc.add( "ymin", toString(_bounds->yMin()) );
00057         bc.add( "xmax", toString(_bounds->xMax()) );
00058         bc.add( "ymax", toString(_bounds->yMax()) );
00059         conf.add( bc );
00060     }
00061     return conf;
00062 }
00063 
00064 Query
00065 Query::combineWith( const Query& rhs ) const
00066 {
00067     Query merged;
00068 
00069     // merge the expressions:
00070 
00071     bool lhsEmptyExpr = !_expression.isSet() || _expression->empty();
00072     bool rhsEmptyExpr = !rhs.expression().isSet() || rhs.expression()->empty();
00073 
00074     if ( !lhsEmptyExpr && !rhsEmptyExpr )
00075     {
00076         std::stringstream buf;
00077         buf << "( " << *_expression << " ) AND ( " << *rhs.expression() << " )";
00078         std::string str = buf.str();
00079         merged.expression() = str;
00080     }
00081     else if ( lhsEmptyExpr && !rhsEmptyExpr )
00082     {
00083         merged.expression() = *rhs.expression();
00084     }
00085     else if ( !lhsEmptyExpr && rhsEmptyExpr )
00086     {
00087         merged.expression() = *_expression;
00088     }
00089 
00090     // merge the bounds:
00091     if ( bounds().isSet() && rhs.bounds().isSet() )
00092     {
00093         merged.bounds() = bounds()->intersectionWith( *rhs.bounds() );
00094     }
00095     else if ( bounds().isSet() )
00096     {
00097         merged.bounds() = *bounds();
00098     }
00099     else if ( rhs.bounds().isSet() )
00100     {
00101         merged.bounds() = *rhs.bounds();
00102     }
00103 
00104     return merged;
00105 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines