Skip to content

Commit

Permalink
[QGIS-Server] Add vectorJoins
Browse files Browse the repository at this point in the history
Vector joins is based on qgsMapLayerRegistry. Vector joins has to be
used for getFeatureInfo and getMap WMS Server Request and for
describeFeatureType and getFeature WFS Server Request.
  • Loading branch information
rldhont committed Jul 25, 2013
1 parent 0756782 commit 46db30c
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/mapserver/qgsconfigparser.h
Expand Up @@ -51,14 +51,17 @@ class QgsConfigParser
virtual void owsGeneralAndResourceList( QDomElement& parentElement, QDomDocument& doc, const QString& strHref ) const = 0;

virtual void describeFeatureType( const QString& aTypeName, QDomElement& parentElement, QDomDocument& doc ) const = 0;
/**Returns one or possibly several maplayers for a given type name. If no layers/style are found, an empty list is returned*/
/**Returns one or possibly several maplayers for a given type name. If no layers are found, an empty list is returned*/
virtual QList<QgsMapLayer*> mapLayerFromTypeName( const QString& tName, bool useCache = true ) const = 0;

/**Returns one or possibly several maplayers for a given layer name and style. If there are several layers, the layers should be drawn in inverse list order.
If no layers/style are found, an empty list is returned
@param allowCache true if layer can be read from / written to cache*/
virtual QList<QgsMapLayer*> mapLayerFromStyle( const QString& layerName, const QString& styleName, bool useCache = true ) const = 0;

/**Returns maplayers for a layer Id.*/
virtual QgsMapLayer* mapLayerFromLayerId( const QString& lId ) const = 0;

/**Returns number of layers in configuration*/
virtual int numberOfLayers() const = 0;

Expand Down
33 changes: 32 additions & 1 deletion src/mapserver/qgsprojectparser.cpp
Expand Up @@ -15,6 +15,8 @@
* *
***************************************************************************/

#include "qgsmaplayerregistry.h"

#include "qgsprojectparser.h"
#include "qgsconfigcache.h"
#include "qgscrscache.h"
Expand Down Expand Up @@ -426,6 +428,23 @@ void QgsProjectParser::describeFeatureType( const QString& aTypeName, QDomElemen
{
continue;
}
if ( layer->vectorJoins().size() > 0 )
{
QList<QgsMapLayer *> joinLayers;
//JoinBuffer is based on qgsmaplayerregistry!!!!!
//insert existing join info
const QList< QgsVectorJoinInfo >& joins = layer->vectorJoins();
for ( int i = 0; i < joins.size(); ++i )
{
QgsMapLayer* joinLayer = mapLayerFromLayerId( joins[i].joinLayerId );
if ( joinLayer )
{
joinLayers << joinLayer;
}
QgsMapLayerRegistry::instance()->addMapLayers( joinLayers, false, true );
}
layer->updateFields();
}

//hidden attributes for this layer
const QSet<QString>& layerExcludedAttributes = layer->excludeAttributesWFS();
Expand Down Expand Up @@ -496,7 +515,8 @@ void QgsProjectParser::describeFeatureType( const QString& aTypeName, QDomElemen
sequenceElem.appendChild( geomElem );
}

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

Expand Down Expand Up @@ -529,6 +549,7 @@ void QgsProjectParser::describeFeatureType( const QString& aTypeName, QDomElemen
}
}
}
QgsMapLayerRegistry::instance()->removeAllMapLayers();
return;
}

Expand Down Expand Up @@ -1456,6 +1477,16 @@ QList<QgsMapLayer*> QgsProjectParser::mapLayerFromStyle( const QString& lName, c
return layerList;
}

QgsMapLayer* QgsProjectParser::mapLayerFromLayerId( const QString& lId ) const
{
QHash< QString, QDomElement >::const_iterator layerIt = mProjectLayerElementsById.find( lId );
if ( layerIt != mProjectLayerElementsById.constEnd() )
{
return createLayerFromElement( layerIt.value(), true );
}
return 0;
}

void QgsProjectParser::addLayersFromGroup( const QDomElement& legendGroupElem, QList<QgsMapLayer*>& layerList, bool useCache ) const
{
if ( legendGroupElem.attribute( "embedded" ) == "1" ) //embedded group
Expand Down
3 changes: 3 additions & 0 deletions src/mapserver/qgsprojectparser.h
Expand Up @@ -56,6 +56,9 @@ class QgsProjectParser: public QgsConfigParser
/**Returns one or possibly several maplayers for a given layer name and style. If no layers/style are found, an empty list is returned*/
virtual QList<QgsMapLayer*> mapLayerFromStyle( const QString& lName, const QString& styleName, bool useCache = true ) const;

/**Returns maplayers for a layer Id.*/
virtual QgsMapLayer* mapLayerFromLayerId( const QString& lId ) const;

/**Fills a layer and a style list. The two list have the same number of entries and the style and the layer at a position belong together (similar to the HTTP parameters 'Layers' and 'Styles'. Returns 0 in case of success*/
virtual int layersAndStyles( QStringList& layers, QStringList& styles ) const;

Expand Down
3 changes: 3 additions & 0 deletions src/mapserver/qgssldparser.h
Expand Up @@ -62,6 +62,9 @@ class QgsSLDParser: public QgsConfigParser
/**Returns one or possibly several maplayers for a given layer name and style. If no layers/style are found, an empty list is returned*/
QList<QgsMapLayer*> mapLayerFromStyle( const QString& layerName, const QString& styleName, bool useCache = true ) const;

/**Returns maplayers for a layer Id.*/
QgsMapLayer* mapLayerFromLayerId( const QString& ) const { return 0;};

/**Fills a layer and a style list. The two list have the same number of entries and the style and the layer at a position belong together (similar to the HTTP parameters 'Layers' and 'Styles'. Returns 0 in case of success*/
int layersAndStyles( QStringList& layers, QStringList& styles ) const;

Expand Down
34 changes: 34 additions & 0 deletions src/mapserver/qgswfsserver.cpp
Expand Up @@ -339,6 +339,22 @@ int QgsWFSServer::getFeature( QgsRequestHandler& request, const QString& format
QgsVectorLayer* layer = dynamic_cast<QgsVectorLayer*>( currentLayer );
if ( layer && wfsLayersId.contains( layer->id() ) )
{
if ( layer->vectorJoins().size() > 0 )
{
QList<QgsMapLayer *> joinLayers;
//insert existing join info
const QList< QgsVectorJoinInfo >& joins = layer->vectorJoins();
for ( int i = 0; i < joins.size(); ++i )
{
QgsMapLayer* joinLayer = mConfigParser->mapLayerFromLayerId( joins[i].joinLayerId );
if ( joinLayer )
{
joinLayers << joinLayer;
}
QgsMapLayerRegistry::instance()->addMapLayers( joinLayers, false, true );
}
layer->updateFields();
}
//is there alias info for this vector layer?
QMap< int, QString > layerAliasInfo;
const QMap< QString, QString >& aliasMap = layer->attributeAliases();
Expand Down Expand Up @@ -540,6 +556,7 @@ int QgsWFSServer::getFeature( QgsRequestHandler& request, const QString& format

}

QgsMapLayerRegistry::instance()->removeAllMapLayers();
if ( featureCounter == 0 )
throw QgsMapServiceException( "RequestNotWellFormed", mErrors.join( ". " ) );
else
Expand Down Expand Up @@ -680,6 +697,22 @@ int QgsWFSServer::getFeature( QgsRequestHandler& request, const QString& format
QgsVectorLayer* layer = dynamic_cast<QgsVectorLayer*>( currentLayer );
if ( layer && wfsLayersId.contains( layer->id() ) )
{
if ( layer->vectorJoins().size() > 0 )
{
QList<QgsMapLayer *> joinLayers;
//insert existing join info
const QList< QgsVectorJoinInfo >& joins = layer->vectorJoins();
for ( int i = 0; i < joins.size(); ++i )
{
QgsMapLayer* joinLayer = mConfigParser->mapLayerFromLayerId( joins[i].joinLayerId );
if ( joinLayer )
{
joinLayers << joinLayer;
}
QgsMapLayerRegistry::instance()->addMapLayers( joinLayers, false, true );
}
layer->updateFields();
}
//is there alias info for this vector layer?
QMap< int, QString > layerAliasInfo;
const QMap< QString, QString >& aliasMap = layer->attributeAliases();
Expand Down Expand Up @@ -985,6 +1018,7 @@ int QgsWFSServer::getFeature( QgsRequestHandler& request, const QString& format
if ( featureCounter == 0 )
startGetFeature( request, format, layerCrs, &searchRect );

QgsMapLayerRegistry::instance()->removeAllMapLayers();
endGetFeature( request, format );

return 0;
Expand Down
37 changes: 37 additions & 0 deletions src/mapserver/qgswmsserver.cpp
Expand Up @@ -895,6 +895,23 @@ int QgsWMSServer::getFeatureInfo( QDomDocument& result, QString version )
QgsVectorLayer* vectorLayer = dynamic_cast<QgsVectorLayer*>( currentLayer );
if ( vectorLayer )
{
if ( vectorLayer->vectorJoins().size() > 0 )
{
QList<QgsMapLayer *> joinLayers;
//JoinBuffer is based on qgsmaplayerregistry!!!!!
//insert existing join info
const QList< QgsVectorJoinInfo >& joins = vectorLayer->vectorJoins();
for ( int i = 0; i < joins.size(); ++i )
{
QgsMapLayer* joinLayer = mConfigParser->mapLayerFromLayerId( joins[i].joinLayerId );
if ( joinLayer )
{
joinLayers << joinLayer;
}
QgsMapLayerRegistry::instance()->addMapLayers( joinLayers, false, true );
}
vectorLayer->updateFields();
}
if ( featureInfoFromVectorLayer( vectorLayer, infoPoint, featureCount, result, layerElement, mMapRenderer, renderContext,
version, featuresRect ) != 0 )
{
Expand Down Expand Up @@ -936,6 +953,7 @@ int QgsWMSServer::getFeatureInfo( QDomDocument& result, QString version )
}

restoreLayerFilters( originalLayerFilters );
QgsMapLayerRegistry::instance()->removeAllMapLayers();
delete featuresRect;
delete infoPoint;
return 0;
Expand Down Expand Up @@ -1306,6 +1324,7 @@ int QgsWMSServer::featureInfoFromVectorLayer( QgsVectorLayer* layer,
QgsFeature feature;
QgsAttributes featureAttributes;
int featureCounter = 0;
layer->updateFields();
const QgsFields& fields = layer->pendingFields();
bool addWktGeometry = mConfigParser && mConfigParser->featureInfoWithWktGeometry();
const QSet<QString>& excludedAttributes = layer->excludeAttributesWMS();
Expand Down Expand Up @@ -1486,6 +1505,24 @@ QStringList QgsWMSServer::layerSet( const QStringList &layersList,
( theMapLayer->minimumScale() <= scaleDenominator && theMapLayer->maximumScale() >= scaleDenominator ) )
{
layerKeys.push_front( theMapLayer->id() );
//joinVectorLayers
QgsVectorLayer* vectorLayer = dynamic_cast<QgsVectorLayer*>( theMapLayer );
if ( vectorLayer && vectorLayer->vectorJoins().size() > 0 )
{
QList<QgsMapLayer *> joinLayers;
//insert existing join info
const QList< QgsVectorJoinInfo >& joins = vectorLayer->vectorJoins();
for ( int i = 0; i < joins.size(); ++i )
{
QgsMapLayer* joinLayer = mConfigParser->mapLayerFromLayerId( joins[i].joinLayerId );
if ( joinLayer )
{
joinLayers << joinLayer;
}
QgsMapLayerRegistry::instance()->addMapLayers( joinLayers, false, true );
}
vectorLayer->updateFields();
}
QgsMapLayerRegistry::instance()->addMapLayers(
QList<QgsMapLayer *>() << theMapLayer, false, false );
}
Expand Down

1 comment on commit 46db30c

@mhugent
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Join code replicated 5 times... Please move that to a function!

Please sign in to comment.