Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

New answers tagged

2

I come from SQL land, so not sure how applicable this to QGIS. But in SQL I would think of two tables: one with original country polygons, another with country polygons buffered by whatever coastal buffer you want to use. Of course, the "buffered countries" would overlap on the land side, but that's simple to fix: you only count points within "buffered ...


0

In QGIS reports, the footer is the last page, not the footer of each page as you would expect in *.doc files, for example. To add variable text to each page of the report, one needs to add labels with expressions. Add a label object Insert an expression like [% @atlas_layername %] If you try with [% @layout_page %], however, the number always remains "1"; ...


0

As @Subgenius said, a workaround would be to create the task variable with global scope. globals()['task1'] = QgsTask.fromFunction( u'function task', do_task, on_finished=completed, wait_time=4 ) And to call it, QgsApplication.taskManager().addTask( globals()['task1'] ) This way, you can call the task from inside a function ...


2

As your data points are regularly distributed (0.25 x 0.25 degrees), you can just rasterize (or "burn") to create a raster layer... you do not have to perform gridding task, About the the linked question in your comment, unfortunately, the interval between data points were only slightly irregular (like 0.1666 vs. 0.1667) which required to be gridded (by ...


0

Many solutions IMHO. In the layout 'Atlas' tab, edit the output expression formula : Solution 1 : attribute(@atlas_feature, 'my_atlas_layer_field_name') Search the original data in the atlas layer with the attribute function and the variable @atlas_feature. Solution 2 : if(substr(@atlas_pagename, -2, 2) = '_2', substr(@atlas_pagename, 1, length('...


0

It is the qgis:fieldcalculator algorithm that complains. Your QgsExpression('y(centroid($geometry))').evaluate() returns nothing, but qgis:fieldcalculator will accept a string for FORMULA. So I tried to change 'FORMULA': QgsExpression('y(centroid($geometry))').evaluate(), to 'FORMULA': 'y(centroid($geometry))', and 'FORMULA': ...


1

I finally figured it out. Open python console in QGis, click show editor to open a new script and execute this script. # create layout p = QgsProject() layout = QgsLayout(p) layout.initializeDefaults() # change first page orientation to portrait pc = layout.pageCollection() pc.page(0).setPageSize('A4', QgsLayoutItemPage.Orientation.Portrait) # insert new ...


4

Just set the form on "Hide form on add feature" in the Layer properties, see attached image


2

If you need modify the "Feature" Blending Mode on "Darken" use this: layer.setFeatureBlendMode(QPainter.CompositionMode_Darken)


0

Ahh - I found the problem. In interface_clean() I made mistake with the code. It should read def interface_clean(self): layers = [layer for layer in QgsProject.instance().mapLayers().values()] print(' Checking existing layers in interface for unwanted files') print('displayName is ',self.displayName) for layer in layers: if (layer....


3

I'm going to answer my own question because I just solved the issue myself. The issue is only with models, not scripts and is caused by this line in QGIS3 code. QgsProcessingAlgorithm::Flags QgsProcessingModelAlgorithm::flags() const { // TODO - check child algorithms, if they all support threading, then the model supports threading... return ...


4

Try controlling drawing order within symbology menu: Note this is just a workaround to get your visual result. It will not change the sort order of attributes. Only the order in which your features will be drawn.


0

I am not really an expert on qgis processing but it is seems that parameters have to be taken in different form: First of all you need to declare the input and ouput variables class CreateGrid(QgsProcessingAlgorithm): INPUT_DISTANCE = 'Input_Distance' INPUT_EXTENT = 'Input_Extent' OUPUT = 'Output' def initAlgorithm(self, config=None): self....


1

I think you are trying to split the polygon with the same polygon. You only use poly.geojson


2

If you look at the second box of your first picture (file encoding) you'll see that your encoding is set to UTF-32BE if you didn't set it that way on purpose (because you need to use this specific encoding) that's probably what is causing your problem, try to set it to UTF-8 or system and try again


2

If you want to reference an existing field in a parameter, you could use: QgsProperty.fromExpression('"fieldName"') So your code would look like: import processing layer = QgsVectorLayer(path_to_routes, 'Routes', "ogr") QgsProject.instance().addMapLayer(layer) processing.run('native:buffer', {"INPUT": layer, "DISTANCE":QgsProperty.fromExpression('"...


1

You are almost there :) GUI option Use the "Assistant" option: then: Select the field you want to use as a buffer distance Elick on the reload icon to see the data range Enter the same min-max values in the fields below Output from and to PyQGIS Expanding on Joseph's answer: from qgis.core import ( QgsVectorLayer, QgsProject, QgsProperty )...


3

You don't need to import/create a custom projection. QGIS understands EPSG:7775 You can set your project to use this CRS with File->Project Properties->CRS


0

No need to reinstall anything. As per: https://stackoverflow.com/questions/53544255/i-am-trying-to-run-the-r-reclass-on-qgis-and-keep-getting-an-indentation-error I just edited the /usr/bin/grass file


0

You can use the following to set up your label placement properties, see comments: layer = iface.activeLayer() layer_settings = QgsPalLayerSettings() layer_settings.fieldName = "Name" # Placement: Cartographic = 6; Around point = 0; Offset from point = 1 layer_settings.placement = 1 # Quadrant position: QuadrantAboveLeft = 0; QuadrantAbove = 1,... ...


1

Proposal for a more robust approach A more robust approach would probably entail: Using the building footprint shapefile, calculate median height of DSM inside each feature. This will represent the absolute height of each building. Using the building footprint shapefile, calculate median height of DTM inside each feature. This will be the absolute height ...


1

When the vertex editing tool is enabled, moving the mouse on a polygon feature should highlight its vertices. Then you can make a right click on the polygon of interest, and only the vertices of this polygon will be highlighted. If you move the mouse over another polygon, its features will not be highlighted. You can then right click again on another ...


2

Finally I arrived to a solution creating the field "concat" by concatenating in a single string: "res" || '_' || "id_malla" Then in the field calculator: count("res", "concat") Now there's only left to calculate the index by the formula: H' = sum( "Pi" / ln(2, "Pi") ) * -1 where Pi = "act_n_cd" / "act_tot_id" for each grid cell


3

The syntax for the count function is as follows: count(expression[,group_by][,filter]) As you can see, it accepts one group_by input. The methods you've tried all had three inputs. The third input will always be interpreted as a filter parameter, not as a second group_by parameter. Instead, you need to combine the two fields ("act_tot_id" and "...


1

Either of these should work. See notes below for further explanation. concat( "PlotL", to_string("PlotC") ) or "PlotL" || to_string("PlotC") Notes: to_string converts a number into a string Double quotation marks around field names are optional, but still a good idea, especially if: your field names have spaces your field name may be confused by the ...


2

You have a few issues in your SQL query. I suppose that your points and multipolygon tables have identical schema with 27 attributes. The reported error about not matching number of columns comes because SELECT * selects all the columns (27), including the origin geometry "geom", and ST_Centroid(geom) as geometry ads one, makes 28 in total. You can't use ...


0

You can use a similar method for the marker but by adding symbol.symbolLayer(0) to identify the initial simple marker layer: layer = iface.activeLayer() single_symbol_renderer = layer.renderer() symbol = single_symbol_renderer.symbol() symbol.symbolLayer(0).setStrokeColor(QColor(255,255,1)) symbol.symbolLayer(0).setStrokeWidth(0.9) layer.triggerRepaint() ...


1

I think I have found the solution to my qestion myself.In my example what I need to do is using Delete duplicates by attribute in my testA layer to generate a new layer with only two features(one is type_A,another is type_B).Next I set the coverage layer is the new layer with only two features and hidden it in the Atlas configuration .My qgis version is 3.6....


0

I found a solution which allows to parse the Tabs in a TabWidget and make a dictionnary of all the Radio buttons inside them: # make a dictionary for each tab and the list of radio buttons in each one self.dockwidget = Filtres_standards_PDSDockWidget() TabWidget = self.dockwidget.FilterTabs.children() StackedWidgets = [SWidget for SWidget in ...


2

Extracting cell values to vector points will allow us to further manipulate them through the Field Calculator. (1) Generate points (pixel centroids) inside polygons tool (Processing Toolbox > Vector creation) This tool takes a raster and a vector polygon layer, to generate a point (vector layer) at the center of each pixel. However, this tool does ...


2

Apparently, setting table config on QgsAttributeTableView has no effect on column visibility. I have to set the column config on QgsAttributeTableFilterModel. This works for me: def setHidenColumns(self, *args): self._config = self._layer.attributeTableConfig() columns = self._config.columns() for column in columns: if column.name in ...


0

I was following the directions in David's answer "to the T" and still having issues... then I realized I was trying to install from the master branch which is very far behind the latest release. So if anyone is having trouble with this, make sure you check the branches and download the latest version. After installing release 3.0 of the plugin it works ...


2

what you're describing is called ‘string interpolation’. In days of old, you could simply add strings together with the + operator, but this looks a bit ugly. As you're using Python 3.6, the easiest way is called “f-strings”, which is new to Python 3.6 I admit I’ve not tried this, but something like this should do the trick. Put an 'f' before the string, ...


1

The preset collections have been renamed and bundled into the QgsMapThemeCollection class so for QGIS 3, you could use something like the following which saves all visible layers of a theme to your desired output directory: suffix = "_Test_save" pathToFile = "C:/Users/david/Desktop/Batch Vector Save testing Python/" layer_list = QgsProject.instance()....


0

I believe this is very much related to how the pixel is constructed. Imagine that QGIS or ArcMAP, or any other software creates a virtual grid on top of the polygons with the extent of these. Then it takes the "centroids" to create the pixels. I did the same with small and medium polygons, of all sort of figures, and those polygons that are thin (like a ...


1

Solved by adding this: vlayer = QgsProject.instance().mapLayersByName("map_layer1")[0]


2

Separate field names with a colon, eg: column1;column2 https://issues.qgis.org/issues/20005


3

The signal you are searching is QgsMapLayer.styleChanged. And here a code below. I use partial to give as parameter the layer who has the rule checked/unchecked, this is for the case you connect multiple layers to the updateRules function. activeRules function create a dictionnary with label rules as keys and checkstate as values. updateRules function ...


5

If you look at the Split vector layer tool script, you will see that .gpkg is hard-coded inside the script. This means there is no way to change the output format of the file directly from the GUI of script tool. However, if you want the output to be shapefile not Geopakage, you need to change that inside the script. The script is called VectorSplit which ...


1

From following the answers at How do I change the font in the QGIS Script Editor? it seems this is a problem with my older version of QGIS 3.2.2 Bonn. It appears to have been fixed at https://issues.qgis.org/issues/20349 Another reason for me to get my organisation to update our QGIS version...


1

QGIS automatically uses the DE color scheme on both of my machines running Plasma/kwin when UI Theme is set to Default. This happens because Plasma is built on QT5. It looks like you're running i3 as your WM (I love that WM!), so you'll probably need to set your QT theme (specifically QT5) to match your DE theme. You can either configure that manually, or ...


2

Use the span tags in an html frame in the print layout. The regular text box only lets you define the style for the entire box, the html frame lets you control individual characters/words.


0

On the right side of your Print Layout Window you switch to the Tab "Element properties" of your legend item. The third point here (below "Legend Elements") should be "Fonts". Here you can configure the fonts used in your legend.


1

first of all as you are working on QGIS 3, the way you define the size is not wrong but now there's a class which allows to do this directly: objTransf = QgsSizeScaleTransformer( QgsSizeScaleTransformer.Flannery, 0, 150, 0, 150, 0, 0.57) you'll find more about this class here: ...


0

It would be useful to know which type of data are you working with. In my case i'm working with shapefiles and when I want to sync the data that I have edited with QField app I just copy the shapefile from the tablet to the PC and overwrite that same file in the QGis PC project. Probably that Sync button does something else with some other type of data or ...


-2

you can use tips tool in qgis and write with html code for insert any file and even open file out of qgis


0

One solution is to make a virtual layer that that summarises the layer, and, then add an attribute table to the print atlas. For example, if the following query is used to create a virtual layer: SELECT atlas_polygon.name, points.class, SUM(points.number) AS number, COUNT(points.class) AS location, atlas_polygon.geometry FROM points INNER JOIN ...


4

For such cases, it is much easier to debug in a browser. You can create a web map with your tile layer and view it in a browser such as Chrome. When you open Developer Tools, you can see the failed requests in the Network tab. I have created a simple leaflet based template using JSFiddle. You can open https://jsfiddle.net/spatialthoughts/6mz4obtw/1/ and ...


1

I found that the problem was with the map size 900x600 (I don't know why?) , so I solved it by initializing the map with lower size (half size in the example) theMap.setRect(QRectF(lm,tm, 450, 300)) Then I resized it the disired dimension using attemptSetSceneRect method: theMap.attemptSetSceneRect(QRectF(lm,tm, w, h))


1

I put my comment as an answer iface.mapCanvas().mapSettings().destinationCrs() QgsMapRenderer has been replaced by QgsMapRendererJob with subclasses and QgsMapSettings.


Top 50 recent answers are included