Skip to content

Commit

Permalink
Update standalone scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonSAMPERE committed Mar 15, 2024
1 parent 7d4ba7f commit cb40e64
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
27 changes: 27 additions & 0 deletions tests/dev/qgis_console/add_polygone_from_geojson_geometry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from qgis.core import Qgis, QgsGeometry, QgsPointXY, QgsFeature, QgsCoordinateReferenceSystem, QgsCoordinateTransform, QgsProject, QgsRenderContext, QgsVectorLayer
from qgis.utils import iface
from qgis.PyQt.QtGui import QColor

geojson_geometry = {"type":"Polygon","coordinates":[[[-179.1435034,51.2750512],[-178.3043662,28.3879122],[-178.3027184,28.3864647],[-173.9599503,26.0553246],[-155.6747556,18.9061171],[109.5612085,18.1693383],[109.5680445,18.1693383],[109.6157333,18.1761742],[109.7011825,18.2040876],[109.7087508,18.2072208],[179.4723413,51.3705508],[179.7750757,51.9554711],[179.7809351,51.9670271],[179.6642359,52.0285098],[179.6369735,52.0353458],[173.1272079,52.9949405],[172.7810979,53.0155297],[-156.4715063,71.4125023],[-159.5196427,70.8357608],[-159.5487768,70.830227],[-161.8881323,70.3539493],[-161.9430639,70.3395857],[-162.3085424,70.2412784],[-166.2226049,68.8858096],[-166.2367651,68.8748233],[-166.8290503,68.3513858],[-171.7393286,63.7912051],[-178.8588761,51.7957217],[-179.1435034,51.2750512]]]}

coords = geojson_geometry.get("coordinates")[0]
li_points = [QgsPointXY(round(i[0], 6), round(i[1], 6))for i in coords]

point_layer = QgsVectorLayer("Point?crs=epsg:4326", "envelope_points", "memory")
for point in li_points:
point_feature = QgsFeature()
point_feature.setGeometry(QgsGeometry.fromPointXY(point))
point_layer.dataProvider().addFeatures([point_feature])

polygon_layer = QgsVectorLayer("Polygon?crs=epsg:4326", "envelope_polygon", "memory")
polygon_feature = QgsFeature()
polygon_feature.setGeometry(QgsGeometry.fromPolygonXY([li_points]))
polygon_layer.dataProvider().addFeatures([polygon_feature])

canvas = iface.mapCanvas()
qgs_prj = QgsProject.instance()

qgs_prj.addMapLayer(polygon_layer)
qgs_prj.addMapLayer(point_layer)

canvas.refresh()
4 changes: 2 additions & 2 deletions tests/dev/qgis_console/remove_layer_except_background.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
qgs_prj = QgsProject.instance()

for layer in qgs_prj.mapLayers().values():
# if not isinstance(layer, QgsRasterLayer):
if layer.name().startswith("BoundingBox"):
if not isinstance(layer, QgsRasterLayer):
# if layer.name().startswith("BoundingBox"):
qgs_prj.removeMapLayer(layer)

iface.mapCanvas().refresh()

0 comments on commit cb40e64

Please sign in to comment.