New answers tagged

2

The expression pre validation sometimes is not working properly in the print composer even if the expression is valid and would work. Your first expression is evaluated on the layer so get_feature_by_id have no problem to verify the formula result and let you click ok button. To make it work you have to add the expression without the expression dialogu box. ...


2

You can do an atlas that will change styling and not change the extent of your map. Finish to add every layer you may use in your project. Verify they have all a different name. Create a new layer with no geometry named "atals_table" without fields. Open the attribute table of this layer and create the same number of features as layers you have. ...


0

The aggreagate formula don't work well in the layout, I have faced this issue also. The solution I found is to do it in two steps, first creating a virtual field and then show in the layout a table with one cell. Create a virtual field in your layer that will contain the total of the area in your layer. Here is the formula : aggregate( @layer , 'sum', $area ...


5

You can find the page type (if exists) with the following code : project = QgsProject.instance() composition = QgsPrintLayout(project) document = QDomDocument() template_file = open("C:/Users/Thysma/Documents/Stage/Composeurs/A4 Portrait.qpt") template_content = template_file.read() template_file.close() document.setContent(template_content) ...


1

My solution would be to do a table that contain the list of the cities filtered. You have a province layer which you want to do atlas with (make a map for each province) and a city layer you want for each atlas page to filter and list only the one linked with your province. Both layer have an attribute (i will name it 9digit_code) like you described. In the ...


0

to change reference point of an item in the layout. for your example, you need to replace legend.setReferencePoint(QgsLayoutItem.LowerLeft) with : legend.setReferencePoint(6) # 6 is for the lowerLeft position you can change 6 with 0 to 8 with 0 for upperLeft(default reference point) / 4 : Middlecenter / 8 : LowerRight


4

right(@project_basename,3) could be an option


8

Use this expression: substr( @project_basename, strpos( @project_basename, '_PR' ) + 3 ) I assume string _PR exists in the project name.


1

You can set the map extent based on your line layer like this : ms = QgsMapSettings() context = QgsRenderContext.fromMapSettings(ms) ms.setLayers([line_layer]) rect = QgsRectangle(ms.fullExtent()) rect.scale(1.2) ms.setExtent(rect) map.setExtent(rect) layout.addLayoutItem(map) Then when you add the legend you can compare the extent of your layers with your ...


0

A solution I have tested in QGIS : Produce a line layer with the tool polygonstolines In your legend add this layer and errase the department and region layer. Activate the filter to show legend only for item inside atlas item (see capture under)


3

If you want the table to dynamically change its location relative to other objects (including growing from the bottom), you have to: Set the "Reference point" to the bottom part. Set the dynamic height of table1 and table2 in the Position and Size settings using the following expression: 6.2 + 6.2 * (1 + aggregate(layer:='table2', aggregate:='...


0

It work only with the name, the solution I think would be to make it the cleaner you can. The best way would be STEP 1 : get the value from expression and make it work, STEP 2 : fill the field with clean name to use it in atlas. To get the layer name clean you can use the expression builder. The function layer_property can give you any property of each layer ...


0

Attribute table shows features controlled by Atlas if relation between tables has been done. Relations are defined in Project properties. Then on Atlas must select 'Relation children'.


1

Make a rectangular polygon the same extent as your layout. I called mine 'limits' Copy your polygons layer to a new layer, and create a new attribute 'legend' using the attribute calculator. I used this expression: overlay_intersects( 'limits') Then set a query on this layer to: legend=True Save changes You should only see the relevant polygons, but the ...


1

You can bend the atlas function to make it change the style based on an attribute of your atlas layer. First create a theme for each of your styling option (the little eye in your layers panel). Name the different themes by really simple name. I suggest style1, style2, style3.. Then create a polygon layer for your atlas definition. You will have at least two ...


2

The project CRS should correspond to your main data, i.e. in UTM (32648) If you want to show a grid in degrees, you must set the grid CRS to 4326, and only then you can show the coordinates as decimal degrees or DMS. Note: if your grid is in UTM and the coordinates are to be shown as degrees, the output is complete garbage.


2

Try going in to the export settings and the output to raster. I have found the pdf output a bit hit and miss.


0

I have two solutions that could work : if your cell height don't vary too much. if your label need to appear only in one atlaspage, or in all atlaspage but not on two atlaspages. You still use the table but make multiple "cadre" (sorry I don't know the English name, it is just above position and size). This is normally used when you have a table ...


2

As Kadir Şahbaz commented, you are mixing QGIS 2 & 3 APIs. A couple of other things: -You don't need to actually open your layout, you just need a reference to the layout object. -If you want to export a png you should use exportToImage() not exportToPdf(). Try the example below which is working for me. project = QgsProject().instance() canvas = iface....


5

Before hitting refresh, you need to click the button to the right of it, which is "Set Map Extent to Match Main Canvas Extent". This will set the zoom and extent of the map to match your main canvas.


1

Thank you Ben this code work ! To my side I tried this code and It work also project = QgsProject().instance() layout = project.layoutManager().layoutByName('Your Layout Name') legend = [i for i in layout.items() if isinstance(i, QgsLayoutItemLegend)][0] legend.setAutoUpdateModel(False) root_admin = legend.model().rootGroup().findGroup('Limites ...


3

There is only a small modification to be made to the code. You just need to get a reference to your legend group and remove the layer from the QgsLayerTreeGroup rather than the root group which is a QgsLayerTree object. Please try the example below. I have used a group and layer name from your screenshot but you will need to change the layout name to match ...


2

Instead of setExtent() you should use zoomToExtent() method. E.g. ... layer_extent = zip_layer.extent() map.zoomToExtent(layer_extent) If you wish too zoom out very slightly from the layer extent you can use the grow() method on the QgsRectangle layer_extent object. E.g. ... layer_extent = zip_layer.extent() layer_extent.grow(0.1)#pass a sensible value ...


Top 50 recent answers are included