source: trunk/zoo-project/zoo-services/data-api/service.py @ 952

Last change on this file since 952 was 743, checked in by djay, 9 years ago

Add WCPS-Proxy, data-api proxy and update Makefile for dealing with specific location of fastcgi. Add status update for contour lines computation.

  • Property svn:keywords set to Id
File size: 1.5 KB
RevLine 
[743]1#!/usr/bin/python
2
3import zoo
4
5import logging
6import logging.config
7import sys
8import errno
9import os
10import json
11import geojson
12import csv
13import argparse
14
15from publicamundi.data.api import *
16
17ERROR_OK = 0
18ERROR_UNKNOWN = 1
19
20def configure_logging(filename):
21    if filename is None:
22        print 'Logging is not configured.'
23    else:
24        logging.config.fileConfig(filename)
25
26def parse_query(filename, text):
27    if not filename is None and os.path.isfile(filename):
28        with open(filename) as query_file:   
29            return json.load(query_file, cls=ShapelyJsonDecoder, encoding='utf-8')
30    if not text is None:
31        return json.loads(text, cls=ShapelyJsonDecoder, encoding='utf-8')
32       
33    return {}
34
35def query(conf,inputs,outputs):   
36    config = {
37        CONFIG_SQL_CATALOG : conf["data-api"]["catalog"],
38        CONFIG_SQL_DATA : conf["data-api"]["vectorstore"],
39        CONFIG_SQL_TIMEOUT : int(conf["data-api"]["timeout"]) * 1000
40    }
41
42    if inputs.keys().count("timeout")>0:
43        config["CONFIG_SQL_TIMEOUT"]=int(inputs["timeout"]["value"]) * 1000
44   
45    metadata = {}
46
47    configure_logging(conf["lenv"]["cwd"]+"/"+conf["lenv"]["metapath"]+"/service.ini")
48   
49    query_executor = QueryExecutor()
50    result = query_executor.execute(config, parse_query(None,inputs["query"]["value"]) )
51   
52    outputs["Result"]["value"]=geojson.dumps(result['data'][0], cls=ShapelyGeoJsonEncoder, encoding='utf-8')
53    return zoo.SERVICE_SUCCEEDED
54       
Note: See TracBrowser for help on using the repository browser.

Search

Context Navigation

ZOO Sponsors

http://www.zoo-project.org/trac/chrome/site/img/geolabs-logo.pnghttp://www.zoo-project.org/trac/chrome/site/img/neogeo-logo.png http://www.zoo-project.org/trac/chrome/site/img/apptech-logo.png http://www.zoo-project.org/trac/chrome/site/img/3liz-logo.png http://www.zoo-project.org/trac/chrome/site/img/gateway-logo.png

Become a sponsor !

Knowledge partners

http://www.zoo-project.org/trac/chrome/site/img/ocu-logo.png http://www.zoo-project.org/trac/chrome/site/img/gucas-logo.png http://www.zoo-project.org/trac/chrome/site/img/polimi-logo.png http://www.zoo-project.org/trac/chrome/site/img/fem-logo.png http://www.zoo-project.org/trac/chrome/site/img/supsi-logo.png http://www.zoo-project.org/trac/chrome/site/img/cumtb-logo.png

Become a knowledge partner

Related links

http://zoo-project.org/img/ogclogo.png http://zoo-project.org/img/osgeologo.png