Hot answers tagged

8

There are a couple of different approaches to that: Start a new project iface.newProject() Add a layer Whenever a new layer gets added to the mapcanvas, the welcome page will disappear Change the configuration In contrast to the other two approaches, this changes the configuration of the QGIS installation permanently. # 0: Welcome page # 1: Most ...


5

I think that your issue is only a "Zoom In" problem. I'm going to render to tif these random points with Raster-> Conversion -> Rasterize (Vector to Raster) Tool (cell resolution 30 x 30) of QGIS; equivalent to your standalone Python script. Loaded raster layer looks as if no point had been rasterized. However, with point layer as first layer, 'Zoom In'...


5

The slashes are going the wrong way in the url directory path to the shp. Python interprets "\" as line return. Use "/" instead or "r" in front of the string path. "C:/Data/scripts/...etc" Or r"C:\Data\scripts...etc"


3

It's not the most efficient way to do this. Instead of creating buffers and looking for intersections, you can do this with scipy.spatial library. First get all of your points (accidents) as numpy array. From csv file it will be: from scipy import loadtxt data = loadtxt("/path/to/file.csv", delimiter=",") Then you can use the most efficient way to find ...


3

You can select layers by name directly with: QgsMapLayerRegistry.instance().mapLayersByName("layer_name") It returns a list of all layers that name contains "layer_name".


3

Here is how I solved the issue, it’s a bit of work, but you can now import the modules without hassle, I created a Python Script, that uses the module subprocess, to write an osgeo4w command called ‘python-qgis’ Its nothing complicated, here it is I called it NotePadPlus.py (No real reason for calling it that) I then call this script from the osgeo4w ...


3

Not sure how to modify the interface of such scripts but you could use an example script like the following where the Enter_field parameter has a default string of ID and if a field name matches this, it prints this field name otherwise it will print the one that is selected in the Or_select_field parameter: ##Example=name ##Input_layer=vector ##...


3

The widgets which you are referring to are leftovers from Qt3. QGIS at the moment is based on Qt4 (which exists since 2005 and has seen end of life in December 2015) and is soon to be updated to Qt5 (2016/2017). Ten years ago, when it was about moving applications from Qt3 to Qt4, a Qt3Support module has been introduced to ease the migration. However, ...


2

I now found a solution to my problem, although it's not the most elegant one. I got access to the elements by calling the actions() method of the view menu: vm = iface.viewMenu() panels = [i for i in vm.actions() if i.title() == 'Panels'][0] toolbars = [i for i in vm.actions() if i.title() == 'Toolbars'][0] Unfortunately the plugin will be used in ...


2

I was fortunate enough to get in touch with the author of the book so I will share his response here: I suspect I may know what the problem is...after looking at this reader's problems in more depth, I've discovered that something has changed in newer versions of QGIS, and the example code no longer works as it is written. In technical terms, it ...


2

Categorized symbols and graduated symbols are applied in pretty much the same way. The only difference is that graduated symbols are taking into account certain ranges, whereas, categorized is simply taking in the actual field value. Quite honestly, you could literally replicate the code given from the PyQGis cookbook site: http://docs.qgis.org/testing/...


2

Your escaping isn't write quite right. It should be: (\"accdate\" >= '1990-01-01' AND \"accdate\" <= '1992-12-31') (You have some extra "s) Also note that: iter = lyr.getFeatures(request) ids = [i.id() for i in iter] lyr.setSelectedFeatures(ids) selected_feats = lyr.selectedFeatures() Is quite inefficient. Try: iter = lyr.getFeatures(request) ...


2

The general logic for setting border color is: # black polygon with red border symbol = QgsSymbolV2.defaultSymbol(layer.geometryType()) layer_style = {} layer_style['color'] = '0, 0, 0' layer_style['size'] = '2.5' layer_style['color_border'] = '255, 0, 0' symbol_layer = QgsSimpleFillSymbolLayerV2.create(layer_style)


2

I’m facing the same problem. I have not found a real solution, but I found out, that in content of the build in variable __name__ changes. It is “qgis.user” one time and “startup” the other. So you can work around the problem by: import qgis if __name__=="qgis.user": qgis.utils.iface.actionShowPythonDialog().trigger() print "Welcome chump"


2

Solved. With use of the modoule thread (>Python 3.0 _thread) you are able to start new threads inside your programm code. import thread # Animation: Button clicked def btnAnimationClicked(self): thread.start_new_thread(self.caller,()) # Animation: Caller def caller(self): for i in range(0,24,1): self.callback(i)


2

If you want to update the options you see in Settings > Snapping Options..., you can use the setSnapSettingsForLayer() function from the QgsProject Class: proj=QgsProject.instance() layer = qgis.utils.iface.activeLayer() proj.setSnapSettingsForLayer(layer.id(), True, 0, 1, 10, True) Note that although you're using the active layer to set the snapping ...


2

I prefer adding rasters described from the QGIS docs which I've incorporated into your script in addition to importing a couple more required classes: import glob, os from PyQt4 import QtGui from PyQt4.QtCore import QFileInfo rast_path = "/home/user/Desktop/data/gsi/output" rasters = glob.glob(os.path.join(rast_path, "*le.tif")) print(rasters) for raster ...


2

I am running a batch file first. call "C:\OSGeo4W64\bin\o4w_env.bat" set PATH=%PATH%;C:\OSGeo4W64\apps\qgis\bin


2

Try out with 'intersects' and 'intersection' methods. Next code produces only two points. mapcanvas = iface.mapCanvas() layers = mapcanvas.layers() feats_line = [ feat for feat in layers[0].getFeatures() ] feats_poly = [ feat for feat in layers[1].getFeatures() ] for feat_l in feats_line: for feat_p in feats_poly: if feat_p.geometry()....


2

This works for me: from PyQt4.QtGui import QGroupBox, QCheckBox, QDialog, QHBoxLayout d = QDialog() gb = QGroupBox("Groupbox") gb.setEnabled(False) cb = QCheckBox("Set active") l = QHBoxLayout(d) l.addWidget(gb) l.addWidget(cb) cb.stateChanged.connect(toggleGroupBox) def toggleGroupBox(state): if state > 0: gb.setEnabled(True) else: ...


2

In this case, it is preferable to use itertools module to avoid repeated indexes. I assumed one feature for each shapefile in next situation: Next code prints all the names of the shapefiles that overlap with each other. import itertools mapcanvas = iface.mapCanvas() layers = mapcanvas.layers() feats = [] for layer in layers: for feat in layer....


2

Do this in that way: def select_input_file(self): self.d.lineEdit.setText(QFileDialog.getOpenFileName(None, "Choose input file ", os.getcwd(), "*.qml")) Without this iface as a parameter.


2

The proper way to dealing with this is to use an alias. You can use addAttributeAlias for this (as usual, check the documentation for this) This way it will not only be used in python-preprocessed forms but also in the attribute table and other places.


1

In answer to my own question...The QMessageBox was called upon execution of the plugin so it only makes sense the main dialog closed after calling the QMessageBox. The quick answer was to create a separate push button allowing the user to validate the entries at any point. Ultimately what I'd like is to have some sort of object listening in the background ...


1

There are existing algorithms from the Processing Toolbox which you can call. We could use two such algorithms: Select by expression - Selects all features based on an expression. Save selected features - Saves the selected features in a shapefile. import processing layer = qgis.utils.iface.activeLayer() expression = """ "fieldName" = 'value_1' OR "...


1

You need to iterate through the segments of the line to find the one that touches/intersect the polygons (as in Get the vertices on a LineString either side of a Point) I show here the results with one line and one polygon as example # transform the line to a list of points linegeom = liengeom.asPolyline() # extract the segments seg_start, seg_end of ...


1

I followed the same steps explained in this question about GML .gz files and it worked. iface.addVectorLayer on a gml file causes "Select vector layers to add" dialog (pyqgis) 1- Open one of the layers 2- Get its full URL iface.activeLayer().dataProvider().dataSourceUri() 3- Iterate through them


1

The "c" in textcolor needs to be upper case like: palyr.textColor = QColor(68,92,249)


1

The method setEditType is really old and no longer recommended (and will disappear with QGIS 3.0). If you have a look at the API documentation, it redirects to the appropriate successor: https://qgis.org/api/classQgsVectorLayer.html#a2d1e5058f8b7cc5c905813485847bc81 layer.editFormConfig().setWidgetType(idx, "ValueMap") or layer.editFormConfig()....


1

The database is locked error is raised when two connections try to access the database in a conflicting way, e.g. when one connection deletes a table which the second one tries to update. So the very first thing to check is, if the database is accessed by something else (in your code or not). What you should also check is that you either work with the layer ...



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