Tag Info

Hot answers tagged

5

The QGIS-plugin manager matches the version number of any locally installed QGIS plugin (this includes your development version) with the version number hosted on the QGIS plugin repo. As you can see in your screenshot your locally installed version has the version number 0.1, while the one on the repo has 1.1. Thus it correctly assumes that the one on the ...


4

It looks like that QGIS creates a new empty project after the initialization. But if you want to open Qgis with the same layer/project you can first save your layer into a project and then define that the project opens on launch. You can find it here: Options-> General-> Project files-> Open projects on launch


4

You can start QGIS Python console when opening a project by writing a couple of lines in QGIS->Project->Project Properties: def openProject(): import qgis qgis.utils.iface.actionShowPythonDialog().trigger() Make sure you enable macros on your project, this way: Settings->Options->General->Enable macros: Always As you want the ...


4

Since there is no custom QGIS GUI widget for that (at least I couldn't find it), you could try something like this: from PyQt4.QtGui import QComboBox lyr = iface.activeLayer() idx = lyr.dataProvider().fieldNameIndex( 'NAME_1' ) uv = lyr.dataProvider().uniqueValues( idx ) cb = QComboBox() cb.addItems( uv ) Note that we are obtaining unique values of the ...


4

You can apply the following code to define fromUtf8 which was taken from the QGIS Workshop describing how to use PyQT for QGIS: _fromUtf8 = QtCore.QString.fromUtf8


3

There are two more possibilities to reload the code in the QGIS cache. You can use the QGIS plugin Plugin Reloader. There you can define your plugin and press the reload button everytime you need to reload the code. Another possibility is to overwrite the closeEvent() event of PyQt if you use it for your interface. def closeEvent(self, event): ...


3

By reading the QGIS source code I figured out how to solve this issue. In your .py file write the following line (could be right below the imports): DEBUGMODE=True This should do the trick, I tested it on QGIS v.2.6. Please tell me if you have any trouble.


3

The PyQGIS Cookbook explains what files are common in QGIS plugins. As you can see there, you would only need three files to run a minimal plugin: __init__.py metadata.txt mainPlugin.py The __init__.py file lets QGIS know the Plugin folder is a Python module. It must contain a classFactory(iface) function that QGIS uses to initialize your plugin, making ...


3

Your are not modifying vector, but features "copies" get with getFeatures. You need to get the feature.id() and updateGeometry using dataProvider of the vector or directly using methods of the vector layer (inside an editing session) you can find reference of the methods in: for QgsVectorDataProvider: virtual bool changeGeometryValues (QgsGeometryMap ...


3

You can set the page background to transparent by creating a transparent symbol and setting the page background to use that symbol: transparent_fill = QgsFillSymbolV2.createSimple({ 'outline_style': 'no', 'style': 'no'}) c.setPageStyleSymbol( transparent_fill ) There's also a few other things wrong with your script: First, mapRenderer = ...


3

You can write defined columns from selected features in a csv file in this way: layer = qgis.utils.iface.activeLayer() features = layer.selectedFeatures() # Here you get a list of selected features columns=['id','country','city'] #here you write the columns you want to export. Or use a list with the columns # Here you write for every selected feature a ...


2

A few things. First, .getFeatures() returns an iterator, and not the features themselves, so putting them in a dictionary is only good to consume memory. I re-did your work using a couple of layers I have for the Phoenix, AZ area and it worked well. See below. The original code also does NOT guarantee that the feature is contained, but rather that it ...


2

You can access QGIS toolbar buttons (actions) by using the iface object (docs here). From those actions you can create a QActionGroup and add your custom action making all actions mutually exclusive. The following code snippet shows you how to do it, step by step. I've put the code snippet in the initGui(self) method of my test plugin. # Make sure your ...


2

I suggest you to do what I state in 1. and choose whether you want to go for 2. while the problem is fixed in QGIS. Indeed, there is a problem with those functions, so you can inform QGIS devs about the issue you found by posting in the QGIS-dev mailing list and/or reporting it in the QGIS bug tracker (see Filing an issue). Implement a workaround. Since ...


2

If your raster is stored in PostGIS, you can load it using PyQGIS (e.g., from the QGIS Python console) this way: connString = "PG: dbname=myDBname host=localhost user=myUser password=myPassword port=5432 mode=2 schema=public column=rast table=myRasterTable" layer = QgsRasterLayer( connString, "My PostGIS Raster" ) if layer.isValid(): ...


2

Wow. Way simpler than I expected. Should not have supposed that 'ogr' wouldn't be able. Anyone have a dunce cap I can borrow? someTableLayer = QgsVectorLayer(ministryOf.csv, 'sillyWalks', 'ogr') QgsMapLayerRegistry.instance().addMapLayer(someTableLayer)


2

The following snippet works for me: uri = "file:///C:/testdata/somecsv.csv?delimiter=%s" % (";") lyr = QgsVectorLayer(uri, 'New CSV','delimitedtext') QgsMapLayerRegistry.instance().addMapLayer(lyr) For reference, if you wanted to add it with geometry: uri = "file:///C:/testdata/somecsv.csv?delimiter=%s&crs=epsg:4326&xField=%s&yField=%s" % ...


2

I suggest you to have a look at PyQt4 tutorials on Internet. They should help you understand how PyQt4 applications are structured, and should introduce you to the wide variety of widgets PyQt4 provides you with. Just to cite some, here is a list of resources you could read: Introduction to PyQt4 PyQt4 Tutorial GUI - PyQt4 Once you've done that, you ...


2

You can first load your virtual environment and then start QuantumGis in the same terminal where you loaded the virtual environment. for example in linux: source /myvirtualenv/bin/activate qgis


2

To set the color of a vector layer feature depending on the feature attributes with PyQGIS is necessary to change the QgsSingleSymbolRendererV2 default object in a, for example, QgsGraduatedSymbolRendererV2 object. To test this I created the 'random' field name in a Polygon Vector Layer and this field was filled with aleatory values between 1 and 24. These ...


2

I assume your road_layer_i (for i in [0-99]) layers are not the same layer, that is, they do not have exactly the same lines. Having said that, I've modified your code snippet a bit, making these changes: Use QgsMapLayerRegistry.instance().mapLayers().values() instead of self.iface.mapCanvas().layers(). This ensures you'll iterate on all layers and not ...


2

An alternative option would be to call the addVectorLayer method within python macro openProject function (Project>Project Properties | Macros): def openProject(): from qgis.utils import iface iface.addVectorLayer("c:/Temp/AA/counties.shp", "ccounty", "ogr") pass


2

If I got you right, you can define the units of the QGIS scale bar this way: Using the GUI: Go to Settings->Options->Map Tools->Measure Tool and set Preferred measurement units to Feet. Programmatically: Open a QGIS console and copy this: from PyQt4.QtCore import QSettings QSettings().setValue("Qgis/measure/displayunits","feet")


2

This is how I'd do it with PyQGIS: In your QGIS ToC, turn off those layers that you want to keep untouched, i.e., leave visible only the layers you want to set the filter to. Now open a QGIS Python console and paste this code: layers = iface.mapCanvas().layers() for layer in layers: layer.setSubsetString('"osm_user" = \'donlaser\'') This should do ...


2

With the new (since QGIS v.2.4) Layer tree by Martin Dobias, you can do this: canvas = qgis.utils.iface.mapCanvas() layers = canvas.layers() for i in layers: if i.name() == "Layer2": alayer = i elif i.name() == "Layer1": blayer = i root = QgsProject.instance().layerTreeRoot() # Move alayer myalayer = root.findLayer(alayer.id()) myClone = ...


2

Try with the text() function, as stated in the Qt docs. I would also parse it directly as a float, being a distance. distance = float( self.dlg.DistancelineEdit.text() ) Note: Actually, I had already told you so.


2

I would try deleting the feature attribute that corresponds to class_field (you can do it right before you call setAttributes()): del featAttr[class_field_index] and deleting the field from fields (you can do it before the loop, once you have instantiated both fields and class_field_index): fields.remove( class_field_index )


2

You must define it first: result3 = QgsVectorLayer("LineString", "ligne", "memory") #it's to create your layer ligneid=result3.id() # it allows you to have the idvalue for your layer QgsProject.instance().setSnapSettingsForLayer(ligneid,True,2,1,1000,True) # it defines the snapping options ligneid : the id of your layer, True : to enable the layer ...


2

You don't really seem to have read at least one of the resources I collected for you in Layer Properties Field Tab in my plugin. If you open, for example this one, you'll see the answer to your question: button.clicked.connect(self.onClicked) In your case it would be something like (you might need to edit it to match your plugin structure): ...


2

The following script works for me in the QGIS Python console: vLayer = QgsVectorLayer("/path/to/vector.shp","my vector","ogr") rasterPath = "/path/to/raster.tif" rLayer = QgsRasterLayer(rasterPath,"my raster") if not ( vLayer.isValid() and rLayer.isValid() ): print "Error loading layers..." band=1 from qgis.analysis import QgsZonalStatistics zonalstats ...



Only top voted, non community-wiki answers of a minimum length are eligible