Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def pc_search(self):
- #Get the postcode to search for
- qid = QInputDialog()
- title = "Enter Postcode"
- label = "Postcode:"
- mode = QLineEdit.Normal
- default = ""
- pc, ok = QInputDialog.getText(qid, title, label, mode, default)
- print pc
- # Open the address data table and search for the postcode
- uri = QgsDataSourceURI()
- uri.setConnection("ictdsgdev5", "5432", "gistest", "postgres", "gistest1")
- uri.setDataSource("public", "OSADDBASE_LEICS", "geom", "POSTCODE like '" + pc.upper() + "%" + "'")
- print uri.sql()
- vlayer = QgsVectorLayer(uri.uri(), "Address", "postgres")
- print vlayer.isValid()
- if vlayer.isValid():
- # Add the address layer to the list of layers
- QgsMapLayerRegistry.instance().addMapLayer(vlayer)
- # Select the found addresses and zoom to them
- selectList=[]
- for feature in vlayer.getFeatures():
- geom = feature.geometry()
- selectList.append(feature.id())
- vlayer.setSelectedFeatures(selectList)
- else:
- #MessageBox displaying no address found
- QMessageBox.information(None, "Information", "No address(es) found for " + pc.upper())
Add Comment
Please, Sign In to add comment