New answers tagged

0

Use f"(mean - {min1}) / ({max1} - {min1})" as expression. ex1 = QgsExpression(f"(mean - {min1}) / ({max1} - {min1})")


0

You need to "format" your expression : expression = '(("mean"- {min1})/({max1}-{min1}))'.format(min1=min1, max1=max1) print(expression) # To let's you check what you have ex1 = QgsExpression(expression) You were not replacing your min and max. It was just a plain string. You can use f-string : f'("mean"-{min1})/({max1}-{min1})'...


0

Use this expression: collect_geometries ( if ( L1_att = array_first (overlay_intersects('Layer2', L2_att)), overlay_intersects('Layer2', $geometry), '' ))


2

Your field named e.g. ID would have to have the field type text/string. Once you created this field, head for the layer properties and the attribute form tab. Choose the field ID, and fill in the preset-field with the following expression: 'QF'||lpad($id+1,5,'0') $id is the "internal" ID of the current feature. Since QGIS starts counting these at 0,...


0

You can draw a line from each point to its two closest neighbours. To do that, you can use QGIS expressions with either Geometry generator or Geometry by expression. Use this expression: union ( make_line ($geometry, array_get (overlay_nearest ('points', $geometry,limit:=3),1)), make_line ($geometry, array_get (overlay_nearest ('points', $geometry,limit:=3),...


1

There are two things you can do to resolve your problem: Set your project CRS to the same (or a similar) CRS that your historical map was produced in. Like this, you can avoid massive warping of the image. See also here: https://gis.stackexchange.com/a/392557/88814 You can get rid of the black pixels by setting them to transparent. In the raster layer's ...


0

Copy the code below and insert it in the Python console within QGIS: Replace the path C:\Users\Username with your path the .xyz files are stored import os import pandas as pd #enter path with .xyz files here --> # replace C:\Users\Username with the path where all files are stored path = r'C:\Users\Username\\' x = [a for a in os.listdir(path) if a....


0

You can always mask every character, including single or double quotes, by using their ascii-code: char(39) returns a single quote: ' char(34) returns a double quote: " To find the ascii code, simply look for it with ascii(): ascii('a') returns 97. To find the ascii code for single quotes, enter ascii('''') - this returns 39. Thus you can also use: ...


0

Thank you for all your suggestions. I tried them all and I certainly shall be taking all your advice moving forwards. After trial and error to sort this issue out I had to go back to basics. I reprojected every individual raster to WGS_84. Resampled each raster to the same pixel size as the DEM. Merged it all and it sorted the issue out. Seems like a really ...


1

You can run Processing algorithms to edit input features in-place (that is, to modify the INPUT layer instead of modifying a copy) in this way: from processing.gui.AlgorithmExecutor import execute_in_place # Get algorithm instance registry = QgsApplication.instance().processingRegistry() alg = registry.algorithmById("native:explodelines") # Run ...


1

This sql query should do what you're asking: select fieldA, fieldB, row_number() over(partition by fieldA order by fieldB) as fieldC from your_table order by fieldA, fieldB;


0

OK, I assume this for your datas: Layer1: Bird's observation, with an attribute with the specie name. Layer2: Home range, with an attribute with the specie name, the same as above. Set the symbol color for the Layer1. Use the plugin "color to attribute" on this layer, to have a new attribute, called symbol_color. Now, in the properties of the ...


5

Get them with: map_get(item_variables('Map 1'),'map_extent_center') which returns a <geometry: Point>. Then extract x and y values as you like, for example: 'X-Centroid: ' || x(centroid(map_get(item_variables('Map 1'),'map_extent'))) || ' - ' || 'Y-Centroid: ' || y(centroid(map_get(item_variables('Map 1'),'map_extent'))) Replace Map 1 with the name ...


1

Based on Babel's initial response this is the expression that provides the required output. You will notice I used regexp_replace to remove the degrees. minutes and seconds part. Also since I am assuming you are in a location where your longitude is less than 100 you can hardcode the 0 as the lead, if not you will need to add a case statement to check if is ...


6

In the raster calculator, use the MIN function: MIN ( "raster1@1","raster2@1")


3

Some of the processing scripts you can use "in place" just press the inplace button. Explode lines is one of them. There will no new layer produced.


4

The easiest way would be to use TIN-Interpolation from the Toolbox which can take a contour-line layer for input:


0

First of all, make sure that you have followed the steps in the video below: https://www.youtube.com/watch?v=XRD19qBzojo&ab_channel=Q-tips Don't forget about the "Update preview" next to the "Export" option, which is always available in the bottom left corner of your QGIS2Web interface. Usually, if it's something up, the preview ...


0

Based on the answer provided by Sanna Jokela, I created the code below which works perfectly for my purposes and can be easily expanded upon: case when relation_aggregate('DormouseSu_Tube_ID_Dormouse_c_id', 'count', "presence" = 1) = 0 then color_rgb(0,0,200) else color_rgb(0,200,0) end For anyone else wanting to use this, the field 'Presence' is ...


0

Because the grid contained many polygons with no data, returning the first value with the solutions ended up including no values within my first column, making them appear with grids WITH values in the first column so tweaking the suggestions provided by other users I used from qgis.core import * from qgis.gui import * @qgsfunction(args='auto', group='...


5

Edit New expression for your desired output in degrees, minutes, seconds but without delimiter symbols (older solution below). What you want to do indeed need installation of Lat Lon Tools plugin: this adds a new funtion to the expression editor: ddmmss. If you have a geometry with vertices 51.06993546 25.58704192, 51.13739268 25.60501474, 51.15957073 25....


1

The QgsCategorizedSymbolRenderer class has a method updateCategorySymbol(). So you could create a new QgsFillSymbol object, set its color and pass it to the updateCategorySymbol() method along with your category index. Try the code snippet below: layer = iface.activeLayer() renderer = layer.renderer() #QgsCategorizedSymbolRenderer symbol = QgsFillSymbol() ...


0

It seems to me that the problem is that you are using the QGIS API to perform the query, if you want to have a performance similar to PgAdmin you must implement the PostgreSQL engine in QGIS. That is, establish a connection to the database and implement a SQL statement to the Database. You can achieve this in several ways, using the QGIS API, specifically ...


0

The principle idea is to add vertices at a constant distance to the line. You can then use these vertices for the heatmap as they have everywhere the same distance between them. Like this, point density is equal everywhere and does not influence the rendering of the heatmap - colors will thus represent attribute values primarily, not density. On your line ...


4

You can't rasterize a point as it has no dimensions. First create a polygon around your point, then rasterize this. Version 1 (straightforward) As on your screenshot, you have set a pixel size of 10 * 10 and you want a 3 * 3 pixel raster, I suppose the polygon should be 30 * 30 meters with the point in the middle of it. To create such a square around your ...


0

I had a similar requirement and solved it using MortenSickel's code as a guide (code below). Any number of detail windows can be added to an Atlas controlled layout and only the once that sre in the detail layer will be displayed. from qgis.core import * from qgis.gui import * @qgsfunction(args='auto', group='Custom', referenced_columns=[]) def ...


1

Another possibility in case you want to concatenate all fields in your attribute table: map_akeys( attributes( )) gets the names of all attributes, array_to_string with delimiter + gets a string like a+b+c that you can than evaluate with eval() so that the actual contents of a, b and c are added: eval (array_to_string (map_akeys( attributes( )), delimiter:='+...


4

First possibility: use concat and replace double commas where you have empty entries: replace( concat (field_a,', ',field_b,', ',field_c), ', ,', ',') Second possibility: use arrays to concatenate, they concatenate NULL values as empty strings that you can then remove. Use one of this expressions: replace( array_to_string (array (field_a,field_b,field_c)),'...


3

Great answer by @Babel! Another option would be: regexp_replace(replace("Field B", string_to_array("Field A"), ''), ',,', ',') The core part of the expression is replace("Field B", string_to_array("Field A"), ''), but it will produce 1,,3,,5 so regexp_replace(~~~, ',,', ',') was added to remove doubled commas.


3

Use this expression: array_to_string ( array_remove_all( array_foreach ( string_to_array(field_B), if ( array_contains (string_to_array(field_A),@element), '', @element ) ), '' ) )


3

Use Select by expression with this expression and change the size of the buffer (end of line 2 - here: 0.0001) depending on the size of your polygons/the CRS you use (in most cases, it should work without adaptions). Explanation: the expression evaluates if the outer boundary of a buffer around a polygon feature is within the nearest neighboring polygon. ...


4

If you want to use python, this is one (complicated) way: #Change the following three lines: layername = 'New scratch layer' fieldwithdups = 'values' fieldwithout = 'values2' lyr = QgsProject.instance().mapLayersByName(layername)[0] #Create a layer object by name attrmap = {} #A dictionary to store and to set new values fieldindex = lyr.fields()....


0

When you save a layer to a new (or already existing) Geopackage, you can define the name of the field that contains the unique ID (called FID for Geopackage). When you add features, QGIS will autogenerate an incrementing number for the field defined as FID. By default, the field containing the FID is named fid, but you can change this: see the second ...


2

Use Select by expression with this expression: overlay_contains(@layer)


3

Use this expression with field calculator to create a new field with duplicates deleted (only distinct values remain). "text" is the fieldname where the initial string is: array_to_string (array_distinct(string_to_array("text")))


4

Since you mention SQL, here's a PostgreSQL approach to this issue: WITH yourvalues AS ( SELECT '37.3,37.8,44.A2,37.3,37.31' AS attributefield ) SELECT DISTINCT UNNEST(STRING_TO_ARRAY(attributefield,',')) AS unique_attributes FROM yourvalues Result: unique_attributes 37.31 44.A2 37.8 37.3 Result without using DISTINCT: attributes 37.3 37.8 44.A2 37.3 37....


3

If you want to define an input as a variable, first create an input, than use this input with Set project variable, give it a name and use the value of the input with Using model input (see screenshot). You can than use this variable with it's name in select by expression. Be sure that in the Select by expression dialog box (bottom left on the screenshot) ...


2

With QGIS 3.x (I used 3.20.0), it's really easy to use the native 3D functionality. Variant 1: constant hight of the glacier Create a polygon grid (squares) with the extent of your glacier and delete all grid cells that do not overlap the gacier's polygon. To do so use Select by location, run it with Grid / Disjoint / Glacier polygon and delete the selected ...


2

You can skip parts of this answer as you need / do not need them. First you can add specific coordinates you want to your attribute table. Such as x(start_point($geometry)) for the x coordinate of your startpoint y(end_point($geometry)) for the y coordinate of the endpoint geom_to_wkt(centroid($geometry)) for the wkt representation of the centroid x(...


1

turns out it's a Windows related bug, after I installed gdal on wsl sudo apt-get install gdal-bin converting the pdf into jpg, size went from 9.2MB to 3.8MB with no loss of quality gdal_translate ban_buc-5951-4.pdf test.jpg -of JPEG Then the jpg opens in QGIS on windows no problem. The only little annoyance is the image appear Cyan tinted as band 1 appears ...


0

Use this expression in field calculator. Be aware: array_max works only with QGIS versions 3.18 or higher: array_max( array_foreach ( array_filter( map_akeys( attributes( )), left (@element,1)='X' ), eval(@element) ))


2

On the line layer, create a new field with field calclulator and the following expression for the start-point. The expression creates a buffer around the start-point of the line, then looks for the two closest points to the line and checks which one lies inside the buffer. From this point, it takes the value of the field name. Adapt the expression as follows ...


1

Have you tried relation_aggregate function for classification of the layer? E.g. relation_aggregate( relation:='relationdomousexblaablaablaa21321144124',aggregate:='max',expression:="precense") relation_aggregate function brings the id or what ever field you need "Up" to your visualization layer and then you can classify your data based ...


2

Regarding the layer becoming uneditable after selecting and applying an SQL query via "Update SQL Layer" on the layer context menu, I discovered selecting "Change Data Source" from the same context menu and then just reselecting the original data source returns the table to editable. I haven't tested this but my guess is the problem ...


2

I finally figured it out, from other parts of the documentation the correct arguments that should be provided to fromPolygonXY is a [[QgsPointsXY_obj1, QgsPointsXY_obj2, ...]] link: https://docs.qgis.org/3.16/en/docs/pyqgis_developer_cookbook/geometry.html?highlight=polygonxy#geometry-construction and the documentation at https://qgis.org/pyqgis/master/core/...


0

Since the cross-hatching seems to occur mostly in areas of high slope, it would appear that the coarser glacier DEM is being resampled using nearest neighbor. Have you tried some other resampling algorithm which actually interpolates between cell centers (EG, bilinear/cubic)?


3

What you need is Menu Vector / Datamanagement Tools / Join attributes by location. Set the points as input and the polygon as overlay layer. As Geometric predicate, use within. Choose fields to add, for Join type use Take attributes of the first matching feature only (one-to-one). If you want, define a prefix. Screenshot: output will by a copy of the point-...


1

Using only QGIS expressions: to get the field name with the largest value: with_variable ('sel', map_avals (attributes ()), map_akeys (attributes ()) [array_find (@sel, array_max (@sel))] ) to delete some fields from the attribute table use the expression: with_variable('deleteField', map_delete( map_delete( map_delete( map_delete( map_delete( map_delete( ...


0

I Think, the GDAL Tool "merge" should do what you want. From GDAL documentation: "In areas of overlap, the last image will be copied over earlier ones." -> You can drag and drop the layers in the layer selection window to be in an order that fits your needs.


2

I found myself a quiet good solution, which allowed to handle with a lot of polygones. First I convert my DEM with the tool from SAGA called "Real surface area". After that, I have a raster with the real surface for each pixels, on band 1. Than I simply use "zonal statistics" with my polygones layer, to get the 'sum' of band 1... and that'...


Top 50 recent answers are included