Skip to content

Commit

Permalink
Update QGIS WFS Server to use the new vector API
Browse files Browse the repository at this point in the history
This update needs to be tested. It should primarily test the
PROPERTYNAME parameter for GetFeature request, and test TRANSACTION.
This update it's just for compatibility. It should be good to update the
code to use all the new vector API capability.
  • Loading branch information
rldhont committed Jan 17, 2013
1 parent a6c5fd8 commit e12d139
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 51 deletions.
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
87 changes: 40 additions & 47 deletions src/mapserver/qgswfsserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" );
Expand All @@ -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 );
Expand All @@ -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 );
Expand All @@ -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() )
Expand All @@ -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 );
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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 );
Expand All @@ -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() )
Expand All @@ -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 )
Expand All @@ -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 );
Expand All @@ -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 );
Expand All @@ -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() )
Expand All @@ -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 );
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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() )
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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() )
Expand All @@ -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";

Expand Down Expand Up @@ -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*/ );
Expand Down
6 changes: 3 additions & 3 deletions src/mapserver/qgswfsserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */;

Expand Down

0 comments on commit e12d139

Please sign in to comment.