SlideShare a Scribd company logo
1 of 20
Download to read offline
WORKSHOP ON THE
PYTHON PROGRAMMING
IN QGIS
Presented by:
Jyoti Dhakal (07)
Archana K.C (09)
Megha Shrestha (27)
Sushmita Timilsina (32)
Python programming and Qgis
• Python is a very powerful, simple and understandable
language
• QGIS is an open source for presenting, interpreting and
analyzing the geographic information
Program schedule
• Setup
• Loading layers in QGIS
• Assessing active layers
• Iterating over vector layers
• Modifying layers
• Communicating with User
• Using map canvas to visualize map
Setup
• QGIS is an open source
• For this workshop we are using QGIS 2.0.1 Dufor
• For python programming in QGIS
• Plugins -> Python console
•Before we begin
• from qgis.core import *
• import qgis.utils
Import the capabilities and utilities to be used through Python in
Python console
Loading vector layer through
python programming
• layer = QgsVectorLayer(data_source, layer_name, provider_name)
where:
QgsVectorLayer is the inbuilt class inside PyQgis
data_source is the location of the vector layer
layer_name is the name displayed in layers
provider_name is the name of the data provider
Contd…
• Layer from PostGIS database can be loaded using QgsDataSourceURI class
uri = QgsDataSourceURI()
uri.setConnection("localhost", "5432", "dbname", "johny", "xxx")
uri.setDataSource("public", "roads", "the_geom", "cityid = 2643")
vlayer = QgsVectorLayer(uri.uri(), "layer_name_you_like", "postgres")
• CSV or other delimited text files can be loaded as follows:
uri = "/some/path/file.csv?delimiter=%s&xField=%s&yField=%s" % (";", "x","y")
vlayer = QgsVectorLayer(uri, "layer_name_you_like", "delimitedtext")
Contd…
• GPX files
• SpatiaLite database
• WFS connection
Adding layer to the qgis map
layer
• QgsMapLayerRegistry is needed which is already defined in qgis.core
module
QgsMapLayerRegistry.instance().addMapLayer(layer)
Adding Raster Layer
• L=qgis.utils.iface.addRasterLayer('D:sushmitaCapture.gif')
Other information about the layer added
• L.width()
• L.height()
• L.extent()
• L.metadata()
Assessing the layers
• There are number of ways to assess the layers
• First of you need to import qgis.utils.iface
• Method 1 :
Run the following command:
>>> aLayer = qgis.utils.iface.activeLayer()
>>> aLayer
• Method 2 :
>>> canvas = qgis.utils.iface.mapCanvas()
>>> cLayer = canvas.currentLayer()
>>> cLayer.name()
• Method 3 :
>>> allLayers = canvas.layers()
>>> for i in allLayers: print i.name()...
It will return only the layers those are visible.
• Method 3 :
• It’s also useful sometimes to access layers in the order they are stacked in the table of
contents
>>> canvas.layer(0)
<qgis.core.QgsVectorLayer object at 0x99eaeec>
>>> canvas.layer(0).name()
Geometry type
• QGIS return 0,1,2 for Point, Line and Polygon features
respectively
Geometry construction
• from coordinates
gPnt = QgsGeometry.fromPoint(QgsPoint(1,1))
gLine = QgsGeometry.fromPolyline( [ QgsPoint(1,1), QgsPoint(2,2) ] )
gPolygon = QgsGeometry.fromPolygon( [ [ QgsPoint(1,1), QgsPoint(2,2), 
QgsPoint(2,1) ] ] )
Accessor functions are required to extract the information
>>>gPnt.asPoint()
(1,1)
>>> gLine.asPolyline()
[(1,1), (2,2)]
>>> gPolygon.asPolygon()
[[(1,1), (2,2), (2,1), (1,1)]]
Iterating over vector layers
• features = layer.getFeatures()
• for f in features:
• geom = f.geometry()
• print "Feature ID %d: " % f.id()
• print "Area:", geom.area()
• print "Perimeter:", geom.length()
•
Modifying vector layers
• Start Editing
layer.startEditing()
• Functionality that supports editing of layer data
caps = layer.dataProvider().capabilities()
• Layer.commitChanges()
• Layer.rollback()
• # create layer
• vl = QgsVectorLayer("Point", "temporary_points", "memory")
• pr = vl.dataProvider()
• # add fields
• pr.addAttributes( [ QgsField("name", QVariant.String),
• QgsField("age", QVariant.Int),
• QgsField("size", QVariant.Double) ] )
• # add a feature
• fet = QgsFeature()
• fet.setGeometry( QgsGeometry.fromPoint(QgsPoint(10,10)) )
• fet.setAttributes(["Johny", 2, 0.3])
• pr.addFeatures([fet])
Communicating with the user
• Making a graphical user interface for easy communicating with the
user
• QgsMessageBar
• QPushButton
• progressMessageBar
• pushMessage
Map visualizing in canvas
• Map canvas is implemented as QgsMapCanvas class in qgis.gui
module
Workshop with python qgis

More Related Content

What's hot

Qgis raster to point
Qgis raster to pointQgis raster to point
Qgis raster to pointFondUS.inc
 
Remote Sensing: Resolution Merge
Remote Sensing: Resolution MergeRemote Sensing: Resolution Merge
Remote Sensing: Resolution MergeKamlesh Kumar
 
GeoServer an introduction for beginners
GeoServer an introduction for beginnersGeoServer an introduction for beginners
GeoServer an introduction for beginnersGeoSolutions
 
Computer Vision - Image Filters
Computer Vision - Image FiltersComputer Vision - Image Filters
Computer Vision - Image FiltersYoss Cohen
 
Using Decision trees with GIS data for modeling and prediction
Using Decision trees with GIS data for modeling and prediction Using Decision trees with GIS data for modeling and prediction
Using Decision trees with GIS data for modeling and prediction Omar F. Althuwaynee
 
Digital image processing ppt
Digital image processing pptDigital image processing ppt
Digital image processing pptkhanam22
 
Log Transformation in Image Processing with Example
Log Transformation in Image Processing with ExampleLog Transformation in Image Processing with Example
Log Transformation in Image Processing with ExampleMustak Ahmmed
 
Quantum QIS (QGIS) Düzenle Menüsü
Quantum QIS (QGIS) Düzenle MenüsüQuantum QIS (QGIS) Düzenle Menüsü
Quantum QIS (QGIS) Düzenle MenüsüLevent Sabah
 
Channel capacity of continuous memory less channel
Channel capacity of continuous memory less channelChannel capacity of continuous memory less channel
Channel capacity of continuous memory less channelVARUN KUMAR
 
Python Programming for ArcGIS: Part I
Python Programming for ArcGIS: Part IPython Programming for ArcGIS: Part I
Python Programming for ArcGIS: Part IDUSPviz
 
State of OpenGXT: 오픈소스 공간분석엔진
State of OpenGXT: 오픈소스 공간분석엔진State of OpenGXT: 오픈소스 공간분석엔진
State of OpenGXT: 오픈소스 공간분석엔진MinPa Lee
 
QGIS Training.pptx
QGIS Training.pptxQGIS Training.pptx
QGIS Training.pptxSeemaAjay7
 
Lecture 06 geometric transformations and image registration
Lecture 06 geometric transformations and image registrationLecture 06 geometric transformations and image registration
Lecture 06 geometric transformations and image registrationobertksg
 
Practical machine learning - Part 1
Practical machine learning - Part 1Practical machine learning - Part 1
Practical machine learning - Part 1Traian Rebedea
 
IMAGE FUSION IN IMAGE PROCESSING
IMAGE FUSION IN IMAGE PROCESSINGIMAGE FUSION IN IMAGE PROCESSING
IMAGE FUSION IN IMAGE PROCESSINGgarima0690
 
Chapter10 image segmentation
Chapter10 image segmentationChapter10 image segmentation
Chapter10 image segmentationasodariyabhavesh
 

What's hot (20)

Qgis raster to point
Qgis raster to pointQgis raster to point
Qgis raster to point
 
Remote Sensing: Resolution Merge
Remote Sensing: Resolution MergeRemote Sensing: Resolution Merge
Remote Sensing: Resolution Merge
 
GeoServer an introduction for beginners
GeoServer an introduction for beginnersGeoServer an introduction for beginners
GeoServer an introduction for beginners
 
Computer Vision - Image Filters
Computer Vision - Image FiltersComputer Vision - Image Filters
Computer Vision - Image Filters
 
Hyperspectral Imaging
Hyperspectral ImagingHyperspectral Imaging
Hyperspectral Imaging
 
Using Decision trees with GIS data for modeling and prediction
Using Decision trees with GIS data for modeling and prediction Using Decision trees with GIS data for modeling and prediction
Using Decision trees with GIS data for modeling and prediction
 
Digital image processing ppt
Digital image processing pptDigital image processing ppt
Digital image processing ppt
 
Log Transformation in Image Processing with Example
Log Transformation in Image Processing with ExampleLog Transformation in Image Processing with Example
Log Transformation in Image Processing with Example
 
Galileo - The European GNSS
Galileo - The European GNSSGalileo - The European GNSS
Galileo - The European GNSS
 
OpenLayers 3
OpenLayers 3OpenLayers 3
OpenLayers 3
 
Quantum QIS (QGIS) Düzenle Menüsü
Quantum QIS (QGIS) Düzenle MenüsüQuantum QIS (QGIS) Düzenle Menüsü
Quantum QIS (QGIS) Düzenle Menüsü
 
Channel capacity of continuous memory less channel
Channel capacity of continuous memory less channelChannel capacity of continuous memory less channel
Channel capacity of continuous memory less channel
 
Python Programming for ArcGIS: Part I
Python Programming for ArcGIS: Part IPython Programming for ArcGIS: Part I
Python Programming for ArcGIS: Part I
 
State of OpenGXT: 오픈소스 공간분석엔진
State of OpenGXT: 오픈소스 공간분석엔진State of OpenGXT: 오픈소스 공간분석엔진
State of OpenGXT: 오픈소스 공간분석엔진
 
OpenLayer's basics
OpenLayer's basicsOpenLayer's basics
OpenLayer's basics
 
QGIS Training.pptx
QGIS Training.pptxQGIS Training.pptx
QGIS Training.pptx
 
Lecture 06 geometric transformations and image registration
Lecture 06 geometric transformations and image registrationLecture 06 geometric transformations and image registration
Lecture 06 geometric transformations and image registration
 
Practical machine learning - Part 1
Practical machine learning - Part 1Practical machine learning - Part 1
Practical machine learning - Part 1
 
IMAGE FUSION IN IMAGE PROCESSING
IMAGE FUSION IN IMAGE PROCESSINGIMAGE FUSION IN IMAGE PROCESSING
IMAGE FUSION IN IMAGE PROCESSING
 
Chapter10 image segmentation
Chapter10 image segmentationChapter10 image segmentation
Chapter10 image segmentation
 

Viewers also liked

WebBased Land Information System Research Presentation
WebBased Land Information System Research PresentationWebBased Land Information System Research Presentation
WebBased Land Information System Research PresentationChamara Prasanna
 
Land information system in Nepal
Land information system in NepalLand information system in Nepal
Land information system in NepalQust04
 
Time Manager Workshop at #QGIS2015 Conference in Nodebo
Time Manager Workshop at #QGIS2015 Conference in NodeboTime Manager Workshop at #QGIS2015 Conference in Nodebo
Time Manager Workshop at #QGIS2015 Conference in NodeboAnita Graser
 

Viewers also liked (7)

WebBased Land Information System Research Presentation
WebBased Land Information System Research PresentationWebBased Land Information System Research Presentation
WebBased Land Information System Research Presentation
 
Land information system in Nepal
Land information system in NepalLand information system in Nepal
Land information system in Nepal
 
Time Manager Workshop at #QGIS2015 Conference in Nodebo
Time Manager Workshop at #QGIS2015 Conference in NodeboTime Manager Workshop at #QGIS2015 Conference in Nodebo
Time Manager Workshop at #QGIS2015 Conference in Nodebo
 
215 spatial db
215 spatial db215 spatial db
215 spatial db
 
Types dbms
Types dbmsTypes dbms
Types dbms
 
Dbms
DbmsDbms
Dbms
 
Basic DBMS ppt
Basic DBMS pptBasic DBMS ppt
Basic DBMS ppt
 

Similar to Workshop with python qgis

Scripting Your Qt Application
Scripting Your Qt ApplicationScripting Your Qt Application
Scripting Your Qt Applicationaccount inactive
 
Infinum Android Talks #04 - Google Maps Android API utility library
Infinum Android Talks #04 - Google Maps Android API utility libraryInfinum Android Talks #04 - Google Maps Android API utility library
Infinum Android Talks #04 - Google Maps Android API utility libraryDenis_infinum
 
Infinum Android Talks #04 - Google Maps Android API utility library
Infinum Android Talks #04 - Google Maps Android API utility libraryInfinum Android Talks #04 - Google Maps Android API utility library
Infinum Android Talks #04 - Google Maps Android API utility libraryInfinum
 
Petri Niemi Qt Advanced Part 1
Petri Niemi Qt Advanced Part 1Petri Niemi Qt Advanced Part 1
Petri Niemi Qt Advanced Part 1NokiaAppForum
 
The Ring programming language version 1.3 book - Part 53 of 88
The Ring programming language version 1.3 book - Part 53 of 88The Ring programming language version 1.3 book - Part 53 of 88
The Ring programming language version 1.3 book - Part 53 of 88Mahmoud Samir Fayed
 
2018 - Grupo QGIS Brasil e o lançamento do QGIS 3.4 LTR (Versão de Longo Prazo)
2018 - Grupo QGIS Brasil e o lançamento do QGIS 3.4 LTR (Versão de Longo Prazo)2018 - Grupo QGIS Brasil e o lançamento do QGIS 3.4 LTR (Versão de Longo Prazo)
2018 - Grupo QGIS Brasil e o lançamento do QGIS 3.4 LTR (Versão de Longo Prazo)George Porto Ferreira
 
下午3 intel fenghaitao_mee_go api and application development
下午3 intel fenghaitao_mee_go api and application development下午3 intel fenghaitao_mee_go api and application development
下午3 intel fenghaitao_mee_go api and application developmentcsdnmobile
 
Calypso Browser
Calypso BrowserCalypso Browser
Calypso BrowserPharo
 
Python Raster Function - Esri Developer Conference - 2015
Python Raster Function - Esri Developer Conference - 2015Python Raster Function - Esri Developer Conference - 2015
Python Raster Function - Esri Developer Conference - 2015akferoz07
 
Witekio custom modern qt quick components
Witekio custom modern qt quick componentsWitekio custom modern qt quick components
Witekio custom modern qt quick componentsWitekio
 
The Ring programming language version 1.4 book - Part 19 of 30
The Ring programming language version 1.4 book - Part 19 of 30The Ring programming language version 1.4 book - Part 19 of 30
The Ring programming language version 1.4 book - Part 19 of 30Mahmoud Samir Fayed
 
Geoint2017 training open interfaces - luis bermudez
Geoint2017 training   open interfaces - luis bermudezGeoint2017 training   open interfaces - luis bermudez
Geoint2017 training open interfaces - luis bermudezLuis Bermudez
 
The Ring programming language version 1.2 book - Part 51 of 84
The Ring programming language version 1.2 book - Part 51 of 84The Ring programming language version 1.2 book - Part 51 of 84
The Ring programming language version 1.2 book - Part 51 of 84Mahmoud Samir Fayed
 
MAtrix Multiplication Parallel.ppsx
MAtrix Multiplication Parallel.ppsxMAtrix Multiplication Parallel.ppsx
MAtrix Multiplication Parallel.ppsxBharathiLakshmiAAssi
 
Mapping in Drupal using OpenLayers
Mapping in Drupal using OpenLayersMapping in Drupal using OpenLayers
Mapping in Drupal using OpenLayersPeter Vanhee
 

Similar to Workshop with python qgis (20)

Scripting Your Qt Application
Scripting Your Qt ApplicationScripting Your Qt Application
Scripting Your Qt Application
 
Infinum Android Talks #04 - Google Maps Android API utility library
Infinum Android Talks #04 - Google Maps Android API utility libraryInfinum Android Talks #04 - Google Maps Android API utility library
Infinum Android Talks #04 - Google Maps Android API utility library
 
Infinum Android Talks #04 - Google Maps Android API utility library
Infinum Android Talks #04 - Google Maps Android API utility libraryInfinum Android Talks #04 - Google Maps Android API utility library
Infinum Android Talks #04 - Google Maps Android API utility library
 
Petri Niemi Qt Advanced Part 1
Petri Niemi Qt Advanced Part 1Petri Niemi Qt Advanced Part 1
Petri Niemi Qt Advanced Part 1
 
The Ring programming language version 1.3 book - Part 53 of 88
The Ring programming language version 1.3 book - Part 53 of 88The Ring programming language version 1.3 book - Part 53 of 88
The Ring programming language version 1.3 book - Part 53 of 88
 
2018 - Grupo QGIS Brasil e o lançamento do QGIS 3.4 LTR (Versão de Longo Prazo)
2018 - Grupo QGIS Brasil e o lançamento do QGIS 3.4 LTR (Versão de Longo Prazo)2018 - Grupo QGIS Brasil e o lançamento do QGIS 3.4 LTR (Versão de Longo Prazo)
2018 - Grupo QGIS Brasil e o lançamento do QGIS 3.4 LTR (Versão de Longo Prazo)
 
51811680 open layers
51811680 open layers51811680 open layers
51811680 open layers
 
下午3 intel fenghaitao_mee_go api and application development
下午3 intel fenghaitao_mee_go api and application development下午3 intel fenghaitao_mee_go api and application development
下午3 intel fenghaitao_mee_go api and application development
 
Calypso browser
Calypso browserCalypso browser
Calypso browser
 
Calypso Browser
Calypso BrowserCalypso Browser
Calypso Browser
 
Python Raster Function - Esri Developer Conference - 2015
Python Raster Function - Esri Developer Conference - 2015Python Raster Function - Esri Developer Conference - 2015
Python Raster Function - Esri Developer Conference - 2015
 
Witekio custom modern qt quick components
Witekio custom modern qt quick componentsWitekio custom modern qt quick components
Witekio custom modern qt quick components
 
The Ring programming language version 1.4 book - Part 19 of 30
The Ring programming language version 1.4 book - Part 19 of 30The Ring programming language version 1.4 book - Part 19 of 30
The Ring programming language version 1.4 book - Part 19 of 30
 
Geoint2017 training open interfaces - luis bermudez
Geoint2017 training   open interfaces - luis bermudezGeoint2017 training   open interfaces - luis bermudez
Geoint2017 training open interfaces - luis bermudez
 
The Ring programming language version 1.2 book - Part 51 of 84
The Ring programming language version 1.2 book - Part 51 of 84The Ring programming language version 1.2 book - Part 51 of 84
The Ring programming language version 1.2 book - Part 51 of 84
 
ChainerX and How to Take Part
ChainerX and How to Take PartChainerX and How to Take Part
ChainerX and How to Take Part
 
MAtrix Multiplication Parallel.ppsx
MAtrix Multiplication Parallel.ppsxMAtrix Multiplication Parallel.ppsx
MAtrix Multiplication Parallel.ppsx
 
matrixmultiplicationparallel.ppsx
matrixmultiplicationparallel.ppsxmatrixmultiplicationparallel.ppsx
matrixmultiplicationparallel.ppsx
 
Mapping in Drupal using OpenLayers
Mapping in Drupal using OpenLayersMapping in Drupal using OpenLayers
Mapping in Drupal using OpenLayers
 
35c
35c35c
35c
 

More from Qust04

PPP methods and geodetic usage
PPP methods and geodetic usagePPP methods and geodetic usage
PPP methods and geodetic usageQust04
 
Impacts of Climate Change in sustainability of hydropower in Nepal
Impacts of Climate Change in sustainability of hydropower in NepalImpacts of Climate Change in sustainability of hydropower in Nepal
Impacts of Climate Change in sustainability of hydropower in NepalQust04
 
Osm application
Osm applicationOsm application
Osm applicationQust04
 
Manual to basic gis
Manual to basic gisManual to basic gis
Manual to basic gisQust04
 
Symbology Automation using ArcPy
Symbology Automation using ArcPySymbology Automation using ArcPy
Symbology Automation using ArcPyQust04
 
Gender discrimination and women at work in nepal
Gender discrimination and women at work in nepalGender discrimination and women at work in nepal
Gender discrimination and women at work in nepalQust04
 
R sprojec3
R sprojec3R sprojec3
R sprojec3Qust04
 
Being Safe
Being SafeBeing Safe
Being SafeQust04
 

More from Qust04 (8)

PPP methods and geodetic usage
PPP methods and geodetic usagePPP methods and geodetic usage
PPP methods and geodetic usage
 
Impacts of Climate Change in sustainability of hydropower in Nepal
Impacts of Climate Change in sustainability of hydropower in NepalImpacts of Climate Change in sustainability of hydropower in Nepal
Impacts of Climate Change in sustainability of hydropower in Nepal
 
Osm application
Osm applicationOsm application
Osm application
 
Manual to basic gis
Manual to basic gisManual to basic gis
Manual to basic gis
 
Symbology Automation using ArcPy
Symbology Automation using ArcPySymbology Automation using ArcPy
Symbology Automation using ArcPy
 
Gender discrimination and women at work in nepal
Gender discrimination and women at work in nepalGender discrimination and women at work in nepal
Gender discrimination and women at work in nepal
 
R sprojec3
R sprojec3R sprojec3
R sprojec3
 
Being Safe
Being SafeBeing Safe
Being Safe
 

Recently uploaded

Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptArduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptSAURABHKUMAR892774
 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEroselinkalist12
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)Dr SOUNDIRARAJ N
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfCCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfAsst.prof M.Gokilavani
 
Introduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHIntroduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHC Sai Kiran
 
An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...Chandu841456
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfme23b1001
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxPoojaBan
 
computer application and construction management
computer application and construction managementcomputer application and construction management
computer application and construction managementMariconPadriquez1
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.eptoze12
 

Recently uploaded (20)

Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptArduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.ppt
 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfCCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
 
Introduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHIntroduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECH
 
An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdf
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptx
 
Design and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdfDesign and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdf
 
computer application and construction management
computer application and construction managementcomputer application and construction management
computer application and construction management
 
young call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Serviceyoung call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Service
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.
 

Workshop with python qgis

  • 1. WORKSHOP ON THE PYTHON PROGRAMMING IN QGIS Presented by: Jyoti Dhakal (07) Archana K.C (09) Megha Shrestha (27) Sushmita Timilsina (32)
  • 2. Python programming and Qgis • Python is a very powerful, simple and understandable language • QGIS is an open source for presenting, interpreting and analyzing the geographic information
  • 3. Program schedule • Setup • Loading layers in QGIS • Assessing active layers • Iterating over vector layers • Modifying layers • Communicating with User • Using map canvas to visualize map
  • 4. Setup • QGIS is an open source • For this workshop we are using QGIS 2.0.1 Dufor • For python programming in QGIS • Plugins -> Python console
  • 5. •Before we begin • from qgis.core import * • import qgis.utils Import the capabilities and utilities to be used through Python in Python console
  • 6. Loading vector layer through python programming • layer = QgsVectorLayer(data_source, layer_name, provider_name) where: QgsVectorLayer is the inbuilt class inside PyQgis data_source is the location of the vector layer layer_name is the name displayed in layers provider_name is the name of the data provider
  • 7. Contd… • Layer from PostGIS database can be loaded using QgsDataSourceURI class uri = QgsDataSourceURI() uri.setConnection("localhost", "5432", "dbname", "johny", "xxx") uri.setDataSource("public", "roads", "the_geom", "cityid = 2643") vlayer = QgsVectorLayer(uri.uri(), "layer_name_you_like", "postgres") • CSV or other delimited text files can be loaded as follows: uri = "/some/path/file.csv?delimiter=%s&xField=%s&yField=%s" % (";", "x","y") vlayer = QgsVectorLayer(uri, "layer_name_you_like", "delimitedtext")
  • 8. Contd… • GPX files • SpatiaLite database • WFS connection
  • 9. Adding layer to the qgis map layer • QgsMapLayerRegistry is needed which is already defined in qgis.core module QgsMapLayerRegistry.instance().addMapLayer(layer)
  • 10. Adding Raster Layer • L=qgis.utils.iface.addRasterLayer('D:sushmitaCapture.gif') Other information about the layer added • L.width() • L.height() • L.extent() • L.metadata()
  • 11. Assessing the layers • There are number of ways to assess the layers • First of you need to import qgis.utils.iface • Method 1 : Run the following command: >>> aLayer = qgis.utils.iface.activeLayer() >>> aLayer • Method 2 : >>> canvas = qgis.utils.iface.mapCanvas() >>> cLayer = canvas.currentLayer() >>> cLayer.name()
  • 12. • Method 3 : >>> allLayers = canvas.layers() >>> for i in allLayers: print i.name()... It will return only the layers those are visible. • Method 3 : • It’s also useful sometimes to access layers in the order they are stacked in the table of contents >>> canvas.layer(0) <qgis.core.QgsVectorLayer object at 0x99eaeec> >>> canvas.layer(0).name()
  • 13. Geometry type • QGIS return 0,1,2 for Point, Line and Polygon features respectively
  • 14. Geometry construction • from coordinates gPnt = QgsGeometry.fromPoint(QgsPoint(1,1)) gLine = QgsGeometry.fromPolyline( [ QgsPoint(1,1), QgsPoint(2,2) ] ) gPolygon = QgsGeometry.fromPolygon( [ [ QgsPoint(1,1), QgsPoint(2,2), QgsPoint(2,1) ] ] ) Accessor functions are required to extract the information >>>gPnt.asPoint() (1,1) >>> gLine.asPolyline() [(1,1), (2,2)] >>> gPolygon.asPolygon() [[(1,1), (2,2), (2,1), (1,1)]]
  • 15. Iterating over vector layers • features = layer.getFeatures() • for f in features: • geom = f.geometry() • print "Feature ID %d: " % f.id() • print "Area:", geom.area() • print "Perimeter:", geom.length() •
  • 16. Modifying vector layers • Start Editing layer.startEditing() • Functionality that supports editing of layer data caps = layer.dataProvider().capabilities() • Layer.commitChanges() • Layer.rollback()
  • 17. • # create layer • vl = QgsVectorLayer("Point", "temporary_points", "memory") • pr = vl.dataProvider() • # add fields • pr.addAttributes( [ QgsField("name", QVariant.String), • QgsField("age", QVariant.Int), • QgsField("size", QVariant.Double) ] ) • # add a feature • fet = QgsFeature() • fet.setGeometry( QgsGeometry.fromPoint(QgsPoint(10,10)) ) • fet.setAttributes(["Johny", 2, 0.3]) • pr.addFeatures([fet])
  • 18. Communicating with the user • Making a graphical user interface for easy communicating with the user • QgsMessageBar • QPushButton • progressMessageBar • pushMessage
  • 19. Map visualizing in canvas • Map canvas is implemented as QgsMapCanvas class in qgis.gui module