[Qgis-user] What can you do with the Python console?
Agustin Lobo
aloboaleu at gmail.com
Thu Oct 30 05:35:49 PDT 2008
Carson,
This is most useful, perhaps could we have a section
in the wiki on "Examples of using the QGIS console" ?
Another section on "Examples of simple python scripts" would
be great also.
Agus
> Message: 10 Date: Thu, 30 Oct 2008 12:15:14 +0000 From: Carson Farmer <carson.farmer at gmail.com> Subject: Re: [Qgis-user] What can you do with the Python console? To: maning sambale <emmanuel.sambale at gmail.com> Cc: qgis-user at lists.osgeo.org Message-ID: <4909A552.40306 at gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Maning,
>> > Hi,
>> >
>> > I'm no programmer just a FOSS GIS/RS user. I know most plugins are
>> > created via python. I'm just curious what can we do with the python
>> > console? Any examples I can practice? I have learned a lot of bash
>> > scripting by using GRASS. Maybe I can learn more python with the QGIS
>> > python console.
>> >
> Anything you can do in QGIS, you can also do via the python console. It
> is also a great tool for python plugin developers for testing the
> functionality of their plugins. As for a user based example, the
> following code will add a feature to the top layer in the TOC (it
> assumes the layer is a point layer):
>
> mc = iface.getMapCanvas()
> layer = mc.getZpos( 0 )
> provider = layer.getDataProvider()
> feat = QgsFeature()
> feat.setGeometry( QgsGeometry( QgsPoint( -10, 53 ) ) )
> provider.addFeatures( [ feat ] )
> layer.updateExtents()
> mc.refresh()
>
> The above is based on using code from QGIS 0.11
>
> I have also developed a python module that you can import into QGIS via
> the console to perform basic geoprocessing functions:
>
> from geoprocessing_engine import Geoprocessing1
> mc = iface.mapCanvas()
> layer_a = mc.layer( 0 )
> layer_b = mc.layer( 1 )
> function = 'Intersect'
> intersect = Geoprocessing1( function, layer_a, layer_b )
> intersect.compute()
> intersect.saveToFile( '/home/cfarmer/Desktop/intersect.shp', 'UTF-8' )
>
> The 'geoprocessing_engine' also allows various geoprocessing functions
> to be linked together, without having to create intermediate files, and
> without having to perform the task more than once:
>
> final_output = Geoprocessing1( 'Difference', Geoprocessing1( function,
> layer_a, layer_b ).compute(), layer_c ).compute()
>
> I imagine that others will develop similar modules for various tasks
> that might benefit from this type of approach (making bulk geoprocessing
> easier for example). This 'geoprocessing_engine' is based on the new
> QGIS API, so will not work with older version of QGIS. I will likely
> release a decent version of this when QGIS 1.0 comes out...
>
> Hope this gives you an idea of the power of the python console.
>
> Carson
--
Dr. Agustin Lobo
Institut de Ciencies de la Terra "Jaume Almera" (CSIC)
LLuis Sole Sabaris s/n
08028 Barcelona
Spain
Tel. 34 934095410
Fax. 34 934110012
email: Agustin.Lobo at ija.csic.es
http://www.ija.csic.es/gt/obster
More information about the Qgis-user
mailing list