Advertisement
Guest User

Untitled

a guest
Jan 28th, 2019
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.68 KB | None | 0 0
  1. %matplotlib  
  2.  
  3. # coding: utf-8
  4.  
  5. #import geopandas as gpd
  6. import matplotlib.pyplot as plt
  7. from descartes import PolygonPatch
  8. from shapely.geometry import Point, LineString
  9. import requests
  10.  
  11.  
  12. code_postal = '92320'
  13.  
  14.  
  15. # Recupération du code Insee
  16. url_api ="https://geo.api.gouv.fr/communes?codePostal={}".format(code_postal)
  17. data_api = requests.get(url_api)
  18. json_api =data_api.json()
  19.  
  20. commune = json_api[0]['code']
  21. nom_ville=json_api[0]['nom']
  22. pop=json_api[0]['population']
  23.        
  24. print('Ville : {0}, Code insee {1}, {2} Habitants'.format(nom_ville,commune,pop))
  25.  
  26.  
  27.  
  28.  
  29.  
  30. url_parcelles =  'https://cadastre.data.gouv.fr/bundler/cadastre-etalab/communes/{}/geojson/parcelles'.format(commune)
  31. data_parcelles = requests.get(url_parcelles)
  32.  
  33.  
  34. # In[ ]:
  35.  
  36.  
  37. surf_min =309   #surface minimum à chercher
  38. surf_max = 309  #surface max à chercher
  39.  
  40.  
  41. BLUE = '#6699cc'
  42. RUE = '#0099CC'
  43. f, ax = plt.subplots(1, figsize=(25,25 ))
  44.  
  45. cpt=0
  46. for bcl in data_parcelles.json()['features']:
  47.     poly=bcl['geometry']
  48.     ax.add_patch(PolygonPatch(poly, fc=BLUE, ec=BLUE, alpha=0.7, zorder=0 ))
  49.     try:
  50.         if bcl['properties']['contenance'] in range(surf_min,surf_max+1):
  51.             cpt+=1
  52.             x,y=zip(*poly['coordinates'][0])
  53.             center=(max(x)+min(x))/2., (max(y)+min(y))/2.
  54.             lon=center[0]
  55.             lat=center[1]
  56.             plt.scatter(lon,lat,color='red',zorder=1)
  57.             ax.annotate(cpt,(lon,lat),size=20)
  58.  
  59.             surf=bcl['properties']['contenance']
  60.             url = 'http://maps.google.com/maps?z=15&t=k&q='+str(lat)+','+str(lon)
  61.             print (cpt, url , surf )
  62.     except:
  63.         pass
  64. ax.axis('auto')
  65.  
  66. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement