Tag Info

New answers tagged

0

Thanks for the idea, I tried it, but with limited speed up. Isn't there a way for a direct memory access? I load the same data with python in Paraview which takes 10sec for 600 000 triangles. QGIS takes >1h ... And, not only changing attributes, but also shift painting triangles or shifting geometry.


0

I just noticed that you missed to set the QGIS installation path, so no provider may be loaded properly and probably this is the root of the problem. Try to change your script as follow: def main(): ## second argument (GUI Enabled) may be False ## if you do not need of GUI stuff QgsApplication([], False) ## installation path for Linux: ...


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


0

loaded plugins and their instance are available in the dict qgis.utils.plugins you can manage load and unload with other methods in qgis.utils (do help(qgis.utils) in pythonconsole to show static methods available) this is only the base to solve you problem, you should manage check if running or not using some method in your plugin, or you can check if ...


1

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


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


0

I'm not sure but maybe you have to disconnect the signal layersWillBeRemoved from the default slot removeMapLayers.


0

thanks for the answers. The problem was that I had to set both 'resp' and 'rast1' variables to None after each iteration in the for loop, so my code end up like this entries = [] rasters = os.listdir("C://test/Rasters/") for i in range(0, len(rasters)): raster = "C://test/Rasters/"+rasters[i] resp = QgsRasterLayer(raster) rast1 = ...


0

The issue is likely that 'resp' goes out of scope and is deleted when the for loop ends. Then when you try to use it in the calc = QgsRasterCalculator... line QGIS crashes. Try initializing 'resp' outside of your loop first. Something like: ... resp = None for i in range(0, len(rasters)): ... should do it.


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

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


0

If you know the coordinates of your rectangles, you can uses following code: zoomRectangle = QgsRectangle(pos[0]-offset, pos[1]-offset,pos[0]+offset,pos[1]+offset) self.canvas.setExtent(zoomRectangle) self.canvas.refresh() here, for you, just use self.canvas.setExtent(rect) And just for precision: self.canvas = qgis.utils.iface.mapCanvas() or ...


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


0

Apparently, the newest version 2.6 solve this problem. Also, make sure you have the correct environment variables setup. The one which is throwing me off is the QGISHOME one, I setup it as C:\Program Files\QGIS Brighton\, but should be C:\Program Files\QGIS Brighton\apps\qgis.


0

What do you mean for "show messages in eclipse-pydev"? Generally speaking, as you can see in the code, QgsDebugMsg is a define tat use QgsLogger, QgsLogger documentation says: http://qgis.org/api/classQgsLogger.html#details that you can use QGIS_DEBUG (level 0,1,2,3) and QGIS_DEBUG_FILE env vars to generate log file regards


0

By using shapely, I accomplish this [http://toblerity.org/shapely/manual.html] code snippet: dist = lineStr.project(refPt) np = lineStr.interpolate(dist) # using shapely


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


0

Now I use this code to filter specific fields out of the layer attributes: fields = ['id', 'name'] filterFields = [] features = layer.getFeatures() for feature in features: attrs = [feature[field] for field in fields] filterFields.append(attrs) This generates a list containing the filtered attributes for every feature of a layer.


0

just do ScaleBar.setBackgroundEnabled(0) in Qgis 2.4


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.


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


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.


3

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



Top 50 recent answers are included