def get_position_geohash(points):
""" This takes points and with these points find out what geohash each falls
under. Then we could get the crime_index and total_crimes
"""
# takes in a list as a parameter of [(lat, lng) ... (lat, lng)]
coords_data = [] # to store the dictionary generated
# do something like a for loop over here
for point in points:
geohash_sql = "SELECT * " + \
"FROM nyc_crimes_by_geohash " + \
"WHERE geohash=" + \
"ST_GeoHash(st_makepoint(%s, %s), 7);" % \
(point[0], point[1])
# execute the raw sql, and there should only be one result... so get that.
geohash_query = db.engine.execute(geohash_sql).fetchone()
if geohash_query is None:
# if the geohash isn't found, need to do something,
# query PostGIS for the geohash (not in db)
# then assume that there are no crimes in the area
geohash_of_point = "SELECT ST_GeoHash(geometry(Point(%s, %s)), 7);" \
% (point[0], point[1])
geohash_found = db.engine.execute(geohash_of_point).fetchone()
geohash_query = [0, geohash_found[0], 0, 0.0]
geohash_query_data = {
'geohash': geohash_query[1],
'total_crimes': geohash_query[2],
'crime_index': float(geohash_query[3]),
'point': point
}
coords_data.append(geohash_query_data)
# return something like [{dicte}, {dictw}], or {dict}, based on total pts
return coords_data
评论列表
文章目录