Is there a way to create QGIS project file(.qgs) using only Python script outside QGIS Python console. I am trying to publish a map using QGIS Web Client using python.
For this, I am trying to do below
Create .qgs file dynamically
Add Legend and Layers to the .qgs file and save
Set WFS,WCS parameters in the .qgs file
Finally use this file to view QGIS web client.
I tried to tweak the tool available at https://github.com/oware/Mxd2Qgs. I am successful to certain extent, i.e. creating a .qgs file. But I need some inputs on Getting layer (vector/raster) properties when path for the files is given.
# Import system modules from xml.dom.minidom import Document import string import os import glob
#Read input parameters from GP dialog
output = "myworld.qgs"
#Create an output qgs file f = open(output, "w")
# Create the minidom doc = Document()
# Create the base element qgis = doc.createElement("qgis")
# Create the element projections = doc.createElement("projections") mapcanvas.appendChild(projections)
# Create the element destinationsrs = doc.createElement("destinationsrs")
mapcanvas.appendChild(destinationsrs)
# Create the element spatialrefsys = doc.createElement("spatialrefsys") destinationsrs.appendChild(spatialrefsys)
# Create the element proj4 = doc.createElement("proj4") proj4.appendChild(proj4id) spatialrefsys.appendChild(proj4)
# Create the element srsid = doc.createElement("srsid") srsid.appendChild(srid2) spatialrefsys.appendChild(srsid)
# Create the element srid = doc.createElement("srid") srid.appendChild(srid1) spatialrefsys.appendChild(srid)
# Create the element authid = doc.createElement("authid") authid.appendChild(authid2) spatialrefsys.appendChild(authid)
# Create the element description = doc.createElement("description") description.appendChild(description1) spatialrefsys.appendChild(description)
# Create the element projectionacronym = doc.createElement("projectionacronym") spatialrefsys.appendChild(projectionacronym) projectionacronym.appendChild(pa)
# Create the ellipsoidacronym = doc.createElement("ellipsoidacronym") ellipsoidacronym.appendChild(ellipsoidacronym1) spatialrefsys.appendChild(ellipsoidacronym)
# Create the element geographicflag = doc.createElement("geographicflag") geographicflag.appendChild(geographicflag1) spatialrefsys.appendChild(geographicflag)
# Legend # Legend
def legend_func(): global count2 # Create the
Answer
Struggled a bit for last 2 days. Abandoned XML approach. Able to accomplish first 2 tasks.
Need to check how I can accomplish setting WFS,WCS parameters
Create .qgs file dynamically
Add Legend and Layers to the .qgs file and save
Set WFS,WCS parameters in the .qgs file
from xml.dom.minidom import Document import string import os import sys from qgis.core import * from qgis.gui import * from PyQt4.QtCore import *
from PyQt4.QtGui import QApplication from PyQt4.QtXml import *
#Read input parameters from GP dialog strProjetName = "C:/OSGeo4W/apache/htdocs/QGIS-Web-Client-master/projects/myworld.qgs"
if os.path.isfile(strProjetName): os.remove(strProjetName)
No comments:
Post a Comment