Skip to main content

Questions tagged [qgsmapcanvas]

class for displaying all GIS data types on a canvas

Filter by
Sorted by
Tagged with
2 votes
1 answer
32 views

Unticking all layers in main canvas with PyQGIS [duplicate]

For a plugin, I simply want to untick all the layers in the layer tree. Was thinking of something like : canvas_layers = QgsProject.instance().mapLayers().values() for layer in canvas_layers: ...
user2730842's user avatar
0 votes
1 answer
59 views

Canvas not responding in QGIS

In QGIS 3.36.1 I have a weird situation as my QGIS canvas is irresponsive to layer on/off and preset theme visualization. It used to work well, but now it is unusable, even after restart. Cache? What ...
Federico Marcantognini's user avatar
1 vote
0 answers
68 views

Map canvas stops working after layers are added via PyQGIS [closed]

I have created a script for automated map production using PyQGIS. One problem I encounter is that the map canvas freezes after I add layers using the following code under QGIS 3.34.6 LTR: for ...
RavenS's user avatar
  • 31
4 votes
2 answers
114 views

Checking if layer has features in map canvas in QGIS Modeler

I have multiple WFS that show the same features (streets) in different regions. I would like to write a model that extracts the features from the current map extent. How do I let the model know, which ...
e-shirt's user avatar
  • 707
2 votes
1 answer
59 views

Setting extent for screenshot via PyQGIS

I am trying to figure out how I can set the extent of the rendered image because with QgsMapSettings().setExtent it doesn't work for me. How can I set the extent as big as the biggest active vector ...
Ckoe22's user avatar
  • 21
0 votes
0 answers
21 views

How to modify URL of an existing QgsVectorTileLayer and retrieve visible tiles in PyQGIS

I am developing a plugin in PyQGIS that involves creating a QgsVectorTileLayer using a URL in XYZ format, which points to a local vector tiles server (in this case, a PG_tile_serv). Creating the ...
SatoshiGG's user avatar
1 vote
0 answers
30 views

How can I set up a keyboard shortcut for canvas rotation in QGIS? [duplicate]

I know that I can set canvas rotation in the bottom right corner of QGIS: and I am aware that I can set some keyboard shortcuts via Settings -> Keyboard Shortcuts...: However, I can't find a way ...
zabop's user avatar
  • 2,650
1 vote
1 answer
113 views

How to create a map tool with QgsMapToolEmitPoint that has snapping functionality?

I'm developing a plugin for creating points and lines, but I noticed that when using QgsMapToolEmitPoint the cursor doesn't have snapping functionality canvas = iface.mapCanvas() addPoint = ...
Aloísio Ângelo's user avatar
7 votes
1 answer
182 views

Hiding/showing layers in legend does not work in QGIS standalone

I'm building a standalone app with PyQGIS. I encountered some difficulties building a canvas that show the result layers after some operations. The canvas works, but the associated legend does not ...
Julien Goletto's user avatar
0 votes
0 answers
55 views

Several initialisation of QGIS triggering an error

I have some troubles about a script using PyQGIS. So, I have a main.py with : import qgis from qgis.core import QgsApplication qgs = QgsApplication([], False) qgs.setPrefixPath("C:/xx", True)...
Tena's user avatar
  • 1
2 votes
2 answers
306 views

Getting the bounding box of labels with QgsLabelingEngine in PyQGIS

I am trying to get the bounding box of my labels in a vector layer in PyQGIS (Version: 3.30.2-'s-Hertogenbosch) with the following script but I need to create a vector layer from a WKT file and not a ...
bdelliott's user avatar
  • 455
5 votes
1 answer
299 views

"Painter not active" error when using QPainter with QgsMapCanvasItem in PyQGIS

I'm trying to plot (superimposed) a rectangle plus some text on the QGIS map canvas, which already has several layers. A similar situation but for a circle is feasible by subclassing QgsMapCanvasItem: ...
afernandezody's user avatar
4 votes
1 answer
147 views

Override the zoom behaviour of QgsMapToolExtent

Context The default behaviour of the QgsMapToolExtent is to draw an extent (using QgsRubberBand) on the map canvas while the left mouse button is held and emit that extent when it is released. Holding ...
Matt's user avatar
  • 17.7k
1 vote
1 answer
175 views

TypeError when adding QgsGeometry object to canvas using PyQGIS

How do we add a QgsGeometry in memory object using QgsProject.addMapLayer() or other PyQGIS code? ERROR TypeError: QgsProject.addMapLayer(): argument 1 has unexpected type 'QgsGeometry' buffer <...
GeorgeC's user avatar
  • 8,258
5 votes
1 answer
2k views

How to mask everything but a polygon in QGIS?

I am able to draw polygons over areas of interest in QGIS. For example via: Layer -> Create Layer -> New Temporary Scratch Layer, name the layer, select Polygon as Geometry type, OK, select the ...
zabop's user avatar
  • 2,650
6 votes
3 answers
831 views

Best practices to show extent of Print Composer maps in main canvas in QGIS

I want to display the extents of print composer maps in the main canvas as polygons ("map footprints"). Currently I am using the geometry generator with the expression make_rectangle_3points ...
sidapo_cartisan's user avatar
1 vote
1 answer
58 views

Unwanted canvas title in QGIS

The main map canvas shows a plain text title or label at the top left. It behaves like a decoration from View > Decorations but it is not accessible from there. The text is relevant to the project, ...
3DGordon's user avatar
3 votes
1 answer
621 views

Using QgsMapCanvas on a QGIS Processing script

I am writing an QGIS Python processing script, the result of this script is a formatted PDF. In one of the steps, I need to set map canvas extent to my shapefile extent, but it is not working. What is ...
ConsalterR-1988's user avatar
1 vote
1 answer
169 views

Rotate mapCanvas with PyQGIS

I'm trying to implement within some code on PyQGIS, a way to rotate the view of my mapCanvas I want it to work the same way as the GUI present on the bottom right corner However when I run the ...
João's user avatar
  • 33
2 votes
3 answers
1k views

Adding and filtering layer with map canvas extent using PyQGIS

I'm creating a small QGIS3.16 plugin with PyQGIS. I'd want to add a vector (PostGIS) layer to QGIS, and immediately filter it with the QGIS canvas extent. I found the QgsFeatureRequest(rectangle:...
V Damoy's user avatar
  • 389
2 votes
0 answers
141 views

Getting same results from QGIS main canvas and the print layout

I am struggling to get the same results from the main canvas to a new print layout. I have seen a few answers but nothing very specific in the GIS Stack Exchange. I have searched other forums and ...
Frank Jimenez's user avatar
1 vote
1 answer
646 views

Change resolution when exporting map canvas as image with python

I want to create a georeference png of the map canvas in QGIS using Python with: mapCanvas().saveAsImage('filename.png') I want to be able to change the resolution from the default of 96 dpi. Is ...
JUNGLE's user avatar
  • 530
8 votes
2 answers
403 views

Highlighting snapping position in PyQGIS

I'm trying to add points on a line with QgsMapTool. I need to show snap indicator (vertex or edge) while moving the mouse on a line. How can I do that? Here is my code: class uubEditTool(...
Velugoti Venkateswarlu's user avatar
1 vote
1 answer
531 views

Layer disappears after changing CRS in QGIS 3.22

I imported a polygon in QGIS which has the CRS 3035 ETRS 89 extended LAEA. Since it is very heavy, I uploaded a shapefile from another source to clip it. My issue is that the second imported layer has ...
Robagb's user avatar
  • 447
2 votes
1 answer
517 views

After creating layer by means of PyQGIS it does not show up on the map

I made a script in PyQGIS to create a layer but the layer does not show up on the map. Can someone help me? from qgis.PyQt.QtCore import QVariant vl = QgsVectorLayer("Point", "...
Sander's user avatar
  • 31
6 votes
1 answer
199 views

Calculating distance between two points using QGIS C++ APIs

I have been trying to find the distance between two points using QGIS C++ APIs in Qt. I used the following code : QgsDistanceArea d; d.setEllipsoid("WGS84"); qDebug()<< "...
Puneet Kumar's user avatar
1 vote
1 answer
466 views

Running standalone script into plugin with Button Click

Below code can be use to get the X,Y Coordinate of clicked location . class PrintSnappedPoint(QgsMapToolEmitPoint): def __init__(self, canvas): self.canvas = canvas ...
Devenepali's user avatar
5 votes
1 answer
263 views

Making a QgsRasterLayer only render what's available in its cache

I have a QgsRasterLayer: raster_layer = QgsRasterLayer(...) The user moved the map around a bit and the layer is currently visible. How can I make QGIS (temporarily) not request new data of this ...
bugmenot123's user avatar
  • 11.1k
0 votes
2 answers
512 views

Canvas refresh not Working in QGIS

The canvas is not showing the changes after 1 second. The point is visible only after the whole script gets executed. Here is the Script: import time def refresh(): cachingEnabled = iface....
Abhinivesh's user avatar
1 vote
1 answer
495 views

Setting iface mapCanvas extent

How to set map canvas extent / view? I've tried with setExtent(Qrect(..)) but does not work. mc = iface.mapCanvas() rect = QgsRectangle() rect.setXMaximum = 5 rect.setXMinimum = 2 rect.setYMaximum = ...
user188858's user avatar
2 votes
1 answer
455 views

Printing message with map canvas coordinates after user click in QGIS Plugin

I need to print a message after the user pushes the button "Prueba". The message must contain coordinates "x", "y" from the user's click in the map canvas. I don't know ...
David Duarte's user avatar
1 vote
1 answer
119 views

Unable to show the polygon I've drawn in PyQGIS

I'm using for my first time QgsMapCanvas() and when I write my script and I then run it, I don't see anything in the canvas. That's my script: canva = QgsMapCanvas() r = QgsRubberBand(canva,True) ...
brahima keita's user avatar
2 votes
0 answers
101 views

Rendering layers of multiple CRS systems(EPSG: 4326 and EPSG:3857)

I m trying to render layers of multiple CRS systems on QgsmapCanvas using QGIS3 C++ APIs. When I render multiple layers of only one CRS( like EPSG:4326 ) at a time, everything works fine. But when I ...
Puneet Kumar's user avatar
3 votes
2 answers
570 views

QgsMapCanvas set layers not showing any layers

I am trying to show selected features of a layer on QDialog within a plugin. I created the QgsMapCanvas widget and add into QDialog, later set the layers but it does not show any feature. self....
Velugoti Venkateswarlu's user avatar
1 vote
0 answers
142 views

Setting layer visibilty in custom QGIS 3.x application (C++ versus Python)

In my QGIS application, I would like to be able to have a QDialog window pop upon clicking a toolbar icon which lists the layers set to the map canvas, and have QCheckBoxes that allow the user to show/...
skew_t_pie's user avatar
1 vote
0 answers
131 views

Hide layers with custom widget in QGIS 3.10 (C++)

I have written a custom application that loads multiple QgsMapLayers onto a basemap (OpenStreetMap raster tiles). I am attempting to include a menu option that allows the user to hide or show one or ...
skew_t_pie's user avatar
2 votes
1 answer
774 views

Adding a raster layer on map canvas in PyQGIS

canvas = QgsMapCanvas() canvas.show() canvas.setCanvasColor(Qt.white) canvas.enableAntiAliasing(True) vlayer = QgsVectorLayer('testdata/airports.shp', "Airports layer", "ogr") ...
Velugoti Venkateswarlu's user avatar
1 vote
0 answers
92 views

Putting SVG images at a particular coordinate in QGIS C++ API

I am using QGIS C++/Python API for making a custom QGIS application. I am trying to import an SVG image at a particular coordinate(QgsPointXY) in qgsmapcanvas. Which classes should be used? I am very ...
Puneet Kumar's user avatar
1 vote
1 answer
188 views

QgsMapCanvas window flashes on then disappears

I am trying to make a standalone app, to be able to select and download some spatial data that I keep around. I've read around and found I can do that with Qgis and Qt, so I grabbed some example code ...
peroman200's user avatar
1 vote
0 answers
76 views

Zoomscale method in QGIS C++ API

I am working on a custom QGIS application using QGIS C++ APIs. I am able to render .mbtiles file of world blue marble as a raster file on Qgsmapcanvas. but when I call zoomscale API on canvas with ...
Puneet Kumar's user avatar
1 vote
1 answer
492 views

Refreshing QgsMapCanvas after removing selected layer using PyQGIS

I am working on a PyQGIS (QGIS 3.10) application to overlay data on OpenStreetMap raster tiles. I am adding a function that removes the most recently added layer from the project and refreshes the ...
skew_t_pie's user avatar
2 votes
1 answer
797 views

Add scale bar to canvas using PyQGIS

Is it possible to get the decorator scale bar onto the map canvas inside a standalone PyQGIS application? It is possible to get a scale bar on the QGIS Desktop version by View -> Decorations -> ...
Sean Ang's user avatar
  • 143
0 votes
0 answers
716 views

Unable to delete .shp and .dbf files from directory when on canvas PyQGIS

I am creating a standalone PyQGIS application and is met with a problem. When a shapefile is shown on my canvas, I am unable to delete the corresponding .shp and .dbf files in my directory. This is ...
Sean Ang's user avatar
  • 143
2 votes
1 answer
254 views

QGIS map canvas: how to hide point of origin?

In the QGIS map canvas (main window), the point of origin of the coordinates is always shown as a small, blue square. How to change the style of and hide this square? I looked for the option in the ...
Babel's user avatar
  • 73.8k
2 votes
1 answer
146 views

Saving each feature in PNG format along with map canvas in certain scale using PyQGIS

I want to export each feature by zooming to certain scale (eg 1:25000 where feature will be inside map canvas) and save into PNG format. I know function iface.mapCanvas().saveAsImage("image_path&...
Devenepali's user avatar
6 votes
1 answer
1k views

Opening embedded canvas in new window with all layers

I am creating a standalone custom PyQGIS application and have some questions regarding canvas. I have read the cookbook: https://docs.qgis.org/testing/en/docs/pyqgis_developer_cookbook/canvas.html ...
Sean Ang's user avatar
  • 143
4 votes
1 answer
389 views

Ignoring features outside the Area of interest in QGIS

I have layers (shapefile and GDB) in my map that have more than 100,000 features. I am not editing them but just using them as a reference. I work only in a particular small area at one time. But my ...
ar-siddiqui's user avatar
  • 1,820
3 votes
1 answer
687 views

Saving map as image using MapCanvas in PyQGIS

I have created a standalone application to display the vector layer using PyQGIS code given below. Now I want to download the map which shows on the window with whatever the zoom level I have chosen. ...
Codee's user avatar
  • 33
1 vote
1 answer
209 views

Reduce image collection to get daily sum from hourly precipitation GSMaP 12:00h pm to 11:00h am

I am trying to adapt a script made available by colleagues from the GEE of the GSMaP image collection. The script obtains data (as a table) of the points of each image available in a given period and ...
Felipe Cardoso's user avatar
6 votes
1 answer
77 views

Using canvas events

I'm trying to get the current coordinates from the canvasClicked-event. Browsing through various posts and documentation, I came up with the following code, but handleCanvasClick never gets hit. What ...
user160032's user avatar