[Lizmap] Publish WFS services in QGIS with Lizmap
René-Luc Dhont
rldhont at gmail.com
Mon May 30 01:27:39 PDT 2022
Hi,
Here is the QGIS code
```c
// Creating a SpatiaLite database can be quite slow on some file systems
// so we create a GDAL in-memory file, and then copy it on
// the file system.
GDALDriverH hDrv = GDALGetDriverByName( "SQLite" );
if ( !hDrv )
{
logMessageWithReason( QStringLiteral( "GDAL SQLite driver not
available" ) );
return false;
}
const QString vsimemFilename = QStringLiteral(
"/vsimem/qgis_cache_template_%1/features.sqlite" ).arg(
reinterpret_cast< quintptr >( this ), QT_POINTER_SIZE * 2, 16,
QLatin1Char( '0' ) );
mCacheTablename = CPLGetBasename( vsimemFilename.toStdString().c_str() );
VSIUnlink( vsimemFilename.toStdString().c_str() );
const char *apszOptions[] = { "INIT_WITH_EPSG=NO", "SPATIALITE=YES",
nullptr };
GDALDatasetH hDS = GDALCreate( hDrv,
vsimemFilename.toUtf8().constData(), 0, 0, 0, GDT_Unknown,
const_cast<char **>( apszOptions ) );
if ( !hDS )
{
logMessageWithReason( QStringLiteral( "GDALCreate() failed: %1"
).arg( CPLGetLastErrorMsg() ) );
return false;
}
GDALClose( hDS );
// Copy the temporary database back to disk
vsi_l_offset nLength = 0;
GByte *pabyData = VSIGetMemFileBuffer(
vsimemFilename.toStdString().c_str(), &nLength, TRUE );
Q_ASSERT( !QFile::exists( mCacheDbname ) );
VSILFILE *fp = VSIFOpenL( mCacheDbname.toStdString().c_str(), "wb" );
if ( fp )
{
VSIFWriteL( pabyData, 1, nLength, fp );
VSIFCloseL( fp );
CPLFree( pabyData );
}
else
{
CPLFree( pabyData );
logMessageWithReason( QStringLiteral( "Cannot copy file to %1: %2"
).arg( mCacheDbname ).arg( CPLGetLastErrorMsg() ) );
return false;
}
```
So the database to store WFS Features has been created in memory with
GDAL/OGR and the path "/vsimem/qgis_cache_template_%1/features.sqlite"
and will be write to disk in QGIS cache directory.
The mCacheDbname is defined like that:
```c
Q_ASSERT( mCacheDbname.isEmpty() );
static QAtomicInt sTmpCounter = 0;
int tmpCounter = ++sTmpCounter;
QString cacheDirectory( acquireCacheDirectory() );
mCacheDbname = QDir( cacheDirectory ).filePath( QStringLiteral(
"cache_%1.sqlite" ).arg( tmpCounter ) );
Q_ASSERT( !QFile::exists( mCacheDbname ) );
```
In the log provided by Günter, we don't have enough reason. The
CPLGetLastErrorMsg is empty.
Günter, can you provide more logs arround the message "Cannot create
temporary SpatiaLite cache.: Cannot copy file to" ?
Regards,
René-Luc DHONT
Le 30/05/2022 à 08:57, FANGAIN Marjorie a écrit :
>
> Hi,
>
> I’ve got also some problems with WFS layers for several months.
>
> I’ve created a ticket on github :
>
> https://github.com/3liz/lizmap-web-client/issues/2792
>
> Marjorie *FANGAIN*
>
> *De :* Lizmap <lizmap-bounces at lists.osgeo.org> *De la part de* Peter
> Berger
> *Envoyé :* vendredi 27 mai 2022 11:26
> *À :* G. Wagner, Wagner-IT <info at wagner-it.de>; lizmap at lists.osgeo.org
> *Objet :* Re: [Lizmap] Publish WFS services in QGIS with Lizmap
>
> EXTERNAL EMAIL
> Original Sender: SRS0=UtB1=WD=lists.osgeo.org=lizmap-bounces at osgeo.org
>
> I made the same observation. On Windows 10 all WFS layers are well
> displayed in Lizmap but not on a osgeolive linux installation with the
> same QGIS file.
>
> Peter
>
> Von meinem iPhone gesendet
>
>
>
> Am 27.05.2022 um 07:34 schrieb G. Wagner, Wagner-IT
> <info at wagner-it.de>:
>
>
>
> Hi everyone,
>
> I am trying to publish a WFS service integrated in QGIS with QGIS
> Server/Lizmap (QGIS-Server 3.22.7, Lizmap 3.5.3).
>
> The corresponding layer name is displayed in the Lizmap client but
> no data is displayed. Or sometimes and only once in a zoom level.
>
> The error message in the QGIS error log could fit to this (cache
> problem?):
>
> WARNING WFS[1497]: Cannot create temporary SpatiaLite cache.:
> Cannot copy file to
> /home/qgis/.local/share/QGIS/QGIS3/profiles/default/cache/wfsprovider/pid_1497/cache_1.sqlite:
>
> Creating the directories
> "/home/qgis/.local/share/QGIS/QGIS3/profiles/default/cache/wfsprovider"
> with appropriate permissions does not change anything.
>
> In the Apache error.log there is still the message:
>
> QNetworkDiskCache::prepare() unable to open temporary file
>
> In the Apache.conf is defined:
>
> FcgidInitialEnv QGIS_SERVER_CACHE_DIRECTORY "/home/qgis/cache"
>
> What am I doing wrong?
>
> Greeting
>
> Günter
>
>
> _______________________________________________
> Lizmap mailing list
> Lizmap at lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/lizmap
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/lizmap/attachments/20220530/abc9063b/attachment-0001.htm>
More information about the Lizmap
mailing list