def __init__( self, iface ): QDialog.__init__( self, iface.mainWindow() ) self.iface = iface self.setupUi( self ) self.osm2pgsql_path.setText( osm_tools.get_osm2pgsql_path() ) self.osmosis_path.setText( osm_tools.get_osmosis_path() ) QObject.connect( self.set_osm2pgsql_path, SIGNAL( "clicked()" ), self.set_osm2pgsql ) QObject.connect( self.set_osmosis_path, SIGNAL( "clicked()" ), self.set_osmosis )
def startCommand(self): self.first = True self.command_output.clear() #proj4 = str(self.parent.canvas.mapRenderer().destinationSrs().toProj4()).strip() #proj_str = '+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs' epsg = self.parent.canvas.mapRenderer().destinationSrs().epsg() if not epsg == 4326: self.err_msg('Projection must be in WGS 84/ESPG 4326 to run this command') input = str(self.input.text()) if not input: self.err_msg('Please provide and input .osm (or compressed .osm.bz2) file') return False if ';' in input: input = ' '.join(["%s" % i for i in input.split(';')]) else: input = '"%s"' % input style = str(self.style.text()) if not style: style = default_style settings = QSettings() selected = self.comboBox.currentText() settings.beginGroup( u"/PostgreSQL/connections/%s" % selected ) if not settings.contains("database"): # non-existent entry? QMessageBox.critical(self, "Error", "Unable to connect: there is no defined database connection \"%s\"." % selected) return get_value_str = lambda x: unicode(settings.value(x).toString()) host, db, username, password = map(get_value_str, ["host", "database", "username", "password"]) port = settings.value("port").toInt()[0] if not password and not settings.value("save").toBool(): (password, ok) = QInputDialog.getText(self, "Enter password", "Enter password for connection (or leave blank) \"%s\":" % selected, QLineEdit.Password) if not ok: return if not username: (username, ok) = QInputDialog.getText(self, "Enter username", "Enter username for connection (or leave blank) \"%s\":" % selected) if not ok: return settings.endGroup() # set env path = os.environ['PATH'] if not '/usr/local/bin' in path: path += ':/usr/local/bin' custom_path = str(osm_tools.get_osm2pgsql_path()) if custom_path and custom_path not in path: path = '%s:%s' % (custom_path,path) os.environ['PATH'] = path #self.command_output.append('sysenv: %s ' % ','.join([str(i) for i in self.process.systemEnvironment()])) cmd = '''osm2pgsql %(input)s -d %(db)s -S "%(style)s"''' % locals() if password: cmd += ' -W' if username: cmd += ' -U %s' % username if self.use_slim.isChecked(): cmd += ' --slim' if self.srs_choice.currentIndex() == 0: cmd += ' -l' if self.use_bbox_filter.isChecked(): # TODO - uninitialized bounds not predicatable across platforms if self.bounds == '0.0,0.0,0.0,0.0': self.command_output.clear() self.err_msg('<span style="color:red;"><b>Please zoom into a relevant area using existing data</b></span>') return else: cmd += ' --bbox %s' % self.bounds # requires extending the style file # should not be used with hstore support if self.use_extra_attributes.isChecked(): cmd += ' --extra-attributes' # not seeing a reason to expose these yet... #if self.use_multigeometry.isChecked(): # cmd += ' --multi-geometry' # Advanced features users will not likely need... # We can enable if need be #if self.use_hstore.isChecked(): # cmd += ' --hstore' #if self.radio_append.isChecked(): # cmd += ' --append' self.command.clear() self.command.append(cmd) self.process.start(cmd) if not self.process.waitForStarted(): self.err_msg('The command line tool osm2pgsql was not found.<br><br> Either it is not installed correctly or it is not available on your system PATH. <br><br>See OSM Tools > Tool Settings where you can set a custom location for the tool. <br><br>For information on installing osm2pgsql see:<br><br> http://wiki.openstreetmap.org/wiki/Osm2pgsql') return # TODO, if password is written, stdout stalls if password: byte_pass = QByteArray() byte_pass.append(password) self.process.write(byte_pass) self.process.closeWriteChannel()