Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #--- Load a csv file and set CRS
- #---1 Reference library
- from PyQt4.QtGui import *
- from PyQt4.QtCore import *
- from qgis.core import *
- from qgis.utils import iface
- #--- 2 Turn of the CRS dialog box
- s = QSettings()
- oldValidation = s.value( "/Projections/defaultBehaviour")
- s.setValue( "/Projections/defaultBehaviour", "useGlobal" )
- #--- 3 Set file name here
- InFlnm='Test.csv'
- #--- 4 Set pathname here
- InDrPth='C:/_Work/PyQGIS/Test/'
- #--- 5 Build file name an path for uri
- InFlPth="file:///"+InDrPth+InFlnm
- #--- 6 Set import Sting here note only need to set x and y other come for free
- uri = InFlPth+"?delimiter=%s&xField=%s&yField=%s" % (",","x","y")
- #--- 7 Load point layer
- bh = QgsVectorLayer(uri, InFlnm, "delimitedtext")
- #--- 8 Set CRS - this does not appear to work not sure why but no matter the damn thing loads!
- bh.setCrs(QgsCoordinateReferenceSystem(4326, QgsCoordinateReferenceSystem.EpsgCrsId))
- #--- 9 Display the layer into QGIS (but it asks for CRS before displaying_
- QgsMapLayerRegistry.instance().addMapLayer(bh)
- #--- 10 turn CRS dialog box back on again
- s.setValue( "/Projections/defaultBehaviour", oldValidation )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement