Commit c45f6dee authored by Christine Plumejeaud's avatar Christine Plumejeaud
Browse files

Changed the way to handle link (getlinks): always return an empty string.

describePlace : a new method to factor code.
database version : portic_v5, port 5433 from now. Was tested as locally. Must be deployed in prod.
Minor fixes.
parent 98d525ca
......@@ -36,8 +36,8 @@ CORS(app)
port = '80'
postgresport = '5432'
database = 'portic_v4'
postgresport = '5433'
database = 'portic_v5'
names = dict()
names['Corse'] = 'Isles de Corse'
......@@ -59,6 +59,8 @@ def retrieveDataFromPostgres(query) :
import pandas as pd
#connection = pg.connect("host='134.158.33.179' port='5433' dbname='portic_v3' user='api_user' password='portic'")
connection = pg.connect("""host='localhost' port='%s' dbname='%s' user='api_user' password='portic'"""% (postgresport, database))
#connection = pg.connect("host='localhost' port='8004' dbname='portic_v5' user='api_user' password='portic'")
#ssh -N -L 8004:localhost:5433 -v navigo@134.158.33.179
df = pd.read_sql_query(query,con=connection)
connection.close()
......@@ -210,15 +212,90 @@ def getPorts():
print (srid)
query = """SELECT ogc_fid, uhgs_id, total, toponyme as toponym, belonging_states, status, geonameid, amiraute as admiralty, province, shiparea , ST_AsGeoJSON(ST_Transform(geom, %s)) as point
query = """SELECT ogc_fid, uhgs_id, total, toponyme as toponym, belonging_states, belonging_substates, status, geonameid, amiraute as admiralty, province, shiparea , ST_AsGeoJSON(ST_Transform(geom, %s)) as point
FROM ports.port_points p,
(select pointcall_uhgs_id, count( *) as total
(select pointcall_uhgs_id, count(*) as total
from navigoviz.pointcall gg group by pointcall_uhgs_id) as k
where p.toponyme is not null and p.uhgs_id = k.pointcall_uhgs_id""" %(srid)
data = retrieveDataFromPostgres(query)
return formatOutput(data, 'ports')
def describePlace(kind_of_entity, identifier):
# Read the template_feature
template = os.path.join(APP_ROOT, 'template_feature.json')
test = os.path.join(APP_ROOT, 'test.json')
#print(template)
template_description = ""
inputjson = open(template, "r")
for x in inputjson:
template_description = template_description + x
inputjson.close()
#param_uhgs_id = 'A0209756' #Menton
#param_uhgs_id = 'A0222919' # Isles de Saint Pierre
#param_uhgs_id = 'A0115898' # Mahon
#param_uhgs_id = 'A0198999' #La Rochelle
param_uhgs_id = identifier
if kind_of_entity == 'port' :
## Read data about the entity port
query = """select uhgs_id, toponyme, country2019_iso2code, relation_state, longitude, latitude, geonameid, toustopos
from ports.port_points where uhgs_id = '%s' """ %( param_uhgs_id)
data = retrieveDataFromPostgres(query)
title = data.loc[0, 'toponyme']
ccodes = data.loc[0, 'country2019_iso2code']
toponym = data.loc[0, 'toponyme']
else :
title = param_uhgs_id
ccodes = 'FR'
toponym = param_uhgs_id
## When
start='1749'
end='1815'
## Les noms
if kind_of_entity == 'port':
names = getPortNames(toponym, param_uhgs_id)
else:
names = getEntityNames(param_uhgs_id)
## Les types
types = getTypes(kind_of_entity)
## Les geometries
if kind_of_entity == 'port':
geometries = getPortGeometry(param_uhgs_id, data.loc[0, 'longitude'] , data.loc[0, 'latitude'], data.loc[0, 'geonameid'])
elif kind_of_entity == 'amiraute':
geometries = getAmirauteGeometry(param_uhgs_id)
else :
geometries = getProvinceGeometry(param_uhgs_id)
## les Links
links = getLinks(param_uhgs_id, kind_of_entity)
## Les Relations
if kind_of_entity == 'port':
relations = getPortRelations(param_uhgs_id)
elif kind_of_entity == 'amiraute' :
relations = getAmirauteRelation(param_uhgs_id)
else :
relations = getProvinceRelation()
## Fill template with description
description = template_description % (param_uhgs_id, title, ccodes, start, end, names[:-1], types, geometries, links, relations)
'''
output = open(test, "w") #"utf-8"
output.write( description) #json.dumps(description)
output.close()
'''
return description
#return json.loads(description)
@app.route('/places/')
def getPlaces():
"""
......@@ -253,75 +330,9 @@ def getPlaces():
#We stop here
return '{ "No entry like this :" '+k+'}'
# Read the template_feature
template = os.path.join(APP_ROOT, 'template_feature.json')
test = os.path.join(APP_ROOT, 'test.json')
#print(template)
template_description = ""
inputjson = open(template, "r")
for x in inputjson:
template_description = template_description + x
inputjson.close()
#param_uhgs_id = 'A0209756' #Menton
#param_uhgs_id = 'A0222919' # Isles de Saint Pierre
#param_uhgs_id = 'A0115898' # Mahon
#param_uhgs_id = 'A0198999' #La Rochelle
param_uhgs_id = k
if kind_of_entity == 'port' :
## Read data about the entity port
query = """select uhgs_id, toponyme, country2019_iso2code, relation_state, longitude, latitude, geonameid, toustopos
from ports.port_points where uhgs_id = '%s' """ %( param_uhgs_id)
data = retrieveDataFromPostgres(query)
title = data.loc[0, 'toponyme']
ccodes = data.loc[0, 'country2019_iso2code']
toponym = data.loc[0, 'toponyme']
else :
title = param_uhgs_id
ccodes = 'FR'
toponym = param_uhgs_id
## Les noms
if kind_of_entity == 'port':
names = getPortNames(toponym, param_uhgs_id)
else:
names = getEntityNames(param_uhgs_id)
## Les types
types = getTypes(kind_of_entity)
## Les geometries
if kind_of_entity == 'port':
geometries = getPortGeometry(param_uhgs_id, data.loc[0, 'longitude'] , data.loc[0, 'latitude'], data.loc[0, 'geonameid'])
elif kind_of_entity == 'amiraute':
geometries = getAmirauteGeometry(param_uhgs_id)
else :
geometries = getProvinceGeometry(param_uhgs_id)
return describePlace(kind_of_entity, k)
## les Links
links = getLinks(param_uhgs_id, kind_of_entity)
## Les Relations
if kind_of_entity == 'port':
relations = getPortRelations(param_uhgs_id)
elif kind_of_entity == 'amiraute' :
relations = getAmirauteRelation(param_uhgs_id)
else :
relations = getProvinceRelation()
## Fill template with description
description = template_description % (param_uhgs_id, title, ccodes, names[:-1], types, geometries, links, relations)
'''
output = open(test, "w") #"utf-8"
output.write( description) #json.dumps(description)
output.close()
'''
return description
#return json.loads(description)
def getPortGeometry(uhgs_id, longitude, latitude, geonameid = None):
"""
......@@ -393,8 +404,8 @@ def getProvinceGeometry(toponyme) :
ports = retrieveDataFromPostgres(query)
geometries = ''
for uhgs_id in ports['uhgs_id'] :
print((ports.loc[ports['uhgs_id'] == uhgs_id, 'longitude'].values[0]))
print(ports.loc[ports['uhgs_id'] == uhgs_id, 'latitude'].values[0])
#print((ports.loc[ports['uhgs_id'] == uhgs_id, 'longitude'].values[0]))
#print(ports.loc[ports['uhgs_id'] == uhgs_id, 'latitude'].values[0])
geometries = geometries + getPortGeometry(uhgs_id, ports.loc[ports['uhgs_id'] == uhgs_id, 'longitude'].values[0], ports.loc[ports['uhgs_id'] == uhgs_id, 'latitude'].values[0]) + ','
return geometries[:-1]
......@@ -482,27 +493,35 @@ def getLinks(uhgs_id, type = 'port') :
wiki_provinces['Flandre'] = 'https://fr.wikipedia.org/wiki/Flandre_fran%C3%A7aise'
wiki_provinces['Corse'] = 'https://fr.wikipedia.org/wiki/Corse_(province)'
links = ""
if type == 'port':
query = """select id2, simtext, distgeo, certainity from ports.matching_port
where source1 = 'geo_general' and source2='geonames' and uhgs_id ='%s' and best is true""" %(uhgs_id)
matches = retrieveDataFromPostgres(query)
link_type = 'exactMatch'
if (matches.shape[0]> 1) :
link_type = 'closeMatch'
links = """{"type": "%s", "identifier": "http://www.geonames.org/%s/"}""" % (link_type, matches.loc[0, 'id2'])
#print(" nombre de links %d pour le port %s " %(matches.shape[0], uhgs_id))
if (matches.shape[0]> 0) :
link_type = 'exactMatch'
if (matches.shape[0]> 1) :
link_type = 'closeMatch'
links = """{"type": "%s", "identifier": "http://www.geonames.org/%s/"}""" % (link_type, matches.loc[0, 'id2'])
#print(links)
if type == 'amiraute' :
links = """{"type": "primaryTopicOf", "identifier": "https://fr.wikipedia.org/wiki/Amiraut%C3%A9_(justice)"} """
if type == 'province' :
links = """{"type": "primaryTopicOf", "identifier": "https://fr.wikipedia.org/wiki/Territoires_du_royaume_de_France"}"""
links = links +""", {"type": "primaryTopicOf", "identifier": "https://fr.wikipedia.org/wiki/Territoires_du_royaume_de_France#Liste_des_anciennes_provinces_de_France"}"""
links = links +""", {"type": "primaryTopicOf", "identifier": "%s"} """% (wiki_provinces[uhgs_id])
if uhgs_id in wiki_provinces.keys():
links = links +""", {"type": "primaryTopicOf", "identifier": "%s"} """% (wiki_provinces[uhgs_id])
else :
print('no entry in wiki_provinces for '+uhgs_id)
if uhgs_id == 'Bretagne' :
links = links +""", {"type": "subjectOf", "identifier": "https://fr.wikipedia.org/wiki/Amiraut%C3%A9s_de_Bretagne"} """
if uhgs_id == 'Guyenne' :
links = links +""", {"type": "subjectOf", "identifier": "https://fr.wikipedia.org/wiki/Amiraut%C3%A9_de_Guyenne"}"""
return links
......@@ -574,7 +593,7 @@ def getPortRelations(uhgs_id) :
},""" % (state.loc[0, 'amiraute'], state.loc[0, 'amiraute'])
# Si il a une province :
if state.loc[0, 'amiraute'] is not None:
if state.loc[0, 'province'] is not None:
relations = relations + """
{ "relationType": "gvp:broaderPartitive",
"relationTo": "http://gaz.portic.fr/places/?%s",
......@@ -647,4 +666,7 @@ def getProvinceRelation() :
if __name__ == '__main__':
app.run(debug=True,port=port,threaded=True)
#describePlace('port', 'A0198999')
#saveGazetteer()
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment