Skip to content

Commit

Permalink
Re-enable WFS Server
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed Apr 2, 2014
1 parent 1a7ad76 commit af7b6be
Show file tree
Hide file tree
Showing 3 changed files with 209 additions and 16 deletions.
203 changes: 203 additions & 0 deletions src/mapserver/qgswfsprojectparser.cpp
Expand Up @@ -17,6 +17,7 @@


#include "qgswfsprojectparser.h" #include "qgswfsprojectparser.h"
#include "qgsconfigparserutils.h" #include "qgsconfigparserutils.h"
#include "qgsmaplayerregistry.h"
#include "qgsvectordataprovider.h" #include "qgsvectordataprovider.h"


QgsWFSProjectParser::QgsWFSProjectParser( QDomDocument* xmlDoc, const QString& filePath ): QgsWFSProjectParser::QgsWFSProjectParser( QDomDocument* xmlDoc, const QString& filePath ):
Expand Down Expand Up @@ -392,3 +393,205 @@ QStringList QgsWFSProjectParser::wfstDeleteLayers() const
} }
return wfsList; return wfsList;
} }

void QgsWFSProjectParser::describeFeatureType( const QString& aTypeName, QDomElement& parentElement, QDomDocument& doc ) const
{
const QList<QDomElement>& projectLayerElements = mProjectParser.projectLayerElements();
if ( projectLayerElements.size() < 1 )
{
return;
}

QStringList wfsLayersId = mProjectParser.wfsLayers();
QStringList typeNameList;
if ( aTypeName != "" )
{
QStringList typeNameSplit = aTypeName.split( "," );
foreach ( const QString &str, typeNameSplit )
{
if ( str.contains( ":" ) )
typeNameList << str.section( ":", 1, 1 );
else
typeNameList << str;
}
}

foreach ( const QDomElement &elem, projectLayerElements )
{
QString type = elem.attribute( "type" );
if ( type == "vector" )
{
//addJoinLayersForElement( elem ); //todo: fixme
QgsMapLayer *mLayer = mProjectParser.createLayerFromElement( elem );
QgsVectorLayer* layer = dynamic_cast<QgsVectorLayer*>( mLayer );
if ( !layer )
continue;

QString typeName = layer->name();
typeName = typeName.replace( " ", "_" );

if ( wfsLayersId.contains( layer->id() ) && ( aTypeName == "" || typeNameList.contains( typeName ) ) )
{
//do a select with searchRect and go through all the features
QgsVectorDataProvider* provider = layer->dataProvider();
if ( !provider )
{
continue;
}

//hidden attributes for this layer
const QSet<QString>& layerExcludedAttributes = layer->excludeAttributesWFS();

//xsd:element
QDomElement elementElem = doc.createElement( "element"/*xsd:element*/ );
elementElem.setAttribute( "name", typeName );
elementElem.setAttribute( "type", "qgs:" + typeName + "Type" );
elementElem.setAttribute( "substitutionGroup", "gml:_Feature" );
parentElement.appendChild( elementElem );

//xsd:complexType
QDomElement complexTypeElem = doc.createElement( "complexType"/*xsd:complexType*/ );
complexTypeElem.setAttribute( "name", typeName + "Type" );
parentElement.appendChild( complexTypeElem );

//xsd:complexType
QDomElement complexContentElem = doc.createElement( "complexContent"/*xsd:complexContent*/ );
complexTypeElem.appendChild( complexContentElem );

//xsd:extension
QDomElement extensionElem = doc.createElement( "extension"/*xsd:extension*/ );
extensionElem.setAttribute( "base", "gml:AbstractFeatureType" );
complexContentElem.appendChild( extensionElem );

//xsd:sequence
QDomElement sequenceElem = doc.createElement( "sequence"/*xsd:sequence*/ );
extensionElem.appendChild( sequenceElem );

//xsd:element
QDomElement geomElem = doc.createElement( "element"/*xsd:element*/ );
geomElem.setAttribute( "name", "geometry" );
QGis::WkbType wkbType = layer->wkbType();
if ( wkbType != QGis::WKBNoGeometry )
{
switch ( wkbType )
{
case QGis::WKBPoint25D:
case QGis::WKBPoint:
geomElem.setAttribute( "type", "gml:PointPropertyType" );
break;
case QGis::WKBLineString25D:
case QGis::WKBLineString:
geomElem.setAttribute( "type", "gml:LineStringPropertyType" );
break;
case QGis::WKBPolygon25D:
case QGis::WKBPolygon:
geomElem.setAttribute( "type", "gml:PolygonPropertyType" );
break;
case QGis::WKBMultiPoint25D:
case QGis::WKBMultiPoint:
geomElem.setAttribute( "type", "gml:MultiPointPropertyType" );
break;
case QGis::WKBMultiLineString25D:
case QGis::WKBMultiLineString:
geomElem.setAttribute( "type", "gml:MultiLineStringPropertyType" );
break;
case QGis::WKBMultiPolygon25D:
case QGis::WKBMultiPolygon:
geomElem.setAttribute( "type", "gml:MultiPolygonPropertyType" );
break;
default:
geomElem.setAttribute( "type", "gml:GeometryPropertyType" );
break;
}
geomElem.setAttribute( "minOccurs", "0" );
geomElem.setAttribute( "maxOccurs", "1" );
sequenceElem.appendChild( geomElem );
}

//const QgsFields& fields = provider->fields();
const QgsFields& fields = layer->pendingFields();
for ( int idx = 0; idx < fields.count(); ++idx )
{

QString attributeName = fields[idx].name();
//skip attribute if excluded from WFS publication
if ( layerExcludedAttributes.contains( attributeName ) )
{
continue;
}

//xsd:element
QDomElement geomElem = doc.createElement( "element"/*xsd:element*/ );
geomElem.setAttribute( "name", attributeName );
QVariant::Type attributeType = fields[idx].type();
if ( attributeType == QVariant::Int )
geomElem.setAttribute( "type", "integer" );
else if ( attributeType == QVariant::Double )
geomElem.setAttribute( "type", "double" );
else
geomElem.setAttribute( "type", "string" );

sequenceElem.appendChild( geomElem );

QString alias = layer->attributeAlias( idx );
if ( !alias.isEmpty() )
{
geomElem.setAttribute( "alias", alias );
}
}
}
}
}
QgsMapLayerRegistry::instance()->removeAllMapLayers();
return;
}

QStringList QgsWFSProjectParser::wfsLayers() const
{
return mProjectParser.wfsLayers();
}

QList<QgsMapLayer*> QgsWFSProjectParser::mapLayerFromTypeName( const QString& aTypeName, bool useCache ) const
{
QList<QgsMapLayer*> layerList;
const QList<QDomElement>& projectLayerElements = mProjectParser.projectLayerElements();

if ( projectLayerElements.size() < 1 )
{
return layerList;
}
QStringList wfsLayersId = wfsLayers();

QStringList typeNameList;
if ( aTypeName != "" )
{
QStringList typeNameSplit = aTypeName.split( "," );
foreach ( const QString &str, typeNameSplit )
{
if ( str.contains( ":" ) )
typeNameList << str.section( ":", 1, 1 );
else
typeNameList << str;
}
}

foreach ( const QDomElement &elem, projectLayerElements )
{
QString type = elem.attribute( "type" );
if ( type == "vector" )
{
//addJoinLayersForElement( elem, useCache ); //todo: fixme
QgsMapLayer *mLayer = mProjectParser.createLayerFromElement( elem );
QgsVectorLayer* layer = dynamic_cast<QgsVectorLayer*>( mLayer );
if ( !layer )
continue;

QString typeName = layer->name();
typeName = typeName.replace( " ", "_" );

if ( wfsLayersId.contains( layer->id() ) && ( aTypeName == "" || typeNameList.contains( typeName ) ) )
layerList.push_back( mLayer );
}
}
return layerList;
}
6 changes: 6 additions & 0 deletions src/mapserver/qgswfsprojectparser.h
Expand Up @@ -31,6 +31,12 @@ class QgsWFSProjectParser
QString wfsServiceUrl() const; QString wfsServiceUrl() const;
void featureTypeList( QDomElement& parentElement, QDomDocument& doc ) const; void featureTypeList( QDomElement& parentElement, QDomDocument& doc ) const;


void describeFeatureType( const QString& aTypeName, QDomElement& parentElement, QDomDocument& doc ) const;

QStringList wfsLayers() const;

QList<QgsMapLayer*> mapLayerFromTypeName( const QString& aTypeName, bool useCache = true ) const;

private: private:
QgsServerProjectParser mProjectParser; QgsServerProjectParser mProjectParser;


Expand Down
16 changes: 0 additions & 16 deletions src/mapserver/qgswfsserver.cpp
Expand Up @@ -307,8 +307,6 @@ QDomDocument QgsWFSServer::describeFeatureType()
QgsDebugMsg( "Entering." ); QgsDebugMsg( "Entering." );
QDomDocument doc; QDomDocument doc;


#if 0 //todo: fixme

//xsd:schema //xsd:schema
QDomElement schemaElement = doc.createElement( "schema"/*xsd:schema*/ ); QDomElement schemaElement = doc.createElement( "schema"/*xsd:schema*/ );
schemaElement.setAttribute( "xmlns", "http://www.w3.org/2001/XMLSchema" ); schemaElement.setAttribute( "xmlns", "http://www.w3.org/2001/XMLSchema" );
Expand Down Expand Up @@ -364,14 +362,11 @@ QDomDocument QgsWFSServer::describeFeatureType()
mConfigParser->describeFeatureType( typeName, schemaElement, doc ); mConfigParser->describeFeatureType( typeName, schemaElement, doc );
} }


#endif //0 //todo: fixme

return doc; return doc;
} }


int QgsWFSServer::getFeature( QgsRequestHandler& request, const QString& format ) int QgsWFSServer::getFeature( QgsRequestHandler& request, const QString& format )
{ {
#if 0 //todo: fixme
QgsDebugMsg( "Info format is:" + format ); QgsDebugMsg( "Info format is:" + format );


QStringList wfsLayersId = mConfigParser->wfsLayers(); QStringList wfsLayersId = mConfigParser->wfsLayers();
Expand Down Expand Up @@ -1080,14 +1075,11 @@ int QgsWFSServer::getFeature( QgsRequestHandler& request, const QString& format
else else
endGetFeature( request, format ); endGetFeature( request, format );


#endif // 0 //todo: fixme

return 0; return 0;
} }


void QgsWFSServer::startGetFeature( QgsRequestHandler& request, const QString& format, QgsCoordinateReferenceSystem& crs, QgsRectangle* rect ) void QgsWFSServer::startGetFeature( QgsRequestHandler& request, const QString& format, QgsCoordinateReferenceSystem& crs, QgsRectangle* rect )
{ {
#if 0 //todo: fixme
QByteArray result; QByteArray result;
QString fcString; QString fcString;
if ( format == "GeoJSON" ) if ( format == "GeoJSON" )
Expand Down Expand Up @@ -1214,9 +1206,6 @@ void QgsWFSServer::startGetFeature( QgsRequestHandler& request, const QString& f
request.sendGetFeatureResponse( &result ); request.sendGetFeatureResponse( &result );
} }
fcString = ""; fcString = "";

#endif //0 //todo: fixme

} }


void QgsWFSServer::sendGetFeature( QgsRequestHandler& request, const QString& format, QgsFeature* feat, int featIdx, QgsCoordinateReferenceSystem& crs, QgsAttributeList attrIndexes, QSet<QString> excludedAttributes ) /*const*/ void QgsWFSServer::sendGetFeature( QgsRequestHandler& request, const QString& format, QgsFeature* feat, int featIdx, QgsCoordinateReferenceSystem& crs, QgsAttributeList attrIndexes, QSet<QString> excludedAttributes ) /*const*/
Expand Down Expand Up @@ -1286,9 +1275,6 @@ QDomDocument QgsWFSServer::transaction( const QString& requestBody )
{ {
// Getting the transaction document // Getting the transaction document
QDomDocument doc; QDomDocument doc;
return doc;

#if 0 //todo: fixme


QString errorMsg; QString errorMsg;
if ( !doc.setContent( requestBody, true, &errorMsg ) ) if ( !doc.setContent( requestBody, true, &errorMsg ) )
Expand Down Expand Up @@ -1650,8 +1636,6 @@ QDomDocument QgsWFSServer::transaction( const QString& requestBody )
respElem.appendChild( trElem ); respElem.appendChild( trElem );


return resp; return resp;

#endif //0 //todo: fixme
} }


QgsFeatureIds QgsWFSServer::getFeatureIdsFromFilter( QDomElement filterElem, QgsVectorLayer* layer ) QgsFeatureIds QgsWFSServer::getFeatureIdsFromFilter( QDomElement filterElem, QgsVectorLayer* layer )
Expand Down

0 comments on commit af7b6be

Please sign in to comment.