/
qgsogrfactory.cpp
126 lines (108 loc) · 3.31 KB
/
qgsogrfactory.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/***************************************************************************
qgsogrfactory.cpp
--------------------------------------
Date : Sun Sep 16 12:18:21 AKDT 2007
Copyright : (C) 2004 Christoph Spoerri
Email : <spoerri@sourceforge.net>
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include <iostream>
#include <qmessagebox.h>
#include "qgsogrfactory.h"
#ifdef WIN32
#define QGISEXTERN extern "C" __declspec( dllexport )
#else
#define QGISEXTERN extern "C"
#endif
QgsOGRFactory::QgsOGRFactory()
{
}
QgsOGRFactory::~QgsOGRFactory()
{
}
bool QgsOGRFactory::testCapability(int t)
{
switch (t)
{
case QgsDataProviderFactory::Copy:
return TRUE;
case QgsDataProviderFactory::Rename:
return FALSE;
case QgsDataProviderFactory::Move:
return TRUE;
default:
return FALSE;
}
}
void QgsOGRFactory::setURI(QString uri)
{
dataSourceURI = uri;
OGRRegisterAll();
// make connection to the data source
std::cerr << "Data source uri is " << dataSourceURI << std::endl;
// try to open for read
ogrDS = OGRSFDriverRegistrar::Open(QFile::encodeName(dataSourceURI).constData(), FALSE, &ogrDriver);
if(ogrDS != NULL)
{
#ifdef QGISDEBUG
std::cerr << "Data source is valid" << std::endl;
#endif
valid = true;
} else
{
QMessageBox::warning(NULL, tr("Wrong Path/URI"), tr("The provided path for the dataset is not valid."));
valid = false;
}
}
bool QgsOGRFactory::create(QString newLocation, QString newName, QString type)
{
}
QgsDataProvider* QgsOGRFactory::open( QString name)
{
QgsDataProvider *d = (QgsDataProvider *) new QgsShapeFileProvider(dataSourceURI+QString("/")+name);
return d;
}
QStringList QgsOGRFactory::getLayers()
{
OGRLayer *lyr;
OGRFeatureDefn *lyrDef;
QStringList lyrList = QStringList();
if (valid) {
for (int i = 0 ; i < ogrDS->GetLayerCount(); i++)
{
lyr = ogrDS->GetLayer(i);
lyrDef = lyr->GetLayerDefn();
std::cerr << "Layer " << i << " is: " << lyrDef->GetName() << "\n";
//TODO append extension to name, so that it can be opened properly
lyrList.append(lyrDef->GetName());
}
}
return lyrList;
}
bool QgsOGRFactory::copy(QString oldName, QString newName)
{
OGRLayer *oldLyr;
std::cout << "Copy ogr datasource" << std::endl;
if (valid)
{
oldLyr = ogrDS->GetLayerByName((const char*) oldName);
std::cout << "datasource is " << ogrDriver->GetName() << std::endl;
if (QString::compare(ogrDriver->GetName(),"ESRI Shapefile")==0) {
std::cout << "Copy shapefile" << std::endl;
}
}
}
/**
* Class factory to return a pointer to a newly created
* QgsShapeFileProvider object
*/
QGISEXTERN QgsOGRFactory * classFactory_Fact()
{
return new QgsOGRFactory();
}