Cities near Paris Saclay


In [ ]:
!wget http://osm13.openstreetmap.fr/~cquest/openfla/export/communes-20180101-shp.zip

In [ ]:
!unzip -u communes-20180101-shp.zip

In [ ]:
import geopandas
  • TODO: put the following lists in a JSON dict and make it avaliable in a public Git repository (it can be usefull for other uses)
  • TODO: put the generated GeoJSON files in a public Git repository

In [ ]:
df = geopandas.read_file("communes-20181110.shp")
#df = df.loc[df.insee == "78646"]

In [ ]:
dept_78 = [str(insee) for insee in df.insee.values if insee.startswith("78")]
dept_91 = [str(insee) for insee in df.insee.values if insee.startswith("91")]
dept_92 = [str(insee) for insee in df.insee.values if insee.startswith("92")]
dept_95 = [str(insee) for insee in df.insee.values if insee.startswith("95")]
dept_78, dept_91, dept_92, dept_95

In [ ]:
## Yvelines ##########################################

# https://fr.wikipedia.org/wiki/Yvelines#D%C3%A9coupage_administratif
# https://commons.wikimedia.org/wiki/File:Yvelines_intercommunalit%C3%A9.svg?uselang=fr

# https://fr.wikipedia.org/wiki/Saint-Quentin-en-Yvelines
communes_sqy = [
    "78621", # Trappes
    "78165", # Les Clayes-sous-Bois
    "78168", # Coignières
    "78208", # Élancourt
    "78297", # Guyancourt
    "78356", # Magny-les-Hameaux
    "78383", # Maurepas
    "78423", # Montigny-le-Bretonneux
    "78490", # Plaisir
    "78644", # La Verrière
    "78674", # Villepreux
    "78688", # Voisins-le-Bretonneux
]

# https://fr.wikipedia.org/wiki/Canton_de_Montigny-le-Bretonneux
canton_montigny = [
    "78423", # Montigny-le-Bretonneux
    "78297", # Guyancourt
]

# https://fr.wikipedia.org/wiki/Canton_de_Versailles-1
canton_versailles1 = [
    "78646", # Versailles
]

# https://fr.wikipedia.org/wiki/Canton_de_Versailles-2
canton_versailles2 = [
    "78646", # Versailles
    "78117", # Buc
    "78322", # Jouy-en-Josas
    "78343", # Les Loges-en-Josas
    "78640", # Vélizy-Villacoublay
    "78686", # Viroflay
]

# https://fr.wikipedia.org/wiki/Canton_de_Maurepas
canton_maurepas = [
    "78383", # Maurepas
    "78143", # Châteaufort
    "78160", # Chevreuse
    "78162", # Choisel
    "78168", # Coignières
    "78193", # Dampierre-en-Yvelines
    "78334", # Lévis-Saint-Nom
    "78356", # Magny-les-Hameaux
    "78397", # Le Mesnil-Saint-Denis
    "78406", # Milon-la-Chapelle
    "78548", # Saint-Forget
    "78561", # Saint-Lambert
    "78575", # Saint-Rémy-lès-Chevreuse
    "78590", # Senlisse
    "78620", # Toussus-le-Noble
    "78688", # Voisins-le-Bretonneux
]

# https://fr.wikipedia.org/wiki/Canton_de_Rambouillet
canton_rambouillet = [
    "78517", # Rambouillet
    "78003", # Ablis
    "78009", # Allainville
    "78030", # Auffargis
    "78071", # Boinville-le-Gaillard
    "78077", # La Boissière-École
    "78087", # Bonnelles
    "78108", # Les Bréviaires
    "78120", # Bullion
    "78125", # La Celle-les-Bordes
    "78128", # Cernay-la-Ville
    "78164", # Clairefontaine-en-Yvelines
    "78209", # Émancé
    "78220", # Les Essarts-le-Roi
    "78264", # Gambaiseuil
    "78269", # Gazeran
    "78307", # Hermeray
    "78349", # Longvilliers
    "78407", # Mittainville
    "78464", # Orcemont
    "78470", # Orphin
    "78472", # Orsonville
    "78478", # Paray-Douaville
    "78486", # Le Perray-en-Yvelines
    "78497", # Poigny-la-Forêt
    "78499", # Ponthévrard
    "78506", # Prunay-en-Yvelines
    "78516", # Raizeux
    "78522", # Rochefort-en-Yvelines
    "78537", # Saint-Arnoult-en-Yvelines
    "78557", # Saint-Hilarion
    "78562", # Saint-Léger-en-Yvelines
    "78564", # Saint-Martin-de-Bréthencourt
    "78569", # Sainte-Mesme
    "78601", # Sonchamp
    "78655", # Vieille-Église-en-Yvelines
]

## Essonne ###########################################

# https://fr.wikipedia.org/wiki/Canton_de_Massy
canton_massy = [
    "91377", # Massy
    "91161", # Chilly-Mazarin
]

# https://fr.wikipedia.org/wiki/Canton_de_Palaiseau
canton_palaiseau = [
    "91477", # Palaiseau
    "91312", # Igny
    "91471", # Orsay
]

# https://fr.wikipedia.org/wiki/Canton_de_Gif-sur-Yvette
canton_gif = [
    "91272", # Gif-sur-Yvette
    "91064", # Bièvres
    "91093", # Boullay-les-Troux
    "91122", # Bures-sur-Yvette
    "91274", # Gometz-la-Ville
    "91411", # Les Molières
    "91482", # Pecqueuse
    "91534", # Saclay
    "91538", # Saint-Aubin
    "91635", # Vauhallan
    "91645", # Verrières-le-Buisson
    "91679", # Villiers-le-Bâcle
]

# https://fr.wikipedia.org/wiki/Canton_des_Ulis
canton_les_ulis = [
    "91692", # Les Ulis
    "91275", # Gometz-le-Châtel
    "91363", # Marcoussis
    "91458", # Nozay
    "91560", # Saint-Jean-de-Beauregard
    "91661", # Villebon-sur-Yvette
    "91666", # Villejust
]

# https://fr.wikipedia.org/wiki/Canton_de_Longjumeau
canton_longjumeau = [
    "91345", # Longjumeau
    "91044", # Ballainvilliers
    "91136", # Champlan
    "91216", # Épinay-sur-Orge
    "91339", # Linas
    "91425", # Montlhéry
    "91587", # Saulx-les-Chartreux
    "91665", # La Ville-du-Bois
]

# https://fr.wikipedia.org/wiki/Canton_de_Savigny-sur-Orge
canton_savigny = [
    "91589", # Savigny-sur-Orge
    "91432", # Morangis
    "91689", # Wissous
]

# https://fr.wikipedia.org/wiki/Communaut%C3%A9_de_communes_du_pays_de_Limours
communes_pays_limours = [
    "91111", # Briis-sous-Forges
    "91017", # Angervilliers
    "91093", # Boullay-les-Troux
    "91186", # Courson-Monteloup
    "91243", # Fontenay-lès-Briis
    "91249", # Forges-les-Bains
    "91274", # Gometz-la-Ville
    "91319", # Janvry
    "91411", # Les Molières
    "91338", # Limours
    "91482", # Pecqueuse
    "91560", # Saint-Jean-de-Beauregard
    "91568", # Saint-Maurice-Montcouronne
    "91634", # Vaugrigneuse
]

## Hauts-de-Seine ####################################

# https://fr.wikipedia.org/wiki/Hauts-de-Seine
dept_92 = [
    "92002", # Antony
    "92004", # Asnières-sur-Seine
    "92007", # Bagneux
    "92009", # Bois-Colombes
    "92012", # Boulogne-Billancourt
    "92014", # Bourg-la-Reine
    "92019", # Châtenay-Malabry
    "92020", # Châtillon
    "92022", # Chaville
    "92023", # Clamart
    "92024", # Clichy
    "92025", # Colombes
    "92026", # Courbevoie
    "92032", # Fontenay-aux-Roses
    "92033", # Garches
    "92035", # Gennevilliers
    "92036", # Issy-les-Moulineaux
    "92040", # La Garenne-Colombes
    "92044", # Le Plessis-Robinson
    "92046", # Levallois-Perret
    "92047", # Malakoff
    "92048", # Marnes-la-Coquette
    "92049", # Meudon
    "92050", # Montrouge
    "92051", # Nanterre
    "92060", # Neuilly-sur-Seine
    "92062", # Puteaux
    "92063", # Rueil-Malmaison
    "92064", # Saint-Cloud
    "92071", # Sceaux
    "92072", # Sèvres
    "92073", # Suresnes
    "92075", # Vanves
    "92076", # Vaucresson
    "92077", # Ville-d'Avray
    "92078", # Villeneuve-la-Garenne
]

######################################################

communes_list = []

# Hauts-de-Seine

communes_list += dept_78
communes_list += dept_91
communes_list += dept_92
communes_list += dept_95

# Yvelines

communes_list += communes_sqy
communes_list += canton_montigny
communes_list += canton_versailles2
communes_list += canton_maurepas
communes_list += canton_rambouillet

# Essonne

communes_list += canton_massy
communes_list += canton_palaiseau
communes_list += canton_gif
communes_list += canton_les_ulis
communes_list += canton_longjumeau
communes_list += canton_savigny
communes_list += communes_pays_limours

df = df.loc[df.insee.isin(communes_list)]

In [ ]:
df

In [ ]:
ax = df.plot(figsize=(10, 10), alpha=0.5, edgecolor='k')

Convert the data to Web Mercator


In [ ]:
df2 = df.to_crs(epsg=3857)

In [ ]:
df2

In [ ]:
ax = df2.plot(figsize=(10, 10), alpha=0.5, edgecolor='k')

Contextily helper function


In [ ]:
import contextily as ctx

def add_basemap(ax, zoom, url='http://tile.stamen.com/terrain/tileZ/tileX/tileY.png'):
    xmin, xmax, ymin, ymax = ax.axis()
    basemap, extent = ctx.bounds2img(xmin, ymin, xmax, ymax, zoom=zoom, url=url)
    ax.imshow(basemap, extent=extent, interpolation='bilinear')
    # restore original x/y limits
    ax.axis((xmin, xmax, ymin, ymax))

Add background tiles to plot


In [ ]:
ax = df2.plot(figsize=(16, 16), alpha=0.5, edgecolor='k')
#add_basemap(ax, zoom=13, url=ctx.sources.ST_TONER_LITE)
add_basemap(ax, zoom=12)
ax.set_axis_off()

Save selected departments into a GeoJSON file


In [ ]:
import fiona
fiona.supported_drivers

In [ ]:
!rm communes.geojson

In [ ]:
df.to_file("communes.geojson", driver="GeoJSON")

In [ ]:
!ls -lh communes.geojson

In [ ]:
df = geopandas.read_file("communes.geojson")

In [ ]:
df

In [ ]:
ax = df.plot(figsize=(10, 10), alpha=0.5, edgecolor='k')