Advertisement
Guest User

Untitled

a guest
Nov 25th, 2014
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. #--- Load a csv file and set CRS
  2. #---1 Reference library
  3. from PyQt4.QtGui import *
  4. from PyQt4.QtCore import *
  5. from qgis.core import *
  6. from qgis.utils import iface
  7.  
  8. #--- 2 Turn of the CRS dialog box
  9. s = QSettings()
  10. oldValidation = s.value( "/Projections/defaultBehaviour")
  11. s.setValue( "/Projections/defaultBehaviour", "useGlobal" )
  12.  
  13. #--- 3 Set file name here
  14. InFlnm='Test.csv'
  15.  
  16. #--- 4 Set pathname here
  17. InDrPth='C:/_Work/PyQGIS/Test/'
  18.  
  19. #--- 5 Build file name an path for uri
  20. InFlPth="file:///"+InDrPth+InFlnm
  21.  
  22. #--- 6 Set import Sting here note only need to set x and y other come for free
  23. uri = InFlPth+"?delimiter=%s&xField=%s&yField=%s" % (",","x","y")
  24.  
  25. #--- 7 Load point layer
  26. bh = QgsVectorLayer(uri, InFlnm, "delimitedtext")
  27.  
  28. #--- 8 Set CRS - this does not appear to work not sure why but no matter the damn thing loads!
  29. bh.setCrs(QgsCoordinateReferenceSystem(4326, QgsCoordinateReferenceSystem.EpsgCrsId))
  30.  
  31. #--- 9 Display the layer into QGIS (but it asks for CRS before displaying_
  32. QgsMapLayerRegistry.instance().addMapLayer(bh)
  33.  
  34. #--- 10 turn CRS dialog box back on again
  35. s.setValue( "/Projections/defaultBehaviour", oldValidation )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement