mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-28 00:17:30 -05:00
[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.
This commit is contained in:
parent
07567820c0
commit
46db30ce3c
@ -51,7 +51,7 @@ 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.
|
||||
@ -59,6 +59,9 @@ class QgsConfigParser
|
||||
@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;
|
||||
|
||||
|
@ -15,6 +15,8 @@
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#include "qgsmaplayerregistry.h"
|
||||
|
||||
#include "qgsprojectparser.h"
|
||||
#include "qgsconfigcache.h"
|
||||
#include "qgscrscache.h"
|
||||
@ -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();
|
||||
@ -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 )
|
||||
{
|
||||
|
||||
@ -529,6 +549,7 @@ void QgsProjectParser::describeFeatureType( const QString& aTypeName, QDomElemen
|
||||
}
|
||||
}
|
||||
}
|
||||
QgsMapLayerRegistry::instance()->removeAllMapLayers();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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();
|
||||
@ -540,6 +556,7 @@ int QgsWFSServer::getFeature( QgsRequestHandler& request, const QString& format
|
||||
|
||||
}
|
||||
|
||||
QgsMapLayerRegistry::instance()->removeAllMapLayers();
|
||||
if ( featureCounter == 0 )
|
||||
throw QgsMapServiceException( "RequestNotWellFormed", mErrors.join( ". " ) );
|
||||
else
|
||||
@ -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();
|
||||
@ -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;
|
||||
|
@ -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 )
|
||||
{
|
||||
@ -936,6 +953,7 @@ int QgsWMSServer::getFeatureInfo( QDomDocument& result, QString version )
|
||||
}
|
||||
|
||||
restoreLayerFilters( originalLayerFilters );
|
||||
QgsMapLayerRegistry::instance()->removeAllMapLayers();
|
||||
delete featuresRect;
|
||||
delete infoPoint;
|
||||
return 0;
|
||||
@ -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();
|
||||
@ -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 );
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user