Skip to content
Permalink
Browse files

[Server][WFS] Update QgsWfsParameters for GetFeature

  • Loading branch information
rldhont committed Oct 12, 2017
1 parent 5d2c035 commit 44754edf16f8a1e8cd33c3309857850eeb868e87
Showing with 359 additions and 4 deletions.
  1. +261 −1 src/server/services/wfs/qgswfsparameters.cpp
  2. +98 −3 src/server/services/wfs/qgswfsparameters.h
@@ -34,15 +34,92 @@ namespace QgsWfs
};
save( pOutputFormat );

const Parameter pResultType = { ParameterName::RESULTTYPE,
QVariant::String,
QVariant( "" ),
QVariant()
};
save( pResultType );

const Parameter pPropertyName = { ParameterName::PROPERTYNAME,
QVariant::String,
QVariant( "" ),
QVariant()
};
save( pPropertyName );

const Parameter pMaxFeatures = { ParameterName::MAXFEATURES,
QVariant::Int,
QVariant( -1 ),
QVariant()
};
save( pMaxFeatures );

const Parameter pStartIndex = { ParameterName::STARTINDEX,
QVariant::Int,
QVariant( 0 ),
QVariant()
};
save( pStartIndex );

const Parameter pSrsName = { ParameterName::SRSNAME,
QVariant::String,
QVariant( "" ),
QVariant()
};
save( pSrsName );

const Parameter pTypeName = { ParameterName::TYPENAME,
QVariant::String,
QVariant( "" ),
QVariant()
};
save( pTypeName );

const Parameter pFeatureId = { ParameterName::FEATUREID,
QVariant::String,
QVariant( "" ),
QVariant()
};
save( pFeatureId );

const Parameter pFilter = { ParameterName::FILTER,
QVariant::String,
QVariant( "" ),
QVariant()
};
save( pFilter );

const Parameter pBbox = { ParameterName::BBOX,
QVariant::String,
QVariant( "" ),
QVariant()
};
save( pBbox );

const Parameter pSortBy = { ParameterName::SORTBY,
QVariant::String,
QVariant( "" ),
QVariant()
};
save( pSortBy );

const Parameter pExpFilter = { ParameterName::EXP_FILTER,
QVariant::String,
QVariant( "" ),
QVariant()
};
save( pExpFilter );

const Parameter pGeometryName = { ParameterName::GEOMETRYNAME,
QVariant::String,
QVariant( "" ),
QVariant()
};
save( pGeometryName );
}

QgsWfsParameters::QgsWfsParameters( const QgsServerRequest::Parameters &parameters )
QgsWfsParameters::QgsWfsParameters( const QgsServerRequest::Parameters &parameters ) : QgsWfsParameters()
{
load( parameters );
}
@@ -144,11 +221,81 @@ namespace QgsWfs
return f;
}

QString QgsWfsParameters::resultTypeAsString() const
{
return value( ParameterName::RESULTTYPE ).toString();
}

QStringList QgsWfsParameters::propertyNames() const
{
return toStringListWithExp( ParameterName::PROPERTYNAME );
}

QString QgsWfsParameters::maxFeatures() const
{
return value( ParameterName::MAXFEATURES ).toString();
}

int QgsWfsParameters::maxFeaturesAsInt() const
{
return toInt( ParameterName::MAXFEATURES );
}

QString QgsWfsParameters::startIndex() const
{
return value( ParameterName::STARTINDEX ).toString();
}

int QgsWfsParameters::startIndexAsInt() const
{
return toInt( ParameterName::STARTINDEX );
}

QString QgsWfsParameters::srsName() const
{
return value( ParameterName::SRSNAME ).toString();
}

QStringList QgsWfsParameters::typeNames() const
{
return toStringList( ParameterName::TYPENAME );
}

QStringList QgsWfsParameters::featureIds() const
{
return toStringList( ParameterName::FEATUREID );
}

QStringList QgsWfsParameters::filters() const
{
return toStringListWithExp( ParameterName::FILTER );
}

QString QgsWfsParameters::bbox() const
{
return value( ParameterName::BBOX ).toString();
}

QgsRectangle QgsWfsParameters::bboxAsRectangle() const
{
return toRectangle( ParameterName::BBOX );
}

QStringList QgsWfsParameters::sortBy() const
{
return toStringListWithExp( ParameterName::SORTBY );
}

QStringList QgsWfsParameters::expFilters() const
{
return toStringListWithExp( ParameterName::EXP_FILTER );
}

QString QgsWfsParameters::geometryNameAsString() const
{
return value( ParameterName::GEOMETRYNAME ).toString();
}

QString QgsWfsParameters::request() const
{
if ( mRequestParameters.contains( "REQUEST" ) )
@@ -186,6 +333,119 @@ namespace QgsWfs
return metaEnum.valueToKey( name );
}

int QgsWfsParameters::toInt( const QVariant &value, const QVariant &defaultValue, bool *error ) const
{
int val = defaultValue.toInt();
QString valStr = value.toString();
bool ok = true;

if ( !valStr.isEmpty() )
{
val = value.toInt( &ok );
}
*error = !ok;

return val;
}

int QgsWfsParameters::toInt( ParameterName p ) const
{
bool error;
int val = toInt( value( p ), defaultValue( p ), &error );
if ( error )
{
QString n = name( p );
QString valStr = value( p ).toString();
QString msg = n + " ('" + valStr + "') cannot be converted into int";
raiseError( msg );
}

return val;
}

QgsRectangle QgsWfsParameters::toRectangle( const QVariant &value, bool *error ) const
{
*error = false;
QString bbox = value.toString();
QgsRectangle extent;

if ( !bbox.isEmpty() )
{
QStringList corners = bbox.split( "," );

if ( corners.size() == 4 )
{
double d[4];
bool ok;

for ( int i = 0; i < 4; i++ )
{
corners[i].replace( QLatin1String( " " ), QLatin1String( "+" ) );
d[i] = corners[i].toDouble( &ok );
if ( !ok )
{
*error = !ok;
return extent;
}
}

extent = QgsRectangle( d[0], d[1], d[2], d[3] );
}
else
{
*error = true;
return extent;
}
}

return extent;
}

QgsRectangle QgsWfsParameters::toRectangle( ParameterName p ) const
{
bool error;
QgsRectangle extent = toRectangle( value( p ), &error );
if ( error )
{
QString n = name( p );
QString valStr = value( p ).toString();
QString msg = n + " ('" + valStr + "') cannot be converted into a rectangle";
raiseError( msg );
}

return extent;
}

QStringList QgsWfsParameters::toStringList( ParameterName p, char delimiter ) const
{
return value( p ).toString().split( delimiter, QString::SkipEmptyParts );
}

QStringList QgsWfsParameters::toStringListWithExp( ParameterName p, const QString &exp ) const
{
QStringList theList;

QString val = value( p ).toString();
if ( val.isEmpty() )
return theList;

QRegExp rx( exp );
if ( rx.indexIn( val, 0 ) == -1 )
{
theList << val;
}
else
{
int pos = 0;
while ( ( pos = rx.indexIn( val, pos ) ) != -1 )
{
theList << rx.cap( 1 );
pos += rx.matchedLength();
}
}
return theList;
}

void QgsWfsParameters::log( const QString &msg ) const
{
QgsMessageLog::logMessage( msg, "Server", QgsMessageLog::INFO );

0 comments on commit 44754ed

Please sign in to comment.
You can’t perform that action at this time.