本文整理汇总了Python中qgis.core.QgsRasterLayer.setAttributionUrl方法的典型用法代码示例。如果您正苦于以下问题:Python QgsRasterLayer.setAttributionUrl方法的具体用法?Python QgsRasterLayer.setAttributionUrl怎么用?Python QgsRasterLayer.setAttributionUrl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qgis.core.QgsRasterLayer
的用法示例。
在下文中一共展示了QgsRasterLayer.setAttributionUrl方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_layer_to_map
# 需要导入模块: from qgis.core import QgsRasterLayer [as 别名]
# 或者: from qgis.core.QgsRasterLayer import setAttributionUrl [as 别名]
#.........这里部分代码省略.........
layer = TileLayer(service_info, False)
layers4add.append(layer)
if ds.type.lower() == KNOWN_DRIVERS.GDAL.lower():
layer = QgsRasterLayer(ds.gdal_source_file, tr(ds.alias))
layers4add.append(layer)
if ds.type.lower() == KNOWN_DRIVERS.WMS.lower():
qgis_wms_uri = u''
if ds.wms_params:
qgis_wms_uri += ds.wms_params
if ds.wms_layers:
layers = ds.wms_layers.split(',')
if layers:
if ds.wms_turn_over:
layers.reverse()
qgis_wms_uri += '&layers=' + '&layers='.join(layers) + '&styles=' * len(layers)
qgis_wms_uri += '&url=' + ds.wms_url + "?" + ds.wms_url_params.replace("=","%3D").replace("&","%26")
layer = QgsRasterLayer(qgis_wms_uri, tr(ds.alias), KNOWN_DRIVERS.WMS.lower())
layers4add.append(layer)
if ds.type.lower() == KNOWN_DRIVERS.WFS.lower():
qgis_wfs_uri_base = ds.wfs_url
if ds.wfs_params is not None:
qgis_wfs_uri_base += ds.wfs_params
o = urlparse.urlparse(qgis_wfs_uri_base)
request_attrs = dict(urlparse.parse_qsl(o.query))
new_request_attrs = {}
for k, v in request_attrs.items():
new_request_attrs[k.upper()] = v
if ds.wfs_epsg is not None:
new_request_attrs['SRSNAME'] = "EPSG:{0}".format(ds.wfs_epsg)
layers = []
if len(ds.wfs_layers) > 0:
layers.extend(ds.wfs_layers)
else:
layers_str = request_attrs.get('TYPENAME', '')
layers.extend(layers_str.split())
for layer_name in layers:
new_request_attrs['TYPENAME'] = layer_name
url_parts = list(o)
url_parts[4] = "&".join(
["%s=%s" % (k, v) for k, v in new_request_attrs.items()]
)
qgis_wfs_uri = urlparse.urlunparse(url_parts)
layer = QgsVectorLayer(
qgis_wfs_uri,
"%s - %s" % (tr(ds.alias), layer_name),
"WFS")
layers4add.append(layer)
if ds.type.lower() == KNOWN_DRIVERS.GEOJSON.lower():
layer = QgsVectorLayer(
ds.geojson_url,
tr(ds.alias),
"ogr")
layers4add.append(layer)
for layer in layers4add:
if not layer.isValid():
error_message = tr('Layer %s can\'t be added to the map!') % ds.alias
iface.messageBar().pushMessage(tr('Error'),
error_message,
level=QGisMessageBarLevel.Critical)
QgsMessageLog.logMessage(error_message, level=QGisMessageLogLevel.Critical)
else:
# Set attribs
layer.setAttribution(ds.copyright_text)
layer.setAttributionUrl(ds.copyright_link)
# Insert layer
toc_root = QgsProject.instance().layerTreeRoot()
selected_node = iface.layerTreeView().currentNode()
if selected_node.nodeType() == selected_node.NodeGroup:
toc_root = selected_node
if ds.type.lower() in (KNOWN_DRIVERS.WMS.lower(), KNOWN_DRIVERS.TMS.lower()):
position = len(toc_root.children()) # Insert to bottom if wms\tms
else:
position = 0 # insert to top
addMapLayer(layer, False)
toc_root.insertLayer(position, layer)
# Save link
service_layers.append(layer)
# Set OTF CRS Transform for map
if PluginSettings.enable_otf_3857() and ds.type == KNOWN_DRIVERS.TMS:
if hasattr(iface.mapCanvas(), "setCrsTransformEnabled"):
# Need for QGIS2. In QGIS3 CRS transformation is always enabled
iface.mapCanvas().setCrsTransformEnabled(True)
iface.mapCanvas().setDestinationCrs(TileLayer.CRS_3857)