Skip to content

Commit 46db30c

Browse files
committedJul 25, 2013
[QGIS-Server] Add vectorJoins
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.
1 parent 0756782 commit 46db30c

File tree

6 files changed

+113
-2
lines changed

6 files changed

+113
-2
lines changed
 

‎src/mapserver/qgsconfigparser.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,17 @@ class QgsConfigParser
5151
virtual void owsGeneralAndResourceList( QDomElement& parentElement, QDomDocument& doc, const QString& strHref ) const = 0;
5252

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

5757
/**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.
5858
If no layers/style are found, an empty list is returned
5959
@param allowCache true if layer can be read from / written to cache*/
6060
virtual QList<QgsMapLayer*> mapLayerFromStyle( const QString& layerName, const QString& styleName, bool useCache = true ) const = 0;
6161

62+
/**Returns maplayers for a layer Id.*/
63+
virtual QgsMapLayer* mapLayerFromLayerId( const QString& lId ) const = 0;
64+
6265
/**Returns number of layers in configuration*/
6366
virtual int numberOfLayers() const = 0;
6467

‎src/mapserver/qgsprojectparser.cpp

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
* *
1616
***************************************************************************/
1717

18+
#include "qgsmaplayerregistry.h"
19+
1820
#include "qgsprojectparser.h"
1921
#include "qgsconfigcache.h"
2022
#include "qgscrscache.h"
@@ -426,6 +428,23 @@ void QgsProjectParser::describeFeatureType( const QString& aTypeName, QDomElemen
426428
{
427429
continue;
428430
}
431+
if ( layer->vectorJoins().size() > 0 )
432+
{
433+
QList<QgsMapLayer *> joinLayers;
434+
//JoinBuffer is based on qgsmaplayerregistry!!!!!
435+
//insert existing join info
436+
const QList< QgsVectorJoinInfo >& joins = layer->vectorJoins();
437+
for ( int i = 0; i < joins.size(); ++i )
438+
{
439+
QgsMapLayer* joinLayer = mapLayerFromLayerId( joins[i].joinLayerId );
440+
if ( joinLayer )
441+
{
442+
joinLayers << joinLayer;
443+
}
444+
QgsMapLayerRegistry::instance()->addMapLayers( joinLayers, false, true );
445+
}
446+
layer->updateFields();
447+
}
429448

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

499-
const QgsFields& fields = provider->fields();
518+
//const QgsFields& fields = provider->fields();
519+
const QgsFields& fields = layer->pendingFields();
500520
for ( int idx = 0; idx < fields.count(); ++idx )
501521
{
502522

@@ -529,6 +549,7 @@ void QgsProjectParser::describeFeatureType( const QString& aTypeName, QDomElemen
529549
}
530550
}
531551
}
552+
QgsMapLayerRegistry::instance()->removeAllMapLayers();
532553
return;
533554
}
534555

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

1480+
QgsMapLayer* QgsProjectParser::mapLayerFromLayerId( const QString& lId ) const
1481+
{
1482+
QHash< QString, QDomElement >::const_iterator layerIt = mProjectLayerElementsById.find( lId );
1483+
if ( layerIt != mProjectLayerElementsById.constEnd() )
1484+
{
1485+
return createLayerFromElement( layerIt.value(), true );
1486+
}
1487+
return 0;
1488+
}
1489+
14591490
void QgsProjectParser::addLayersFromGroup( const QDomElement& legendGroupElem, QList<QgsMapLayer*>& layerList, bool useCache ) const
14601491
{
14611492
if ( legendGroupElem.attribute( "embedded" ) == "1" ) //embedded group

‎src/mapserver/qgsprojectparser.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ class QgsProjectParser: public QgsConfigParser
5656
/**Returns one or possibly several maplayers for a given layer name and style. If no layers/style are found, an empty list is returned*/
5757
virtual QList<QgsMapLayer*> mapLayerFromStyle( const QString& lName, const QString& styleName, bool useCache = true ) const;
5858

59+
/**Returns maplayers for a layer Id.*/
60+
virtual QgsMapLayer* mapLayerFromLayerId( const QString& lId ) const;
61+
5962
/**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*/
6063
virtual int layersAndStyles( QStringList& layers, QStringList& styles ) const;
6164

‎src/mapserver/qgssldparser.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ class QgsSLDParser: public QgsConfigParser
6262
/**Returns one or possibly several maplayers for a given layer name and style. If no layers/style are found, an empty list is returned*/
6363
QList<QgsMapLayer*> mapLayerFromStyle( const QString& layerName, const QString& styleName, bool useCache = true ) const;
6464

65+
/**Returns maplayers for a layer Id.*/
66+
QgsMapLayer* mapLayerFromLayerId( const QString& ) const { return 0;};
67+
6568
/**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*/
6669
int layersAndStyles( QStringList& layers, QStringList& styles ) const;
6770

‎src/mapserver/qgswfsserver.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,22 @@ int QgsWFSServer::getFeature( QgsRequestHandler& request, const QString& format
339339
QgsVectorLayer* layer = dynamic_cast<QgsVectorLayer*>( currentLayer );
340340
if ( layer && wfsLayersId.contains( layer->id() ) )
341341
{
342+
if ( layer->vectorJoins().size() > 0 )
343+
{
344+
QList<QgsMapLayer *> joinLayers;
345+
//insert existing join info
346+
const QList< QgsVectorJoinInfo >& joins = layer->vectorJoins();
347+
for ( int i = 0; i < joins.size(); ++i )
348+
{
349+
QgsMapLayer* joinLayer = mConfigParser->mapLayerFromLayerId( joins[i].joinLayerId );
350+
if ( joinLayer )
351+
{
352+
joinLayers << joinLayer;
353+
}
354+
QgsMapLayerRegistry::instance()->addMapLayers( joinLayers, false, true );
355+
}
356+
layer->updateFields();
357+
}
342358
//is there alias info for this vector layer?
343359
QMap< int, QString > layerAliasInfo;
344360
const QMap< QString, QString >& aliasMap = layer->attributeAliases();
@@ -540,6 +556,7 @@ int QgsWFSServer::getFeature( QgsRequestHandler& request, const QString& format
540556

541557
}
542558

559+
QgsMapLayerRegistry::instance()->removeAllMapLayers();
543560
if ( featureCounter == 0 )
544561
throw QgsMapServiceException( "RequestNotWellFormed", mErrors.join( ". " ) );
545562
else
@@ -680,6 +697,22 @@ int QgsWFSServer::getFeature( QgsRequestHandler& request, const QString& format
680697
QgsVectorLayer* layer = dynamic_cast<QgsVectorLayer*>( currentLayer );
681698
if ( layer && wfsLayersId.contains( layer->id() ) )
682699
{
700+
if ( layer->vectorJoins().size() > 0 )
701+
{
702+
QList<QgsMapLayer *> joinLayers;
703+
//insert existing join info
704+
const QList< QgsVectorJoinInfo >& joins = layer->vectorJoins();
705+
for ( int i = 0; i < joins.size(); ++i )
706+
{
707+
QgsMapLayer* joinLayer = mConfigParser->mapLayerFromLayerId( joins[i].joinLayerId );
708+
if ( joinLayer )
709+
{
710+
joinLayers << joinLayer;
711+
}
712+
QgsMapLayerRegistry::instance()->addMapLayers( joinLayers, false, true );
713+
}
714+
layer->updateFields();
715+
}
683716
//is there alias info for this vector layer?
684717
QMap< int, QString > layerAliasInfo;
685718
const QMap< QString, QString >& aliasMap = layer->attributeAliases();
@@ -985,6 +1018,7 @@ int QgsWFSServer::getFeature( QgsRequestHandler& request, const QString& format
9851018
if ( featureCounter == 0 )
9861019
startGetFeature( request, format, layerCrs, &searchRect );
9871020

1021+
QgsMapLayerRegistry::instance()->removeAllMapLayers();
9881022
endGetFeature( request, format );
9891023

9901024
return 0;

‎src/mapserver/qgswmsserver.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -895,6 +895,23 @@ int QgsWMSServer::getFeatureInfo( QDomDocument& result, QString version )
895895
QgsVectorLayer* vectorLayer = dynamic_cast<QgsVectorLayer*>( currentLayer );
896896
if ( vectorLayer )
897897
{
898+
if ( vectorLayer->vectorJoins().size() > 0 )
899+
{
900+
QList<QgsMapLayer *> joinLayers;
901+
//JoinBuffer is based on qgsmaplayerregistry!!!!!
902+
//insert existing join info
903+
const QList< QgsVectorJoinInfo >& joins = vectorLayer->vectorJoins();
904+
for ( int i = 0; i < joins.size(); ++i )
905+
{
906+
QgsMapLayer* joinLayer = mConfigParser->mapLayerFromLayerId( joins[i].joinLayerId );
907+
if ( joinLayer )
908+
{
909+
joinLayers << joinLayer;
910+
}
911+
QgsMapLayerRegistry::instance()->addMapLayers( joinLayers, false, true );
912+
}
913+
vectorLayer->updateFields();
914+
}
898915
if ( featureInfoFromVectorLayer( vectorLayer, infoPoint, featureCount, result, layerElement, mMapRenderer, renderContext,
899916
version, featuresRect ) != 0 )
900917
{
@@ -936,6 +953,7 @@ int QgsWMSServer::getFeatureInfo( QDomDocument& result, QString version )
936953
}
937954

938955
restoreLayerFilters( originalLayerFilters );
956+
QgsMapLayerRegistry::instance()->removeAllMapLayers();
939957
delete featuresRect;
940958
delete infoPoint;
941959
return 0;
@@ -1306,6 +1324,7 @@ int QgsWMSServer::featureInfoFromVectorLayer( QgsVectorLayer* layer,
13061324
QgsFeature feature;
13071325
QgsAttributes featureAttributes;
13081326
int featureCounter = 0;
1327+
layer->updateFields();
13091328
const QgsFields& fields = layer->pendingFields();
13101329
bool addWktGeometry = mConfigParser && mConfigParser->featureInfoWithWktGeometry();
13111330
const QSet<QString>& excludedAttributes = layer->excludeAttributesWMS();
@@ -1486,6 +1505,24 @@ QStringList QgsWMSServer::layerSet( const QStringList &layersList,
14861505
( theMapLayer->minimumScale() <= scaleDenominator && theMapLayer->maximumScale() >= scaleDenominator ) )
14871506
{
14881507
layerKeys.push_front( theMapLayer->id() );
1508+
//joinVectorLayers
1509+
QgsVectorLayer* vectorLayer = dynamic_cast<QgsVectorLayer*>( theMapLayer );
1510+
if ( vectorLayer && vectorLayer->vectorJoins().size() > 0 )
1511+
{
1512+
QList<QgsMapLayer *> joinLayers;
1513+
//insert existing join info
1514+
const QList< QgsVectorJoinInfo >& joins = vectorLayer->vectorJoins();
1515+
for ( int i = 0; i < joins.size(); ++i )
1516+
{
1517+
QgsMapLayer* joinLayer = mConfigParser->mapLayerFromLayerId( joins[i].joinLayerId );
1518+
if ( joinLayer )
1519+
{
1520+
joinLayers << joinLayer;
1521+
}
1522+
QgsMapLayerRegistry::instance()->addMapLayers( joinLayers, false, true );
1523+
}
1524+
vectorLayer->updateFields();
1525+
}
14891526
QgsMapLayerRegistry::instance()->addMapLayers(
14901527
QList<QgsMapLayer *>() << theMapLayer, false, false );
14911528
}

0 commit comments

Comments
 (0)