Advertisement
Guest User

Untitled

a guest
Jan 16th, 2019
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. import pandas as pd
  2. import folium
  3. from folium.plugins import HeatMap
  4. import psycopg2
  5. import geopandas as gpd
  6. from unidecode import unidecode
  7.  
  8. db = psycopg2.connect(user = "postgres", password = "psql", host = "localhost", database = "postgres")
  9. cursor = db.cursor()
  10. cursor.execute("select st_y(st_centroid(st_collect(geom))),st_x(st_centroid(st_collect(geom)))"\
  11. ",concelho from cont_aad_caop2017 group by 3 order by 3;")
  12. results = cursor.fetchall()
  13. lat = []
  14. log = []
  15. conc = []
  16. amount = []
  17. for row in results:
  18. lat.append(row[0])
  19. log.append(row[1])
  20. conc.append(row[2])
  21.  
  22. for i in conc:
  23. cursor.execute("select count(final_point) from cont_aad_caop2017,"\
  24. "taxi_services where st_contains(geom,final_point) and concelho ilike '"+i+"';")
  25. results_1 = cursor.fetchone()
  26. amount.append(results_1[0])
  27.  
  28. for_map = pd.DataFrame()
  29.  
  30. for_map['concelho'] = conc
  31. for_map['latitude'] = lat
  32. for_map['longitude'] = log
  33. for_map['amount'] = amount
  34.  
  35. max_amount = float(for_map['amount'].max())
  36.  
  37. hmap = folium.Map(location=[38.6817,-7.996], zoom_start=7)
  38.  
  39. hm_wide = HeatMap( list(zip(for_map.latitude.values, for_map.longitude.values, for_map.amount.values)),
  40. min_opacity=0.2,
  41. max_val=max_amount,
  42. radius=17, blur=15,
  43. max_zoom=1,
  44. )
  45.  
  46. hmap.add_child(hm_wide)
  47. hmap.save('index.html')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement