Created
March 10, 2014 09:07
-
-
Save scari/21c297bf71ca4fa92bd1 to your computer and use it in GitHub Desktop.
get administrative name for given lat/lng
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import psycopg2 | |
from flask import Flask, request | |
app = Flask(__name__) | |
app.debug = True | |
conn = psycopg2.connect(host='', database='', user='', password='') | |
@app.route('/city', methods=['GET']) | |
def city(): | |
print 'city' | |
lat = request.form['lat'] | |
lng = request.form['lng'] | |
level = request.form.get('admin_level', '8') | |
curs = conn.cursor() | |
q = "SELECT DISTINCT name FROM planet_osm_polygon WHERE ST_Contains(way, ST_SetSRID(ST_MakePoint(%s, %s), 4326)) AND boundary='administrative' AND admin_level='%s';" % (lat, lng, level) | |
print q | |
curs.execute(q) | |
for row in curs.fetchall(): | |
print row | |
return row | |
return "" | |
if __name__ == '__main__': | |
app.run(port=5000, host='0.0.0.0') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment