Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
J
jr
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jiří Kalvoda
jr
Commits
1e39503e
Commit
1e39503e
authored
Jun 30, 2024
by
Jiří Kalvoda
Browse files
Options
Downloads
Patches
Plain Diff
working on qgis UI
parent
cc9c0570
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
prog/main.py
+31
-43
31 additions, 43 deletions
prog/main.py
with
31 additions
and
43 deletions
prog/main.py
+
31
−
43
View file @
1e39503e
...
@@ -2,12 +2,12 @@
...
@@ -2,12 +2,12 @@
from
qgis.core
import
*
from
qgis.core
import
*
from
qgis.gui
import
*
from
qgis.gui
import
*
from
PyQt
5
.Qt
Widgets
import
*
from
qgis.
PyQt.Qt
Xml
import
QDomDocument
,
QDomElement
from
PyQt5
import
*
from
qgis.PyQt.QtWidgets
import
*
from
PyQt
5
.Qt
Xml
import
QDomDocument
,
QDomElement
from
qgis.
PyQt.Qt
Core
import
*
import
asyncio
from
qasync
import
QEventLoop
,
asyncClose
,
asyncSlot
,
QApplication
from
qasync
import
QEventLoop
,
asyncClose
,
asyncSlot
,
QApplication
import
asyncio
import
communication
import
communication
from
communication
import
dt_to_path
from
communication
import
dt_to_path
...
@@ -16,38 +16,31 @@ import json
...
@@ -16,38 +16,31 @@ import json
import
sys
,
os
import
sys
,
os
# Supply the path to the qgis install location
QgsApplication
.
setPrefixPath
(
"
/usr/
"
,
True
)
QgsApplication
.
setPrefixPath
(
"
/usr/
"
,
True
)
# Create a reference to the QgsApplication.
# Setting the second argument to True enables the GUI. We need
# this since this is a custom application.
qgs
=
QgsApplication
([],
True
)
qgs
=
QgsApplication
([],
True
)
# load providers
qgs
.
initQgis
()
qgs
.
initQgis
()
my_crs
=
QgsCoordinateReferenceSystem
(
4326
)
QgsProject
.
instance
().
setCrs
(
my_crs
)
# Write your code here to load some layers, use processing
# algorithms, etc.
from
qgis.core
import
QgsSettings
from
qgis.gui
import
*
crs_wgs
=
QgsCoordinateReferenceSystem
(
4326
)
from
qgis.PyQt.QtWidgets
import
QAction
,
QMainWindow
crs_wgs_mercator
=
QgsCoordinateReferenceSystem
(
3857
)
from
qgis.PyQt.QtCore
import
Qt
crs_transform
=
QgsCoordinateTransform
(
crs_wgs
,
crs_wgs_mercator
,
QgsProject
.
instance
())
class
M
yW
nd
(
QMainWindow
):
class
M
ainWi
nd
(
QMainWindow
):
def
__init__
(
self
):
def
__init__
(
self
):
self
.
map
=
MapWidget
()
QMainWindow
.
__init__
(
self
)
QMainWindow
.
__init__
(
self
)
self
.
setCentralWidget
(
self
.
map
)
class
MapWidget
(
QWidget
):
def
__init__
(
self
):
QWidget
.
__init__
(
self
)
self
.
canvas
=
QgsMapCanvas
()
self
.
canvas
=
QgsMapCanvas
()
self
.
canvas
.
setCanvasColor
(
Qt
.
white
)
self
.
canvas
.
setCanvasColor
(
Qt
.
white
)
self
.
canvas
.
enableAntiAliasing
(
True
)
self
.
canvas
.
enableAntiAliasing
(
True
)
self
.
setCentralWidget
(
self
.
canvas
)
self
.
_layout
=
QVBoxLayout
(
self
)
self
.
setLayout
(
self
.
_layout
)
self
.
_layout
.
addWidget
(
self
.
canvas
)
self
.
actionZoomIn
=
QAction
(
"
Zoom in
"
,
self
)
self
.
actionZoomIn
=
QAction
(
"
Zoom in
"
,
self
)
self
.
actionZoomOut
=
QAction
(
"
Zoom out
"
,
self
)
self
.
actionZoomOut
=
QAction
(
"
Zoom out
"
,
self
)
...
@@ -62,10 +55,10 @@ class MyWnd(QMainWindow):
...
@@ -62,10 +55,10 @@ class MyWnd(QMainWindow):
#self.canvas.xyCoordinates.connect(self.xyCoordinates)
#self.canvas.xyCoordinates.connect(self.xyCoordinates)
self
.
actionPan
.
triggered
.
connect
(
self
.
pan
)
self
.
actionPan
.
triggered
.
connect
(
self
.
pan
)
self
.
toolbar
=
self
.
addToolBar
(
"
Canvas actions
"
)
#
self.toolbar = self.addToolBar("Canvas actions")
self
.
toolbar
.
addAction
(
self
.
actionZoomIn
)
#
self.toolbar.addAction(self.actionZoomIn)
self
.
toolbar
.
addAction
(
self
.
actionZoomOut
)
#
self.toolbar.addAction(self.actionZoomOut)
self
.
toolbar
.
addAction
(
self
.
actionPan
)
#
self.toolbar.addAction(self.actionPan)
# create the map tools
# create the map tools
self
.
toolPan
=
QgsMapToolPan
(
self
.
canvas
)
self
.
toolPan
=
QgsMapToolPan
(
self
.
canvas
)
...
@@ -146,20 +139,17 @@ class MyWnd(QMainWindow):
...
@@ -146,20 +139,17 @@ class MyWnd(QMainWindow):
app
=
QApplication
([])
app
=
QApplication
([])
# create main window
# create main window
wnd
=
M
yW
nd
()
wnd
=
M
ainWi
nd
()
canvas
=
wnd
.
canvas
canvas
=
wnd
.
map
.
canvas
# Move the app window to upper left
# Move the app window to upper left
wnd
.
size
()
wnd
.
size
()
wnd
.
show
()
wnd
.
show
()
orm
=
QgsRasterLayer
(
'
crs=EPSG:4326&format&type=xyz&url=https://a.tiles.openrailwaymap.org/standard/%7Bz%7D/%7Bx%7D/%7By%7D.png&zmax=19&zmin=0
'
,
'
ORM-standard
'
,
'
wms
'
)
orm
=
QgsRasterLayer
(
'
crs=EPSG:4326&format&type=xyz&url=https://a.tiles.openrailwaymap.org/standard/%7Bz%7D/%7Bx%7D/%7By%7D.png&zmax=19&zmin=0
'
,
'
ORM-standard
'
,
'
wms
'
)
osm
=
QgsRasterLayer
(
'
crs=EPSG:4326&format&type=xyz&url=http://tile.openstreetmap.org/%7Bz%7D/%7Bx%7D/%7By%7D.png&zmax=19&zmin=0
'
,
'
ORM-standard
'
,
'
wms
'
)
mapy_cz
=
QgsRasterLayer
(
'
http-header:referer=https://mapy.cz/ &referer=https://mapy.cz/ &type=xyz&url=https://mapserver.mapy.cz/base-m/%7Bz%7D-%7Bx%7D-%7By%7D
'
,
'
mapycz-standard
'
,
'
wms
'
)
mapy_cz
=
QgsRasterLayer
(
'
http-header:referer=https://mapy.cz/ &referer=https://mapy.cz/ &type=xyz&url=https://mapserver.mapy.cz/base-m/%7Bz%7D-%7Bx%7D-%7By%7D
'
,
'
mapycz-standard
'
,
'
wms
'
)
vlayer
=
QgsVectorLayer
(
'
/aux/jiri/QGIS-Sampledata/shapefiles/airports.shp
'
,
"
Airports layer
"
,
"
ogr
"
)
if
not
vlayer
.
isValid
():
print
(
"
Layer failed to load!
"
)
uri
=
"
Point?field=vehicle_type:string(100)&field=route_short_name:string(20)&index=yes
"
uri
=
"
Point?field=vehicle_type:string(100)&field=route_short_name:string(20)&index=yes
"
mem_layer
=
QgsVectorLayer
(
uri
,
mem_layer
=
QgsVectorLayer
(
uri
,
...
@@ -175,20 +165,17 @@ mem_layer.setLabeling(labeling)
...
@@ -175,20 +165,17 @@ mem_layer.setLabeling(labeling)
mem_layer
.
setLabelsEnabled
(
True
)
mem_layer
.
setLabelsEnabled
(
True
)
prov
=
mem_layer
.
dataProvider
()
prov
=
mem_layer
.
dataProvider
()
layer_fields
=
mem_layer
.
fields
()
layer_fields
=
mem_layer
.
fields
()
canvas
.
setExtent
(
QgsRectangle
(
# add layer to the registry
crs_transform
.
transform
(
QgsPointXY
(
14.373
,
50.034
)),
QgsProject
.
instance
().
addMapLayer
(
vlayer
)
crs_transform
.
transform
(
QgsPointXY
(
14.500
,
50.103
)))
)
# set extent to the extent of our layer
canvas
.
setExtent
(
vlayer
.
extent
())
# set the map canvas layer set
# set the map canvas layer set
canvas
.
setLayers
([
mapy_cz
])
canvas
.
setLayers
([
mem_layer
,
orm
,
mapy_cz
])
feature_identifier
=
QgsMapToolIdentifyFeature
(
canvas
)
feature_identifier
=
QgsMapToolIdentifyFeature
(
canvas
)
feature_identifier
.
setLayer
(
vlayer
)
feature_identifier
.
featureIdentified
.
connect
(
wnd
.
map
.
callback
)
feature_identifier
.
featureIdentified
.
connect
(
wnd
.
callback
)
canvas
.
setDestinationCrs
(
mapy_cz
.
crs
())
canvas
.
setDestinationCrs
(
mapy_cz
.
crs
())
...
@@ -198,6 +185,7 @@ asyncio.set_event_loop(event_loop)
...
@@ -198,6 +185,7 @@ asyncio.set_event_loop(event_loop)
app_close_event
=
asyncio
.
Event
()
app_close_event
=
asyncio
.
Event
()
app
.
aboutToQuit
.
connect
(
app_close_event
.
set
)
app
.
aboutToQuit
.
connect
(
app_close_event
.
set
)
print
(
mem_layer
,
mem_layer
.
crs
())
with
event_loop
:
with
event_loop
:
event_loop
.
run_until_complete
(
app_close_event
.
wait
())
event_loop
.
run_until_complete
(
app_close_event
.
wait
())
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment