Skip to content

Commit 94e9133

Browse files
author
mhugent
committedAug 27, 2008

File tree

14 files changed

+1953
-1
lines changed

14 files changed

+1953
-1
lines changed
 

‎src/plugins/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,6 @@ INSTALL(FILES qgisplugin.h qgsrendererplugin.h DESTINATION ${QGIS_INCLUDE_DIR})
2121
SUBDIRS (quick_print)
2222

2323

24-
SUBDIRS (coordinate_capture dxf2shp_converter)
24+
SUBDIRS (coordinate_capture dxf2shp_converter)
25+
26+
SUBDIRS (ogr_converter)
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# $Id$
2+
#
3+
# CMake configuration file for OGR Converter plugin
4+
# Author: Mateusz Loskot <mateusz@loskot.net>
5+
########################################################
6+
# Files
7+
8+
SET (OGR_CONVERTER_SRCS
9+
plugin.cpp
10+
dialog.cpp
11+
format.cpp
12+
translator.cpp
13+
)
14+
15+
SET (OGR_CONVERTER_UIS ogrconverterguibase.ui)
16+
17+
SET (OGR_CONVERTER_MOC_HDRS
18+
plugin.h
19+
dialog.h
20+
)
21+
22+
SET (OGR_CONVERTER_RCCS ogrconverter.qrc)
23+
24+
SET (OGR_CONVERTER_PLUGIN ogrconverterplugin)
25+
26+
########################################################
27+
# Build
28+
29+
QT4_WRAP_UI (OGR_CONVERTER_UIS_H ${OGR_CONVERTER_UIS})
30+
31+
QT4_WRAP_CPP (OGR_CONVERTER_MOC_SRCS ${OGR_CONVERTER_MOC_HDRS})
32+
33+
QT4_ADD_RESOURCES(OGR_CONVERTER_RCC_SRCS ${OGR_CONVERTER_RCCS})
34+
35+
ADD_LIBRARY (${OGR_CONVERTER_PLUGIN} MODULE
36+
${OGR_CONVERTER_SRCS}
37+
${OGR_CONVERTER_MOC_SRCS}
38+
${OGR_CONVERTER_RCC_SRCS}
39+
${OGR_CONVERTER_UIS_H}
40+
)
41+
42+
INCLUDE_DIRECTORIES (
43+
${CMAKE_CURRENT_BINARY_DIR}
44+
../../core
45+
../../core/raster
46+
../../core/renderer
47+
../../core/symbology
48+
../../gui
49+
..
50+
${GDAL_INCLUDE_DIR}
51+
)
52+
53+
TARGET_LINK_LIBRARIES(${OGR_CONVERTER_PLUGIN}
54+
${GDAL_LIBRARY}
55+
qgis_core
56+
qgis_gui
57+
)
58+
59+
########################################################
60+
# Install
61+
62+
INSTALL(TARGETS ${OGR_CONVERTER_PLUGIN}
63+
RUNTIME DESTINATION ${QGIS_PLUGIN_DIR}
64+
LIBRARY DESTINATION ${QGIS_PLUGIN_DIR}
65+
)

‎src/plugins/ogr_converter/README

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
OGR Layer Converter Pluginm, Version 0.1 (Alpha)
2+
------------------------------------------------------------------------------
3+
Author: Mateusz Loskot <mateusz@loskot.net>
4+
5+
OGR Layer Converter aims to be a GUI-based implementation of well-known
6+
ogr2ogr utility from GDAL/OGR package. The plugin translates layers
7+
between OGR supported formats built-in GDAL/OGR library available for
8+
particular QGIS installation.
9+
Built-in formats are listed in drop-down boxes.
10+
11+
Currently, it is possible to translate one selected source
12+
layer to another OGR format.
13+
14+
Testing appreciated.
15+
16+
------------------------------------------------------------------------------
17+
TODO
18+
------------------------------------------------------------------------------
19+
translator.h: // TODO: Implement, currently always overwrite
20+
translator.h: // TODO: Append option not supported
21+
dialog.cpp:// TODO: Add support of QGIS projection selector
22+
dialog.cpp: // TODO: Transformation support
23+
dialog.cpp: // TODO: Transformation support
24+
dialog.cpp: // TODO: SRS transformation support
25+
dialog.cpp: // TODO: Use try-catch to display more meaningful error messages from Translator
26+
plugin.cpp: // TODO: Who is responsible for OGR cleanup?
27+
translator.cpp: // TODO: RAII for OGR handlers!!!
28+
translator.cpp: // TODO: Support translation of all layers from input data source
29+
translator.cpp: // TODO: -nlt option support
30+
translator.cpp: // TODO: Implement SRS transformation
31+
translator.cpp: // TODO: Append and createion options not implemented
32+
translator.cpp: // TODO: RAII for feature handlers!!!
33+
translator.cpp: // TODO: Transform feature geometry
34+
translator.cpp: // TODO: Skip failures support
35+
translator.cpp: // TODO: Add support for creation options

‎src/plugins/ogr_converter/dialog.cpp

Lines changed: 453 additions & 0 deletions
Large diffs are not rendered by default.

‎src/plugins/ogr_converter/dialog.h

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// $Id$
2+
//////////////////////////////////////////////////////////////////////////////
3+
//
4+
// Copyright (C) 2008 by Mateusz Loskot <mateusz@loskot.net>
5+
//
6+
// This program is free software; you can redistribute it and/or modify
7+
// it under the terms of the GNU General Public License as published by
8+
// the Free Software Foundation; either version 2 of the License,
9+
// or (at your option) any later version.
10+
//
11+
//////////////////////////////////////////////////////////////////////////////
12+
#ifndef QGIS_PLUGIN_OGRCONV_DIALOG_H_INCLUDED
13+
#define QGIS_PLUGIN_OGRCONV_DIALOG_H_INCLUDED
14+
15+
// qgis::plugin::ogrconv
16+
#include "format.h"
17+
#include <ui_ogrconverterguibase.h>
18+
// Qt4
19+
#include <QDialog>
20+
21+
namespace qgis { namespace plugin { namespace ogrconv {
22+
23+
/**
24+
@author Mateusz Loskot
25+
*/
26+
class Dialog : public QDialog, private Ui::OgrConverterGuiBase
27+
{
28+
Q_OBJECT
29+
30+
public:
31+
32+
Dialog(QWidget* parent = 0, Qt::WFlags fl = 0);
33+
~Dialog();
34+
35+
private:
36+
37+
static const int context_id = 0;
38+
39+
FormatsRegistry mFrmts;
40+
Format mSrcFormat;
41+
Format mDstFormat;
42+
43+
void resetSrcUi();
44+
void resetDstUi();
45+
void setButtonState(QPushButton* btn, bool isProtocol);
46+
47+
void populateFormats();
48+
void populateLayers(QString const& url);
49+
bool testConnection(QString const& url);
50+
QString openFile();
51+
QString openDirectory();
52+
53+
private slots:
54+
55+
void on_buttonBox_accepted();
56+
void on_buttonBox_rejected();
57+
void on_buttonBox_helpRequested();
58+
void on_radioSrcFile_toggled(bool checked);
59+
void on_radioSrcDirectory_toggled(bool checked);
60+
void on_radioSrcProtocol_toggled(bool checked);
61+
void on_buttonSelectSrc_clicked();
62+
void on_buttonSelectDst_clicked();
63+
void on_comboSrcFormats_currentIndexChanged(int index);
64+
void on_comboDstFormats_currentIndexChanged(int index);
65+
};
66+
67+
}}} // namespace qgis::plugin::ogrconv
68+
69+
#endif // QGIS_PLUGIN_OGRCONV_DIALOG_H_INCLUDED

‎src/plugins/ogr_converter/format.cpp

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
// $Id$
2+
//////////////////////////////////////////////////////////////////////////////
3+
//
4+
// Copyright (C) 2008 by Mateusz Loskot <mateusz@loskot.net>
5+
//
6+
// This program is free software; you can redistribute it and/or modify
7+
// it under the terms of the GNU General Public License as published by
8+
// the Free Software Foundation; either version 2 of the License,
9+
// or (at your option) any later version.
10+
//
11+
//////////////////////////////////////////////////////////////////////////////
12+
13+
// qgis::plugin::ogrconv
14+
#include "format.h"
15+
// Qt4
16+
#include <QString>
17+
18+
namespace qgis { namespace plugin { namespace ogrconv {
19+
20+
Format::Format()
21+
{
22+
}
23+
24+
Format::Format(QString const& c, QString const& n)
25+
: mCode(c), mName(n), mTypeFlags(0)
26+
{
27+
}
28+
29+
Format::Format(QString const& c, QString const& n, unsigned char const& t)
30+
: mCode(c), mName(n), mTypeFlags(t)
31+
{
32+
}
33+
34+
Format::Format(QString const& c, QString const& n, QString const& p, unsigned char const& t)
35+
: mCode(c), mName(n), mProtocol(p), mTypeFlags(t)
36+
{
37+
}
38+
39+
QString const& Format::code() const
40+
{
41+
return mCode;
42+
}
43+
44+
QString const& Format::name() const
45+
{
46+
return mName;
47+
}
48+
49+
QString const& Format::protocol() const
50+
{
51+
return mProtocol;
52+
}
53+
54+
unsigned char const& Format::type() const
55+
{
56+
return mTypeFlags;
57+
}
58+
59+
60+
FormatsRegistry::FormatsRegistry()
61+
{
62+
init();
63+
}
64+
65+
void FormatsRegistry::add(Format const& frmt)
66+
{
67+
QString code = frmt.code();
68+
mFrmts[code] = frmt;
69+
}
70+
71+
Format const& FormatsRegistry::find(QString const& code)
72+
{
73+
mCache = mFrmts.value(code);
74+
return mCache;
75+
}
76+
77+
void FormatsRegistry::init()
78+
{
79+
add(Format("AVCBin", "Arc/Info Binary Coverage", Format::eFile));
80+
add(Format("AVCE00", "Arc/Info .E00 (ASCII) Coverage", Format::eFile));
81+
add(Format("BNA", "Atlas BNA", Format::eFile));
82+
add(Format("CSV", "Comma Separated Value", Format::eFile | Format::eDirectory));
83+
add(Format("DODS", "DODS/OPeNDAP", Format::eFile));
84+
add(Format("DGN", "Microstation DGN", Format::eFile));
85+
add(Format("ESRI Shapefile", "ESRI Shapefile", Format::eFile | Format::eDirectory));
86+
add(Format("FMEObjects Gateway", "FMEObjects Gateway", Format::eFile));
87+
add(Format("Geoconcept Text Export", "Geoconcept", Format::eFile));
88+
add(Format("GML", "Geography Markup Language", Format::eFile));
89+
add(Format("GMT", "GMT ASCII Vectors", Format::eFile));
90+
add(Format("GPX", "GPS Exchange Format", Format::eFile));
91+
add(Format("GeoJSON", "GeoJSON", Format::eFile)); // FIXME: Format::eProtocol));
92+
add(Format("GRASS", "GRASS", Format::eDirectory));
93+
add(Format("Informix DataBlade", "IDB", "IDB:", Format::eProtocol));
94+
add(Format("Interlis 1", "INTERLIS", Format::eFile));
95+
add(Format("Interlis 2", "INTERLIS", Format::eFile));
96+
add(Format("Ingres Database", "INGRES", "@driver=ingres,", Format::eProtocol));
97+
add(Format("KML", "KML", Format::eFile));
98+
add(Format("MapInfo", "MapInfo File", Format::eFile));
99+
add(Format("Memory", "Memory", Format::eFile));
100+
add(Format("MySQL", "MySQL", "MySQL:", Format::eProtocol));
101+
add(Format("ODBC", "Open DataBase Connectivity", "ODBC:", Format::eProtocol));
102+
add(Format("OGDI", "Open Geographic Datastore Interface Vectors", "gltp:", Format::eProtocol));
103+
add(Format("OCI", "Oracle Spatial", "OCI:", Format::eProtocol));
104+
add(Format("PGeo", "ESRI Personal GeoDatabase", "PGeo:", Format::eFile | Format::eProtocol));
105+
add(Format("PostgreSQL", "PostgreSQL", "PG:", Format::eProtocol));
106+
add(Format("S57", "IHO S-57", Format::eFile));
107+
add(Format("SDE", "ESRI ArcSDE", "SDE:", Format::eProtocol));
108+
add(Format("SDTS", "SDTS Topological Vector Profile", Format::eFile));
109+
add(Format("SQLite", "SQLite Database File", Format::eFile));
110+
add(Format("UK.NTF", "UK National Transfer Format", Format::eFile));
111+
add(Format("TIGER", "U.S. Census TIGER/Line", Format::eFile));
112+
add(Format("VRT", "Virtual Datasource", Format::eFile));
113+
add(Format("XPLANE", "X-Plane/Flighgear Aeronautical Data", Format::eFile));
114+
}
115+
116+
}}} // namespace qgis::plugin::ogrconv
117+

‎src/plugins/ogr_converter/format.h

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// $Id$
2+
//////////////////////////////////////////////////////////////////////////////
3+
//
4+
// Copyright (C) 2008 by Mateusz Loskot <mateusz@loskot.net>
5+
//
6+
// This program is free software; you can redistribute it and/or modify
7+
// it under the terms of the GNU General Public License as published by
8+
// the Free Software Foundation; either version 2 of the License,
9+
// or (at your option) any later version.
10+
//
11+
//////////////////////////////////////////////////////////////////////////////
12+
#ifndef QGIS_PLUGIN_OGRCONV_FORMATS_H_INCLUDED
13+
#define QGIS_PLUGIN_OGRCONV_FORMATS_H_INCLUDED
14+
15+
// Qt4
16+
#include <QMap>
17+
#include <QString>
18+
19+
namespace qgis { namespace plugin { namespace ogrconv {
20+
21+
class Format
22+
{
23+
public:
24+
25+
enum Type
26+
{
27+
eUnknown = 0,
28+
eFile = 1,
29+
eDirectory = 2,
30+
eProtocol = 4
31+
};
32+
33+
Format();
34+
Format(QString const& c, QString const& n);
35+
Format(QString const& c, QString const& n, unsigned char const& t);
36+
Format(QString const& c, QString const& n, QString const& p, unsigned char const& t);
37+
38+
QString const& code() const;
39+
QString const& name() const;
40+
QString const& protocol() const;
41+
unsigned char const& type() const;
42+
43+
private:
44+
45+
QString mCode;
46+
QString mName;
47+
QString mProtocol;
48+
unsigned char mTypeFlags;
49+
};
50+
51+
inline bool isFormatType(unsigned char const& frmt, Format::Type const& type)
52+
{
53+
return ((frmt & type) == type);
54+
}
55+
56+
class FormatsRegistry
57+
{
58+
public:
59+
60+
FormatsRegistry();
61+
62+
void add(Format const& frmt);
63+
Format const& find(QString const& code);
64+
65+
private:
66+
67+
void init();
68+
69+
QMap<QString, Format> mFrmts;
70+
Format mCache;
71+
};
72+
73+
74+
}}} // namespace qgis::plugin::ogrconv
75+
76+
#endif // QGIS_PLUGIN_OGRCONV_FORMATS_H_INCLUDED
1.2 KB
Loading
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<RCC>
2+
<qresource prefix="/ogrconverter/" >
3+
<file>ogrconverter.png</file>
4+
</qresource>
5+
</RCC>
Lines changed: 378 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,378 @@
1+
<ui version="4.0" >
2+
<class>OgrConverterGuiBase</class>
3+
<widget class="QDialog" name="OgrConverterGuiBase" >
4+
<property name="geometry" >
5+
<rect>
6+
<x>0</x>
7+
<y>0</y>
8+
<width>521</width>
9+
<height>450</height>
10+
</rect>
11+
</property>
12+
<property name="sizePolicy" >
13+
<sizepolicy vsizetype="MinimumExpanding" hsizetype="MinimumExpanding" >
14+
<horstretch>0</horstretch>
15+
<verstretch>0</verstretch>
16+
</sizepolicy>
17+
</property>
18+
<property name="minimumSize" >
19+
<size>
20+
<width>520</width>
21+
<height>450</height>
22+
</size>
23+
</property>
24+
<property name="windowTitle" >
25+
<string>OGR Layer Converter</string>
26+
</property>
27+
<property name="windowIcon" >
28+
<iconset>
29+
<normaloff/>
30+
</iconset>
31+
</property>
32+
<layout class="QGridLayout" name="gridLayout" >
33+
<item row="0" column="0" >
34+
<widget class="QGroupBox" name="srcGroupBox" >
35+
<property name="title" >
36+
<string>Source</string>
37+
</property>
38+
<widget class="QWidget" name="" >
39+
<property name="geometry" >
40+
<rect>
41+
<x>20</x>
42+
<y>30</y>
43+
<width>461</width>
44+
<height>28</height>
45+
</rect>
46+
</property>
47+
<layout class="QHBoxLayout" name="horizontalLayout" >
48+
<item>
49+
<widget class="QLabel" name="labelSrcFormat" >
50+
<property name="minimumSize" >
51+
<size>
52+
<width>52</width>
53+
<height>22</height>
54+
</size>
55+
</property>
56+
<property name="text" >
57+
<string>Format:</string>
58+
</property>
59+
</widget>
60+
</item>
61+
<item>
62+
<widget class="QComboBox" name="comboSrcFormats" >
63+
<property name="minimumSize" >
64+
<size>
65+
<width>200</width>
66+
<height>0</height>
67+
</size>
68+
</property>
69+
<property name="maxCount" >
70+
<number>200</number>
71+
</property>
72+
</widget>
73+
</item>
74+
<item>
75+
<spacer name="horizontalSpacer_3" >
76+
<property name="orientation" >
77+
<enum>Qt::Horizontal</enum>
78+
</property>
79+
<property name="sizeHint" stdset="0" >
80+
<size>
81+
<width>40</width>
82+
<height>20</height>
83+
</size>
84+
</property>
85+
</spacer>
86+
</item>
87+
</layout>
88+
</widget>
89+
<widget class="QWidget" name="" >
90+
<property name="geometry" >
91+
<rect>
92+
<x>20</x>
93+
<y>70</y>
94+
<width>461</width>
95+
<height>21</height>
96+
</rect>
97+
</property>
98+
<layout class="QHBoxLayout" name="horizontalLayout_4" >
99+
<item>
100+
<widget class="QRadioButton" name="radioSrcFile" >
101+
<property name="text" >
102+
<string>File</string>
103+
</property>
104+
</widget>
105+
</item>
106+
<item>
107+
<widget class="QRadioButton" name="radioSrcDirectory" >
108+
<property name="text" >
109+
<string>Directory</string>
110+
</property>
111+
</widget>
112+
</item>
113+
<item>
114+
<widget class="QRadioButton" name="radioSrcProtocol" >
115+
<property name="text" >
116+
<string>Remote source</string>
117+
</property>
118+
</widget>
119+
</item>
120+
</layout>
121+
</widget>
122+
<widget class="QWidget" name="" >
123+
<property name="geometry" >
124+
<rect>
125+
<x>21</x>
126+
<y>140</y>
127+
<width>461</width>
128+
<height>28</height>
129+
</rect>
130+
</property>
131+
<layout class="QHBoxLayout" name="horizontalLayout_2" >
132+
<item>
133+
<widget class="QLabel" name="labelSrcLayer" >
134+
<property name="minimumSize" >
135+
<size>
136+
<width>52</width>
137+
<height>22</height>
138+
</size>
139+
</property>
140+
<property name="text" >
141+
<string>Layer:</string>
142+
</property>
143+
</widget>
144+
</item>
145+
<item>
146+
<widget class="QComboBox" name="comboSrcLayer" >
147+
<property name="minimumSize" >
148+
<size>
149+
<width>300</width>
150+
<height>0</height>
151+
</size>
152+
</property>
153+
</widget>
154+
</item>
155+
<item>
156+
<spacer name="horizontalSpacer_2" >
157+
<property name="orientation" >
158+
<enum>Qt::Horizontal</enum>
159+
</property>
160+
<property name="sizeHint" stdset="0" >
161+
<size>
162+
<width>88</width>
163+
<height>17</height>
164+
</size>
165+
</property>
166+
</spacer>
167+
</item>
168+
</layout>
169+
</widget>
170+
<widget class="QWidget" name="" >
171+
<property name="geometry" >
172+
<rect>
173+
<x>21</x>
174+
<y>100</y>
175+
<width>457</width>
176+
<height>34</height>
177+
</rect>
178+
</property>
179+
<layout class="QHBoxLayout" name="horizontalLayout_6" >
180+
<item>
181+
<widget class="QLabel" name="labelSrcDataset" >
182+
<property name="text" >
183+
<string>Dataset:</string>
184+
</property>
185+
</widget>
186+
</item>
187+
<item>
188+
<widget class="QLineEdit" name="inputSrcDataset" >
189+
<property name="minimumSize" >
190+
<size>
191+
<width>300</width>
192+
<height>0</height>
193+
</size>
194+
</property>
195+
</widget>
196+
</item>
197+
<item>
198+
<widget class="QPushButton" name="buttonSelectSrc" >
199+
<property name="minimumSize" >
200+
<size>
201+
<width>90</width>
202+
<height>0</height>
203+
</size>
204+
</property>
205+
<property name="text" >
206+
<string>Browse</string>
207+
</property>
208+
</widget>
209+
</item>
210+
</layout>
211+
</widget>
212+
</widget>
213+
</item>
214+
<item row="2" column="0" >
215+
<widget class="QDialogButtonBox" name="buttonBox" >
216+
<property name="standardButtons" >
217+
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
218+
</property>
219+
</widget>
220+
</item>
221+
<item row="1" column="0" >
222+
<widget class="QGroupBox" name="dstGroupBox" >
223+
<property name="title" >
224+
<string>Target</string>
225+
</property>
226+
<widget class="QWidget" name="" >
227+
<property name="geometry" >
228+
<rect>
229+
<x>22</x>
230+
<y>33</y>
231+
<width>454</width>
232+
<height>28</height>
233+
</rect>
234+
</property>
235+
<layout class="QHBoxLayout" name="horizontalLayout_3" >
236+
<item>
237+
<widget class="QLabel" name="labelDstFormat" >
238+
<property name="minimumSize" >
239+
<size>
240+
<width>52</width>
241+
<height>22</height>
242+
</size>
243+
</property>
244+
<property name="text" >
245+
<string>Format:</string>
246+
</property>
247+
</widget>
248+
</item>
249+
<item>
250+
<widget class="QComboBox" name="comboDstFormats" >
251+
<property name="minimumSize" >
252+
<size>
253+
<width>300</width>
254+
<height>0</height>
255+
</size>
256+
</property>
257+
<property name="maxCount" >
258+
<number>200</number>
259+
</property>
260+
</widget>
261+
</item>
262+
<item>
263+
<spacer name="horizontalSpacer" >
264+
<property name="orientation" >
265+
<enum>Qt::Horizontal</enum>
266+
</property>
267+
<property name="sizeHint" stdset="0" >
268+
<size>
269+
<width>88</width>
270+
<height>17</height>
271+
</size>
272+
</property>
273+
</spacer>
274+
</item>
275+
</layout>
276+
</widget>
277+
<widget class="QWidget" name="" >
278+
<property name="geometry" >
279+
<rect>
280+
<x>20</x>
281+
<y>71</y>
282+
<width>457</width>
283+
<height>34</height>
284+
</rect>
285+
</property>
286+
<layout class="QHBoxLayout" name="horizontalLayout_7" >
287+
<item>
288+
<widget class="QLabel" name="labelDstDataset" >
289+
<property name="text" >
290+
<string>Dataset:</string>
291+
</property>
292+
</widget>
293+
</item>
294+
<item>
295+
<widget class="QLineEdit" name="inputDstDataset" >
296+
<property name="minimumSize" >
297+
<size>
298+
<width>300</width>
299+
<height>0</height>
300+
</size>
301+
</property>
302+
</widget>
303+
</item>
304+
<item>
305+
<widget class="QPushButton" name="buttonSelectDst" >
306+
<property name="minimumSize" >
307+
<size>
308+
<width>90</width>
309+
<height>0</height>
310+
</size>
311+
</property>
312+
<property name="text" >
313+
<string>Browse</string>
314+
</property>
315+
</widget>
316+
</item>
317+
</layout>
318+
</widget>
319+
<widget class="QWidget" name="" >
320+
<property name="geometry" >
321+
<rect>
322+
<x>20</x>
323+
<y>110</y>
324+
<width>451</width>
325+
<height>24</height>
326+
</rect>
327+
</property>
328+
<layout class="QHBoxLayout" name="horizontalLayout_8" >
329+
<item>
330+
<widget class="QLabel" name="labelDstLayer" >
331+
<property name="minimumSize" >
332+
<size>
333+
<width>52</width>
334+
<height>0</height>
335+
</size>
336+
</property>
337+
<property name="text" >
338+
<string>Layer:</string>
339+
</property>
340+
</widget>
341+
</item>
342+
<item>
343+
<widget class="QLineEdit" name="inputDstLayer" >
344+
<property name="minimumSize" >
345+
<size>
346+
<width>300</width>
347+
<height>0</height>
348+
</size>
349+
</property>
350+
</widget>
351+
</item>
352+
<item>
353+
<spacer name="horizontalSpacer_5" >
354+
<property name="orientation" >
355+
<enum>Qt::Horizontal</enum>
356+
</property>
357+
<property name="sizeHint" stdset="0" >
358+
<size>
359+
<width>40</width>
360+
<height>20</height>
361+
</size>
362+
</property>
363+
</spacer>
364+
</item>
365+
</layout>
366+
</widget>
367+
</widget>
368+
</item>
369+
</layout>
370+
</widget>
371+
<layoutdefault spacing="6" margin="11" />
372+
<tabstops>
373+
<tabstop>inputSrcDataset</tabstop>
374+
<tabstop>buttonSelectSrc</tabstop>
375+
</tabstops>
376+
<resources/>
377+
<connections/>
378+
</ui>

‎src/plugins/ogr_converter/plugin.cpp

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
// $Id$
2+
//////////////////////////////////////////////////////////////////////////////
3+
//
4+
// begin : Aug 24, 2008
5+
// copyright : (C) 2008 by Mateusz Loskot
6+
// email : mateusz@loskot.net
7+
//
8+
//////////////////////////////////////////////////////////////////////////////
9+
//
10+
// This program is free software; you can redistribute it and/or modify
11+
// it under the terms of the GNU General Public License as published by
12+
// the Free Software Foundation; either version 2 of the License,
13+
// or (at your option) any later version.
14+
//
15+
//////////////////////////////////////////////////////////////////////////////
16+
17+
// qgis::plugin::ogrconv
18+
#include "plugin.h"
19+
#include "dialog.h"
20+
// QGIS
21+
#include <qgisinterface.h>
22+
#include <qgisgui.h>
23+
#include <qgslogger.h>
24+
// Qt
25+
#include <QAction>
26+
#include <QToolBar>
27+
// std
28+
#include <cassert>
29+
30+
namespace qgis { namespace plugin { namespace ogrconv {
31+
32+
// GDAL/OGR loaded into private namesapce
33+
#include <ogr_api.h>
34+
35+
static const char * const sIdent = "$Id$";
36+
static const QString sName = QObject::tr("OGR Layer Converter");
37+
static const QString sDescription = QObject::tr("Translates vector layers between formats supported by OGR library");
38+
static const QString sPluginVersion = QObject::tr("Version 0.1");
39+
static const QgisPlugin::PLUGINTYPE sPluginType = QgisPlugin::UI;
40+
41+
//////////////////////////////////////////////////////////////////////////////
42+
// THE FOLLOWING METHODS ARE MANDATORY FOR ALL PLUGINS
43+
//////////////////////////////////////////////////////////////////////////////
44+
45+
OgrPlugin::OgrPlugin(QgisInterface * theQgisInterface) :
46+
QgisPlugin(sName, sDescription, sPluginVersion, sPluginType),
47+
mQGisIface(theQgisInterface),
48+
mQActionPointer(0)
49+
{
50+
assert(0 != mQGisIface);
51+
}
52+
53+
OgrPlugin::~OgrPlugin()
54+
{
55+
}
56+
57+
void OgrPlugin::initGui()
58+
{
59+
// Create the action for tool
60+
mQActionPointer = new QAction(QIcon(":/ogrconverter/ogrconverter.png"), tr("Run OGR Layer Converter"), this);
61+
62+
// Set the what's this text
63+
mQActionPointer->setWhatsThis(tr("Replace this with a short description of the what the plugin does"));
64+
65+
// Connect the action to the run
66+
connect(mQActionPointer, SIGNAL(triggered()), this, SLOT(run()));
67+
68+
// Add the icon to the toolbar
69+
mQGisIface->addToolBarIcon(mQActionPointer);
70+
mQGisIface->addPluginMenu(tr("OG&R Converter"), mQActionPointer);
71+
}
72+
73+
//method defined in interface
74+
void OgrPlugin::help()
75+
{
76+
//implement me!
77+
}
78+
79+
void OgrPlugin::run()
80+
{
81+
assert(0 != mQGisIface);
82+
83+
Dialog* ogrDialog = new Dialog(mQGisIface->getMainWindow(), QgisGui::ModalDialogFlags);
84+
ogrDialog->setAttribute(Qt::WA_DeleteOnClose);
85+
ogrDialog->show();
86+
}
87+
88+
void OgrPlugin::unload()
89+
{
90+
assert(0 != mQGisIface);
91+
92+
// TODO: Who is responsible for OGR cleanup?
93+
//OGRCleanupAll();
94+
95+
// remove the GUI
96+
mQGisIface->removePluginMenu("&OGR Layer Converter", mQActionPointer);
97+
mQGisIface->removeToolBarIcon(mQActionPointer);
98+
delete mQActionPointer;
99+
}
100+
101+
/////////////////////////////////////////////////////////////////////////////
102+
// THE FOLLOWING CODE IS AUTOGENERATED BY THE PLUGIN BUILDER SCRIPT
103+
// YOU WOULD NORMALLY NOT NEED TO MODIFY THIS, AND YOUR PLUGIN
104+
// MAY NOT WORK PROPERLY IF YOU MODIFY THIS INCORRECTLY
105+
/////////////////////////////////////////////////////////////////////////////
106+
107+
// Required extern functions needed for every plugin
108+
// These functions can be called prior to creating an instance
109+
// of the plugin class.
110+
111+
// Class factory to return a new instance of the plugin class
112+
QGISEXTERN QgisPlugin * classFactory(QgisInterface * theQgisInterfacePointer)
113+
{
114+
return new OgrPlugin(theQgisInterfacePointer);
115+
}
116+
117+
// Return the name of the plugin - note that we do not user class members as
118+
// the class may not yet be insantiated when this method is called.
119+
QGISEXTERN QString name()
120+
{
121+
return sName;
122+
}
123+
124+
// Return the description
125+
QGISEXTERN QString description()
126+
{
127+
return sDescription;
128+
}
129+
130+
// Return the type (either UI or MapLayer plugin)
131+
QGISEXTERN int type()
132+
{
133+
return sPluginType;
134+
}
135+
136+
// Return the version number for the plugin
137+
QGISEXTERN QString version()
138+
{
139+
return sPluginVersion;
140+
}
141+
142+
// Delete ourself
143+
QGISEXTERN void unload(QgisPlugin * thePluginPointer)
144+
{
145+
delete thePluginPointer;
146+
}
147+
148+
}}} // namespace qgis::plugin::ogrconv
149+

‎src/plugins/ogr_converter/plugin.h

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
// $Id$
2+
//////////////////////////////////////////////////////////////////////////////
3+
//
4+
// begin : Aug 24, 2008
5+
// copyright : (C) 2008 by Mateusz Loskot
6+
// email : mateusz@loskot.net
7+
//
8+
//////////////////////////////////////////////////////////////////////////////
9+
//
10+
// This program is free software; you can redistribute it and/or modify
11+
// it under the terms of the GNU General Public License as published by
12+
// the Free Software Foundation; either version 2 of the License,
13+
// or (at your option) any later version.
14+
//
15+
//////////////////////////////////////////////////////////////////////////////
16+
#ifndef QGIS_PLUGIN_OGRCONV_PLUGIN_H_INCLUDED
17+
#define QGIS_PLUGIN_OGRCONV_PLUGIN_H_INCLUDED
18+
19+
// QGIS
20+
#include "../qgisplugin.h"
21+
// Qt4
22+
#include <QObject>
23+
24+
// Forward declarations
25+
class QAction;
26+
class QToolBar;
27+
class QgisInterface;
28+
29+
namespace qgis { namespace plugin { namespace ogrconv {
30+
31+
/**
32+
* \class OgrPlugin
33+
* \brief Translates vector layers between formats supported by OGR library.
34+
*/
35+
class OgrPlugin : public QObject, public QgisPlugin
36+
{
37+
Q_OBJECT
38+
39+
public:
40+
41+
//////////////////////////////////////////////////////////////////////////
42+
// MANDATORY PLUGIN METHODS FOLLOW
43+
//////////////////////////////////////////////////////////////////////////
44+
45+
/**
46+
* Constructor for a plugin. The QgisInterface pointer is passed by
47+
* QGIS when it attempts to instantiate the plugin.
48+
* @param theInterface Pointer to the QgisInterface object.
49+
*/
50+
OgrPlugin(QgisInterface * theInterface);
51+
52+
//! Destructor
53+
virtual ~OgrPlugin();
54+
55+
public slots:
56+
57+
/**
58+
* Initialize the GUI interface for the plugin.
59+
* This is only called once when the plugin is added to the plugin
60+
* registry in the QGIS application.
61+
*/
62+
virtual void initGui();
63+
64+
/**
65+
* Slot called when the menu item is triggered.
66+
* If you created more menu items / toolbar buttons in initiGui,
67+
* you should create a separate handler for each action - this
68+
* single run() method will not be enough.
69+
*/
70+
void run();
71+
72+
/**
73+
* Unload the plugin by cleaning up the GUI.
74+
*/
75+
void unload();
76+
77+
//! show the help document
78+
void help();
79+
80+
private:
81+
82+
//////////////////////////////////////////////////////////////////////////
83+
// MANDATORY PLUGIN PROPERTY DECLARATIONS
84+
//////////////////////////////////////////////////////////////////////////
85+
86+
// FIXME: Is it used at all?
87+
int mPluginType;
88+
89+
//! Pointer to the QGIS interface object
90+
QgisInterface *mQGisIface;
91+
92+
//!pointer to the qaction for this plugin
93+
QAction * mQActionPointer;
94+
95+
//////////////////////////////////////////////////////////////////////////
96+
// ADD YOUR OWN PROPERTY DECLARATIONS AFTER THIS POINT.....
97+
//////////////////////////////////////////////////////////////////////////
98+
99+
}; // OgrPlugin
100+
101+
}}} // namespace qgis::plugin::ogrconv
102+
103+
#endif // QGIS_PLUGIN_OGRCONV_PLUGIN_H_INCLUDED

‎src/plugins/ogr_converter/translator.cpp

Lines changed: 419 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// $Id$
2+
//////////////////////////////////////////////////////////////////////////////
3+
//
4+
// Copyright (C) 2008 by Mateusz Loskot <mateusz@loskot.net>
5+
//
6+
// This program is free software; you can redistribute it and/or modify
7+
// it under the terms of the GNU General Public License as published by
8+
// the Free Software Foundation; either version 2 of the License,
9+
// or (at your option) any later version.
10+
//
11+
//////////////////////////////////////////////////////////////////////////////
12+
#ifndef QGIS_PLUGIN_OGRCONV_TRANSLATOR_H_INCLUDED
13+
#define QGIS_PLUGIN_OGRCONV_TRANSLATOR_H_INCLUDED
14+
15+
// Qt4
16+
#include <QString>
17+
18+
namespace qgis { namespace plugin { namespace ogrconv {
19+
20+
// GDAL/OGR loaded into private namespace
21+
#include <ogr_api.h>
22+
23+
class Translator
24+
{
25+
public:
26+
27+
Translator();
28+
Translator(QString const& src, QString const& dst, QString const& format);
29+
30+
QString const& targetFormat() const;
31+
void setTargetFormat(QString const& format);
32+
33+
QString const& targetLayer() const;
34+
void setTargetLayer(QString const& layer);
35+
36+
QString const& sourceLayer() const;
37+
void setSourceLayer(QString const& layer);
38+
39+
QString const& targetReferenceSystem() const;
40+
void setTargetReferenceSystem(QString const& srs);
41+
42+
QString const& sourceReferenceSystem() const;
43+
void setSourceReferenceSystem(QString const& srs);
44+
45+
bool isTargetUpdate() const;
46+
void setUpdateTarget(bool update);
47+
48+
bool isTargetLayerOverwrite() const;
49+
// TODO: Implement, currently always overwrite
50+
// void setTargetLayerOverwrite(bool overwrite);
51+
52+
bool translate();
53+
54+
private:
55+
56+
QString mSrcUrl;
57+
QString mDstUrl;
58+
QString mDstFormat;
59+
QString mSrcLayer;
60+
QString mDstLayer;
61+
QString mSrcSrs;
62+
QString mDstSrs;
63+
bool mDstUpdate;
64+
bool mDstLayerOverwrite;
65+
// TODO: Append option not supported
66+
// bool mDstLayerAppend;
67+
68+
bool translateLayer(OGRDataSourceH srcDs, OGRLayerH srcLayer, OGRDataSourceH dstDs);
69+
bool copyFields(OGRFeatureDefnH layerDefn, OGRLayerH layer);
70+
bool copyFeatures(OGRLayerH srcLayer, OGRLayerH dstLayer);
71+
72+
OGRSFDriverH findDriver(QString const& name);
73+
OGRLayerH findLayer(OGRDataSourceH ds, QString const& name, int& index);
74+
OGRDataSourceH openDataSource(QString const& url, bool readOnly);
75+
OGRDataSourceH openDataTarget(QString const& url, bool update);
76+
77+
};
78+
79+
}}} // namespace qgis::plugin::ogrconv
80+
81+
#endif // QGIS_PLUGIN_OGRCONV_TRANSLATOR_H_INCLUDED

0 commit comments

Comments
 (0)
Please sign in to comment.