2

I have the coordinates of a geographical point in WGS84 and I want to show it on the map on a separate layer (so that it does not belong to the map layer).

Then I would like to give it a dot symbol of my choice.

How do I achieve this in QGIS with Python?

Taras
35.8k5 gold badges77 silver badges152 bronze badges
asked May 4, 2020 at 12:26
0

2 Answers 2

8

You can use the QgsVertexMarker and QgsRubberBand classes to show points on the map canvas as temporary markers which are not part of a layer. Here are are a couple of short examples to get you started.

Vertex Marker:

canvas = iface.mapCanvas()
lon = 131.2
lat = -12.5
pnt = QgsPointXY(lon, lat)
m = QgsVertexMarker(canvas)
m.setCenter(pnt)
m.setColor(QColor('Black'))
m.setIconType(QgsVertexMarker.ICON_CIRCLE)
m.setIconSize(12)
m.setPenWidth(1)
m.setFillColor(QColor(0, 200, 0))
#run line below to remove:
#canvas.scene().removeItem(m)

Rubber Band:

canvas = iface.mapCanvas()
lon = 131.2
lat = -12.5
pnt = QgsPointXY(lon, lat)
geom = QgsGeometry().fromPointXY(pnt)
rb = QgsRubberBand(canvas, QgsWkbTypes.PointGeometry)
rb.setColor(QColor('Blue'))
rb.setIcon(QgsRubberBand.ICON_CIRCLE)
rb.setIconSize(10)
rb.setToGeometry(geom)
rb.show()
#run line below to remove:
#rb.reset()

See the following links:

I haven't tested it, but since QGIS 3.10 you should be able to use an SVG icon with a rubber band:

Taras
35.8k5 gold badges77 silver badges152 bronze badges
answered May 5, 2020 at 1:01
1
5

The following script adds a memorylayer with one point at lat/lon 20/20:

layer = QgsVectorLayer('Point?crs=epsg:4326', 'MyPoint' ,'memory')
pr = layer.dataProvider()
pt = QgsFeature()
point1 = QgsPointXY(20,20)
pt.setGeometry(QgsGeometry.fromPointXY(point1))
pr.addFeatures([pt])
layer.updateExtents()
QgsProject.instance().addMapLayer(layer)

you can set the symbol then with the normal QGIS stuff (F7->layer styling)

Taras
35.8k5 gold badges77 silver badges152 bronze badges
answered May 4, 2020 at 12:35
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.