Skip to content

Commit d52c510

Browse files
author
marco
committed
WMS server: support relative pathes to spatialite dbs
1 parent f8bbe8f commit d52c510

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

src/mapserver/qgsprojectparser.cpp

+26-7
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "qgsprojectparser.h"
1919
#include "qgsconfigcache.h"
2020
#include "qgscrscache.h"
21+
#include "qgsdatasourceuri.h"
2122
#include "qgsmslayercache.h"
2223
#include "qgslogger.h"
2324
#include "qgsmapserviceexception.h"
@@ -773,18 +774,36 @@ QgsMapLayer* QgsProjectParser::createLayerFromElement( const QDomElement& elem,
773774
return 0;
774775
}
775776

776-
QString uri;
777-
QString absoluteUri;
778777
QDomElement dataSourceElem = elem.firstChildElement( "datasource" );
778+
QString uri = dataSourceElem.text();
779+
QString absoluteUri;
779780
if ( !dataSourceElem.isNull() )
780781
{
781782
//convert relative pathes to absolute ones if necessary
782-
uri = dataSourceElem.text();
783-
absoluteUri = convertToAbsolutePath( uri );
784-
if ( uri != absoluteUri )
783+
if ( uri.startsWith( "dbname" ) ) //database
784+
{
785+
QgsDataSourceURI dsUri( uri );
786+
if ( dsUri.host().isEmpty() ) //only convert path for file based databases
787+
{
788+
QString dbnameUri = dsUri.database();
789+
QString dbNameUriAbsolute = convertToAbsolutePath( dbnameUri );
790+
if ( dbnameUri != dbNameUriAbsolute )
791+
{
792+
dsUri.setDatabase( dbNameUriAbsolute );
793+
absoluteUri = dsUri.uri();
794+
QDomText absoluteTextNode = mXMLDoc->createTextNode( absoluteUri );
795+
dataSourceElem.replaceChild( absoluteTextNode, dataSourceElem.firstChild() );
796+
}
797+
}
798+
}
799+
else //file based data source
785800
{
786-
QDomText absoluteTextNode = mXMLDoc->createTextNode( absoluteUri );
787-
dataSourceElem.replaceChild( absoluteTextNode, dataSourceElem.firstChild() );
801+
absoluteUri = convertToAbsolutePath( uri );
802+
if ( uri != absoluteUri )
803+
{
804+
QDomText absoluteTextNode = mXMLDoc->createTextNode( absoluteUri );
805+
dataSourceElem.replaceChild( absoluteTextNode, dataSourceElem.firstChild() );
806+
}
788807
}
789808
}
790809

0 commit comments

Comments
 (0)