-
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #521 wrong coordinates send to JOSM
- Loading branch information
Showing
3 changed files
with
53 additions
and
35 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
from qgis.core import ( | ||
QgsCoordinateReferenceSystem, | ||
QgsCoordinateTransform, | ||
QgsNetworkAccessManager, | ||
QgsProject, | ||
QgsRectangle, | ||
) | ||
from qgis.PyQt.QtCore import QUrl | ||
from qgis.PyQt.QtNetwork import QNetworkReply, QNetworkRequest | ||
|
||
__copyright__ = 'Copyright 2025, 3Liz' | ||
__license__ = 'GPL version 3' | ||
__email__ = '[email protected]' | ||
|
||
URL = "http://localhost:8111" | ||
|
||
|
||
def open_object(object_id: str) -> bool: | ||
""" Open the given OSM object in JOSM. """ | ||
return _josm_request(f"load_object?objects={object_id}") | ||
|
||
|
||
def open_extent(extent: QgsRectangle, crs_map: QgsCoordinateReferenceSystem) -> bool: | ||
""" Open the given extent in JOSM. """ | ||
if crs_map.authid() != 'EPSG:4326': | ||
crs_4326 = QgsCoordinateReferenceSystem("EPSG:4326") | ||
transform = QgsCoordinateTransform(crs_map, crs_4326, QgsProject.instance()) | ||
extent = transform.transform(extent) | ||
|
||
url = ( | ||
f'load_and_zoom?' | ||
f'left={extent.xMinimum()}&right={extent.xMaximum()}&' | ||
f'top={extent.yMaximum()}&bottom={extent.yMinimum()}' | ||
) | ||
|
||
return _josm_request(url) | ||
|
||
|
||
def _josm_request(request_url: str) -> bool: | ||
""" Do the request to JOSM. """ | ||
request = QNetworkRequest() | ||
# noinspection PyArgumentList | ||
request.setUrl(QUrl(f"{URL}/{request_url}")) | ||
# noinspection PyArgumentList | ||
reply: QNetworkReply = QgsNetworkAccessManager.instance().get(request) | ||
return reply.error() == QNetworkReply.NetworkError.NoError |
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