Skip to content

Commit

Permalink
Server: create wfs layer objects only if layer is published as wfs. B…
Browse files Browse the repository at this point in the history
…ugfix funded by Sourcepole QGIS Enterprise
  • Loading branch information
mhugent committed Jan 30, 2015
1 parent c19eb60 commit 57a5794
Showing 1 changed file with 106 additions and 100 deletions.
206 changes: 106 additions & 100 deletions src/server/qgswfsprojectparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,120 +66,126 @@ void QgsWFSProjectParser::featureTypeList( QDomElement& parentElement, QDomDocum
QString type = elem.attribute( "type" );
if ( type == "vector" )
{
QString layerId = mProjectParser->layerId( elem );
if ( !wfsLayersId.contains( layerId ) )
{
continue;
}
QgsMapLayer *layer = mProjectParser->createLayerFromElement( elem );
if ( layer && wfsLayersId.contains( layer->id() ) )
if ( !layer )
{
QgsDebugMsg( QString( "add layer %1 to map" ).arg( layer->id() ) );
layerMap.insert( layer->id(), layer );

QDomElement layerElem = doc.createElement( "FeatureType" );
QDomElement nameElem = doc.createElement( "Name" );
//We use the layer name even though it might not be unique.
//Because the id sometimes contains user/pw information and the name is more descriptive
QString typeName = layer->name();
typeName = typeName.replace( " ", "_" );
QDomText nameText = doc.createTextNode( typeName );
nameElem.appendChild( nameText );
layerElem.appendChild( nameElem );

QDomElement titleElem = doc.createElement( "Title" );
QString titleName = layer->title();
if ( titleName.isEmpty() )
{
titleName = layer->name();
}
QDomText titleText = doc.createTextNode( titleName );
titleElem.appendChild( titleText );
layerElem.appendChild( titleElem );
continue;
}
QgsDebugMsg( QString( "add layer %1 to map" ).arg( layer->id() ) );
layerMap.insert( layer->id(), layer );

QDomElement abstractElem = doc.createElement( "Abstract" );
QString abstractName = layer->abstract();
if ( abstractName.isEmpty() )
{
abstractName = "";
}
QDomText abstractText = doc.createTextNode( abstractName );
abstractElem.appendChild( abstractText );
layerElem.appendChild( abstractElem );
QDomElement layerElem = doc.createElement( "FeatureType" );
QDomElement nameElem = doc.createElement( "Name" );
//We use the layer name even though it might not be unique.
//Because the id sometimes contains user/pw information and the name is more descriptive
QString typeName = layer->name();
typeName = typeName.replace( " ", "_" );
QDomText nameText = doc.createTextNode( typeName );
nameElem.appendChild( nameText );
layerElem.appendChild( nameElem );

//keyword list
if ( !layer->keywordList().isEmpty() )
{
QDomElement keywordsElem = doc.createElement( "Keywords" );
QDomText keywordsText = doc.createTextNode( layer->keywordList() );
keywordsElem.appendChild( keywordsText );
layerElem.appendChild( keywordsElem );
}
QDomElement titleElem = doc.createElement( "Title" );
QString titleName = layer->title();
if ( titleName.isEmpty() )
{
titleName = layer->name();
}
QDomText titleText = doc.createTextNode( titleName );
titleElem.appendChild( titleText );
layerElem.appendChild( titleElem );

//appendExGeographicBoundingBox( layerElem, doc, layer->extent(), layer->crs() );
QDomElement abstractElem = doc.createElement( "Abstract" );
QString abstractName = layer->abstract();
if ( abstractName.isEmpty() )
{
abstractName = "";
}
QDomText abstractText = doc.createTextNode( abstractName );
abstractElem.appendChild( abstractText );
layerElem.appendChild( abstractElem );

QDomElement srsElem = doc.createElement( "SRS" );
QDomText srsText = doc.createTextNode( layer->crs().authid() );
srsElem.appendChild( srsText );
layerElem.appendChild( srsElem );
//keyword list
if ( !layer->keywordList().isEmpty() )
{
QDomElement keywordsElem = doc.createElement( "Keywords" );
QDomText keywordsText = doc.createTextNode( layer->keywordList() );
keywordsElem.appendChild( keywordsText );
layerElem.appendChild( keywordsElem );
}

//wfs:Operations element
QDomElement operationsElement = doc.createElement( "Operations"/*wfs:Operations*/ );
//wfs:Query element
QDomElement queryElement = doc.createElement( "Query"/*wfs:Query*/ );
operationsElement.appendChild( queryElement );
//appendExGeographicBoundingBox( layerElem, doc, layer->extent(), layer->crs() );

QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer*>( layer );
QgsVectorDataProvider* provider = vlayer->dataProvider();
if (( provider->capabilities() & QgsVectorDataProvider::AddFeatures ) && wfstInsertLayersId.contains( layer->id() ) )
{
//wfs:Insert element
QDomElement insertElement = doc.createElement( "Insert"/*wfs:Insert*/ );
operationsElement.appendChild( insertElement );
}
if (( provider->capabilities() & QgsVectorDataProvider::ChangeAttributeValues ) &&
( provider->capabilities() & QgsVectorDataProvider::ChangeGeometries ) &&
wfstUpdateLayersId.contains( layer->id() ) )
{
//wfs:Update element
QDomElement updateElement = doc.createElement( "Update"/*wfs:Update*/ );
operationsElement.appendChild( updateElement );
}
if (( provider->capabilities() & QgsVectorDataProvider::DeleteFeatures ) && wfstDeleteLayersId.contains( layer->id() ) )
{
//wfs:Delete element
QDomElement deleteElement = doc.createElement( "Delete"/*wfs:Delete*/ );
operationsElement.appendChild( deleteElement );
}
QDomElement srsElem = doc.createElement( "SRS" );
QDomText srsText = doc.createTextNode( layer->crs().authid() );
srsElem.appendChild( srsText );
layerElem.appendChild( srsElem );

//wfs:Operations element
QDomElement operationsElement = doc.createElement( "Operations"/*wfs:Operations*/ );
//wfs:Query element
QDomElement queryElement = doc.createElement( "Query"/*wfs:Query*/ );
operationsElement.appendChild( queryElement );

QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer*>( layer );
QgsVectorDataProvider* provider = vlayer->dataProvider();
if (( provider->capabilities() & QgsVectorDataProvider::AddFeatures ) && wfstInsertLayersId.contains( layer->id() ) )
{
//wfs:Insert element
QDomElement insertElement = doc.createElement( "Insert"/*wfs:Insert*/ );
operationsElement.appendChild( insertElement );
}
if (( provider->capabilities() & QgsVectorDataProvider::ChangeAttributeValues ) &&
( provider->capabilities() & QgsVectorDataProvider::ChangeGeometries ) &&
wfstUpdateLayersId.contains( layer->id() ) )
{
//wfs:Update element
QDomElement updateElement = doc.createElement( "Update"/*wfs:Update*/ );
operationsElement.appendChild( updateElement );
}
if (( provider->capabilities() & QgsVectorDataProvider::DeleteFeatures ) && wfstDeleteLayersId.contains( layer->id() ) )
{
//wfs:Delete element
QDomElement deleteElement = doc.createElement( "Delete"/*wfs:Delete*/ );
operationsElement.appendChild( deleteElement );
}

layerElem.appendChild( operationsElement );
layerElem.appendChild( operationsElement );

QgsRectangle layerExtent = layer->extent();
QDomElement bBoxElement = doc.createElement( "LatLongBoundingBox" );
bBoxElement.setAttribute( "minx", QString::number( layerExtent.xMinimum() ) );
bBoxElement.setAttribute( "miny", QString::number( layerExtent.yMinimum() ) );
bBoxElement.setAttribute( "maxx", QString::number( layerExtent.xMaximum() ) );
bBoxElement.setAttribute( "maxy", QString::number( layerExtent.yMaximum() ) );
layerElem.appendChild( bBoxElement );
QgsRectangle layerExtent = layer->extent();
QDomElement bBoxElement = doc.createElement( "LatLongBoundingBox" );
bBoxElement.setAttribute( "minx", QString::number( layerExtent.xMinimum() ) );
bBoxElement.setAttribute( "miny", QString::number( layerExtent.yMinimum() ) );
bBoxElement.setAttribute( "maxx", QString::number( layerExtent.xMaximum() ) );
bBoxElement.setAttribute( "maxy", QString::number( layerExtent.yMaximum() ) );
layerElem.appendChild( bBoxElement );

// layer metadata URL
QString metadataUrl = layer->metadataUrl();
if ( !metadataUrl.isEmpty() )
// layer metadata URL
QString metadataUrl = layer->metadataUrl();
if ( !metadataUrl.isEmpty() )
{
QDomElement metaUrlElem = doc.createElement( "MetadataURL" );
QString metadataUrlType = layer->metadataUrlType();
metaUrlElem.setAttribute( "type", metadataUrlType );
QString metadataUrlFormat = layer->metadataUrlFormat();
if ( metadataUrlFormat == "text/xml" )
{
QDomElement metaUrlElem = doc.createElement( "MetadataURL" );
QString metadataUrlType = layer->metadataUrlType();
metaUrlElem.setAttribute( "type", metadataUrlType );
QString metadataUrlFormat = layer->metadataUrlFormat();
if ( metadataUrlFormat == "text/xml" )
{
metaUrlElem.setAttribute( "format", "XML" );
}
else
{
metaUrlElem.setAttribute( "format", "TXT" );
}
QDomText metaUrlText = doc.createTextNode( metadataUrl );
metaUrlElem.appendChild( metaUrlText );
layerElem.appendChild( metaUrlElem );
metaUrlElem.setAttribute( "format", "XML" );
}

parentElement.appendChild( layerElem );
else
{
metaUrlElem.setAttribute( "format", "TXT" );
}
QDomText metaUrlText = doc.createTextNode( metadataUrl );
metaUrlElem.appendChild( metaUrlText );
layerElem.appendChild( metaUrlElem );
}

parentElement.appendChild( layerElem );
}
}
return;
Expand Down

0 comments on commit 57a5794

Please sign in to comment.