Skip to content

Instantly share code, notes, and snippets.

@CEZERT
Created July 27, 2022 11:17
Show Gist options
  • Save CEZERT/9a3729cbfe2546b9d9877118f8b348c3 to your computer and use it in GitHub Desktop.
Save CEZERT/9a3729cbfe2546b9d9877118f8b348c3 to your computer and use it in GitHub Desktop.
from qgis.core import *
from qgis.gui import *
from qgis.utils import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
app = QgsApplication([], True)
app.setPrefixPath("C:/Program Files/QGIS Brighton/apps/qgis", True)
app.initQgis()
canvas = QgsMapCanvas()
canvas.setWindowTitle("PyQGIS Standalone Application Example")
canvas.setCanvasColor(Qt.white)
layer = QgsVectorLayer('LineString?crs=epsg:4326', 'MyLine' , "memory")
pr = layer.dataProvider()
linstr = QgsFeature()
geom = QgsGeometry.fromWkt("LINESTRING (1 1, 10 15, 40 35)")
linstr.setGeometry(geom)
pr.addFeatures([linstr])
layer.updateExtents()
QgsProject.instance().addMapLayer(layer)
canvas.setExtent(layer.extent())
canvas.setLayers([layer])
canvas.zoomToFullExtent()
canvas.freeze(True)
canvas.show()
canvas.refresh()
canvas.freeze(False)
canvas.repaint()
exitcode = app.exec()
QgsApplication.exitQgis()
sys.exit(exitcode)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment