Tag Info

Hot answers tagged

5

First case: insert new polyline You have to define the Polyline like so: pLine = [QgsPoint(1,1), QgsPoint(2,1), QgsPoint(2,2)] it is a list-of-QgsPoint. After you can put more QgsPoint into the list by append to insert the element at the end of the list: pLine.append(QgsPoint(3,2)) or inserting some vertex point at a specific location of the list: ...


3

The openlayers plugin does not work with map composers - it only functions in the main map canvas. See http://hub.qgis.org/issues/5827 , http://hub.qgis.org/issues/8824 or http://hub.qgis.org/issues/10992 , amongst many others...


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


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


2

In general you should look at this page of the APIs documentation. As a working example see as follows: vl = iface.activeLayer() ## get default style myStyle = QgsStyleV2().defaultStyle() ## get a list of default color ramps [u'Blues', u'BrBG', u'BuGn'....] defaultColorRampNames = myStyle.colorRampNames() ## setting ramp to Blues, first index of ...


2

With QgsCoordinateReferenceSystem you can also get the WKT(well known text) as QString (using toWkt() ). You can then parse your WKT to extract the properties of your ellipsoid <spheroid> ::= SPHEROID ["<name>", <semi major axis>, <inverse flattening> ]


1

similar to .area(), you can use .length() . For a polygon it yields the perimeter. perimeter=feature.geometry().length()


1

So, for the first python script for QGIS, I have: from qgis.core import * from PyQt4.QtCore import * from PyQt4 import QtGui, QtCore import math COMP = 1.0 FACS = 0.0 ORIG = 1.0 OROM = 1.0 ORZE = 1.0 coeff_a = 1.6 coeff_b = 3 seuil_1 = 1000000 seuil_2 = 300000000 # supply path to where is your qgis installed ...


1

As directly using a Openlayers plugin layer in a programatically created print composition is not possible (see the accepted answer), this approach can at least be used to create a stationary image file (jpg/png) from a desired Openlayers map extent. Maybe this is helpful to somebody somehow... It is based on the basemap2Image script which I modified ...


1

THe short answer is: I can;t see a way. However, changing attributes on a feature is time consuming at times (I have have a hard time figuring out why it happens). Thus, this should speed up your code a bit: pr.addAttributes( [QgsField(aName, QVariant.Double) ] ) attrs={} #------ # Add Values to Triangle Features in Values ...


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


1

Looking at your comment above, for QGIS 2.6 you can do something like this to insert a layer into the legend model: ####### # create legend ####### composerLegend = QgsComposerLegend(comp) layerGroup = QgsLayerTreeGroup() layerGroup.insertLayer(0, the_layer) composerLegend.modelV2().setRootGroup(layerGroup)


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.


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

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

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



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