import os
|
import requests
|
from config import StagingConfig as conf
|
|
from flask import Flask
|
from flask import request
|
|
from ctls import Db
|
from pub.utils import Coords
|
from pub.extactJSON import ParserMOI as moiParser
|
from pub.queryMoi import QueryElevation as moiEvApi
|
from pub.postgis import Dbconnect as gis3d
|
|
#from parser import FeatureTableParser
|
|
app = Flask(__name__)
|
#app.config.from_envvar('YOURAPPLICATION_SETTINGS')
|
#app.config.from_object(os.environ['APP_SETTINGS'])
|
app.config.from_object(conf)
|
|
dbConf={"host": os.environ.get("PG_HOST", '192.168.11.42'),
|
"port": os.environ.get("PG_PORT", '5115'),
|
"database": os.environ.get("PG_DATABASE",'pgDMMSNS'),
|
"user": os.environ.get("PG_USER",'postgres'),
|
"password": os.environ.get("PG_PASS",'simple000'),
|
"default97": os.environ.get("DB_SRS",'3826')
|
}
|
|
dbSRS=os.environ.get("DB_SRS",'3826')
|
|
#dbConf= { "host":"192.168.11.42" ,
|
# "port":"5115",
|
# "database":"pgDMMSNS",
|
# "user":"postgres",
|
# "password":"simple000"
|
#}
|
|
def printcol(col):
|
print(col)
|
|
|
@app.route('/')
|
def hello():
|
return '?1/2/'
|
|
@app.route('/testPostgis')
|
def testdb():
|
gis3d.testSelect();
|
return 'done'
|
|
@app.route('/resetEv/<string:tablename>')
|
def resetTableEv(tablename):
|
print('running resetEv')
|
colgeom= request.args.get('geom',default='geom')
|
|
#poi= Updateev0 (self.updDB)
|
#gis3d.fetchTable(dbConf,
|
# poi.sql_sel() ,
|
# poi)
|
procSetTableEv= Db(dbConf)
|
procSetTableEv.resetTabelEv(tablename,dbSRS=dbSRS,srcgeom=colgeom,desgeom=colgeom)
|
|
return 'done'
|
|
@app.route('/getEv/<string:tablename>')
|
def featureEvby84(tablename):
|
|
limit= request.args.get('limit',default=100,type=int)
|
colgeom= request.args.get('geom',default='geom')
|
print('running getEv')
|
print(request.query_string)
|
procGetTableEv=Db(dbConf)
|
procGetTableEv.getTableEv(tablename,limit=limit,dbSRS=dbSRS,srcgeom=colgeom,desgeom=colgeom)
|
|
return 'table={}({}-{}),limit={}'.format(tablename,colgeom,dbSRS,(limit))
|
|
|
@app.route('/test') #/<string:name>')
|
def hello_name():
|
proj= request.args.get('proj', default =3857 , type = int)
|
|
print( "proj={}".format(proj))
|
moiApi= moiEvApi()
|
(result, urltext)= moiApi.test()
|
if(result.status_code == requests.codes.ok):
|
resultjs=moiParser.toJSON(result.text)
|
|
|
return "testmoi={},\n url={}".format(resultjs,urltext)
|
|
@app.route('/transform')
|
def transformCoord():
|
src_proj= request.args.get('src',default=3826,type=int)
|
des_proj= request.args.get('des',default=4326,type=int)
|
dx = request.args.get('x',default=0,type=float)
|
dy = request.args.get('y',default=0,type=float)
|
result=[]
|
ret_json ={'message':'input format GET/POST ','src':3826,'des':4326,'x':0,'y':0}
|
#print( src_proj,des_proj,dx,dy)
|
trans=Coords()
|
if(src_proj == 3826 and des_proj==4326):
|
result= trans.crs_t97tow84(dx,dy)
|
ret_json= {'x':result[0],'y':result[1],'srid':4326}
|
if(src_proj == 4326 and des_proj==3826):
|
result= trans.crs_w84tot97(dx,dy)
|
ret_json= {'x':result[0],'y':result[1],'srid':3826}
|
if(src_proj == des_proj):
|
ret_json= {'x':dx,'y':dy,'srid':src_proj}
|
return ret_json
|
|
|
if __name__ == '__main__':
|
print (dbConf)
|
moiapi=os.environ.get("MOI_API","TW_DLA_2001084_20061226_20M_3826_DEM")
|
moikey=os.environ.get("MOI_KEY","43da4f4a-e2e0-43b0-a432-8b7975f43d9e")
|
|
print('moikey=',moikey)
|
print('moiapi=',moiapi)
|
app.run(host='0.0.0.0',port=5000)
|