def formatMetadata(self, process): """Create structure suitble for template form process.metadata :param process: :attr:`pywps.Process` :returns: hash with formated metadata """ metadata = process.metadata if isinstance(metadata, dict): metadata = [metadata] metadatas = [] for metad in metadata: meta_structure = {} if "title" in metad.keys(): meta_structure["title"] = metad["title"] else: meta_structure["title"] = process.title if "href" in metad.keys(): meta_structure["href"] = metad["href"] else: meta_structure["href"] = ( config.getConfigValue("wps", "serveraddress") + "?service=WPS&request=DescribeProcess&version=" + config.getConfigValue("wps", "version") + "&identifier=" + process.identifier) metadatas.append(meta_structure) return metadatas
def formatMetadata(self,process): """Create structure suitble for template form process.metadata :param process: :attr:`pywps.Process` :returns: hash with formated metadata """ metadata = process.metadata if type(metadata) == type({}): metadata = [metadata] metadatas = [] for metad in metadata: metaStructure = {} if metad.has_key("title"): metaStructure["title"] = metad["title"] else: metaStructure["title"] = process.title if metad.has_key("href"): metaStructure["href"] = metad["href"] else: metaStructure["href"] = config.getConfigValue("wps","serveraddress")+\ "?service=WPS&request=DescribeProcess&version="+config.getConfigValue("wps","version")+\ "&identifier="+ process.identifier metadatas.append(metaStructure) return metadatas
def formatMetadata(self, process): """Create structure suitble for template form process.metadata :param process: :attr:`pywps.Process` :returns: hash with formated metadata """ metadata = process.metadata if isinstance(metadata, dict): metadata = [metadata] metadatas = [] for metad in metadata: meta_structure = {} if "title" in metad.keys(): meta_structure["title"] = metad["title"] else: meta_structure["title"] = process.title if "href" in metad.keys(): meta_structure["href"] = metad["href"] else: meta_structure["href"] = ( config.getConfigValue("wps", "serveraddress") + "?service=WPS&request=DescribeProcess&version=" + config.getConfigValue("wps", "version") + "&identifier=" + process.identifier ) metadatas.append(meta_structure) return metadatas
def formatMetadata(self, process): """Create structure suitble for template form process.metadata :param process: :attr:`pywps.Process` :returns: hash with formated metadata """ metadata = process.metadata if type(metadata) == type({}): metadata = [metadata] metadatas = [] for metad in metadata: metaStructure = {} if metad.has_key("title"): metaStructure["title"] = metad["title"] else: metaStructure["title"] = process.title if metad.has_key("href"): metaStructure["href"] = metad["href"] else: metaStructure["href"] = config.getConfigValue("wps", "serveraddress") +\ "?service=WPS&request=DescribeProcess&version=" + config.getConfigValue("wps", "version") +\ "&identifier=" + process.identifier metadatas.append(metaStructure) return metadatas
def __init__(self, executeRequest): """ Initialization of GRASS environmental variables (except GISRC). """ self.executeRequest = executeRequest self.wps = self.executeRequest.wps self.envs = { "path": "PATH", "addonPath": "GRASS_ADDON_PATH", "version": "GRASS_VERSION", "gui": "GRASS_GUI", "gisbase": "GISBASE", "ldLibraryPath": "LD_LIBRARY_PATH", "home": "HOME" } # put env for key in self.envs.keys(): try: self.setEnv(self.envs[key], config.getConfigValue("grass", key)) logging.info("GRASS environment variable %s set to %s" %\ (key, config.getConfigValue("grass",key))) except: logging.info("GRASS environment variable %s set to %s" %\ (key, self.envs[key])) pass # GIS_LOCK self.setEnv('GIS_LOCK', str(os.getpid())) logging.info("GRASS GIS_LOCK set to %s" % str(os.getpid()))
def __init__(self,process,sessId): tmp = os.path.basename(tempfile.mkstemp()[1]) self.outputs = {} self.process = process self.sessionId = sessId self.project = QgsProject.instance() self.projectFileName = os.path.join(config.getConfigValue("server","outputPath"),self.sessionId+".qgs") self.project.writePath( self.projectFileName ) self.project.setTitle( "%s-%s"%(self.process.identifier,self.sessionId) ) self.project.writeEntry("WMSServiceCapabilities", "/", True) self.project.writeEntry("WMSServiceTitle", "/", config.getConfigValue("wps","title")) self.project.writeEntry("WMSServiceAbstract", "/", config.getConfigValue("wps","abstract")) self.project.writeEntry("WMSKeywordList", "/", config.getConfigValue("wps","keywords")) self.project.writeEntry("WMSFees", "/", config.getConfigValue("wps","fees")) self.project.writeEntry("WMSAccessConstraints", "/", config.getConfigValue("wps","constraints")) self.project.writeEntry("WMSContactOrganization", "/", config.getConfigValue("provider","providerName")) self.project.writeEntry("WMSContactPerson", "/", config.getConfigValue("provider","individualName")) self.project.writeEntry("WMSContactPhone", "/", config.getConfigValue("provider","phoneVoice")) self.project.writeEntry("WMSContactPhone", "/", config.getConfigValue("provider","electronicMailAddress")) self.project.write( QFileInfo( self.projectFileName ) )
def __init__(self,executeRequest): """ Initialization of GRASS environmental variables (except GISRC). """ self.executeRequest = executeRequest self.wps = self.executeRequest.wps self.envs = { "path":"PATH", "addonPath":"GRASS_ADDON_PATH", "version":"GRASS_VERSION", "gui":"GRASS_GUI", "gisbase": "GISBASE", "ldLibraryPath": "LD_LIBRARY_PATH" } # put env for key in self.envs.keys(): try: self.setEnv(self.envs[key],config.getConfigValue("grass",key)) logging.info("GRASS environment variable %s set to %s" %\ (key, config.getConfigValue("grass",key))) except : logging.info("GRASS environment variable %s set to %s" %\ (key, self.envs[key])) pass # GIS_LOCK self.setEnv('GIS_LOCK',str(os.getpid())) logging.info("GRASS GIS_LOCK set to %s" % str(os.getpid()))
def getCapabilities(self, output): """Get the URL for qgis-server GetCapabilities request of the output""" if output.format["mimetype"] == 'application/x-ogc-wms': return config.getConfigValue("qgis", "qgisserveraddress") + "?map=" + self.projectFileName + "&SERVICE=WMS" + "&REQUEST=GetCapabilities" elif output.format["mimetype"] == 'application/x-ogc-wfs': return config.getConfigValue("qgis", "qgisserveraddress") + "?map=" + self.projectFileName + "&SERVICE=WFS" + "&REQUEST=GetCapabilities" elif output.format["mimetype"] == 'application/x-ogc-wcs': return config.getConfigValue("qgis", "qgisserveraddress") + "?map=" + self.projectFileName + "&SERVICE=WCS" + "&REQUEST=GetCapabilities" else: return config.getConfigValue("qgis", "qgisserveraddress") + "?map=" + self.projectFileName + "&SERVICE=WMS" + "&REQUEST=GetCapabilities"
def getCapabilities(self,output): """Get the URL for qgis-server GetCapapbilities request of the output""" if output.format["mimetype"] == 'application/x-ogc-wms': return config.getConfigValue("qgis","qgisserveraddress")+"?map="+self.projectFileName+"&SERVICE=WMS"+ "&REQUEST=GetCapabilities" elif output.format["mimetype"] == 'application/x-ogc-wfs': return config.getConfigValue("qgis","qgisserveraddress")+"?map="+self.projectFileName+"&SERVICE=WFS"+ "&REQUEST=GetCapabilities" elif output.format["mimetype"] == 'application/x-ogc-wcs': return config.getConfigValue("qgis","qgisserveraddress")+"?map="+self.projectFileName+"&SERVICE=WCS"+ "&REQUEST=GetCapabilities" else: return config.getConfigValue("qgis","qgisserveraddress")+"?map="+self.projectFileName+"&SERVICE=WMS"+ "&REQUEST=GetCapabilities"
def __init__(self, wps): """ Arguments: self wps - parent WPS instance """ Request.__init__(self, wps) # # global variables # serverName = "".join( map(lambda x: x.capitalize(), config.getConfigValue("wps", "title").split())) # self.templateProcessor.set("name",name) # self.templateProcessor.set("address",config.getConfigValue("wps","serveraddress")) serverURL = config.getConfigValue("wps", "serveraddress") # Generating a describeProcess for all processes wps2 = pywps.Pywps() wps2.inputs = { 'identifier': ['all'], 'version': '1.0.0', 'request': 'describeprocess', 'language': 'eng', 'service': 'wps' } requestDescribeProcess = DescribeProcess(wps2) describeProcessXML = requestDescribeProcess.response # Transforming the describeProcessXML into WSDL document describeProcess2WSDLXSL = open( pywps.XSLT.__path__[0] + "/describeProcess2WSDL.xsl", "r") transformerXSLT = etree.XSLT(etree.parse(describeProcess2WSDLXSL)) # Recall: serverName/serverURL parameters are XPath structures, # therefore we need '' in the string: 'http://foo/dummy' to be used by # XSLT WSDLTree = transformerXSLT(etree.parse( StringIO.StringIO(describeProcessXML)), serverName="'" + serverName + "'", serverURL="'" + serverURL + "'") # Concerting to String from tree WSDL = etree.tostring(WSDLTree) # Attention: It's not possible to set the tns namespace to the server's URL # with XSLT, since it is in the root element. The XML contains a REPLACEME string that # will be replaced only once (so the process is very efficient) WSDL = re.sub(r'REPLACEME', serverURL, WSDL, 1) self.response = WSDL return
def __init__(self, process, sessId): MapServer.__init__(self, process, sessId) # initial myself # the catagory of this geoserver self.cat = Catalog( '/'.join( (config.getConfigValue('geoserver', 'geoserveraddress'), 'rest') ), config.getConfigValue('geoserver', 'admin'), config.getConfigValue('geoserver', 'adminpassword') ) # get the workspace that datas will be saved and if workspace not set at configure file or # not exit then the default workspace will be used self.workspace = self.cat.get_workspace ( config.getConfigValue('geoserver', 'workspace') ) if not self.workspace: self.workspace = self.cat.get_default_workspace()
def _asReferenceOutput(self, templateOutput, output): # copy the file to output directory # literal value if output.type == "LiteralValue": tmp = tempfile.mkstemp( prefix="%s-%s" % (output.identifier, self.pid), dir=os.path.join(config.getConfigValue("server", "outputPath")), text=True, ) f = open(tmp[1], "w") f.write(str(output.value)) f.close() templateOutput["reference"] = escape(tmp[1]) # complex value else: outName = os.path.basename(output.value) outSuffix = os.path.splitext(outName)[1] tmp = tempfile.mkstemp( suffix=outSuffix, prefix="%s-%s" % (output.identifier, self.pid), dir=os.path.join(config.getConfigValue("server", "outputPath")), text=True, ) outFile = tmp[1] outName = os.path.basename(outFile) if not self._samefile(output.value, outFile): COPY(os.path.abspath(output.value), outFile) templateOutput["reference"] = escape(config.getConfigValue("server", "outputUrl") + "/" + outName) output.value = outFile # mapscript supported and the mapserver should be used for this # output # redefine the output # Mapserver needs the format information, therefore checkMimeType has to be called before self.checkMimeTypeOutput(output) if self.umn and output.useMapscript: owsreference = self.umn.getReference(output) if owsreference: templateOutput["reference"] = escape(owsreference) templateOutput["mimetype"] = output.format["mimetype"] templateOutput["schema"] = output.format["schema"] templateOutput["encoding"] = output.format["encoding"] return templateOutput
def outputUrl_path(): try: outputUrl = wpsconfig.getConfigValue("server", "outputUrl") except: outputUrl = None logger.warn('no outputUrl configured') return outputUrl
def output_path(): try: output_path = wpsconfig.getConfigValue("server", "outputPath") except: output_path = None logger.warn('no output path configured') return output_path
def setRawData(self): """Sets response and contentType """ output = self.process.outputs[self.rawDataOutput] if output.type == "LiteralValue": self.contentType = "text/plain" self.response = output.value elif output.type == "ComplexValue": # self.checkMimeTypeIn(output) # copy the file to safe place outName = os.path.basename(output.value) outSuffix = os.path.splitext(outName)[1] tmp = tempfile.mkstemp( suffix=outSuffix, prefix="%s-%s" % (output.identifier, self.pid), dir=os.path.join(config.getConfigValue("server", "outputPath")), ) outFile = tmp[1] if not self._samefile(output.value, outFile): COPY(os.path.abspath(output.value), outFile) # check self.contentType = output.format["mimetype"] self.response = open(outFile, "rb")
def www_url(): try: url = wpsconfig.getConfigValue("flyingpigeon", "www_url") except: url = None logger.warn('no www-url configured') return url
def getProjs(self): """Gets projections from config file and it returns a len=0 list if no projs present""" projs = config.getConfigValue("mapserver", "projs").lower().split( ",") #List with projs projs = [item for item in projs if 'epsg' in item] #cleaning a bit (specially from '') return projs
def setValue(self, value): """Set the output value :param value: value to be returned (file name or file itself) :type value: string or file """ #Note: cStringIO and StringIO are totally messed up, StringIO is type instance, cString is type cStringIO.StringO #Better to also use __class__.__name__ to be certain what is is # StringIO => StringIO but cStringIO => StringO if type(value) == types.StringType or type(value)==types.UnicodeType: self.value = value elif type(value) == types.FileType: self.value = value.name elif value.__class__.__name__=='StringIO' or value.__class__.__name__=='StringO': from pywps import config fh, stringIOName = tempfile.mkstemp(prefix="%s-" % self.identifier, dir=config.getConfigValue("server","outputPath")) os.write(fh, value.getvalue()) os.close(fh) self.value=stringIOName # TODO add more types, like Arrays and lists for example else: raise Exception("Output type '%s' of '%s' output not known, not FileName, File or (c)StringIO object" %\ (type(value),self.identifier))
def __init__(self,wps,processes=None): """ Arguments: self wps - parent WPS instance """ Request.__init__(self,wps,processes) # # HEAD # self.templateProcessor.set("encoding", config.getConfigValue("wps","encoding")) self.templateProcessor.set("lang", self.wps.inputs["language"]) # # Processes # self.templateProcessor.set("Processes",self.processesDescription()) self.response = self.templateProcessor.__str__() return
def save(self, output): MapServer.save(self,output) name = "%s-%s-%s"%(output.identifier, self.process.identifier,self.sessId) service_url = '/'.join([config.getConfigValue('geoserver', 'geoserveraddress'), self.workspace.name]) if self.datatype == "raster": # save logging.info("upload raster file with name: {0} ".format(name)) self.cat.create_coveragestore(name, output.value, self.workspace, False) # construct the wcs url return urllib2.quote('/'.join( (service_url, 'wcs') ) + "?SERVICE=WCS"+ "&REQUEST=GetCoverage"+ "&VERSION=1.0.0"+ "&COVERAGE="+name+"&CRS="+output.projection+ "&BBOX=%s,%s,%s,%s"%(output.bbox[0],output.bbox[1],output.bbox[2],output.bbox[3])+ "&HEIGHT=%s" %(output.height)+"&WIDTH=%s"%(output.width)+"&FORMAT=%s"%output.format["mimetype"]) elif self.datatype == "vector": #save logging.info("upload vector file with name: {0} ".format(name)) zip_shpf,lyname = self.compressFeatureData(output.value) self.cat.create_featurestore(name, zip_shpf, self.workspace, False) # construct the wfs url return urllib2.quote('/'.join( (service_url, 'wfs') ) + "?SERVICE=WFS"+ "&REQUEST=GetFeature"+ "&VERSION=1.0.0"+ "&TYPENAME="+lyname) else: return None
def initProcesses(self, processes=None): """Initialize list of :attr:`processes` :param processes: processes input processes. If none, environment and default settings will be used. :type processes: list of :class:`pywps.Process.WPSProcess`, list of it's instances, string with directory, where processes are located, ...""" global pywps if processes and type(processes) == type(""): logging.info("Reading processes from directory [%s]" % processes) self.processes = self._initFromDirectory(processes) # processes are some list -- use them directly elif processes and type(processes) in [type(()), type([])]: logging.info( "Setting PYWPS_PROCESSES not set, we are using the processes array directly" ) self.processes = self._initFromCode(processes) # processes will be set from configuration file elif config.getConfigValue("server", "processesPath"): logging.info( "Setting PYWPS_PROCESSES from configuration file to %s" % config.getConfigValue("server", "processesPath")) self.processes = self._initFromDirectory( config.getConfigValue("server", "processesPath")) # processes will be set from default directory else: logging.info( "Importing the processes from default (pywps/processes) location" ) from pywps import processes as pywpsprocesses self.processes = self._initFromDirectory( os.path.abspath(pywpsprocesses.__path__[-1])) if len(self.processes) == 0: logging.warning( "No processes found in any place. Continuing, but you can not execute anything." ) logging.info("Following processes are imported: %s" % map(lambda p: p.identifier, self.processes)) return self.processes
def cache_path(): cache_path = None try: cache_path = wpsconfig.getConfigValue("cache", "cache_path") except: logger.warn("No cache path configured. Using default value.") cache_path = os.path.join(os.sep, "tmp", "cache") return cache_path
def getMapServerWCS(self, output): """Get the URL for mapserver WCS request of the output""" return urllib2.quote(config.getConfigValue("mapserver", "mapserveraddress") + "?map=" + self.mapFileName + "&SERVICE=WCS" + "&REQUEST=GetCoverage" + "&VERSION=1.0.0" + "&COVERAGE=" + output.identifier + "&CRS=" + output.projection.replace("+init=", "") + "&BBOX=%s,%s,%s,%s" % (output.bbox[0], output.bbox[1], output.bbox[2], output.bbox[3]) + "&HEIGHT=%s" % (output.height) + "&WIDTH=%s" % (output.width) + "&FORMAT=%s" % output.format["mimetype"])
def getMapServerWCS(self,output): """Get the URL for mapserver WCS request of the output""" return urllib2.quote(config.getConfigValue("mapserver","mapserveraddress")+ "?map="+self.mapFileName+ "&SERVICE=WCS"+ "&REQUEST=GetCoverage"+ "&VERSION=1.0.0"+ "&COVERAGE="+output.identifier+"&CRS="+output.projection.replace("+init=","")+ "&BBOX=%s,%s,%s,%s"%(output.bbox[0],output.bbox[1],output.bbox[2],output.bbox[3])+ "&HEIGHT=%s" %(output.height)+"&WIDTH=%s"%(output.width)+"&FORMAT=%s"%output.format["mimeType"])
def importEnvironmentVariable( env_var ): try: value = config.getConfigValue( "cds", env_var ) except: value = os.getenv( env_var ) if value <> None: os.environ[ env_var ] = value logging.info("CDS environment variable %s set to %s" % ( env_var, value ) )
def initEnv(self): """Create process working directory, initialize GRASS environment, if required. """ # find out number of running sessions maxOperations = int(config.getConfigValue("server", "maxoperations")) tempPath = config.getConfigValue("server", "tempPath") dirs = os.listdir(tempPath) pyWPSDirs = 0 for dir in dirs: if dir.find(TEMPDIRPREFIX) == 0: pyWPSDirs += 1 if pyWPSDirs >= maxOperations and maxOperations != 0: raise pywps.ServerBusy(value="Maximal number of permitted operations exceeded") # create temp dir self.workingDir = tempfile.mkdtemp(prefix=TEMPDIRPREFIX, dir=tempPath) self.workingDir = os.path.join(config.getConfigValue("server", "tempPath"), self.workingDir) os.chdir(self.workingDir) self.dirsToBeRemoved.append(self.workingDir) # init GRASS try: if self.process.grassLocation: from pywps import Grass grass = Grass.Grass(self) if self.process.grassLocation == True: self.process.grassMapset = grass.mkMapset() elif os.path.exists( os.path.join(config.getConfigValue("grass", "gisdbase"), self.process.grassLocation) ): self.process.grassMapset = grass.mkMapset(self.process.grassLocation) else: raise Exception("Location [%s] does not exist" % self.process.grassLocation) except Exception, e: self.cleanEnv() traceback.print_exc(file=pywps.logFile) raise pywps.NoApplicableCode("Could not init GRASS: %s" % e)
def initProcesses(self, processes=None): """Initialize list of :attr:`processes` :param processes: processes input processes. If none, environment and default settings will be used. :type processes: list of :class:`pywps.Process.WPSProcess`, list of it's instances, string with directory, where processes are located, ...""" global pywps if processes and isinstance(processes, str): logging.info("Reading processes from directory [%s]" % processes) self.processes = self._init_from_directory(processes) # processes are some list -- use them directly elif processes and type(processes) in [type(()), type([])]: logging.info("Setting PYWPS_PROCESSES not set, we are using " "the processes array directly") self.processes = self._init_from_code(processes) # processes will be set from configuration file elif config.getConfigValue("server", "processesPath"): logging.info( "Setting PYWPS_PROCESSES from configuration file " "to %s" % config.getConfigValue("server", "processesPath") ) self.processes = self._init_from_directory( config.getConfigValue("server", "processesPath")) # processes will be set from default directory else: logging.info("Importing the processes from default " "(pywps/processes) location") from pywps import processes as pywpsprocesses self.processes = self._init_from_directory( os.path.abspath(pywpsprocesses.__path__[-1])) if len(self.processes) == 0: logging.warning("No processes found in any place. Continuing, " "but you can not execute anything.") logging.info("Following processes are imported: " "%s" % map(lambda p: p.identifier, self.processes)) return self.processes
def updateEnv( envs ): for key in envs.keys(): try: value = config.getConfigValue("cds",key) setEnv( envs[key], value ) logging.info("CDS environment variable %s set to %s" % ( key, value ) ) except : logging.info("Error setting CDS environment variable %s to %s" % ( key, envs[key]) ) pass
def __init__(self, process, sessId): MapServer.__init__(self, process, sessId) # initial myself # the catagory of this geoserver self.cat = Catalog( '/'.join((config.getConfigValue('geoserver', 'geoserveraddress'), 'rest')), config.getConfigValue('geoserver', 'admin'), config.getConfigValue('geoserver', 'adminpassword')) # get the workspace that datas will be saved and if workspace not set at configure file or # not exit then the default workspace will be used self.workspace = self.cat.get_workspace( config.getConfigValue('geoserver', 'workspace')) if not self.workspace: self.workspace = self.cat.get_default_workspace()
def __init__(self,wps): """ Arguments: self wps - parent WPS instance """ Request.__init__(self,wps) # # global variables # serverName = "".join(map(lambda x: x.capitalize(),config.getConfigValue("wps","title").split())) #self.templateProcessor.set("name",name) #self.templateProcessor.set("address",config.getConfigValue("wps","serveraddress")) serverURL=config.getConfigValue("wps","serveraddress") #Generating a describeProcess for all processes wps2=pywps.Pywps() wps2.inputs={'identifier': ['all'], 'version': '1.0.0', 'request': 'describeprocess', 'language': 'eng', 'service': 'wps'} requestDescribeProcess=DescribeProcess(wps2) describeProcessXML=requestDescribeProcess.response #Transforming the describeProcessXML into WSDL document describeProcess2WSDLXSL=open(pywps.XSLT.__path__[0]+"/describeProcess2WSDL.xsl","r") transformerXSLT=etree.XSLT(etree.parse(describeProcess2WSDLXSL)) #Recall: serverName/serverURL parameters are XPath structures, therefore we need '' in the string: 'http://foo/dummy' to be used by XSLT WSDLTree=transformerXSLT(etree.parse(StringIO.StringIO(describeProcessXML)),serverName="'"+serverName+"'",serverURL="'"+serverURL+"'") #Concerting to String from tree WSDL=etree.tostring(WSDLTree) #Attention: It's not possible to set the tns namespace to the server's URL #with XSLT, since it is in the root element. The XML contains a REPLACEME string that #will be replaced only once (so the process is very efficient) WSDL=re.sub(r'REPLACEME',serverURL,WSDL,1) self.response=WSDL return
def getReference(self,output): if output.format["mimetype"] in [ 'text/csv', 'application/x-zipped-shp', 'application/x-zipped-tab' ] : return None mlr = QgsMapLayerRegistry.instance() logging.info(output.identifier+' '+output.value) layersByName = mlr.mapLayersByName( output.identifier ) outputLayer = None if not layersByName : if output.format["mimetype"] == 'image/tiff' : outputLayer = QgsRasterLayer( output.value, output.identifier, 'gdal' ) mlr.addMapLayer( outputLayer ) else : outputLayer = QgsVectorLayer( output.value, output.identifier, 'ogr' ) mlr.addMapLayer( outputLayer ) else : outputLayer = layersByName[0] treeRoot = self.project.layerTreeRoot() if config.config.has_section( 'qgis' ) and config.config.has_option( 'qgis', 'output_ows_crss' ) : outputOWSCRSs = config.getConfigValue( 'qgis', 'output_ows_crss' ) outputOWSCRSs = outputOWSCRSs.split(',') outputOWSCRSs = [ proj.strip().upper() for proj in outputOWSCRSs ] self.canvas.setDestinationCrs( QgsCoordinateReferenceSystem( outputOWSCRSs[0] ) ) else: self.canvas.setDestinationCrs( QgsCoordinateReferenceSystem( 'EPSG:4326' ) ) if not treeRoot.findLayer( outputLayer.id() ) : treeRoot.addLayer( outputLayer ) self.bridge.setCanvasLayers() self.canvas.zoomToFullExtent() self.project.write( QFileInfo( self.projectFileName ) ) if outputLayer.type() == QgsMapLayer.VectorLayer : WFSLayers = self.project.readListEntry( "WFSLayers", "/" )[0] if outputLayer.id() not in WFSLayers : WFSLayers.append( outputLayer.id() ) self.project.writeEntry( "WFSLayers", "/", WFSLayers ) self.project.write( QFileInfo( self.projectFileName ) ) return self.getMapServerWFS(output) elif outputLayer.type() == QgsMapLayer.RasterLayer : output.projection = outputLayer.crs().authid() output.height = outputLayer.height() output.width = outputLayer.width() outputExtent = outputLayer.extent() output.bbox = [outputExtent.xMinimum(), outputExtent.yMinimum(), outputExtent.xMaximum(), outputExtent.yMaximum()] WCSLayers = self.project.readListEntry( "WCSLayers", "/" )[0] if outputLayer.id() not in WCSLayers : WCSLayers.append( outputLayer.id() ) self.project.writeEntry( "WCSLayers", "/", WCSLayers ) self.project.write( QFileInfo( self.projectFileName ) ) return self.getMapServerWCS(output)
def getMapServerWFS(self,output): """Get the URL for mapserver WFS request of the output""" url = config.getConfigValue("qgis","qgisserveraddress")+"?map="+self.projectFileName+"&SERVICE=WFS"+ "&REQUEST=GetFeature"+ "&VERSION=1.0.0"+"&TYPENAME="+output.identifier if output.format["mimetype"] == 'application/json' : url+= "&OUTPUTFORMAT=GeoJSON" elif output.format["mimetype"] in ('text/xml; subtype=gml/3.1.1','application/gml+xml; version=3.1.1') : url+= "&OUTPUTFORMAT=GML3" else : url+= "&OUTPUTFORMAT=GML2" return url;
def getMapServerWFS(self, output): """Get the URL for qgis-server WFS request of the output""" url = config.getConfigValue("qgis", "qgisserveraddress") + "?map=" + self.projectFileName + \ "&SERVICE=WFS" + "&REQUEST=GetFeature" + \ "&VERSION=1.0.0" + "&TYPENAME=" + output.identifier if output.format["mimetype"] == 'application/json': url += "&OUTPUTFORMAT=GeoJSON" elif output.format["mimetype"] in ('text/xml; subtype=gml/3.1.1', 'application/gml+xml; version=3.1.1'): url += "&OUTPUTFORMAT=GML3" else: url += "&OUTPUTFORMAT=GML2" return url
def compressFeatureData(self, s_ftfile): """ @return: 1. the zip file path; 2. layer name at geoserver """ from osgeo import ogr def zipFiles(zipname, files, arcnames): assert len(files) == len(arcnames), "size of file names and rename container not equal" zipf = zipfile.ZipFile(zipname, 'w') for i in range(len(files)): if os.path.exists(files[i]): zipf.write(files[i], arcnames[i]) zipf = None ft = ogr.Open(s_ftfile) ftDrv = ft.GetDriver() sft = os.path.splitext(s_ftfile)[0] archive_files = [sft+'.shp', sft+'.shx', sft+'.prj', sft+'.dbf'] filename = os.path.split(sft)[1] arcnames = [filename +'.shp', filename +'.shx', filename+'.prj', filename +'.dbf'] logging.info("the driver of vector data {0} is {1}".format(s_ftfile, ftDrv.name)) if (ftDrv.name != "ESRI Shapefile"): tempshpf = os.path.join(config.getConfigValue('server', 'tempPath'),str(uuid.uuid4())) shpDrv = ogr.GetDriverByName("ESRI Shapefile") shpft = shpDrv.CopyDataSource(ft, tempshpf+'.shp') if not shpft: raise exceptions.IOError("{0} format vector data to shapefile format fault".format(s_ftfile)) # close the vector datasource ft = None shpft = None # zip shape files and delete them # create an defautl prj file for this shapefile if thereis not projection information if not os.path.exists(tempshpf+'.prj'): f = open(tempshpf+'.prj', 'w') f.write('GEOGCS["GCS_WGS_1984",DATUM["WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]') f.close() archive_files = [tempshpf+'.shp', tempshpf+'.shx', tempshpf+'.prj', tempshpf+'.dbf'] zipFiles(tempshpf+'.zip', archive_files, arcnames) for f in archive_files: if os.path.exists(f): os.remove(f) return tempshpf+'.zip', filename else: zipFiles(sft+'.zip', archive_files, arcnames) return sft+'.zip', filename
def setEnvVariable( key, env_var ): try: value = config.getConfigValue( "cds", key ) os.environ[ env_var ] = value setEnv( env_var, value ) logging.info("CDS environment variable %s set to %s" % ( env_var, value ) ) for identifier in [ 'path', 'library' ]: if identifier in env_var.lower(): for path in value.split(':'): if path not in sys.path: sys.path.append(path) logging.info("Adding %s to sys.path" % ( path ) ) except: logging.info("Error setting CDS environment variable %s" % ( env_var ) )
def __init__(self,wps): """ Arguments: self wps - parent WPS instance """ Request.__init__(self,wps) # # global variables # name = "".join(map(lambda x: x.capitalize(),config.getConfigValue("wps","title").split())) self.templateProcessor.set("name",name) self.templateProcessor.set("address",config.getConfigValue("wps","serveraddress")) # # Processes # #self.templateProcessor.set("Processes",self.processesDescription()) self.response = self.templateProcessor.__str__() return
def __init__(self,wps, processes=None): Request.__init__(self,wps,processes) self.wps = wps self.process = None # initialization self.statusTime = time.localtime() self.pid = os.getpid() self.status = None self.id = self.makeSessionId() self.outputFileName = os.path.join(config.getConfigValue("server","outputPath"),self.id+".xml") self.statusLocation = config.getConfigValue("server","outputUrl")+"/"+self.id+".xml" # rawDataOutput if len(self.wps.inputs["responseform"]["rawdataoutput"])>0: self.rawDataOutput = self.wps.inputs["responseform"]["rawdataoutput"].keys()[0] # is status required self.statusRequired = False if self.wps.inputs["responseform"]["responsedocument"].has_key("status"): if self.wps.inputs["responseform"]["responsedocument"]["status"]: self.statusRequired = True # is store response required ? self.storeRequired = False if self.wps.inputs["responseform"]["responsedocument"].has_key("storeexecuteresponse"): if self.wps.inputs["responseform"]["responsedocument"]["storeexecuteresponse"]: try: self.outputFile = open(self.outputFileName,"w") except Exception, e: traceback.print_exc(file=pywps.logFile) self.cleanEnv() raise pywps.NoApplicableCode(e.__str__()) self.storeRequired = True
def getServer(process, sessId): mapserver = config.getConfigValue("server","mapserverdriver") if mapserver: if mapserver == "geoserver": from pywps.Wps.Execute import GEOS return GEOS.GeoServer(process, sessId) elif mapserver == "mapserver": from pywps.Wps.Execute import UMN return UMN.UMN(process, sessId) else: return None else: return None
def serviceInstanceUrl(self): """Creates URL of GetCapabilities for this WPS :return: server address """ serveraddress = config.getConfigValue("wps", "serveraddress") if not serveraddress.endswith("?") and not serveraddress.endswith("&"): if serveraddress.find("?") > -1: serveraddress += "&" else: serveraddress += "?" serveraddress += "service=WPS&request=GetCapabilities&version=" + pywps.DEFAULT_VERSION serveraddress = serveraddress.replace("&", "&") # Must be done first! serveraddress = serveraddress.replace("<", "<") serveraddress = serveraddress.replace(">", ">") return serveraddress
def calculateMaxInputSize(self): """Calculates maximal size for input file based on configuration and units :return: maximum file size bytes """ maxSize = config.getConfigValue("server","maxfilesize") maxSize = maxSize.lower() units = re.compile("[gmkb].*") size = float(re.sub(units,'',maxSize)) if maxSize.find("g") > -1: size *= 1024*1024*1024 elif maxSize.find("m") > -1: size *= 1024*1024 elif maxSize.find("k") > -1: size *= 1024 else: size *= 1 return size
def save(self, output): MapServer.save(self, output) name = "%s-%s-%s" % (output.identifier, self.process.identifier, self.sessId) service_url = '/'.join([ config.getConfigValue('geoserver', 'geoserveraddress'), self.workspace.name ]) if self.datatype == "raster": # save logging.info("upload raster file with name: {0} ".format(name)) self.cat.create_coveragestore(name, output.value, self.workspace, False) # construct the wcs url return urllib2.quote('/'.join((service_url, 'wcs')) + "?SERVICE=WCS" + "&REQUEST=GetCoverage" + "&VERSION=1.0.0" + "&COVERAGE=" + name + "&CRS=" + output.projection + "&BBOX=%s,%s,%s,%s" % (output.bbox[0], output.bbox[1], output.bbox[2], output.bbox[3]) + "&HEIGHT=%s" % (output.height) + "&WIDTH=%s" % (output.width) + "&FORMAT=%s" % output.format["mimetype"]) elif self.datatype == "vector": #save logging.info("upload vector file with name: {0} ".format(name)) zip_shpf, lyname = self.compressFeatureData(output.value) self.cat.create_featurestore(name, zip_shpf, self.workspace, False) # construct the wfs url return urllib2.quote('/'.join((service_url, 'wfs')) + "?SERVICE=WFS" + "&REQUEST=GetFeature" + "&VERSION=1.0.0" + "&TYPENAME=" + lyname) else: return None
def __init__(self, wps, processes=None): """ Arguments: self wps - parent WPS instance """ Request.__init__(self, wps, processes) # # HEAD # self.templateProcessor.set("encoding", config.getConfigValue("wps", "encoding")) self.templateProcessor.set("lang", self.wps.inputs["language"]) # # Processes # self.templateProcessor.set("Processes", self.processesDescription()) self.response = self.templateProcessor.__str__() return
def __init__(self, process): if ((mapscript == False) or (gdal == False)): return tmp = os.path.basename(tempfile.mkstemp()[1]) self.pid = "%s-%s" % (os.getpid(), tmp) self.outputs = {} self.process = process self.mapObj = mapObj() #self.mapObj.setExtent(-180,-90,180,90) self.mapObj.setExtent(-20037508.34, -20037508.34, 20037508.34, 20037508.34) #self.mapObj.setProjection("+init=epsg:3857") self.mapObj.setProjection("+init=epsg:900913") #4326//epsg:3857 self.mapObj.name = "%s-%s" % (self.process.identifier, self.pid) self.mapObj.setMetaData("ows_title", config.getConfigValue("wps", "title")) self.mapObj.setMetaData("wms_abstract", config.getConfigValue("wps", "abstract")) self.mapObj.setMetaData("wcs_abstract", config.getConfigValue("wps", "abstract")) self.mapObj.setMetaData("wcs_label", process.title) self.mapObj.setMetaData("wms_srs", "EPSG:4326 EPSG:900913") self.mapObj.setMetaData("wfs_abstract", config.getConfigValue("wps", "abstract")) self.mapObj.setMetaData("ows_keywordlist", config.getConfigValue("wps", "keywords")) self.mapObj.setMetaData("ows_fees", config.getConfigValue("wps", "fees")) self.mapObj.setMetaData("ows_accessconstraints", config.getConfigValue("wps", "constraints")) self.mapObj.setMetaData( "ows_contactorganization", config.getConfigValue("provider", "providerName")) self.mapObj.setMetaData( "ows_contactperson", config.getConfigValue("provider", "individualName")) self.mapObj.setMetaData( "ows_contactposition", config.getConfigValue("provider", "positionName")) self.mapObj.setMetaData("ows_enable_request", "*") self.mapObj.debug = 5 self.mapObj.setFontSet( "/usr/share/fonts/truetype/msttcorefonts/fonts.txt") self.mapObj.setConfigOption("MS_ERRORFILE", "/var/www/html/pywps/mapserver.log") phone = config.getConfigValue("provider", "phoneVoice") if phone: self.mapObj.setMetaData( "ows_contactvoicetelephone", config.getConfigValue("provider", "phoneVoice")) phone = config.getConfigValue("provider", "phoneFacsimile") if phone: self.mapObj.setMetaData( "ows_contactfacsimiletelephone", config.getConfigValue("provider", "phoneFacsimile")) self.mapObj.setMetaData( "ows_address", config.getConfigValue("provider", "deliveryPoint")) self.mapObj.setMetaData("ows_city", config.getConfigValue("provider", "city")) self.mapObj.setMetaData("ows_country", config.getConfigValue("provider", "country")) self.mapObj.setMetaData( "ows_postcode", config.getConfigValue("provider", "postalCode")) self.mapObj.setMetaData( "ows_contactelectronicmailaddress", config.getConfigValue("provider", "electronicMailAddress")) self.mapObj.setMetaData("ows_role", config.getConfigValue("provider", "role")) self.mapFileName = os.path.join( config.getConfigValue("server", "outputPath"), "wps" + str(self.pid) + ".map") self.mapObj.setMetaData( "wms_onlineresource", config.getConfigValue("mapserver", "mapserveraddress") + "?map=" + self.mapFileName) # LEGEND OPTIONS self.label = legendObj() self.label.angle = 30 self.label.status = MS_ON #label.backgroundcolor.setHex('#00ff00') self.label.buffer = 15 self.label.imagecolor.setHex('#ff0000') self.label.font = "arial" self.label.force = MS_TRUE self.label.encoding = "utf8" self.label.mindistance = 15 self.label.minfeaturesize = 12 self.label.outlinecolor.setHex('#aa00aa') self.label.position = MS_AUTO self.label.priority = 5 self.label.size = 8 self.label.type = MS_TRUETYPE
def mkMapset(self, location=None): """ Create GRASS mapset in current directory. Mapsets name is 'mapset'. At the end, GRASS will believe, it has run correctly. Returns name of new created mapset. location!=None, this mapset should be deleted! Arguments: location - Should the new mapset be created in the some old location, which is already on this server? Default: only mapset within /tmp/grasstmpSOMEHTIN/ will be created """ if location == None: self.locationDir = self.executeRequest.workingDir self.mapsetDir = tempfile.mkdtemp(prefix="pywps", dir=self.locationDir) self.mapsetName = os.path.split(self.mapsetDir)[1] self.locationName = os.path.split(self.locationDir)[1] # create new WIND file self._windFile(self.mapsetName) # create mapset PERMANENT os.mkdir("PERMANENT") self._windFile("PERMANENT") self.gisdbase = os.path.split(os.path.abspath(os.path.curdir))[0] # location is here, we justhave to use it else: self.locationDir = os.path.join( config.getConfigValue("grass", "gisdbase"), location) self.mapsetDir = tempfile.mkdtemp(prefix="pywps", dir=self.locationDir) self.mapsetName = os.path.split(self.mapsetDir)[1] self.locationName = os.path.split(location)[-1] self.executeRequest.dirsToBeRemoved.append( os.path.abspath(self.mapsetDir)) # copy shutil.copy( os.path.join(self.locationDir, "PERMANENT", "DEFAULT_WIND"), os.path.join(self.mapsetDir, "WIND")) # export env. vars (self.gisdbase, location) = os.path.split(self.locationDir) # GRASS creates a temp dir for the display driver. # Add it to dirsToBeRemoved try: grassTmpDir = os.path.join(tempfile.gettempdir(), "grass"+config.getConfigValue("grass","version")[:1]+\ "-"+os.getenv("USERNAME")+\ "-"+str(os.getpid())) self.executeRequest.dirsToBeRemoved.append(grassTmpDir) except: pass self.setEnv('MAPSET', self.mapsetName) self.setEnv('LOCATION_NAME', self.locationName) self.setEnv('GISDBASE', self.gisdbase) # gisrc gisrc = open(os.path.join(self.executeRequest.workingDir, "grassrc"), "w") gisrc.write("LOCATION_NAME: %s\n" % self.locationName) gisrc.write("MAPSET: %s\n" % self.mapsetName) gisrc.write("DIGITIZER: none\n") gisrc.write("GISDBASE: %s\n" % self.gisdbase) gisrc.write("OVERWRITE: 1\n") gisrc.write("GRASS_GUI: text\n") gisrc.close() logging.info("GRASS MAPSET set to %s" % self.mapsetName) logging.info("GRASS LOCATION_NAME set to %s" % self.locationName) logging.info("GRASS GISDBASE set to %s" % self.gisdbase) self.setEnv("GISRC", os.path.join(self.executeRequest.workingDir, "grassrc")) logging.info("GRASS GISRC set to %s" % os.path.join(self.executeRequest.workingDir, "grassrc")) return self.mapsetName
def __init__(self, process, sessId): if ((mapscript == False) or (gdal == False)): return tmp = os.path.basename(tempfile.mkstemp()[1]) self.outputs = {} self.process = process self.sessionId = sessId self.projs = self.getProjs() self.mapObj = mapObj() self.mapObj.setExtent(-180, -90, 180, 90) # irrelevant for WCS/WFS #self.mapObj.setProjection("+init=%s" % self.projs[0]) self.mapObj.name = "%s-%s" % (self.process.identifier, self.sessionId) self.mapObj.setMetaData("ows_title", config.getConfigValue("wps", "title")) self.mapObj.setMetaData("wms_abstract", config.getConfigValue("wps", "abstract")) self.mapObj.setMetaData("wcs_abstract", config.getConfigValue("wps", "abstract")) self.mapObj.setMetaData("wcs_label", process.title) self.mapObj.setMetaData("wfs_abstract", config.getConfigValue("wps", "abstract")) self.mapObj.setMetaData("ows_keywordlist", config.getConfigValue("wps", "keywords")) self.mapObj.setMetaData("ows_fees", config.getConfigValue("wps", "fees")) self.mapObj.setMetaData("ows_accessconstraints", config.getConfigValue("wps", "constraints")) self.mapObj.setMetaData( "ows_contactorganization", config.getConfigValue("provider", "providerName")) self.mapObj.setMetaData( "ows_contactperson", config.getConfigValue("provider", "individualName")) self.mapObj.setMetaData( "ows_contactposition", config.getConfigValue("provider", "positionName")) self.mapObj.setMetaData("ows_enable_request", "*") self.mapObj.debug = 5 self.mapObj.setConfigOption("MS_ERRORFILE", "stderr") phone = config.getConfigValue("provider", "phoneVoice") if phone: self.mapObj.setMetaData( "ows_contactvoicetelephone", config.getConfigValue("provider", "phoneVoice")) phone = config.getConfigValue("provider", "phoneFacsimile") if phone: self.mapObj.setMetaData( "ows_contactfacsimiletelephone", config.getConfigValue("provider", "phoneFacsimile")) self.mapObj.setMetaData( "ows_address", config.getConfigValue("provider", "deliveryPoint")) self.mapObj.setMetaData("ows_city", config.getConfigValue("provider", "city")) self.mapObj.setMetaData("ows_country", config.getConfigValue("provider", "country")) self.mapObj.setMetaData( "ows_postcode", config.getConfigValue("provider", "postalCode")) self.mapObj.setMetaData( "ows_contactelectronicmailaddress", config.getConfigValue("provider", "electronicMailAddress")) self.mapObj.setMetaData("ows_role", config.getConfigValue("provider", "role")) self.mapFileName = os.path.join( config.getConfigValue("server", "outputPath"), self.sessionId + ".map") self.mapObj.setMetaData( "wms_onlineresource", config.getConfigValue("mapserver", "mapserveraddress") + "?map=" + self.mapFileName)
def getMapServerWFS(self, output): """Get the URL for mapserver WFS request of the output""" return urllib2.quote( config.getConfigValue("mapserver", "mapserveraddress") + "?map=" + self.mapFileName + "&SERVICE=WFS" + "&REQUEST=GetFeature" + "&VERSION=1.0.0" + "&TYPENAME=" + output.identifier)
if not inputQuery: err = NoApplicableCode("No query string found.") pywps.response.response(err, sys.stdout) sys.exit(1) else: inputQuery = sys.stdin # create the WPS object wps = None try: # Get or define user_folder config.loadConfiguration() user_folder = os.path.dirname(os.path.abspath( inspect.getfile(inspect.currentframe()))) if config.config.has_option('qgis', 'user_folder'): user_folder = config.getConfigValue('qgis', 'user_folder') # init QgsApplication QgsApplication(sys.argv, False, user_folder) # supply path to where is your qgis installed QgsApplication.setPrefixPath(config.getConfigValue("qgis", "prefix"), True) # load providers QgsApplication.initQgis() # initialize application qa = QApplication(sys.argv) wps = pywps.Pywps(method) if wps.parseRequest(inputQuery): pywps.debug(wps.inputs) response = wps.performRequest()
def compressFeatureData(self, s_ftfile): """ @return: 1. the zip file path; 2. layer name at geoserver """ from osgeo import ogr def zipFiles(zipname, files, arcnames): assert len(files) == len( arcnames), "size of file names and rename container not equal" zipf = zipfile.ZipFile(zipname, 'w') for i in range(len(files)): if os.path.exists(files[i]): zipf.write(files[i], arcnames[i]) zipf = None ft = ogr.Open(s_ftfile) ftDrv = ft.GetDriver() sft = os.path.splitext(s_ftfile)[0] archive_files = [ sft + '.shp', sft + '.shx', sft + '.prj', sft + '.dbf' ] filename = os.path.split(sft)[1] arcnames = [ filename + '.shp', filename + '.shx', filename + '.prj', filename + '.dbf' ] logging.info("the driver of vector data {0} is {1}".format( s_ftfile, ftDrv.name)) if (ftDrv.name != "ESRI Shapefile"): tempshpf = os.path.join( config.getConfigValue('server', 'tempPath'), str(uuid.uuid4())) shpDrv = ogr.GetDriverByName("ESRI Shapefile") shpft = shpDrv.CopyDataSource(ft, tempshpf + '.shp') if not shpft: raise exceptions.IOError( "{0} format vector data to shapefile format fault".format( s_ftfile)) # close the vector datasource ft = None shpft = None # zip shape files and delete them # create an defautl prj file for this shapefile if thereis not projection information if not os.path.exists(tempshpf + '.prj'): f = open(tempshpf + '.prj', 'w') f.write( 'GEOGCS["GCS_WGS_1984",DATUM["WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]' ) f.close() archive_files = [ tempshpf + '.shp', tempshpf + '.shx', tempshpf + '.prj', tempshpf + '.dbf' ] zipFiles(tempshpf + '.zip', archive_files, arcnames) for f in archive_files: if os.path.exists(f): os.remove(f) return tempshpf + '.zip', filename else: zipFiles(sft + '.zip', archive_files, arcnames) return sft + '.zip', filename
def __init__(self, process, sessId): tmp = os.path.basename(tempfile.mkstemp()[1]) self.outputs = {} self.process = process self.sessionId = sessId self.project = QgsProject.instance() treeRoot = self.project.layerTreeRoot() model = QgsLayerTreeModel(treeRoot) view = QgsLayerTreeView() view.setModel(model) self.canvas = QgsMapCanvas() self.canvas.setCrsTransformEnabled(True) self.bridge = QgsLayerTreeMapCanvasBridge(treeRoot, self.canvas) self.project.writeProject.connect(self.bridge.writeProject) self.project.writeProject.connect(self.__writeProject__) self.projectFileName = os.path.join( config.getConfigValue("server", "outputPath"), self.sessionId + ".qgs") if os.path.exists(self.projectFileName): self.project.read(QFileInfo(self.projectFileName)) else: self.project.writePath(self.projectFileName) self.project.setTitle("%s-%s" % (self.process.identifier, self.sessionId)) self.project.writeEntry("WMSServiceCapabilities", "/", True) self.project.writeEntry("WMSServiceTitle", "/", config.getConfigValue("wps", "title")) self.project.writeEntry("WMSServiceAbstract", "/", config.getConfigValue("wps", "abstract")) self.project.writeEntry("WMSKeywordList", "/", config.getConfigValue("wps", "keywords")) self.project.writeEntry("WMSFees", "/", config.getConfigValue("wps", "fees")) self.project.writeEntry("WMSAccessConstraints", "/", config.getConfigValue("wps", "constraints")) self.project.writeEntry( "WMSContactOrganization", "/", config.getConfigValue("provider", "providerName")) self.project.writeEntry( "WMSContactPerson", "/", config.getConfigValue("provider", "individualName")) self.project.writeEntry( "WMSContactPhone", "/", config.getConfigValue("provider", "phoneVoice")) self.project.writeEntry( "WMSContactPhone", "/", config.getConfigValue("provider", "electronicMailAddress")) if config.config.has_section('qgis') and config.config.has_option( 'qgis', 'output_ows_crss'): outputOWSCRSs = config.getConfigValue('qgis', 'output_ows_crss') outputOWSCRSs = outputOWSCRSs.split(',') outputOWSCRSs = [proj.strip().upper() for proj in outputOWSCRSs] self.project.writeEntry("WMSCrsList", "/", outputOWSCRSs) else: self.project.writeEntry("WMSCrsList", "/", ['EPSG:4326', 'EPSG:3857']) self.project.write(QFileInfo(self.projectFileName))
def getReference(self, output): if output.format["mimetype"] in ('text/csv', 'application/x-zipped-shp', 'application/x-zipped-tab'): return None mlr = QgsMapLayerRegistry.instance() logging.info('getReference: ' + output.identifier + ' ' + output.value) layersByName = mlr.mapLayersByName(output.identifier) outputLayer = None if not layersByName: outputLayer = QgsRasterLayer(output.value, output.identifier, 'gdal') if not outputLayer.isValid(): outputLayer = QgsVectorLayer(output.value, output.identifier, 'ogr') mlr.addMapLayer(outputLayer) else: outputLayer = layersByName[0] # Update CRS if not outputLayer.dataProvider().crs().authid() and output.projection: outputLayer.setCrs(QgsCoordinateReferenceSystem(output.projection)) treeRoot = self.project.layerTreeRoot() if config.config.has_section('qgis') and config.config.has_option( 'qgis', 'output_ows_crss'): outputOWSCRSs = config.getConfigValue('qgis', 'output_ows_crss') outputOWSCRSs = outputOWSCRSs.split(',') outputOWSCRSs = [proj.strip().upper() for proj in outputOWSCRSs] self.canvas.setDestinationCrs( QgsCoordinateReferenceSystem(outputOWSCRSs[0])) else: self.canvas.setDestinationCrs( QgsCoordinateReferenceSystem('EPSG:4326')) if not treeRoot.findLayer(outputLayer.id()): treeRoot.addLayer(outputLayer) self.bridge.setCanvasLayers() self.canvas.zoomToFullExtent() self.project.write(QFileInfo(self.projectFileName)) if outputLayer.type() == QgsMapLayer.VectorLayer: WFSLayers = self.project.readListEntry("WFSLayers", "/")[0] if outputLayer.id() not in WFSLayers: WFSLayers.append(outputLayer.id()) self.project.writeEntry("WFSLayers", "/", WFSLayers) self.project.write(QFileInfo(self.projectFileName)) if output.format['mimetype'] in ('application/x-ogc-wms', 'application/x-ogc-wfs'): return self.getCapabilities(output) return self.getMapServerWFS(output) elif outputLayer.type() == QgsMapLayer.RasterLayer: output.projection = outputLayer.crs().authid() output.height = outputLayer.height() output.width = outputLayer.width() outputExtent = outputLayer.extent() output.bbox = [ outputExtent.xMinimum(), outputExtent.yMinimum(), outputExtent.xMaximum(), outputExtent.yMaximum() ] WCSLayers = self.project.readListEntry("WCSLayers", "/")[0] if outputLayer.id() not in WCSLayers: WCSLayers.append(outputLayer.id()) self.project.writeEntry("WCSLayers", "/", WCSLayers) self.project.write(QFileInfo(self.projectFileName)) if output.format['mimetype'] in ('application/x-ogc-wms', 'application/x-ogc-wcs'): return self.getCapabilities(output) return self.getMapServerWCS(output)
def __init__(self, wps, processes=None): """ """ Request.__init__(self, wps, processes) # # ServiceIdentification # self.templateProcessor.set("encoding", config.getConfigValue("wps", "encoding")) self.templateProcessor.set("lang", self.wps.inputs["language"]) self.templateProcessor.set("servertitle", config.getConfigValue("wps", "title")) self.templateProcessor.set("serverabstract", config.getConfigValue("wps", "abstract")) keywordList = [] for keyword in config.getConfigValue("wps", "keywords").split(','): keywordList.append({'keyword': keyword.strip()}) self.templateProcessor.set("Keywords", keywordList) self.templateProcessor.set("Versions", [{'version': config.getConfigValue("wps", "version")}]) self.templateProcessor.set("fees", config.getConfigValue("wps", "fees")) self.templateProcessor.set("constraints", config.getConfigValue("wps", "constraints")) self.templateProcessor.set("url", config.getConfigValue("wps", "serveraddress")) # # ServiceProvider # self.templateProcessor.set("providername", config.getConfigValue("provider", "providerName")) self.templateProcessor.set("individualname", config.getConfigValue("provider", "individualName")) self.templateProcessor.set("positionname", config.getConfigValue("provider", "positionName")) self.templateProcessor.set("providersite", config.getConfigValue("provider", "providerSite")) # phone if config.getConfigValue("provider", "phoneVoice") or \ config.getConfigValue("provider", "phoneFacsimile"): self.templateProcessor.set("phone", 1) if config.getConfigValue("provider", "phoneVoice"): self.templateProcessor.set("phonevoice", config.getConfigValue("provider", "phoneVoice")) if config.getConfigValue("provider", "phoneFacsimile"): self.templateProcessor.set("phonefacsimile", config.getConfigValue("provider", "phoneFacsimile")) else: self.templateProcessor.set("phone", 0) # address if config.getConfigValue("provider", "deliveryPoint") or \ config.getConfigValue("provider", "city") or \ config.getConfigValue("provider", "administrativeArea") or \ config.getConfigValue("provider", "postalCode") or \ config.getConfigValue("provider", "country") or \ config.getConfigValue("provider", "electronicMailAddress"): self.templateProcessor.set("address", 1) if config.getConfigValue("provider", "deliveryPoint"): self.templateProcessor.set("deliverypoint", config.getConfigValue("provider", "deliveryPoint")) if config.getConfigValue("provider", "city"): self.templateProcessor.set("city", config.getConfigValue("provider", "city")) if config.getConfigValue("provider", "administrativeArea"): self.templateProcessor.set("administrativearea", config.getConfigValue("provider", "administrativeArea")) if config.getConfigValue("provider", "postalCode"): self.templateProcessor.set("postalcode", config.getConfigValue("provider", "postalCode")) if config.getConfigValue("provider", "country"): self.templateProcessor.set("country", config.getConfigValue("provider", "country")) if config.getConfigValue("provider", "electronicMailAddress"): self.templateProcessor.set("electronicmailaddress", config.getConfigValue("provider", "electronicMailAddress")) else: self.templateProcessor.set("address", 0) # other ContactInfo if config.getConfigValue("provider", "role"): self.templateProcessor.set("role", config.getConfigValue("provider", "role")) if config.getConfigValue("provider", "hoursofservice"): self.templateProcessor.set("hoursofservice", config.getConfigValue("provider", "hoursofservice")) if config.getConfigValue("provider", "contactinstructions"): self.templateProcessor.set("contactinstructions", config.getConfigValue("provider", "contactinstructions")) # OperationsMetadata self.templateProcessor.set("Operations", [{"operation": "GetCapabilities", "url": config.getConfigValue("wps", "serveraddress")}, {"operation": "DescribeProcess", "url": config.getConfigValue("wps", "serveraddress")}, {"operation": "Execute", "url": config.getConfigValue("wps", "serveraddress")}]) # Processes processesData = [] for process in self.getProcesses("all"): processData = {} if type(process) == types.InstanceType: process.lang.setCode(self.wps.inputs["language"]) processData["processok"] = 1 processData["identifier"] = process.identifier processData["processversion"] = process.version processData["title"] = process.i18n(process.title) if process.abstract: processData["abstract"] = process.i18n(process.abstract) if process.metadata: processData["Metadata"] = self.formatMetadata(process) if process.profile: profiles = [] if type(process.profile) == types.ListType: for profile in process.profile: profiles.append({"profile": profile}) else: profiles.append({"profile": process.profile}) processData["Profiles"] = profiles if process.wsdl: processData["wsdl"] = process.wsdl else: processData["processok"] = 0 processData["process"] = repr(process) processesData.append(processData) self.templateProcessor.set("Processes", processesData) # Language self.templateProcessor.set("defaultlanguage", pywps.DEFAULT_LANG) languages = [] for lang in self.wps.languages: languages.append({"language": lang}) self.templateProcessor.set("Languages", languages) self.response = self.templateProcessor.__str__() return
def responseComplete(self): QgsMessageLog.logMessage("wpsFilter.responseComplete") request = self.serverInterface().requestHandler() params = request.parameterMap() service = params.get('SERVICE', '') if service and service.upper() == 'WPS': # prepare query inputQuery = '&'.join([ "%s=%s" % (k, params[k]) for k in params if k.lower() != 'map' and k.lower() != 'config' and k.lower != 'request_body' ]) request_body = params.get('REQUEST_BODY', '') # get config configPath = os.getenv("PYWPS_CFG") if not configPath and 'config' in params: configPath = params['config'] elif not configPath and 'CONFIG' in params: configPath = params['CONFIG'] QgsMessageLog.logMessage("configPath " + str(configPath)) if configPath: os.environ["PYWPS_CFG"] = configPath pywpsConfig.loadConfiguration() try: providerList = '' algList = '' algsFilter = '' if pywpsConfig.config.has_section('qgis'): # get the providers to publish if pywpsConfig.config.has_option('qgis', 'providers'): providerList = pywpsConfig.getConfigValue( 'qgis', 'providers') if providerList: providerList = providerList.split(',') # get the algorithm list to publish if pywpsConfig.config.has_option('qgis', 'algs'): algList = pywpsConfig.getConfigValue('qgis', 'algs') if algList: algList = algList.split(',') # get the algorithm filter if pywpsConfig.config.has_option('qgis', 'algs_filter'): algsFilter = pywpsConfig.getConfigValue( 'qgis', 'algs_filter') # init Processing Processing.initialize() # load QGIS Processing config if pywpsConfig.config.has_section('qgis_processing'): for opt in pywpsConfig.config.options('qgis_processing'): opt_val = pywpsConfig.getConfigValue( 'qgis_processing', opt) ProcessingConfig.setSettingValue(opt.upper(), opt_val) # Reload algorithms Processing.loadAlgorithms() # modify processes path and reload algorithms if pywpsConfig.config.has_section( 'qgis') and pywpsConfig.config.has_option( 'qgis', 'processing_folder'): processingPath = pywpsConfig.getConfigValue( 'qgis', 'processing_folder') if not os.path.exists(processingPath): if configPath and os.path.exists(configPath): processingPath = os.path.join( os.path.dirname(configPath), processingPath) processingPath = os.path.abspath(processingPath) else: configFilesLocation = pywpsConfig._getDefaultConfigFilesLocation( ) for configFileLocation in configFilesLocation: if os.path.exists(configFileLocation): processingPath = os.path.join( os.path.dirname(configFileLocation), processingPath) processingPath = os.path.abspath( processingPath) QgsMessageLog.logMessage("processing_folder: " + processingPath) if os.path.exists(processingPath) and os.path.isdir( processingPath): ProcessingConfig.setSettingValue( 'MODELS_FOLDER', os.path.join(processingPath, 'models')) ProcessingConfig.setSettingValue( 'SCRIPTS_FOLDER', os.path.join(processingPath, 'scripts')) ProcessingConfig.setSettingValue( 'R_SCRIPTS_FOLDER', os.path.join(processingPath, 'rscripts')) # Reload algorithms Processing.loadAlgorithms() crsList = [] if pywpsConfig.config.has_section( 'qgis') and pywpsConfig.config.has_option( 'qgis', 'input_bbox_crss'): inputBBoxCRSs = pywpsConfig.getConfigValue( 'qgis', 'input_bbox_crss') inputBBoxCRSs = inputBBoxCRSs.split(',') crsList = [proj.strip().upper() for proj in inputBBoxCRSs] # get QGIS project path projectPath = os.getenv("QGIS_PROJECT_FILE") if not projectPath and 'map' in params: projectPath = params['map'] elif not projectPath and 'MAP' in params: projectPath = params['MAP'] #projectFolder projectFolder = '' if projectPath and os.path.exists(projectPath): projectFolder = os.path.dirname(projectPath) QgsMessageLog.logMessage("projectPath " + str(projectPath)) rasterLayers = [] vectorLayers = [] if projectPath and os.path.exists(projectPath): p_dom = minidom.parse(projectPath) for ml in p_dom.getElementsByTagName('maplayer'): l = { 'type': ml.attributes["type"].value, 'name': ml.getElementsByTagName( 'layername')[0].childNodes[0].data, 'datasource': ml.getElementsByTagName( 'datasource')[0].childNodes[0].data, 'provider': ml.getElementsByTagName( 'provider')[0].childNodes[0].data, 'crs': ml.getElementsByTagName( 'srs')[0].getElementsByTagName( 'authid')[0].childNodes[0].data, 'proj4': ml.getElementsByTagName('srs')[0]. getElementsByTagName('proj4')[0].childNodes[0].data } # Update relative path if l['provider'] in ['ogr', 'gdal'] and str( l['datasource']).startswith('.'): l['datasource'] = os.path.abspath( os.path.join(projectFolder, l['datasource'])) if not os.path.exists(l['datasource']): continue elif l['provider'] in ['gdal'] and str( l['datasource']).startswith('NETCDF:'): theURIParts = l['datasource'].split(":") src = theURIParts[1] src = src.replace('"', '') if src.startswith('.'): src = os.path.abspath( os.path.join(projectFolder, src)) theURIParts[1] = '"' + src + '"' l['datasource'] = ':'.join(theURIParts) if l['type'] == "raster": rasterLayers.append(l) elif l['type'] == "vector": l['geometry'] = ml.attributes["geometry"].value vectorLayers.append(l) deafultCrs = '' for mapcanvas in p_dom.getElementsByTagName('mapcanvas'): for destinationsrs in mapcanvas.getElementsByTagName( 'destinationsrs'): for authid in destinationsrs.getElementsByTagName( 'authid'): defaultCrs = authid.childNodes[0].data crsList.append(defaultCrs) for wmsCrsList in p_dom.getElementsByTagName('WMSCrsList'): for wmsCrs in wmsCrsList.getElementsByTagName('value'): wmsCrsValue = wmsCrs.childNodes[0].data if wmsCrsValue and wmsCrsValue != defaultCrs: crsList.append(wmsCrsValue) processes = [ None ] # if no processes found no processes return (deactivate default pywps process) identifier = params.get('IDENTIFIER', '').lower() for i in Processing.algs: if providerList and i not in providerList: continue QgsMessageLog.logMessage("provider " + i + " " + str(len(Processing.algs[i]))) for m in Processing.algs[i]: if identifier and identifier != m: continue if algList and m not in algList: continue if algsFilter: alg = Processing.getAlgorithm(m) if algsFilter.lower() not in alg.name.lower( ) and algsFilter.lower() not in m.lower(): continue QgsMessageLog.logMessage("provider " + i + " " + m) processes.append( QGISProcessFactory(m, projectPath, vectorLayers, rasterLayers, crsList)) #pywpsConfig.setConfigValue("server","outputPath", '/tmp/wpsoutputs') #pywpsConfig.setConfigValue("server","logFile", '/tmp/pywps.log') qgisaddress = self.serverInterface().getEnv( 'SERVER_NAME') + self.serverInterface().getEnv( 'SCRIPT_NAME') if self.serverInterface().getEnv('HTTPS'): qgisaddress = 'https://' + qgisaddress else: qgisaddress = 'http://' + qgisaddress qgisaddress = qgisaddress + '?' if 'map' in params: qgisaddress = qgisaddress + 'map=' + params['map'] + '&' elif 'MAP' in params: qgisaddress = qgisaddress + 'MAP=' + params['MAP'] + '&' if 'config' in params: qgisaddress = qgisaddress + 'config=' + params[ 'config'] + '&' elif 'CONFIG' in params: qgisaddress = qgisaddress + 'CONFIG=' + params[ 'CONFIG'] + '&' #pywpsConfig.setConfigValue("wps","serveraddress", qgisaddress) QgsMessageLog.logMessage("qgisaddress " + qgisaddress) #pywpsConfig.setConfigValue("qgis","qgisserveraddress", qgisaddress) # init wps method = 'GET' if request_body: method = 'POST' QgsMessageLog.logMessage("method " + method) wps = pywps.Pywps(method) # create the request file for POST request if request_body: tmpPath = pywpsConfig.getConfigValue("server", "tempPath") requestFile = open( os.path.join(tmpPath, "request-" + str(wps.UUID)), "w") requestFile.write(str(request_body)) requestFile.close() requestFile = open( os.path.join(tmpPath, "request-" + str(wps.UUID)), "r") inputQuery = requestFile if wps.parseRequest(inputQuery): try: response = wps.performRequest(processes=processes) if response: request.clearHeaders() request.clearBody() #request.setHeader('Content-type', 'text/xml') QgsMessageLog.logMessage("contentType " + wps.request.contentType) request.setInfoFormat(wps.request.contentType) resp = wps.response if not pywpsConfig.getConfigValue( "wps", "serveraddress" ) and wps.request.contentType == 'application/xml': import re import xml.sax.saxutils as saxutils resp = re.sub( r'Get xlink:href=".*"', 'Get xlink:href="' + saxutils.escape(qgisaddress) + '"', resp) resp = re.sub( r'Post xlink:href=".*"', 'Post xlink:href="' + saxutils.escape(qgisaddress) + '"', resp) elif pywpsConfig.getConfigValue( "wps", "serveraddress" ) and wps.request.contentType == 'application/xml': import re m = re.search(r'Get xlink:href="(.*)"', resp) if m and m.group(1).count('?') == 2: import xml.sax.saxutils as saxutils resp = re.sub( r'Get xlink:href=".*"', 'Get xlink:href="' + m.group(1)[:-1] + saxutils.escape('&') + '"', resp) # test response type if isinstance(resp, file): request.appendBody(resp.read()) else: request.appendBody(resp) else: QgsMessageLog.logMessage("no response") except: QgsMessageLog.logMessage("Exception perform request") else: QgsMessageLog.logMessage("parseRequest False") except WPSException as e: QgsMessageLog.logMessage("WPSException: " + str(e)) request.clearHeaders() #request.setHeader('Content-type', 'text/xml') request.clearBody() request.setInfoFormat('text/xml') request.appendBody(str(e)) except Exception as e: QgsMessageLog.logMessage("Exception: " + str(e)) request.clearHeaders() #request.setHeader('Content-type', 'text/xml') request.clearBody() request.setInfoFormat('text/xml') request.appendBody(str(e))
def process_init(self): # Automatically init the process attributes WPSProcess.__init__( self, identifier=alg_name, # must be same, as filename title=escape(alg.name).replace('\\', ''), version="0.1", storeSupported="true", statusSupported="true", abstract=algDesc, grassLocation=False) self.alg = alg # Test parameters if not len(self.alg.parameters): self.alg.defineCharacteristics() # Get parameters description algParamDescs = alg.getParameterDescriptions() # Add I/O i = 1 for parm in alg.parameters: minOccurs = 1 if getattr(parm, 'optional', False): minOccurs = 0 parmDesc = '' if algParamDescs and parm.name in algParamDescs: parmDesc = algParamDescs[parm.name] parmDesc = '<![CDATA[' + parmDesc + ']]>' # TODO: create "LiteralValue", "ComplexValue" or "BoundingBoxValue" # this can be done checking the class: # parm.__class__, one of # ['Parameter', 'ParameterBoolean', 'ParameterCrs', 'ParameterDataObject', 'ParameterExtent', 'ParameterFile', 'ParameterFixedTable', 'ParameterMultipleInput', 'ParameterNumber', 'ParameterRange', 'ParameterRaster', 'ParameterSelection', 'ParameterString', 'ParameterTable','ParameterTableField', 'ParameterVector'] if parm.__class__.__name__ == 'ParameterVector': values = [] if vectorLayers and ParameterVector.VECTOR_TYPE_ANY in parm.shapetype: values = [l['name'] for l in vectorLayers] elif vectorLayers: if ParameterVector.VECTOR_TYPE_POINT in parm.shapetype: values += [ l['name'] for l in vectorLayers if l['geometry'] == 'Point' ] if ParameterVector.VECTOR_TYPE_LINE in parm.shapetype: values += [ l['name'] for l in vectorLayers if l['geometry'] == 'Line' ] if ParameterVector.VECTOR_TYPE_POLYGON in parm.shapetype: values += [ l['name'] for l in vectorLayers if l['geometry'] == 'Polygon' ] if values: self._inputs['Input%s' % i] = self.addLiteralInput( escape(parm.name), escape(parm.description).replace('\\', ''), parmDesc, minOccurs=minOccurs, type=types.StringType) self._inputs['Input%s' % i].values = values else: self._inputs['Input%s' % i] = self.addComplexInput( escape(parm.name), escape(parm.description).replace('\\', ''), parmDesc, minOccurs=minOccurs, formats=[{ 'mimeType': 'text/xml' }]) elif parm.__class__.__name__ == 'ParameterRaster': if rasterLayers: self._inputs['Input%s' % i] = self.addLiteralInput( escape(parm.name), escape(parm.description).replace('\\', ''), parmDesc, minOccurs=minOccurs, type=types.StringType) self._inputs['Input%s' % i].values = [l['name'] for l in rasterLayers] else: self._inputs['Input%s' % i] = self.addComplexInput( escape(parm.name), escape(parm.description).replace('\\', ''), parmDesc, minOccurs=minOccurs, formats=[{ 'mimeType': 'image/tiff' }]) elif parm.__class__.__name__ == 'ParameterTable': self._inputs['Input%s' % i] = self.addComplexInput( escape(parm.name), escape(parm.description).replace('\\', ''), parmDesc, minOccurs=minOccurs, formats=[{ 'mimeType': 'text/csv' }]) elif parm.__class__.__name__ == 'ParameterExtent': self._inputs['Input%s' % i] = self.addBBoxInput( escape(parm.name), escape(parm.description).replace('\\', ''), parmDesc, minOccurs=minOccurs) # Add supported CRSs from project or config if crss: self._inputs['Input%s' % i].crss = crss elif parm.__class__.__name__ == 'ParameterSelection': self._inputs['Input%s' % i] = self.addLiteralInput( escape(parm.name), escape(parm.description).replace('\\', ''), parmDesc, minOccurs=minOccurs, type=types.StringType, default=getattr(parm, 'default', None)) self._inputs['Input%s' % i].values = parm.options elif parm.__class__.__name__ == 'ParameterRange': tokens = parm.default.split(',') n1 = float(tokens[0]) n2 = float(tokens[1]) self._inputs['Input%s' % i] = self.addLiteralInput( escape(parm.name), escape(parm.description).replace('\\', ''), parmDesc, minOccurs=minOccurs, type=types.FloatType, default=n1) self._inputs['Input%s' % i].values = ((n1, n2)) else: type = types.StringType if parm.__class__.__name__ == 'ParameterBoolean': type = types.BooleanType elif parm.__class__.__name__ == 'ParameterNumber': type = types.FloatType self._inputs['Input%s' % i] = self.addLiteralInput( escape(parm.name), escape(parm.description).replace('\\', ''), parmDesc, minOccurs=minOccurs, type=type, default=getattr(parm, 'default', None)) if parm.__class__.__name__ == 'ParameterBoolean': self._inputs['Input%s' % i].values = (True, False) i += 1 i = 1 for parm in alg.outputs: # TODO: create "LiteralOutput", "ComplexOutput" or "BoundingBoxOutput" # this can be done checking the class: # parm.__class__, one of # ['Output', 'OutputDirectory', 'OutputExtent', 'OutputFile', 'OutputHtml', 'OutputNumber', 'OutputRaster', 'OutputString', 'OutputTable', 'OutputVector'] if parm.__class__.__name__ == 'OutputVector': outputFormats = [{ 'mimeType': 'text/xml', 'encoding': 'utf-8' }, { 'mimeType': 'text/xml; subtype=gml/2.1.2', 'encoding': 'utf-8' }, { 'mimeType': 'text/xml; subtype=gml/3.1.1', 'encoding': 'utf-8' }, { 'mimeType': 'application/gml+xml', 'encoding': 'utf-8' }, { 'mimeType': 'application/gml+xml; version=2.1.2', 'encoding': 'utf-8' }, { 'mimeType': 'application/gml+xml; version=3.1.1', 'encoding': 'utf-8' }, { 'mimeType': 'application/json', 'encoding': 'utf-8' }, { 'mimeType': 'application/x-zipped-shp', 'encoding': 'utf-8' }, { 'mimeType': 'application/x-zipped-tab', 'encoding': 'utf-8' }, { 'mimeType': 'application/x-ogc-wms', 'encoding': 'utf-8' }, { 'mimeType': 'application/x-ogc-wfs', 'encoding': 'utf-8' }] if pywpsConfig.config.has_option('qgis', 'outputs_minetypes_vector'): outputsMimetypes = pywpsConfig.getConfigValue( 'qgis', 'outputs_minetypes_vector').strip() if outputsMimetypes: outputsMimetypes = outputsMimetypes.split(',') outputFormats = [{ 'mimeType': m.strip(), 'encoding': 'utf-8' } for m in outputsMimetypes] self._outputs['Output%s' % i] = self.addComplexOutput( parm.name, parm.description, formats=outputFormats) if pywpsConfig.getConfigValue("qgis", "qgisserveraddress"): self._outputs['Output%s' % i].useQgisServer = True elif parm.__class__.__name__ == 'OutputRaster': outputFormats = [{ 'mimeType': 'image/tiff' }, { 'mimeType': 'application/x-ogc-wms', 'encoding': 'utf-8' }, { 'mimeType': 'application/x-ogc-wcs', 'encoding': 'utf-8' }] if pywpsConfig.config.has_option('qgis', 'outputs_minetypes_raster'): outputsMimetypes = pywpsConfig.getConfigValue( 'qgis', 'outputs_minetypes_raster').strip() if outputsMimetypes: outputsMimetypes = outputsMimetypes.split(',') outputFormats = [{ 'mimeType': m.strip(), 'encoding': 'utf-8' } for m in outputsMimetypes] self._outputs['Output%s' % i] = self.addComplexOutput( parm.name, parm.description, formats=outputFormats) if pywpsConfig.getConfigValue("qgis", "qgisserveraddress"): self._outputs['Output%s' % i].useQgisServer = True elif parm.__class__.__name__ == 'OutputTable': self._outputs['Output%s' % i] = self.addComplexOutput( parm.name, parm.description, formats=[{ 'mimeType': 'text/csv' }]) elif parm.__class__.__name__ == 'OutputHtml': self._outputs['Output%s' % i] = self.addComplexOutput( parm.name, parm.description, formats=[{ 'mimeType': 'text/html' }]) elif parm.__class__.__name__ == 'OutputExtent': self._outputs['Output%s' % i] = self.addBBoxOutput( parm.name, parm.description) else: type = types.StringType if parm.__class__.__name__ == 'OutputNumber': type = types.FloatType self._outputs['Output%s' % i] = self.addLiteralOutput( parm.name, parm.description, type=type) i += 1 for k in self._inputs: setattr(self, k, self._inputs[k]) for k in self._outputs: setattr(self, k, self._outputs[k])