Created
July 27, 2022 11:17
-
-
Save CEZERT/9a3729cbfe2546b9d9877118f8b348c3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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