Geographic Information Systems Asked by Surya Jai on April 8, 2021
I have a wms layer hosted on a Geoserver used to display on a web map application using OpenLayers. I will get the map image using the proxy URL which sends a request to the Geoserver and returns the wms layer image as a response. But, I couldn’t use the same URL in pyqgis to load the layer as the Raster layer in QGIS. I could load my localhost GeoServer data successfully using the QgsRasterLater function, but since my remote server’s GeoServer could only be accessed via proxy URL, I am getting an invalid layer response.
Function to load localhost layer (Works successfully):
urlWithParams = "crs=EPSG:4326&format=image/png&layers=roads&styles=roads&url=http://localhost:7080/geoserver/demo_workspace/ows"
rlayer = QgsRasterLayer(urlWithParams, 'roads', 'wms')
print(rlayer.results())
if not rlayer.isValid():
print("Layer failed to load!")
else:
QgsProject.instance().addMapLayer(rlayer)
Function to load remote GeoServer layer which is proxy protected(Not working):
Case 1:
urlWithParams = "SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap&FORMAT=image/png&TRANSPARENT=true&LAYERS=demo_worksapce:layer1&CRS=EPSG:3857&TILED=true&WIDTH=256&HEIGHT=256&STYLES=&BBOX=8844681.416934315,1408887.3053523675,8922952.933898335,1487158.822316388&url=https://demo.com:2080/api/v1/proxy/image"
rlayer = QgsRasterLayer(urlWithParams, 'roads', 'wms')
print(rlayer.isValid())
if not rlayer.isValid():
print("Layer failed to load!")
else:
QgsProject.instance().addMapLayer(rlayer)
Case 2:
urlWithParams = "FORMAT=image/png&LAYERS=demo_worksapce:layer1&CRS=EPSG:3857&STYLES=&url=https://demo.com:2080/api/v1/proxy/image"
rlayer = QgsRasterLayer(urlWithParams, 'roads', 'wms')
print(rlayer.isValid())
if not rlayer.isValid():
print("Layer failed to load!")
else:
QgsProject.instance().addMapLayer(rlayer)
Both cases are failing. Kindly help me.
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP