Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 554304
Collapse All | Expand All

(-)file_not_specified_in_diff (-18 / +101 lines)
Line  Link Here
0
-- a/src/ImportExport/ImportExportGdal.cpp 2015-06-15 18:48:39.604575423 +0200
0
++ b/src/ImportExport/ImportExportGdal.cpp 2015-06-15 18:48:39.604575423 +0200
Lines 21-30 Link Here
21
#include "ProjectionChooser.h"
21
#include "ProjectionChooser.h"
22
#include "Global.h"
22
#include "Global.h"
23
23
24
#include "cpl_vsi.h"
24
#include <cpl_vsi.h>
25
#include <gdal.h>
26
#include <gdal_priv.h>
25
27
26
#include <QDir>
28
#include <QDir>
27
29
30
28
bool parseContainer(QDomElement& e, Layer* aLayer);
31
bool parseContainer(QDomElement& e, Layer* aLayer);
29
32
30
ImportExportGdal::ImportExportGdal(Document* doc)
33
ImportExportGdal::ImportExportGdal(Document* doc)
Lines 55-60 bool ImportExportGdal::saveFile(QString) Link Here
55
bool ImportExportGdal::export_(const QList<Feature *>& featList)
58
bool ImportExportGdal::export_(const QList<Feature *>& featList)
56
{
59
{
57
    const char *pszDriverName = "SQLite";
60
    const char *pszDriverName = "SQLite";
61
    QString fileName(HOMEDIR + "/test.sqlite");
62
#ifdef GDAL2
63
    GDALDriver *poDriver;
64
    GDALDriverManager *driverManager = GetGDALDriverManager();
65
    GDALAllRegister();
66
    driverManager->AutoLoadDrivers();
67
68
    poDriver = driverManager->GetDriverByName(pszDriverName);
69
    if( poDriver == NULL )
70
    {
71
        qDebug( "%s driver not available.", pszDriverName );
72
        return false;
73
    }
74
75
    /* Create create options */
76
    char **createOptions = NULL;
77
    createOptions = CSLSetNameValue( createOptions, "SPATIALITE", "YES" );
78
79
    /* Open new dataset */
80
    GDALDataset *poDS;
81
82
    QFile::remove(fileName);
83
    poDS = poDriver->Create( fileName.toUtf8().constData(), 0, 0, 0, GDT_Unknown, createOptions );
84
    if( poDS == NULL )
85
    {
86
        qDebug( "Creation of output file failed." );
87
        return false;
88
    }
89
    poDS->ExecuteSQL("PRAGMA synchronous = OFF", NULL, NULL);
90
91
    /* Create Spatial reference object */
92
    OGRSpatialReference *poSRS;
93
    poSRS = new OGRSpatialReference();
94
    poSRS->importFromEPSG(4326);
95
96
    /* Create layer options */
97
    char **layerOptions = NULL;
98
    layerOptions = CSLSetNameValue( layerOptions, "FORMAT", "SPATIALITE" );
99
    layerOptions = CSLSetNameValue( layerOptions, "SPATIAL_INDEX", "YES" );
100
101
    /* Create layer */
102
    OGRLayer *poLayer;
103
    poLayer = poDS->CreateLayer( "osm", poSRS, wkbUnknown, layerOptions);
104
105
    /* Free the options */
106
    CSLDestroy( createOptions );
107
    CSLDestroy( layerOptions );
108
#else
109
    /* This is legacy code, and is not tested at all */
58
    OGRSFDriver *poDriver;
110
    OGRSFDriver *poDriver;
59
111
60
    OGRRegisterAll();
112
    OGRRegisterAll();
Lines 68-75 bool ImportExportGdal::export_(const QList<Feature *>& featList) Link Here
68
120
69
    OGRDataSource *poDS;
121
    OGRDataSource *poDS;
70
122
71
    QFile::remove(QString(HOMEDIR + "/test.sqlite"));
123
    QFile::remove(fileName);
72
    poDS = poDriver->CreateDataSource( QString(HOMEDIR + "/test.sqlite").toUtf8().constData(), NULL );
124
    poDS = poDriver->CreateDataSource( fileName.toUtf8().constData(), NULL );
73
    if( poDS == NULL )
125
    if( poDS == NULL )
74
    {
126
    {
75
        qDebug( "Creation of output file failed." );
127
        qDebug( "Creation of output file failed." );
Lines 89-94 bool ImportExportGdal::export_(const QList<Feature *>& featList) Link Here
89
    OGRLayer *poLayer;
141
    OGRLayer *poLayer;
90
    poLayer = poDS->CreateLayer( "osm", poSRS, wkbUnknown, papszOptions);
142
    poLayer = poDS->CreateLayer( "osm", poSRS, wkbUnknown, papszOptions);
91
    CSLDestroy( papszOptions );
143
    CSLDestroy( papszOptions );
144
#endif
145
92
146
93
    if( poLayer == NULL )
147
    if( poLayer == NULL )
94
    {
148
    {
Lines 142-148 bool ImportExportGdal::export_(const QList<Feature *>& featList) Link Here
142
        }
196
        }
143
        OGRFeature::DestroyFeature( poFeature );
197
        OGRFeature::DestroyFeature( poFeature );
144
    }
198
    }
199
#ifdef GDAL2
200
    GDALClose( (GDALDatasetH) poDS );
201
#else
145
    OGRDataSource::DestroyDataSource( poDS );
202
    OGRDataSource::DestroyDataSource( poDS );
203
#endif
146
    return true;
204
    return true;
147
}
205
}
148
206
Lines 264-270 Feature* ImportExportGdal::parseGeometry(Layer* aLayer, OGRGeometry *poGeometry) Link Here
264
322
265
// import the  input
323
// import the  input
266
324
267
bool ImportExportGdal::importGDALDataset(OGRDataSource* poDS, Layer* aLayer, bool confirmProjection)
325
#ifndef GDAL2
326
#define GDALDataset OGRDataSource
327
#endif
328
bool ImportExportGdal::importGDALDataset(GDALDataset* poDS, Layer* aLayer, bool confirmProjection)
329
#undef GDALDataset
268
{
330
{
269
    int ogrError;
331
    int ogrError;
270
332
Lines 422-432 bool ImportExportGdal::importGDALDataset(OGRDataSource* poDS, Layer* aLayer, boo Link Here
422
484
423
bool ImportExportGdal::import(Layer* aLayer)
485
bool ImportExportGdal::import(Layer* aLayer)
424
{
486
{
487
#ifdef GDAL2
488
    GDALAllRegister();
489
    GDALDataset *poDS;
490
    poDS = (GDALDataset *) GDALOpen( FileName.toUtf8().constData(), GA_ReadOnly );
491
#else
425
    OGRRegisterAll();
492
    OGRRegisterAll();
426
493
    OGRDataSource *poDS;
427
    OGRDataSource       *poDS;
428
429
    poDS = OGRSFDriverRegistrar::Open( FileName.toUtf8().constData(), FALSE );
494
    poDS = OGRSFDriverRegistrar::Open( FileName.toUtf8().constData(), FALSE );
495
#endif
496
430
    if( poDS == NULL )
497
    if( poDS == NULL )
431
    {
498
    {
432
        qDebug( "GDAL Open failed.\n" );
499
        qDebug( "GDAL Open failed.\n" );
Lines 435-456 bool ImportExportGdal::import(Layer* aLayer) Link Here
435
502
436
    importGDALDataset(poDS, aLayer, M_PREFS->getGdalConfirmProjection());
503
    importGDALDataset(poDS, aLayer, M_PREFS->getGdalConfirmProjection());
437
504
438
    OGRDataSource::DestroyDataSource( poDS );
505
    GDALClose( (GDALDatasetH) poDS );
439
506
440
    return true;
507
    return true;
441
}
508
}
442
509
443
bool ImportExportGdal::import(Layer* aLayer, const QByteArray& ba, bool confirmProjection)
510
bool ImportExportGdal::import(Layer* aLayer, const QByteArray& ba, bool confirmProjection)
444
{
511
{
445
    OGRRegisterAll();
446
447
    OGRDataSource       *poDS;
448
//    int ogrError;
449
450
    GByte* content = (GByte*)(ba.constData());
512
    GByte* content = (GByte*)(ba.constData());
451
    /*FILE* f = */VSIFileFromMemBuffer("/vsimem/temp", content, ba.size(), FALSE);
513
    /*FILE* f = */VSIFileFromMemBuffer("/vsimem/temp", content, ba.size(), FALSE);
452
514
515
#ifdef GDAL2
516
    GDALAllRegister();
517
    GDALDataset *poDS;
518
    poDS = (GDALDataset *) GDALOpen( "/vsimem/temp", GA_ReadOnly );
519
#else
520
    OGRRegisterAll();
521
    OGRDataSource *poDS;
453
    poDS = OGRSFDriverRegistrar::Open( "/vsimem/temp", FALSE );
522
    poDS = OGRSFDriverRegistrar::Open( "/vsimem/temp", FALSE );
523
#endif
524
454
    if( poDS == NULL )
525
    if( poDS == NULL )
455
    {
526
    {
456
        qDebug( "GDAL Open failed.\n" );
527
        qDebug( "GDAL Open failed.\n" );
Lines 458-464 bool ImportExportGdal::import(Layer* aLayer, const QByteArray& ba, bool confirmP Link Here
458
    }
529
    }
459
    importGDALDataset(poDS, aLayer, confirmProjection);
530
    importGDALDataset(poDS, aLayer, confirmProjection);
460
531
461
    OGRDataSource::DestroyDataSource( poDS );
532
    GDALClose( (GDALDatasetH) poDS );
462
533
463
    return true;
534
    return true;
464
}
535
}
465
-- a/src/ImportExport/ImportExportGdal.h 2015-06-15 18:50:42.884995287 +0200
536
++ b/src/ImportExport/ImportExportGdal.h 2015-06-15 18:50:42.884995287 +0200
Lines 13-19 Link Here
13
#define ImportExportGDAL_H
13
#define ImportExportGDAL_H
14
14
15
#include "IImportExport.h"
15
#include "IImportExport.h"
16
#include "ogrsf_frmts.h"
16
17
#include <ogrsf_frmts.h>
18
#include <gdal.h>
19
#include <gdal_priv.h>
20
#include <gdal_version.h>
21
22
#if GDAL_VERSION_MAJOR == 2
23
#define GDAL2
24
#endif
17
25
18
class Projection;
26
class Projection;
19
class Layer;
27
class Layer;
Lines 52-58 class ImportExportGdal : public IImportExport Link Here
52
    Node *nodeFor(Layer* aLayer, OGRPoint point);
60
    Node *nodeFor(Layer* aLayer, OGRPoint point);
53
    Way *readWay(Layer* aLayer, OGRLineString *poRing);
61
    Way *readWay(Layer* aLayer, OGRLineString *poRing);
54
62
55
    bool importGDALDataset(OGRDataSource *poDs, Layer *aLayer, bool confirmProjection);
63
#ifndef GDAL2
64
#define GDALDataset OGRDataSource
65
#endif
66
    bool importGDALDataset(GDALDataset *poDs, Layer *aLayer, bool confirmProjection);
67
#undef GDALDataset
56
68
57
private:
69
private:
58
    QHash<OGRPoint, Node*> pointHash;
70
    QHash<OGRPoint, Node*> pointHash;

Return to bug 554304