-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b65c502
commit 9ae9efd
Showing
6 changed files
with
125 additions
and
53 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
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,50 @@ | ||
from qgis.core import QgsCoordinateReferenceSystem | ||
from qgis.gui import QgsMessageBar | ||
|
||
from .plugin_settings import PluginSettings | ||
|
||
|
||
class ProjectionHelper: | ||
CRS_3857 = QgsCoordinateReferenceSystem(3857) | ||
|
||
@classmethod | ||
def set_tile_layer_proj(cls, layer, epsg_crs_id, postgis_crs_id, custom_proj): | ||
|
||
# set standard crs for tiled layer | ||
layer.setCrs(cls.CRS_3857) | ||
# set standard/custom crs | ||
try: | ||
crs = None | ||
if epsg_crs_id is not None: | ||
crs = QgsCoordinateReferenceSystem(epsg_crs_id, QgsCoordinateReferenceSystem.EpsgCrsId) | ||
if postgis_crs_id is not None: | ||
crs = QgsCoordinateReferenceSystem(postgis_crs_id, QgsCoordinateReferenceSystem.PostgisCrsId) | ||
if custom_proj is not None: | ||
# create form proj4 str | ||
custom_crs = QgsCoordinateReferenceSystem() | ||
custom_crs.createFromProj4(custom_proj) | ||
# try to search in db | ||
searched = custom_crs.findMatchingProj() | ||
if searched: | ||
crs = QgsCoordinateReferenceSystem(searched, QgsCoordinateReferenceSystem.InternalCrsId) | ||
else: | ||
# create custom and use it | ||
custom_crs.saveAsUserCRS(u'quickmapservices ' + layer.name()) | ||
searched = custom_crs.findMatchingProj() | ||
if searched: | ||
crs = QgsCoordinateReferenceSystem(searched, QgsCoordinateReferenceSystem.InternalCrsId) | ||
else: | ||
crs = custom_crs | ||
|
||
if crs: | ||
layer.setCrs(crs) | ||
except: | ||
msg = "Custom crs can't be set for layer {0}!".format(layer.name()) | ||
self.show_bar_message(msg, QgsMessageBar.WARNING, 4) | ||
|
||
@classmethod | ||
def show_bar_message(cls, text, level=QgsMessageBar.INFO, duration=0, title=None): | ||
if PluginSettings.show_messages_in_bar(): | ||
if title is None: | ||
title = PluginSettings.product_name() | ||
iface.messageBar().pushMessage(title, text, level, duration) |
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