Created
June 12, 2020 17:35
-
-
Save ThomasG77/6c84e6bd706f58c3c7a9c1dc684cd7bf to your computer and use it in GitHub Desktop.
Call QGIS Server via Flask
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
from flask import Flask, request, Response | |
app = Flask(__name__) | |
from qgis.core import QgsApplication | |
from qgis.server import * | |
QgsApplication.setPrefixPath("/usr", True) | |
qgisapp = QgsApplication([], False) | |
qgisapp.initQgis() | |
qgisserver = QgsServer() | |
@app.route('/qgis-server') | |
def qgisServer(): | |
qgisrequest = QgsBufferServerRequest(request.url) | |
qgisresponse = QgsBufferServerResponse() | |
qgisserver.handleRequest(qgisrequest, qgisresponse) | |
response = Response(qgisresponse.body().data(), status=str(qgisresponse.statusCode()), headers=qgisresponse.headers()) # | |
return(response) | |
if __name__ == '__main__': | |
app.debug = True | |
app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment