-
Notifications
You must be signed in to change notification settings - Fork 0
/
gml_loader_dialog.py
84 lines (69 loc) · 3.36 KB
/
gml_loader_dialog.py
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
# -*- coding: utf-8 -*-
"""
/***************************************************************************
GmlLoaderDialog
A QGIS plugin
Load GML using OGR with customized config options
-------------------
begin : 2015-04-07
copyright : (C) 2015 by Juergen Weichand
email : juergen@weichand.de
website : http://www.weichand.de
***************************************************************************/
/***************************************************************************
* *
* 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. *
* *
***************************************************************************/
"""
from PyQt4 import QtGui, QtCore
from gml_loader_dialog_base import Ui_GmlLoaderDialogBase
import shutil
from osgeo import gdal
import os
class GmlLoaderDialog(QtGui.QDialog):
def __init__(self, parent):
QtGui.QDialog.__init__(self)
self.parent = parent
self.ui = Ui_GmlLoaderDialogBase()
self.ui.setupUi(self)
self.gfs_file = ''
QtCore.QObject.connect(self.ui.cmdSelectGfs, QtCore.SIGNAL('clicked()'), self.select_gfs)
QtCore.QObject.connect(self.ui.cmdSelectGml, QtCore.SIGNAL('clicked()'), self.select_gml)
def select_gfs(self):
self.gfs_file = QtGui.QFileDialog.getOpenFileName(self, 'Open File', '', 'OGR GFS (*.gfs)')
self.ui.lblGfs.setText(self.gfs_file)
def select_gml(self):
gdaltimeout = 5
gdal.SetConfigOption('GDAL_HTTP_TIMEOUT', str(gdaltimeout))
if self.ui.chkAttributesToFields.isChecked():
gdal.SetConfigOption('GML_ATTRIBUTES_TO_OGR_FIELDS', 'YES')
else:
gdal.SetConfigOption('GML_ATTRIBUTES_TO_OGR_FIELDS', 'NO')
if self.ui.chkResolveXlinkHref.isChecked():
gdal.SetConfigOption('GML_SKIP_RESOLVE_ELEMS', 'NONE')
else:
gdal.SetConfigOption('GML_SKIP_RESOLVE_ELEMS', 'ALL')
gml_file = QtGui.QFileDialog.getOpenFileName(self, 'Open File', '', 'GML (*.gml)')
target_gfs = str(gml_file).replace('.gml', '.gfs')
if len(self.gfs_file) > 0:
if len(gml_file):
if self.gfs_file != target_gfs:
if os.path.isfile(target_gfs):
shutil.copyfile(target_gfs, target_gfs + '.bak')
os.remove(target_gfs)
shutil.copyfile(self.gfs_file, target_gfs)
else:
if os.path.isfile(target_gfs):
shutil.copyfile(target_gfs, target_gfs + '.bak')
os.remove(target_gfs)
if len(gml_file) > 0:
gml_resolved = gml_file.replace('.gml', '.resolved.gml')
if os.path.isfile(gml_resolved):
os.remove(gml_resolved)
head, tail = os.path.split(gml_file)
self.parent.iface.addVectorLayer(gml_file, tail, 'ogr')
self.close()