Tag Info

Hot answers tagged

4

QgsMapLayerRegistry.instance().mapLayers() will give you all layers that are opened. If you want the names then: names = [layer.name() for layer in QgsMapLayerRegistry.instance().mapLayers().values()] names will be a list of layer names or using a normal function: for layer in QgsMapLayerRegistry.instance().mapLayers().values(): print layer.name() ...


3

I just found a solution. There is also an active psycop2 connection. When I commit it or close the connection before osm2pgsql runs and open it afterwards again it works. Probably osm2pgsql can't access to the database if this connection is open.


3

Let us imagine your UI file name is MyDialogFile.py. Then, from PyQt4.QtGui import QFileDialog from MyDialogFile import MyDialog def InitGui(self): #other stuff.... self.dialog = MyDialog() def OpenBrowse(self): filename1 = QFileDialog.getOpenFileName() self.dialog.Input_TB.setText(filename1)


2

Problem solved! The object QgsMapRenderer is deprecated in 2.4 and above, that’s why the script wasn’t working properly. To make the script work it’s necessary to replace it by the object QgsMapSettings. Consequently, also some function names need to be slightly changed (e.g. from setProjectionsEnabled() to setCrsTransformEnabled(), from setLayerSet() to ...


2

It turned out I did not properly initialize QGis like you're supposed to when writing standalone scripts. Adding the following lines made everything work: QgsApplication([], True) #a path was not needed QgsApplication.initQgis() #do all the things with your QgsProject here QgsApplication.exitQgis() This question and the PyQGIS Developer Cookbook got me ...


2

Using hurry.filesize you could do something like this : import os from hurry.filesize import size raster_size = os.path.getsize('YOUR_PATH_HERE') size(raster_size, system=alternative)


2

Try referring to this post. They are looking at zip files, but it should work fine for your raster file. If you are using a type of raster that is made up of multiple files, then I would suggest getting the file size of each and summing it. The code would be similar to: import os os.path.getsize(#your file here) As the post says, you can shift it to MB ...


2

At the moment (and I know it's a bit gross) but you also have to update the layer set on the canvas to update the layer state change canvas.setLayerSet([ml2, ml]) This will also control the render order. m1 will reneder first then ml2 on top of it.


2

You could do this if you have the Raster Interpolation plugin installed using Plugin Manager. from rasterinterpolation.core.rasterinterpolator import RasterInterpolator rastLayer = iface.activeLayer() interpolator = RasterInterpolator(rastLayer,0,1) a= interpolator.linear(QgsPoint(10.662629, 76.225421)) print a Note: i don't really know what the above ...


1

I have a layer containing lots of elements of type Point, Line and Polygon It is impossible in QGIS, look at how to open layers with multiple geometry types in qgis? ( only points layers, polylines layers or polygons layers and multi-parts geometries layers, MultiPoints, etc.). So, no need of if geom.type()==QGis.Polygon, unless the geometry type is ...


1

Legend interface has been refactored since 2.4 version. A detailed description how to add nodes, groups and subgroups can be found here: http://www.lutraconsulting.co.uk/blog/2014/07/06/qgis-layer-tree-api-part-1/ and here http://www.lutraconsulting.co.uk/blog/2014/07/25/qgis-layer-tree-api-part-2/ regards


1

Generally you access the QgsMapLayerRegistry if you want access to the layer object again. The layer may or may not be in the canvas i.e layers that are not visible are not in canvas.layers(). addMapLayer() should add it to the canvas and update layers() automatically. If not it might be a bug. Like I said it's safer to use the registry to find the layer ...


1

You can find multiple versions of routing scripts which use the QGIS network analysis library in my Github repository, e.g. https://github.com/anitagraser/QGIS-Processing-tools/blob/master/2.2/scripts/point_layer_to_route.py which converts an ordered set of points into a route. None of the scripts use the intersections of an input line with the network. ...


1

MMQGIS plugin have your merge funcion... other merge funcion can be found in Processing/gdal Processing/saga but MMGIS works as you aspected


1

As far as I can see, the example in the documentation is working, but not with the NASA JPL service. It says that NASA has stopped providing WMS support. You just have to look for another WMS service and fill in the required parameters: urlWithParams = ...


1

As shown in: http://docs.qgis.org/testing/en/docs/pyqgis_developer_cookbook/loadlayer.html#vector-layers The second parameter of QqgVectorLayer() is the name of the layer to be shown in qgis. This should work: QgsVectorLayer("/home/ali/Python Work/work for centerline/pnt.shp","pnt", "ogr") QgsVectorLayer("/home/ali/Python Work/work for ...


1

The solution for me was not to use the Plugin Builder Plugin that is recommended in the PYQgis Cookbook. When I create the files manually everything is working fine and the icon is displayed.


1

Modifications need to be made in 3 different files in the folder generated by Plugin Builder... QtCore.QObject.connect(self.Input, QtCore.SIGNAL("clicked()"), self.OpenBrowse) To be added in the UI File under the main Class... def OpenBrowse(self): filename1 = QFileDialog.getOpenFileName() self.dialog.Input_TB.setText(filename1) ...


1

Yes, you can store settings in separate files/ways with QSettings, and within the same Q(Core)Application. This makes it ideal for what you are looking to do. When initializing your PyQGIS plugin's QSettings, you will want to do something like this for a standard settings setup: my_settings = QtCore.QSettings(QtCore.QSettings.IniFormat, ...



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