12 votes
Accepted

Renaming GeoPackage layer to be the same as GeoPackage file

Try this. (You'll have to adjust it to match your exact data/situation) import os geopackage_folder = r'/home/bera/Desktop' for root, folder, files in os.walk(geopackage_folder): for file in ...
BERA's user avatar
  • 72.6k
11 votes
Accepted

Adding multiple Additional options to QGIS Batch processing?

You use the pipe character "|" to separate your options, so for your options you would use: COMPRESS=JPEG|JPEG_QUALITY=75|PHOTOMETRIC=YCBCR|TILED=YES i.e This is now documented: For Batch ...
user2856's user avatar
  • 65.8k
10 votes
Accepted

Write output of QGIS Batch Processing to temporary layers

Yes it is. You must use the keyword TEMPORARY_OUTPUT in the field that sets the output location. Don't forget to check Load layers on completion then!
malbles's user avatar
  • 288
10 votes

Refactoring several attribute fields at the same time

You can use pyqgis with a dictionary: Change first four lines: lyr = QgsProject.instance().mapLayersByName('ok_ak_riks')[0] sourcefield = 'A' destfield = 'abcd' remap = {1:'foo', 2:'bar'} ...
BERA's user avatar
  • 72.6k
10 votes

Refactoring several attribute fields at the same time

You can use "Refactor Fields" tool. Specify field Type as Text for the fields you need to change. Copy the expression to the fields and change the field names in the expression. (I ...
Kadir Şahbaz's user avatar
10 votes

Batch renaming of columns in attribute table for shapefiles using QGIS

Use this script. As a precaution, backup the shapefile first. #generate monthyear months = ["JAN","FEB","MAR","APR","MAY","JUN","JUL&...
Kadir Şahbaz's user avatar
9 votes

Batch removing null geometries

Removing null geometries from just a few layers Use the "select by expression" button to select features with null geometries. The "select by expression" button is found by clicking the arrow next to ...
csk's user avatar
  • 24.8k
9 votes
Accepted

Creating several new fields at once with QGIS field calculator in batch mode in the same layer/file

You can do stuff close to that using refactor fields in batch mode or in graphical modeler. However, when not using this in combination with graphical modeler, I think it is way more convenient to use ...
MrXsquared's user avatar
  • 34.4k
9 votes
Accepted

Batch processing of numerous shapefiles in common folder with PyQGIS

While using QGIS processing tool in a script, two parameters are mandatory: the tool name and dictionary-like tool parameters (must be in a dictionary). Therefore, you have to pass the second ...
Kadir Şahbaz's user avatar
8 votes
Accepted

What's the batched Refactor Fields tool "field mapping" syntax in QGIS?

It is not very comfortable to do, but the following is the required syntax for that textbox (I write it in several lines only for the sake of clearness): {'expression': u'type the expression here', '...
mgri's user avatar
  • 16.2k
8 votes

Calculating sum of line length for hundred vector layers

Use PyQGIS: #Create an empty table in memory and add fields newtable = QgsVectorLayer("None", "Results", "memory") provider = newtable.dataProvider() provider....
BERA's user avatar
  • 72.6k
7 votes

Batch Clipping Single Raster with Multiple Shapefiles in ArcPy?

This uses multiple shape features in a single shapefile (based on your code snippet). If you have a single shape feature in multiple shapefiles I have added code for that further down. The following ...
Midavalo's user avatar
  • 29.7k
7 votes
Accepted

Batch export from multiple QGS projects to image or PDF

First try. Thanks to PyQGIS, we can call the Maps Printer plugin's functions to achieve what you want! So, having such plugin installed, adjust your own settings in Your settings section of the ...
Germán Carrillo's user avatar
7 votes

Renaming Shapefiles in QGIS?

For R users, I wrote a quick R function that batch renames the .shp file and all files associated. It's pretty bare bones, and there is no error checking, etc., so if it fails you'll need to do a ...
ndimhypervol's user avatar
7 votes
Accepted

Batch flip direction of selected lines in ArcGIS 10.3

The Editing toolbox in ArcToolbox has a tool called Flip Line, which will reverse the direction of every line (or selected lines if any are selected) in the chosen feature class or layer. This can be ...
Midavalo's user avatar
  • 29.7k
7 votes
Accepted

Updating field with layer name on multiple layers with PyQGIS script?

Just happens that I created a script for a very similar thing recently (my script merges multiple layers into a new layer, while adding a new attribute to each feature describing where it stems from; ...
Senshi's user avatar
  • 1,767
7 votes

Using Batch Raster Calculator in QGIS

This is actually fairly easy to do. I think others might have an easier solution but this is how I do it: Go to the Processing tab -> Graphical Modeler 2. Under inputs, add raster layer two times. ...
MapInfoNewbie's user avatar
7 votes

Exporting multiple point shapefiles from one file using QGIS

In QGIS, you can find a tool in Vector/Data Management Tools/Split Vector Layer. There you can define the column containing the species information as Unique ID field and it will generate a new file ...
karpfen's user avatar
  • 2,307
7 votes

Copying all visible layers to new group

Use the following script. root = QgsProject.instance().layerTreeRoot() group = root.addGroup("group") for layer in root.children(): if layer.isVisible() and layer != group: _layer ...
Kadir Şahbaz's user avatar
7 votes
Accepted

QGIS 3 changing layer CRS for multiple layers simultaneously

You can group all layers you want to change, right click the group and then "Set group CRS" should do what you asked for.
sn1ks's user avatar
  • 3,002
7 votes
Accepted

QGIS 3 batch processing - INPUT value not correct when autofill

That weird string is not a memory address, but the layer's id. You can use the following expression to construct INPUTLAYERNAME_clipped string. And no need string_to_array(@INPUT,'_')[0]. ...
Kadir Şahbaz's user avatar
7 votes
Accepted

Joining multiple layers in QGIS

You can use a Virtual layer through Layer > Add Layer > Add/Edit Virtual Layer... for that. Use this query: select * from layer1 as l1, layer2 as l2, layer3 as l3, layer4 as ...
Babel's user avatar
  • 71.2k
7 votes
Accepted

Deleting the same column(s) from different shapefiles in QGIS

A PyQGIS solution. Tested on QGIS 3.24.1-Tisler. Proceed with Plugins > Python Console > Show Editor and paste one of the scripts below. The press Run script and get the output. This approach ...
Taras's user avatar
  • 32.8k
7 votes

Exporting several layers as GeoPackages at the same time in QGIS

Another solution is to use the "Package layers" tool as a Batch Process.
Taras's user avatar
  • 32.8k
6 votes

Can I export all print composers at the same time?

You can use the "Maps Printer" plugin, or the "multiprint" plugin which has this functionality. To take it even further, you can export multiple print composers from multiple .qgs files using the ...
SaultDon's user avatar
  • 10.4k
6 votes
Accepted

Programmatically naming outputs from the QGIS Modeler?

Hit the ... button, set output file name and save like with usual saving single file. This create a basis for the files names. After hittingSave the Autofill settings should appear. There you can ...
Oto Kaláb's user avatar
  • 6,895
6 votes
Accepted

Batch save multiple rasters in QGIS

With this code snipped you would get all layers in your current project: layers = QgsMapLayerRegistry.instance().mapLayers() # for testing for name, layer in layers.iteritems(): print name, ...
LaughU's user avatar
  • 4,176
6 votes

Batch saving of multiple shapefiles of different types

This is working if you manually change the layer group name by editing line 7: import datetime, os out_folder = r'/home/bera/Desktop/tempgis/shapes/' yearmonth = datetime.datetime.today().strftime('%...
BERA's user avatar
  • 72.6k
6 votes

Convert/migrate QGIS 2 Project to QGIS 3 Project automatically

Within QGIS, you can open your qgs files and save them as qgz # Here simple list of files but you can use: # - `os.walk` from `os` module https://pymotw.com/3/os/, # - `pathlib` module https://pymotw....
ThomasG77's user avatar
  • 30.7k
6 votes

QGIS 3 changing layer CRS for multiple layers simultaneously

Be aware: you want to reproject your layer or change the CRS of the layer? That are two fundamentally different things and the linked post presents options for both: that could lead to confusion. ...
Babel's user avatar
  • 71.2k

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