Skip to content
Permalink
Browse files
Merge pull request #392 from rldhont/new_vector_api
Update QGIS WFS Server to use the new vector API
  • Loading branch information
rldhont committed Jan 17, 2013
2 parents a6c5fd8 + e12d139 commit 11d5bd38462e0b80c8b760c9b97738e3a0730c7f
Showing with 44 additions and 51 deletions.
  1. +1 −1 src/CMakeLists.txt
  2. +40 −47 src/mapserver/qgswfsserver.cpp
  3. +3 −3 src/mapserver/qgswfsserver.h
@@ -17,7 +17,7 @@ IF (WITH_BINDINGS)
ENDIF (WITH_BINDINGS)

IF (WITH_MAPSERVER)
#ADD_SUBDIRECTORY(mapserver) # TODO: enable again once compilation is fixed
ADD_SUBDIRECTORY(mapserver) # TODO: enable again once compilation is fixed
ENDIF (WITH_MAPSERVER)

IF (WITH_ASTYLE)
@@ -453,7 +453,7 @@ int QgsWFSServer::getFeature( QgsRequestHandler& request, const QString& format
if ( maxFeatures == -1 )
maxFeat += layer->featureCount();

provider->select( attrIndexes, searchRect, mWithGeom, true );
layer->select( attrIndexes, searchRect, mWithGeom, true );

long featCounter = 0;
QDomNodeList filterNodes = queryElem.elementsByTagName( "Filter" );
@@ -476,7 +476,8 @@ int QgsWFSServer::getFeature( QgsRequestHandler& request, const QString& format
fid = fid.section( ".", 1, 1 );
}

provider->featureAtId( fid.toInt(), feature, mWithGeom, attrIndexes );
//Need to be test for propertyname
layer->featureAtId( fid.toInt(), feature, mWithGeom, true );

if ( featureCounter == 0 )
startGetFeature( request, format, layerCrs, &searchRect );
@@ -497,16 +498,16 @@ int QgsWFSServer::getFeature( QgsRequestHandler& request, const QString& format
if ( childElem.tagName() == "Box" )
{
QgsRectangle* rect = new QgsRectangle( childElem );
provider->select( attrIndexes, *rect, mWithGeom, true );
layer->select( attrIndexes, *rect, mWithGeom, true );
}
else if ( childElem.tagName() != "PropertyName" )
{
QgsGeometry* geom = QgsGeometry::fromGML2( childElem );
provider->select( attrIndexes, geom->boundingBox(), mWithGeom, true );
layer->select( attrIndexes, geom->boundingBox(), mWithGeom, true );
}
childElem = childElem.nextSiblingElement();
}
while ( provider->nextFeature( feature ) && featureCounter < maxFeat )
while ( layer->nextFeature( feature ) && featureCounter < maxFeat )
{
if ( featureCounter == 0 )
startGetFeature( request, format, layerCrs, &searchRect );
@@ -525,7 +526,7 @@ int QgsWFSServer::getFeature( QgsRequestHandler& request, const QString& format
}
if ( mFilter )
{
while ( provider->nextFeature( feature ) && featureCounter < maxFeat )
while ( layer->nextFeature( feature ) && featureCounter < maxFeat )
{
QVariant res = mFilter->evaluate( &feature, fields );
if ( mFilter->hasEvalError() )
@@ -547,7 +548,7 @@ int QgsWFSServer::getFeature( QgsRequestHandler& request, const QString& format
}
else
{
while ( provider->nextFeature( feature ) && featureCounter < maxFeat )
while ( layer->nextFeature( feature ) && featureCounter < maxFeat )
{
if ( featureCounter == 0 )
startGetFeature( request, format, layerCrs, &searchRect );
@@ -731,7 +732,7 @@ int QgsWFSServer::getFeature( QgsRequestHandler& request, const QString& format

QgsFeature feature;
QgsAttributeMap featureAttributes;
const QgsFieldMap& fields = provider->fields();
const QgsFields& fields = provider->fields();

//map extent
QgsRectangle searchRect = layer->extent();
@@ -782,7 +783,8 @@ int QgsWFSServer::getFeature( QgsRequestHandler& request, const QString& format
{
if ( !fidStr.startsWith( tnStr ) )
continue;
provider->featureAtId( fidStr.section( ".", 1, 1 ).toInt(), feature, mWithGeom, attrIndexes );
//Need to be test for propertyname
layer->featureAtId( fidStr.section( ".", 1, 1 ).toInt(), feature, mWithGeom, true );

if ( featureCounter == 0 )
startGetFeature( request, format, layerCrs, &searchRect );
@@ -794,15 +796,15 @@ int QgsWFSServer::getFeature( QgsRequestHandler& request, const QString& format
}
else if ( expFilterOk )
{
provider->select( attrIndexes, searchRect, mWithGeom, true );
layer->select( attrIndexes, searchRect, mWithGeom, true );
QgsExpression *mFilter = new QgsExpression( expFilter );
if ( mFilter->hasParserError() )
{
throw QgsMapServiceException( "RequestNotWellFormed", mFilter->parserErrorString() );
}
if ( mFilter )
{
while ( provider->nextFeature( feature ) && featureCounter < maxFeat )
while ( layer->nextFeature( feature ) && featureCounter < maxFeat )
{
QVariant res = mFilter->evaluate( &feature, fields );
if ( mFilter->hasEvalError() )
@@ -824,7 +826,7 @@ int QgsWFSServer::getFeature( QgsRequestHandler& request, const QString& format
}
else if ( filterOk )
{
provider->select( attrIndexes, searchRect, mWithGeom, true );
layer->select( attrIndexes, searchRect, mWithGeom, true );
QDomElement filterElem = filter.firstChildElement();
QDomNodeList fidNodes = filterElem.elementsByTagName( "FeatureId" );
if ( fidNodes.size() > 0 )
@@ -842,7 +844,8 @@ int QgsWFSServer::getFeature( QgsRequestHandler& request, const QString& format
fid = fid.section( ".", 1, 1 );
}

provider->featureAtId( fid.toInt(), feature, mWithGeom, attrIndexes );
//Need to be test for propertyname
layer->featureAtId( fid.toInt(), feature, mWithGeom, true );

if ( featureCounter == 0 )
startGetFeature( request, format, layerCrs, &searchRect );
@@ -863,16 +866,16 @@ int QgsWFSServer::getFeature( QgsRequestHandler& request, const QString& format
if ( childElem.tagName() == "Box" )
{
QgsRectangle* rect = new QgsRectangle( childElem );
provider->select( attrIndexes, *rect, mWithGeom, true );
layer->select( attrIndexes, *rect, mWithGeom, true );
}
else if ( childElem.tagName() != "PropertyName" )
{
QgsGeometry* geom = QgsGeometry::fromGML2( childElem );
provider->select( attrIndexes, geom->boundingBox(), mWithGeom, true );
layer->select( attrIndexes, geom->boundingBox(), mWithGeom, true );
}
childElem = childElem.nextSiblingElement();
}
while ( provider->nextFeature( feature ) && featureCounter < maxFeat )
while ( layer->nextFeature( feature ) && featureCounter < maxFeat )
{
if ( featureCounter == 0 )
startGetFeature( request, format, layerCrs, &searchRect );
@@ -891,7 +894,7 @@ int QgsWFSServer::getFeature( QgsRequestHandler& request, const QString& format
}
if ( mFilter )
{
while ( provider->nextFeature( feature ) && featureCounter < maxFeat )
while ( layer->nextFeature( feature ) && featureCounter < maxFeat )
{
QVariant res = mFilter->evaluate( &feature, fields );
if ( mFilter->hasEvalError() )
@@ -914,8 +917,8 @@ int QgsWFSServer::getFeature( QgsRequestHandler& request, const QString& format
}
else
{
provider->select( attrIndexes, searchRect, mWithGeom, true );
while ( provider->nextFeature( feature ) && featureCounter < maxFeat )
layer->select( attrIndexes, searchRect, mWithGeom, true );
while ( layer->nextFeature( feature ) && featureCounter < maxFeat )
{
if ( featureCounter == 0 )
startGetFeature( request, format, layerCrs, &searchRect );
@@ -1068,7 +1071,7 @@ void QgsWFSServer::startGetFeature( QgsRequestHandler& request, const QString& f
fcString = "";
}

void QgsWFSServer::sendGetFeature( QgsRequestHandler& request, const QString& format, QgsFeature* feat, int featIdx, QgsCoordinateReferenceSystem& crs, QMap< int, QgsField > fields, QSet<QString> excludedAttributes ) /*const*/
void QgsWFSServer::sendGetFeature( QgsRequestHandler& request, const QString& format, QgsFeature* feat, int featIdx, QgsCoordinateReferenceSystem& crs, QgsFields fields, QSet<QString> excludedAttributes ) /*const*/
{
if ( !feat->isValid() )
return;
@@ -1267,8 +1270,7 @@ QDomDocument QgsWFSServer::transaction( const QString& requestBody )
}

// Update the features
const QgsFieldMap& fields = provider->fields();
QgsFieldMap::const_iterator fieldIt;
const QgsFields& fields = provider->fields();
QMap<QString, int> fieldMap = provider->fieldNameMap();
QMap<QString, int>::const_iterator fieldMapIt;
QString fieldName;
@@ -1286,17 +1288,13 @@ QDomDocument QgsWFSServer::transaction( const QString& requestBody )
{
continue;
}
fieldIt = fields.find( fieldMapIt.value() );
if ( fieldIt == fields.constEnd() )
{
continue;
}
if ( fieldIt.value().type() == 2 )
layer->changeAttributeValue( *fidIt, fieldIt.key(), it.value().toInt( &conversionSuccess ) );
else if ( fieldIt.value().type() == 6 )
layer->changeAttributeValue( *fidIt, fieldIt.key(), it.value().toDouble( &conversionSuccess ) );
const QgsField& field = fields[fieldMapIt.value()];
if ( field.type() == 2 )
layer->changeAttributeValue( *fidIt, fieldMapIt.value(), it.value().toInt( &conversionSuccess ) );
else if ( field.type() == 6 )
layer->changeAttributeValue( *fidIt, fieldMapIt.value(), it.value().toDouble( &conversionSuccess ) );
else
layer->changeAttributeValue( *fidIt, fieldIt.key(), it.value() );
layer->changeAttributeValue( *fidIt, fieldMapIt.value(), it.value() );
}

if ( !geometryElem.isNull() )
@@ -1370,8 +1368,7 @@ QDomDocument QgsWFSServer::transaction( const QString& requestBody )
if ( cap & QgsVectorDataProvider::AddFeatures )
{
// Get Layer Field Information
const QgsFieldMap& fields = provider->fields();
QgsFieldMap::const_iterator fieldIt;
const QgsFields& fields = provider->fields();
QMap<QString, int> fieldMap = provider->fieldNameMap();
QMap<QString, int>::const_iterator fieldMapIt;
QString fieldName;
@@ -1406,19 +1403,15 @@ QDomDocument QgsWFSServer::transaction( const QString& requestBody )
{
continue;
}
fieldIt = fields.find( fieldMapIt.value() );
if ( fieldIt == fields.constEnd() )
{
continue;
}
const QgsField& field = fields[fieldMapIt.value()];
QString attrValue = currentAttributeElement.text();
int attrType = fieldIt.value().type();
int attrType = field.type();
if ( attrType == 2 )
f->addAttribute( fieldIt.key(), attrValue.toInt() );
f->setAttribute( fieldMapIt.value(), attrValue.toInt() );
else if ( attrType == 6 )
f->addAttribute( fieldIt.key(), attrValue.toDouble() );
f->setAttribute( fieldMapIt.value(), attrValue.toDouble() );
else
f->addAttribute( fieldIt.key(), attrValue );
f->setAttribute( fieldMapIt.value(), attrValue );
}
else //a geometry attribute
{
@@ -1523,8 +1516,8 @@ QgsFeatureIds QgsWFSServer::getFeatureIdsFromFilter( QDomElement filterElem, Qgs
if ( mFilter )
{
QgsFeature feature;
const QgsFieldMap& fields = provider->fields();
while ( provider->nextFeature( feature ) )
const QgsFields& fields = provider->fields();
while ( layer->nextFeature( feature ) )
{
QVariant res = mFilter->evaluate( &feature, fields );
if ( mFilter->hasEvalError() )
@@ -1542,7 +1535,7 @@ QgsFeatureIds QgsWFSServer::getFeatureIdsFromFilter( QDomElement filterElem, Qgs
return fids;
}

QString QgsWFSServer::createFeatureGeoJSON( QgsFeature* feat, QgsCoordinateReferenceSystem &, QMap< int, QgsField > fields, QSet<QString> excludedAttributes ) /*const*/
QString QgsWFSServer::createFeatureGeoJSON( QgsFeature* feat, QgsCoordinateReferenceSystem &, QgsFields fields, QSet<QString> excludedAttributes ) /*const*/
{
QString fStr = "{\"type\": \"Feature\",\n";

@@ -1603,7 +1596,7 @@ QString QgsWFSServer::createFeatureGeoJSON( QgsFeature* feat, QgsCoordinateRefer
return fStr;
}

QDomElement QgsWFSServer::createFeatureGML2( QgsFeature* feat, QDomDocument& doc, QgsCoordinateReferenceSystem& crs, QMap< int, QgsField > fields, QSet<QString> excludedAttributes ) /*const*/
QDomElement QgsWFSServer::createFeatureGML2( QgsFeature* feat, QDomDocument& doc, QgsCoordinateReferenceSystem& crs, QgsFields fields, QSet<QString> excludedAttributes ) /*const*/
{
//gml:FeatureMember
QDomElement featureElement = doc.createElement( "gml:featureMember"/*wfs:FeatureMember*/ );
@@ -96,17 +96,17 @@ class QgsWFSServer
protected:

void startGetFeature( QgsRequestHandler& request, const QString& format, QgsCoordinateReferenceSystem& crs, QgsRectangle* rect );
void sendGetFeature( QgsRequestHandler& request, const QString& format, QgsFeature* feat, int featIdx, QgsCoordinateReferenceSystem& crs, QMap< int, QgsField > fields, QSet<QString> excludedAttributes );
void sendGetFeature( QgsRequestHandler& request, const QString& format, QgsFeature* feat, int featIdx, QgsCoordinateReferenceSystem& crs, QgsFields fields, QSet<QString> excludedAttributes );
void endGetFeature( QgsRequestHandler& request, const QString& format );

//method for transaction
QgsFeatureIds getFeatureIdsFromFilter( QDomElement filter, QgsVectorLayer* layer );

//methods to write GeoJSON
QString createFeatureGeoJSON( QgsFeature* feat, QgsCoordinateReferenceSystem& crs, QMap< int, QgsField > fields, QSet<QString> excludedAttributes ) /*const*/;
QString createFeatureGeoJSON( QgsFeature* feat, QgsCoordinateReferenceSystem& crs, QgsFields fields, QSet<QString> excludedAttributes ) /*const*/;

//methods to write GML2
QDomElement createFeatureGML2( QgsFeature* feat, QDomDocument& doc, QgsCoordinateReferenceSystem& crs, QMap< int, QgsField > fields, QSet<QString> excludedAttributes ) /*const*/;
QDomElement createFeatureGML2( QgsFeature* feat, QDomDocument& doc, QgsCoordinateReferenceSystem& crs, QgsFields fields, QSet<QString> excludedAttributes ) /*const*/;

QDomElement createBoxGML2( QgsRectangle* box, QDomDocument& doc ) /* const */;

0 comments on commit 11d5bd3

Please sign in to comment.