6

The input parameters can be accessed as a dictionary object, so parameters['SPECIES_POINTS'] will give you the path to the input layer. The call to the algorithm would then be: pointsReprojected = processing.run("native:reprojectlayer", { 'INPUT': parameters['SPECIES_POINTS'], 'TARGET_CRS': CRS, 'OUTPUT' : ...


5

Well, the error message is correct. According to the QGIS API documentation, QgsMapRendererJob is an abstract class. So you cannot directly use it. Instead you need to use one of the subclasses: QgsMapRendererSequentialJob - renders map in one background thread to an image QgsMapRendererParallelJob - renders map in multiple background threads to an ...


5

In QGIS 3.4 (Ubuntu), I've created a polygon layer (WGS 84, EPSG: 4326) with a unique "value" field, type decimal (4, 1). Here the layer datas : wkt_geom value Polygon ((0.5 0.6, 0.2 0.4, 0.5 0.2, 0.8 0.4, 0.5 0.6)) 174 Polygon ((0 1, 1 0.8, 1 0, 0 0.2, 0 1),(0.5 0.6, 0.2 0.4, 0.5 0.2, 0.8 0.4, 0.5 0.6)) 92.3 Or just create a diamond shape polygon ...


5

There is a fairly rigid structure for creating a processing script for the QGIS processing tool box, the basis of which is sub-classing and creating an instance of the QgsProcessingAlgorithm class. In addition to the QGIS3 processing script template by @underdark, there is an excellent tutorial by @spatialthoughts, "Writing Python Scripts for Processing ...


5

There are several issues filed on the QGIS Issue Tracking list concerning this problem (this one being the one referencing the possible fix). Until the patch has been released through the official software update repositories you seem to be able to solve the problem manually (according to the proposed fix): locate file dlg_sql_window.py (in <QGIS>/...


5

Here is the code which is working for me: urlWithParams = 'type=xyz&url=https://a.tile.openstreetmap.org/%7Bz%7D/%7Bx%7D/%7By%7D.png&zmax=19&zmin=0&crs=EPSG3857' rlayer = QgsRasterLayer(urlWithParams, 'OpenStreetMap', 'wms') if rlayer.isValid(): QgsProject.instance().addMapLayer(rlayer) else: print('invalid ...


4

try: from qgis.core import QgsApplication QgsApplication.qgisSettingsDirPath() for show profiles folder https://qgis.org/api/classQgsApplication.html#a89ad50b0d0fd60ccae803f22f6c5cf46


4

Assuming you only want to keep the first part of the value (i.e. before the first space), you could try using the following: layer = iface.activeLayer() with edit(layer): for feature in layer.getFeatures(): new_value = feature['fieldName'].split(' ', 1)[0] feature.setAttribute(feature.fieldNameIndex('fieldName'), new_value) layer....


4

As you say, the bit before the colon is the provider name, in this case 'native' (can see the code for this here). From what I can tell, the processing algorithms named native have been ported to C++ (they were written in Python in previous versions). This has the obvious advantage of speed and is why some algorithms are considerably faster in 3.x There ...


4

According to the pyqgis api documentation there is a method layer.selectByIds([s.id() for s in selection]) And for some performance improvements and good practice, don't request any attributes or geometry, if you only need the feature id request = QgsFeatureRequest(QgsExpression('"CODE_MERC" is NULL')).setFlags(QgsFeatureRequest.NoGeometry)....


4

Welcome to GIS.SE! As you thought, there is a way to know if a field exists in a layer not by iterating features but by looking at the layer structure. In the QGIS Layers Panel, select a layer. Then in the Python Console inside QGIS, run the following code: field_name = "my_field" layer = iface.activeLayer() # Gives you the layer you have selected in the ...


4

The easiest approach is to run the algorithm through the GUI, and then look in the Processing "history". You'll see the equivalent Python command shown there for the operation you just performed via the gui.


4

After some reasearching I found that the key problem seems to be that you first defined sink (sink, dest_id) = self.parameterAsSink( ... and later on overwrite it with the result of processing.run... sink=processing.run("native:buffer", { ... I tried the following which worked for me: #create a temporary layer as a processing result lyr = processing.run(...


4

Don't use print in QGIS3 processing algorithms. Explanation from QGIS processing guide draft: Give feedback via the feedback object, not directly to QgsMessageLog (and avoid print statements - these are dangerous to use for algorithms which may be executed in a background thread!). Replace print with: feedback.pushInfo("finished ...")


4

Probably, your problem is in this command: pyrcc5 -o resources_rc.py resources.qrc QGIS documentation has some issues due lack of adequate actualization. I did same plugin and right command is: pyrcc5 -o resources.py resources.qrc Additional details can be observed here: Compiling resources in QGIS 2.99 (Windows) for creating plugin? where same plugin ...


4

You could get a HUGE speed boost by iterating through the features in the first layer and building a QgsSpatialIndex on them. Then query the index when iterating through the second layer to determine what features possibly overlap. Secondly, you can get another huge speed boost by preparing the geometry from the features from your outer loop. Since these ...


4

The correct approach looks somewhat like this: # create the map item map = QgsLayoutItemMap(layout) # setup its initial position on the page map.attemptSetSceneRect(QRectF(20, 20, 200, 100)) # setup an initial extent to view in the map rectangle = QgsRectangle(-13838977, 2369660, -8672298, 6250909) map.setExtent(rectangle) ...


4

The order of when you set the extent, add the map to the layout, and resize the rectangle is important. Steps to add a map to a new layout in QGIS 3. Instantiate the map object with QgsLayoutItemMap(layout) Set a base Rectangle Set the extent Add the map to the layout object, layout.addLayoutItem(map) Now you can Move & Resize the rectangle as ...


4

The method setLegendFilterByMapEnabled will filter legend items to those layers which are spatially located i.e. have features which are within the area shown in your layout map, it won't filter out layers which are not checked in your table of contents panel. Correction: setLegendFilterByMapEnabled(True) filters the legend items to show just the ones ...


4

You can do that by using 'block' method from QgsRasterDataProvider for accessing the individual pixel values in a raster object. Below code adds necessary lines to your code for producing each desired counts. layer = iface.activeLayer() print("Active Layer: ", layer.name()) provider = layer.dataProvider() extent = layer.extent() stats = provider....


4

You attempt to set a name to a deleted object. You need to create a new object : [...] for layout in layouts_list: if layout.name() == layoutName: manager.removeLayout(layout) layout = QgsPrintLayout(project) layout.setName(layoutName) [...]


4

Have a look at the API Documentation which mentions the following signature for this method: writeAsVectorFormat(layer: QgsVectorLayer, fileName: str, fileEncoding: str, destCRS: QgsCoordinateReferenceSystem = QgsCoordinateReferenceSystem(), driverName: str = '', onlySelected: bool = False, datasourceOptions: Iterable[str] = [], layerOptions: Iterable[str]...


4

To add an existing single layer: vlayer = QgsVectorLayer("some/path/to/shapefile.shp", "admin", "ogr") QgsProject.instance().addMapLayer(vlayer) To add existing multiple layers: vlayer1 = QgsVectorLayer("some/path/to/shapefile1.shp", "admin1", "ogr") vlayer2 = QgsVectorLayer("some/path/to/shapefile2.shp", "admin2", "ogr") layers = [vlayer1 , vlayer2] ...


4

You can try code below (backup data prior): layer = iface.activeLayer() textfields = [f.name() for f in layer.fields() if f.typeName()=='String'] replacedict = {'Hus,':'HusXYZ,','1':'ONE'} with edit(layer): for feature in layer.getFeatures(): for f in textfields: value = feature[f] if type(value)== str: ...


4

I tried to understand the behavior of the setFlags method by see on a vector layer the results of : vl = iface.activeLayer() flags = 1 vl.setFlags(QgsMapLayer.LayerFlag(flags)) # result : the layer is identifiable and required I looked at the Python API doc for QgsMapLayer, in these attributes and : Identifiable = 1 (= 2 power 0) Removable = 2 (= 2 power ...


4

Great idea you need place startup.py in C:\Users\<username>\AppData\Roaming\QGIS\QGIS3 and add missing import ,and voilá from qgis.utils import iface from PyQt5.QtWidgets import QAction import webbrowser def open_gis_se(): webbrowser.open('https://gis.stackexchange.com') iface.helpMenu().addSeparator() gis_se_action = QAction('Go to gis....


4

You can use Processing Tool: Import geotagged photos or Plugin: ImportPhotos


4

If you look at step 23 in the tutorial you'll see some lines in the run method: if self.first_start == True: self.first_start == False self.dlg = SaveAttributeDialog() You need to find those lines and make sure they are called before you try to use the dialog anywhere. Also check that the name matches the name of your dialog (probably something ...


3

HTML layout items are "multi frame" items, which means that their content is split over multiple QgsLayoutFrame items. After creating your QgsLayoutItemHtml, you need to then create frames to display the content. E.g.: blockStats = QgsLayoutItemHtml.create(comp) # create a frame for showing content from blockStats frame1 = QgsLayoutFrame(comp, blockStats) ...


3

In QGIS you can't use an application object, because qgis itself is a QtApplication. Try to execute lines 6-10 alone and you'll see a widget on the screen. To have a full functional dialog, you'll need to a have something like a qgis-plugin. To work with pyqt only, try an standalone python shell or an ide. For plugin creation, you use the qgis plugin "...


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