Guest User

Untitled

a guest
Jan 16th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. def pc_search(self):
  2. #Get the postcode to search for
  3. qid = QInputDialog()
  4. title = "Enter Postcode"
  5. label = "Postcode:"
  6. mode = QLineEdit.Normal
  7. default = ""
  8.  
  9. pc, ok = QInputDialog.getText(qid, title, label, mode, default)
  10. print pc
  11.  
  12. # Open the address data table and search for the postcode
  13. uri = QgsDataSourceURI()
  14. uri.setConnection("ictdsgdev5", "5432", "gistest", "postgres", "gistest1")
  15. uri.setDataSource("public", "OSADDBASE_LEICS", "geom", "POSTCODE like '" + pc.upper() + "%" + "'")
  16. print uri.sql()
  17. vlayer = QgsVectorLayer(uri.uri(), "Address", "postgres")
  18. print vlayer.isValid()
  19.  
  20. if vlayer.isValid():
  21. # Add the address layer to the list of layers
  22. QgsMapLayerRegistry.instance().addMapLayer(vlayer)
  23.  
  24. # Select the found addresses and zoom to them
  25. selectList=[]
  26.  
  27. for feature in vlayer.getFeatures():
  28. geom = feature.geometry()
  29. selectList.append(feature.id())
  30.  
  31. vlayer.setSelectedFeatures(selectList)
  32.  
  33. else:
  34. #MessageBox displaying no address found
  35. QMessageBox.information(None, "Information", "No address(es) found for " + pc.upper())
Add Comment
Please, Sign In to add comment