Tag Info

New answers tagged

0

To do that you should access to data defined properties for the symbol layer and set the color by passing the field name as expression. You can do it like: uri = "file:///C:/data/balls.csv?type=csv&xField=longitude&yField=latitude&spatialIndex=no&subsetIndex=no&watchFile=no" vlayer = QgsVectorLayer(uri, 'Balls', "delimitedtext") ...


1

Hi Athena and welcome to PyQGIS programming! For having a good start you could take a look at PyQGIS Cookbook! Anyway, the snippets below is an example what you are trying to do of: from PyQt4.QtCore import QVariant ## create an empty memory layer vl = QgsVectorLayer("Point", "myLayer", "memory") ## define and add a field ID to memory layer "myLayer" ...


2

You have forgotten to add the feature: lineLayer = QgsVectorLayer("LineString", 'test layer', "memory") pr = lineLayer.dataProvider() # define the fields of the layer pr.addAttributes([ QgsField("ID", QVariant.String), QgsField("latStart", QVariant.String), QgsField("lonStart", QVariant.String), QgsField("latEnd", QVariant.String), QgsField("lonEnd", ...


1

In your case you can add the item to define the crs string to the URI like &crs=EPSG:4326. Your code should look as follows: uri = "file:///C:/data.csv?type=csv&xField=lng&yField=lat&spatialIndex=no&subsetIndex=no&watchFile=no&crs=EPSG:4326" vlayer = QgsVectorLayer(uri, 'Points', "delimitedtext") ...


1

I am no expert but I would assume when you draw any points, lines or polygons, they will have to be placed in a vector layer beforehand. The following code is from here which describes how to add a line layer and attributes: from qgis.core import QgsVectorLayer, QgsField, QgsMapLayerRegistry from PyQt4.QtCore import QVariant #create Layer ...


1

Since QGIS 2.4 Chugiak, the OpenLayers plugin has moved in the QGIS Gui to Web->OpenLayers plugin, hence the first method described above won't work anymore. I updated it to match the new menu structure, see my answer here. Still, it would be interesting to know how to adapt the second method to QGIS 2.4 and above.


0

This isn't really possible. Plugins make use of setup which you don't have in your custom application, mainly a iface variable which points to a whole heap of stuff that is normally a QGIS session, e.g mapcanvas, toolbars, actions, composers, etc. You could in theory create a standalone application that could load plugins but you would have to pretty much ...


2

That is pretty simple by using custom properties by the setCustomProperty() method. The below example adds a memory layer to the legend and set the "showFeatureCount" property to True (you can run it from pyqgis console): ## create the memory layer and add to the registry myLayer = QgsVectorLayer("Point", "myLayer", "memory") ...


0

The problem is solved by Matthias Kuhn, see Here. QgsLayerTreeMapCanvasBridge should help you there header: QgsLayerTreeMapCanvasBridge* mLayerTreeCanvasBridge; source: mLayerTreeCanvasBridge = new QgsLayerTreeMapCanvasBridge( QgsProject::instance()->layerTreeRoot(), mMapCanvas, this ); QgsProject::instance()->read( path_to_your_project_file ...


1

You may want to read this tutorial on the PyQGIS Tree Layer API (Part I & II). This contains a part on how to move a layer within the layer TOC.


1

pseudocode for your problem would be: for point1 in csv: for point2 in csv: distance = haversine(point1, point2) where haversine is defined as (from e.g. http://gis.stackexchange.com/a/56589/15183) : def haversine(lon1, lat1, lon2, lat2): """ Calculate the great circle distance between two points on the earth (specified in decimal ...


1

I just tested the script and works fine also by ScriptRunner. The only thing that I had to change to the above code was initializing the QgsFillSymbolV2 class ;-): redsym = QgsFillSymbolV2() redsym.createSimple(red) Anyway, we are going to get another great release on 31th :)


1

It's caused by a bug in QGIS 2.4 (fixed for 2.6). The crash is caused when python cleans up the redsym symbol. To workaround it, make sure redsym is stored somewhere where python won't automatically clean it (eg, store it in a global variable).


1

Adding a toolbar: # Create toolbar self.toolbar = self.iface.addToolBar("My Toolbar") self.toolbar.setObjectName("My toolbar Plugin") self.toolbar.addAction(self.action) self.btn = QAction(QIcon(":/plugins/import_PostGIS/icon.png"), "button1", self.iface.mainWindow()) QObject.connect(self.btn, SIGNAL("triggered()"), self.method) ...


1

I may have found why the call to SAGA:MERGESHAPESLAYERS is not working in ubuntu from QGis Regardless of my 2.0.8 syntax setting QGis generates the following line of shell script shapes_tools "Merge Shapes Layers" -MAIN "/tmp/vlayer_01.shp" -LAYERS "/tmp/vlayer_01.shp;/tmp/vlayer_02.shp" -OUT "/tmp/output.shp" When run it generates the following error: ...


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.


0

You have to refresh the mapCanvas as well: ml.setVisible(True) ml2.setVisible(False) qgis.utils.iface.mapCanvas().refresh() After this the map Canvas will redraw and you can see the changes. Normally you should see changes when you zoom in and out to force a refresh of the mapCanvas manually. To set the layer visibility you can use this: ...


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.


1

The community edition doesn't support remote debugging, meaning you can't test your plugin while running in QGIS. You can use Winpdb (cross platform despite the name) to remotely debug a QGIS plugin. See: http://winpdb.org/ From the PyQGIS Programmers Guide (http://locatepress.com/ppg): In your code, add lines to enable debugging: import rpdb2 ...


0

for ubuntu users : open software center and search "python-mapscript" and install "python library for MapServer" and enjoy using "RT mapserver exporter".


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 ...


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() ...


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

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. ...


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 ...


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 ...


0

look at Martin Dobias's QGIS Layer Tree API (Part 1) from PyQt4.QtCore import QFileInfo # no need of from qgis.core import * in the console) root=proj.layerTreeRoot() proj.read(QFileInfo("/var/qgis-projects/testproject.qgs")) root=proj.layerTreeRoot() for child in root.children(): if isinstance(child, QgsLayerTreeGroup): print "- group: " ...


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 ...


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)


3

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 ...


0

method exist but you wrote it uncorrectly help(QgsVectorLayer.readXml) Help on built-in function readXml: readXml(...) QgsVectorLayer.readXml(QDomNode) -> bool


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 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

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 = ...


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 ...


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.


0

I had the same problem.Try picture resolution 24x24 and with less shades of color.



Top 50 recent answers are included