Tag Info

New answers tagged

0

Here's what I was thinking, and it's based on the way a lot of attribute-heavy government data is official disseminated (like US soil surveys, etc.): --Create a single shapefile with an attribute Name to hold your geometry. --Create series of a-spatial tables, each with different fields but all with the Name field (sorry, not familiar with how to do this ...


0

You have to use a Canvas-Object as first agrument in QObject.connect(). Here snippset that works for me: def _onRenderComplete(): print("do something") _canvas = qgis.utils.iface.mapCanvas() QObject.connect(_canvas, SIGNAL("renderComplete(QPainter *)"), _onRenderComplete)


1

I just solved the same problem. The Cookbook (linked by Dan) is my main source, but this time it shows only how to make points, not polygons. I've solved it with gene's answer elsewhere: surface = QgsGeometry.fromPolygon ([points]) Assumming you have your points stored in a list named points. Don't forget the square brackets around the list's name.


3

You could loop through the the Layers panel to check if the layer exists or not by the name before assigning: layers = QgsMapLayerRegistry.instance().mapLayers().values() foundLayer = False for layer in layers: if layer.name() == 'my_layer': inputLayer = QgsMapLayerRegistry.instance().mapLayersByName("my_layer")[0] foundLayer = True if ...


1

You can have multiple layers (or shapefiles) with different attributes. It sounds like from your description that you want to do a JOIN - which is basically connecting a number of layers together by a common attribute. So you could, for example, have a single layer which is joined to a number of other layers by using the name attribute. Then that layer will ...


1

You will have to copy your python module in the plugin dir. and then you will get the path to your plugin with a small python script import os dirname, filename = os.path.split(os.path.abspath(__file__)) print "running from", dirname print "file is", filename This works with a C library, should be the same with a python module


1

You need to call legend.setFrameEnabled(True) The relevant api docs are here http://qgis.org/api/classQgsComposerItem.html#a84db6541af98f47b090abf1860c0c8e6


1

I used a function to get all possible methods (or constants) with the word 'frame' or 'Frame' in the class QgsComposerLegend (a list with 511 members). The result was: 1) With 'frame': ['frameChanged', 'frameJoinStyle', 'frameOutlineColor', 'frameOutlineWidth'] 2) With 'Frame': ['ComposerFrame', 'drawFrame', 'estimatedFrameBleed', 'hasFrame', ...


1

You could try the Polygonize tool in the QGIS Processing Toolbox. If you ran this on your example (after appending the two tables together) the loop would be identified by the presence of a polygon in the output dataset.


1

So I've found out what was it ! I added into the code a column with city names to add as labels on the map. But it only contain a small number of them, and Qgis probably don't like Null values that much... After replacing them with zeros the importation of the .xlsx files went smoothly ;) !


-1

Have you looked into the Maplex Label Engine? It's a pretty powerful labeling option that might be suited for your needs. It comes with all ArcMap versions over 10.0 IIRC.


0

After seeing the raster image of the field, I though of this process - I used Arcgis 10.2.1. (Note: Just realised that I have got the length and widths around the wrong way when compared to the image, but If I was to recreate the answer I would use the same process below but amend the lengths and widths) Using the dimensions provided I worked out what the ...


1

Short answer: I don't believe this is possible using WFS (or any of the OGC standards). The WFS standard offers no way of knowing how many features are in the entire dataset. Nor does it offer any way of showing data history. The only real way of knowing if anything is different is by downloading the entire dataset and doing comparisons (spatial and ...


1

If you want to use a solution with processing as in How to merge shape files with attributes from a python script in QGIS? (without in the solution of gcarillo): 1) The easiest solution is to is to run the wanted algorithm from the toolbox and look at the /.../.qgis2/processing/processing.log file. The last lines gives the solution: ALGORITHM|Mon Jul 27 ...


1

You can join your two layers in this way: # Get input and target layers targetLyr = iface.mapCanvas().layers()[1] # Second layer from the ToC inLyr = iface.mapCanvas().layers()[0] # First layer from the ToC # Set properties for the join targetField='myTargetField' inField='myInputField' joinObject = QgsVectorJoinInfo() joinObject.joinLayerId = inLyr.id() ...


0

The canvas does not communicate its state back to the widget. The layer order is managed by QgsLayerTreeMapCanvasBridge which is only exposed as of (upcoming) QGIS 2.12 and in the nightlies since now. l = iface.layerTreeCanvasBridge() l.setCustomLayerOrder(a) # a is a list of layer ids, make sure all the layers are in there l.setHasCustomLayerOrder(True)


1

To avoid "layer is not valid" errors you should carefully set your QGIS prefix path. The prefix path must be set to let QGIS know where to find resources such as data providers and the reference system database. If you look at your QGIS installation, you should be able to access lib/qgis/plugins on Unix (or just plugins on Windows), relative to the prefix ...


2

QGIS updated to the SIP API V2 between 1.8 and 2.0. See: https://hub.qgis.org/wiki/17/Python_plugin_API_changes_from_18_to_20#Replace-QStringList-with-list It will transparently convert some types (like QString or QList) between python and Qt types. So you can just use a python list of str or unicode objects and pass it to the pyqgis and pyqt API wherever ...


3

Why not data define the image path? Next to the image filename is a button which allows you to link the path to an attribute in your data (or set via an expression).


1

You can get the attributes toolbar and iterate through its actions (buttons) until you get the "deselect" one. Then you can trigger it. Try this in your QGIS Python console: for a in iface.attributesToolBar().actions(): if a.objectName() == 'mActionDeselectAll': a.trigger() break


0

Brute force ;-) A new selection overrides the old one. Then simply deselect by selecting nothing. for layer_id in QgsMapLayerRegistry.instance().mapLayers(): layer = QgsMapLayerRegistry.instance().mapLayer(layer_id) layer.setSelectedFeatures([feat.id() \ for feat in layer.selectedFeaturesIterator() if feat.id() < 0]) Maybe there is a more ...


0

Not sure why you're getting NULL values but the following code worked for me (note that I call the QGIS Zonal Statistics tool from the Processing plugin and I want to load the result): vectorlayer = qgis.utils.iface.mapCanvas().layer(0) rasterfile = qgis.utils.iface.mapCanvas().layer(1).source() processing.runandload('qgis:zonalstatistics', rasterfile, 3, ...


0

it seems that my problem was in the GRASS algorithm I was using. Now, I've moved to GDAL algorithm named "Grid - InverseDistance To a Power" and it works. I don't really know what was wrong: my only suspect is that after running grass algorithm I would need to "convert" the grass raster map created to a "readble" raster, to be loaded in QGis correctly. I ...


2

Reason When you create a symbol it has ownership of its layers. When you add a layer to an existing symbol, it takes ownership of the added layer. Ownership means it is free to delete it whenever it wants. In your example both symbols assume ownership of symbol_layer2 (symbol2 because it created symbol_layer2, symbol1 because symbol_layer2 was added to ...


14

You could use PyQGIS for that (not sure is the best solution for it, though). Select (or activate) the layer in the QGIS ToC, open the QGIS Python console, and copy this code snippet: prefix = "'" layer = iface.activeLayer() attr = layer.rendererV2().classAttribute() attrColor = 'color' # Name of the field to store colors fieldIndex = ...


1

To be honest, a python script (if you are familiar with Python) would be the most efficient method of creating your polygons in your use-case. However, if you are not familiar with scripting, then there are a variety of tools that you should investigate in QGIS (e.g. Vector->Research Tools->Vector Grid). You will have to use a crazy combination of ...


1

Thanks to Nathan Woodrows blog, and some API doc reading i figured method using QgsMapRenderer is deprecated. (Seems that pyqgis cookbook is often way out of date) So, instead, i used QgsMapSettings and QgsMapRendererSequentialJob classes. I got settings from a canvas via canvas.mapSettings() method. Then the rendering procedure goes like this: job = ...


2

A point inside a polygon canvas = qgis.utils.iface.mapCanvas() aLayer = canvas.layer(0) # or code to select the layer of interest for f in aLayer.getFeatures(): geom = f.geometry() p = geom.pointOnSurface() print p.asPoint() Get Inner Rings canvas = qgis.utils.iface.mapCanvas() aLayer = canvas.layer(0) # or code to select the layer of ...


2

Add the second line in my code: layer = QgsVectorLayer("LineString", "points", "memory") QgsMapLayerRegistry.instance().addMapLayer(layer) pr = layer.dataProvider() pt = QgsFeature() point1 = QgsPoint(0,0) point2 = QgsPoint(100,100) pt.setGeometry(QgsGeometry.fromPolyline([point1,point2])) pr.addFeatures([pt]) layer.updateExtents() The result is in the ...


1

You can move cursor like that: from PyQt4.QtGui import * from PyQt4.QtCore import * cursor = QCursor() cursor.setPos(100, 200) It moves your cursor to point 100,200 in your screen. If you want to get coordinate of a point on the map canvas, you need to translate them: # coordinates of point on map canvas point = QPoint(100,100) # translate widget ...


1

You need to set your map to use the atlas feature's extent, using QgsComposerMap.setAtlasScalingMode, eg myAtlasMap.setAtlasScalingMode( QgsComposerMap.Auto ) Place this line after you've setup your atlas, but before the beginRender call.


1

Never used the QgsGeometryAnalyzer() method before (I should take a look at this) but you could use the following code which I think should do what your code does (tested this on Python Console in QGIS 2.8.2): import processing, os, glob result_path = "C:\Temp\Dissolved\\" os.chdir("C:\Temp\\") for fname in glob.glob("*.shp"): name= ...


1

SQL query is wrong, it should be: result = dataSource.ExecuteSQL("select * from roi_classMacro WHERE C_info = 'g19' or C_info = 'g22' or C_info = 'g23'") For attribute filter try: mylayer.SetAttributeFilter("C_info = 'g19' or C_info = 'g22' or C_info = 'g23'")


1

Your version of QGIS (2.11 = QGIS dev) use a new geometry class (QGIS dev: New geometry classes merged and many other posts in this mailing list as Questions regarding new geometry engine, QGIS QgsGeometry.fromWkt not accepting polygons with Z values? , Potentially serious performance regression in new geometry - should 2.10 be delayed?, ...) What is the ...


1

Worked for myself as well, as Matthias suggested if you add the following to your import statements: import resources_rc It works as long as you have updated and recompiled your resources file: pyrcc4 -o resources_rc.py resources.qrc (In windows easiest to run with the OSGeo4W shell, cd to directory)


0

Try with processing.tools.vector instead of processing.core.VectorWriter.


0

If you have your layer for example as: layer = iface.activeLayer() You should get legend: legend = iface.legendInterface() Then you can check layers visibility (it returns bool): legend.isLayerVisible(layer) Or toggle visibility: # off legend.setLayerVisible(layer, False) # on legend.setLayerVisible(layer, True)


1

What about the QgsFeatureRequest.NoGeometry flag? all_matrix=[] request = QgsFeatureRequest() request.setFlags(QgsFeatureRequest.NoGeometry) for f in matrix.getFeatures(request): a=feat.attributes()[origin] b=feat.attributes()[destination] c=feat.attributes()[flow] all_matrix.append([a,b,c]) matrix=np.array(all_matrix)


1

Thanks to promting by Joseph I had a look at the docs for the application class reference. In order to utilise functions from qgis in your script you need to add a qgis application class reference object. app = QgsApplication([],False, None) after the QgsApplication.initQgis() line and app.exit() At the end. The docs describe the parameters but ...


0

Have you tried copying the fmeobjects.pyd to QGIS site ? similar : From: \fmeobjects\python27\fmeobjects.pyd To: \Lib\site-packages\fmeobjects.pyd


1

In Windows QGIS has its own Python version. By default if you instal libraries (ex. pip install name_of_library) it will be installed only in your pure Python version not for QGIS. Here is a guide, I think it may be helpful: http://quantumofgis.blogspot.be/2014/11/qgis-standalone-and-python-modules.html


2

I think some of the tools you are looking for can be found in a single plugin - the Processing plugin. Importing this plugin from PyQGIS would allow you to call various tools (I am not an ArcGIS user so I am judging the tools you mentioned by their name and a quick search): ArcGIS QGIS arcpy.AddField_management ...


1

Just as a remark: QgisInterface is an abstract class and has virtual functions so it may not be instantiated, i.e. it defines an interface and not a complete implementation. But you can use QgisInterface class within a standalone application where the iface class is not available. There you can reimplement and override the main functions of the class. An ...


0

Here is an older post about "Python script for identifying duplicate records (follow up)", but may it helps: Python script for identifying duplicate records (follow up)


2

Try simply: layer = iface.addVectorLayer("/path/to/shapefile/file.shp", "layer_name_you_like", "ogr") Here you have a nice guide for PyQGIS: http://docs.qgis.org/testing/en/docs/pyqgis_developer_cookbook/intro.html


1

If you look at the source code for the context manager qgisapp: https://github.com/qgis/QGIS/blob/master/python/core/contextmanagers.py you'll see it is just a neat wrapper for running code inside a QgsApplication context. Following what Nathan W does with his Qgis python is usually a good idea, so I'd go with this.


0

First of all, checking the QGIS API doc, I can see that the ranges method from the QgsGraduatedSymbolRendererV2 class returns a const QgsRangeList & probably meaning that you have little chance to modify its return value. Additionally, when looping the way you do in Python, you cannot modify a list's values as explained here. => twice impossible :) ...


3

SimpleSVG is a Python plugin https://plugins.qgis.org/plugins/simplesvg/ --> using PyQGIS! Therefore its source code should be the perfect example of how to export SVG from QGIS.


3

As Luigi suggests, you can have a look at the API documentation, specifically to QgsVectorFileWriter::writeAsVectorFormat, and realize you're just missing one parameter (from the docs): bool onlySelected = false, It says that the parameter onlySelected is of type boolean and is false by default. This parameter is right after the driver name. So, calling ...


1

You can listen to the extent changed event and reset it back if it goes outside of the bounds: def extentsChanged(): extent = iface.mapCanvas().extent() outofbounds = # Do your check if outofbounds: iface.mapCanvas().setExtent(newextent) iface.mapCanvas().extentsChanged.connect(extentsChanged)



Top 50 recent answers are included