Hot answers tagged

43

Update for QGIS 3.x: The old OSM importer from QGIS 2 was dropped in QGIS 3 due to lots of unresolved bugs. The QuickOSM plugin also enables to read osm raw files. You can use user Layer - Add Layer - Add Vector Layer instead. In that case, OSM data are opened with GDAL as documented by http://gdal.org/drv_osm.html In QGIS 2.x, There are 3 steps involved ...


38

It does now :) Only in the dev version but something like this could be added in an older release using a plugin. If I get some time I might just do that. A QGIS Layer Definition file will have the *.qlr extension and is a XML dump of the maplayer node for the project. The start of the file will look like this: <!DOCTYPE qgis-layer-definition> &...


30

it is not realy complicated, look at Memory provider in vector: : a point is created with QgsPoint(x,y) and QgsGeometry.fromPoint(QgsPoint(x,y)) a line is created with two points: QgsGeometry.fromPolyline([QgsPoint(x1,y1),QgsPoint(x2,y2)])) a polygon is created with a list of points: QgsGeometry.fromPolygon([[QgsPoint(x1,y1),QgsPoint(x2,y2), QgsPoint(x3,y3)]...


29

When I get errors like this I usually find applying a zero distance buffer can fix the geometries. So use the buffer tool in QGIS and set the buffer distance to 0 units. Then try and use this buffered layer as the mask.


28

One method is to use the IN function followed by your list of values all inside brackets. E.g. "Column_Name" IN ('Value_1', 'Value_2', 'Value_N') Hope this helps!


26

It is simpler than with version 1.8: layer = qgis.utils.iface.activeLayer() fields = layer.pendingFields() field_names = [field.name() for field in fields] or in one line field_names = [field.name() for field in layer.pendingFields() ] an after for elem in layer.getFeatures(): print dict(zip(field_names, elem.attributes())) {u'adip': 17, u'dipdir'...


23

I'm not sure how to enforce it for existing polygons, but you could make it work for any future ones that you create. In Project Properties>Default styles>Style Manager, you could create your own default symbol style for "Fill": Edit the Border color's expression and set it to @symbol_color: Lastly, set your new fill style as the default: This will make ...


21

I think there's atleast two methods: Select your features and run the Save selected features tool from the Processing Toolbox. As described in this answer to a related question: Select your features Copy them with either Ctrl + C or from the menubar (Edit > Copy Features) Paste the features as a temporary scratch layer (Edit > Paste Features as > ...


20

Update 27/07/2018: As of QGIS 3.2.1, my workaround below no longer works! If I find an alternative solution I will post here again. This is very, very annoying... There is a way to do this. In the Item properties tab for your map item, click on the black-and-yellow "data defined override" icon to the right of the "scale" box. Click on "Edit". In the "...


19

If anyone is interested here is the code I ended up with. This will turn on/off specific layers in the table of contents (from a list of layers), load a selected composer template from file, generate an atlas and export the map. Finally, returning the table of contents to its original state. def sort_toc(self): # Turn on/off layers as required by ...


19

Use Refactor Field in the Processing Toolbox. Go to Processing > Toolbox > QGIS geoalgorithms > Vector table tools > Refactor fields This will open the Refactor fields window where you can select the layer that you want to make changes to. From the Type drop down choose Integer or Double depending if you want a whole number or a decimal number, ...


18

It's not temporary. I know that people hate change, but that's the way it is. QGIS 3.4.5 replaced 2.18 as a LTR. You can find older versions here: http://download.osgeo.org/qgis/


17

I found downloading OSM data using the plugin and going through the import and export motions very tedious. That's why I wrote up a different solution: http://anitagraser.com/2014/05/31/a-guide-to-googlemaps-like-maps-with-osm-in-qgis/ Summary: Raw OSM files can be quite huge. That’s why it’s definitely preferable to download the compressed binary .pbf ...


16

I have exactly the same use case at work, so this is what I have come up with: Solution 1 (ellipse) This looks fairly regular, but is the least precise generally, IMO. Use the ellipse marker symbology with the following data-defined overrides and change the units from Millimeter to Map Unit (essential!): Symbol width: "E" + "W" Symbol ...


15

Since you're not worried about simultaneous edits on features, I'd say that in theory you have nothing to worry about. The main danger w/ QGIS is that simultaneous editors can stomp on each other's edits without noticing ("last edit wins"). For data under active editing with multiple users you might want to at least keep track of history, which you can do w/...


15

TL;DR To get all features of a layer by the layer name you do not need to activate it. Just use name = 'counties' layer = QgsProject.instance().mapLayersByName( name )[0] poles = layer.getFeatures() for pole in poles: if is_north(pole): print('it is the north pole') Active Layer First of all, you do not need to care about the active layer. ...


14

The north arrow is added as an image. The behaviour of the scale depends on the CRS of your data/map. Once you start inserting an image in the composer, you should get the option to select from a library of icons, and a subfolder is arrows, of which there are are many types. Once the image is installed, there is an option to keep the rotation of the arrow ...


14

Something like below should work. vLayer = iface.activeLayer() canvas = iface.mapCanvas() extent = vLayer.extent() canvas.setExtent(extent)


14

I had the same problem. This should solve the bug (QGIS 2.6 under Windows): close QGIS using regedit.exe, search for "Plugin-GeoReferencer". This should point to a folder under \HKEY_CURRENT_USER\Software\QGIS\QGIS2\Plugins (optional: export a .reg version of the folder for back-up) delete the folder "Plugin-Georeferencer" restart QGIS. Georeferencer window ...


14

What you want is creating the Atlas. In print composer, go to Atas generation tab and check Generate atlas. As covarage layer set your counties layer, and as output set your name of counties attribute (somtheing like "counties_names"). Go to layer properties and set rule-based symbology, create empty rule with grey color and in this rule nest a rule like $...


13

In the Processing/Toolbox, there are two scripts: and Delete duplicate geometries works very well (better than MMQGIS).


13

I will write a quick explanation of the pyuic4 and pyrcc4 commands for future reference. Most tutorials simply tell you to copy some code, but no one explains exactly what you are about to do. It is quite simple actually, but beginners might still struggle with it. The Plugin Builder generates a fairly 'empty' plugin template. The two files that are of ...


12

We have the rpad function for that: rpad('1', 2, '0') rpad('10', 2, '0') result 01 10 rpad("yourcolumn", 2, '0') rpad() function Returns a string with supplied width padded using the fill character. Syntax rpad(string, width, fill) Arguments string - is string. The string. width - is int. The length of the new string. ...


12

Working on QGIS 2.18.20 I see a different behavior of the one described by @NathanW: lpad("id",2,'0')-> '02' rpad("id",2,'0')-> '20' Where I think r stands for right and l for left. Quoting the man page of the function rpad: Returns a string padded to supplied width using a fill character. Syntax rpad(string, width, fill) ...


12

QGIS comes with "offline editing" functionality in core. This downloads the data to a local spatialite database, so you can work on an offline copy and the delay caused by network roundtrips is gone. This is not a memory layer but if I understand correctly, that's just an example and not mandatory. To enable offline editing, you have to check the offline ...


12

In the 2.18.11 QGIS version there is a easy way to calculate buffers. This option is in build in the MMQGIS plugin . Once you have the QGIS plugin you have the option to create buffer When you are making the buffer take care to choose the right distance unit for the buffer radius This is a great tool from the QGIS Las Palmas developers!


11

Firstly, you can use gdal_calc.py to change all -9999 to 0 and set the NoData value to 0. For instance: gdal_calc.py -A input.tif --outfile=input_with_NoData.tif --calc="A+9999*(A==-9999)" --NoDataValue=0 Then, you can ignore NoData value using gdal_translate with the -a_nodata option followed by none. -a_nodata value: Assign a specified nodata ...


11

In QGIS at bottom right corner, there is an option called 'Rotation'. There you can rotate your canvas (or extent of view) by any angle.


10

I found a plugin called rasparenza today that got me going on the transparency issue. For QGIS 2.x it looks like we want the setOpacity() method: rlayer = qgis.utils.iface.activeLayer() # Set opacity rlayer.renderer().setOpacity(0.5) # Trigger a repaint if hasattr(rlayer, "setCacheImage"): rlayer.setCacheImage(None) rlayer.triggerRepaint() For some ...


10

In QGIS 2.8 you have the option to lock the styles in a map. First add number of map pages in the print composer. Example with two maps: And the corresponding print composer In the Print Composer Map properties check the "Lock layers for map item" and "Lock layer styles for map item" properties. Do this for each map, after setting the layers shown and ...


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