Skip to content

Commit

Permalink
update with half of the solution for the gerry mandering
Browse files Browse the repository at this point in the history
  • Loading branch information
sdpython committed Oct 23, 2016
1 parent 8ea2747 commit e48322d
Show file tree
Hide file tree
Showing 6 changed files with 2,544 additions and 25 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -284,4 +284,5 @@ _doc/notebooks/population/toxicode_circonscriptions_legislatives/*
_doc/notebooks/population/LG12_BV_T1T2/*
_doc/notebooks/population/__MACOSX/*
_doc/notebooks/population/*.htm
_doc/notebooks/population/fond07*.*

124 changes: 121 additions & 3 deletions _doc/notebooks/population/election_carte_electorale.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@
"* [Countours des circonscriptions des l\u00e9gislatives](https://www.data.gouv.fr/fr/datasets/countours-des-circonscriptions-des-legislatives-nd/)\n",
"* [Localisation des buraux de votes](http://www.xavierdupre.fr/enseignement/complements/bureauxvotegeo.zip)\n",
"* [Localisation des villes](https://github.com/sdpython/actuariat_python/raw/master/src/actuariat_python/data/data_elections/villes_geo.zip)\n",
"* [Localisation des bureaux de vote avec Cartelec](http://www.cartelec.net/?page_id=3609), cette base requiert la conversion des coordonn\u00e9es (lire ce [notebook](http://www.xavierdupre.fr/app/ensae_teaching_cs/helpsphinx3/notebooks/td1a_cenonce_session_12.html#cartographie))\n",
"\n",
"Il est conseill\u00e9 de t\u00e9l\u00e9charger directement ces donn\u00e9es. Les paragraphes suivants expliquent comment ceux-ci ont \u00e9t\u00e9 r\u00e9cup\u00e9r\u00e9s ou construit. Il n'est pas imm\u00e9diat d'obtenir la localisation des bureaux de vote. Celle-ci n'est d'ailleurs pas compl\u00e8te."
]
Expand Down Expand Up @@ -1397,14 +1398,131 @@
"villes_geo.head()"
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
"## G\u00e9olocation des bureaux de vote avec Cart\u00e9lec\n",
"\n",
"Le site [cartelec](http://www.cartelec.net/?page_id=3609) recense beaucoup plus de bureaux de vote mais pour les \u00e9lections 2007. Ils ne devraient pas avoir chang\u00e9 beaucoup."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
"collapsed": false
},
"outputs": [],
"source": []
"outputs": [
{
"data": {
"text/plain": [
"['fond0710.dbf', 'fond0710.shp', 'fond0710.shx']"
]
},
"execution_count": null,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from pyensae.datasource import download_data\n",
"shp_vote = download_data(\"base_cartelec_2007_2010.zip\")\n",
"shp_vote"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"(50578, 50578)"
]
},
"execution_count": null,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import shapefile\n",
"r = shapefile.Reader(\"fond0710.shp\")\n",
"shapes = r.shapes()\n",
"records = r.records()\n",
"len(shapes), len(records)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"{'BUREAU': '01001',\n",
" 'CANTON': '04',\n",
" 'CODE': b\"L'Abergement-Cl\\xe9menciat\",\n",
" 'CODEARRT': '01',\n",
" 'CODECANT': 'CHATILLON-SUR-CHALARONNE',\n",
" 'CODEDEP': '82',\n",
" 'CODEREG': '10',\n",
" 'DeletionFlag': '01001',\n",
" 'NOM': '012'}"
]
},
"execution_count": null,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"{k[0]:v for k,v in zip(r.fields, records[0])}"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"[[846774.7025280485, 6563840.655779875],\n",
" [847430.4726776106, 6566444.631470905],\n",
" [848975.0615885032, 6566530.102978201],\n",
" [849532.5253064571, 6565971.4588501565],\n",
" [848969.0813380895, 6564398.911644492],\n",
" [850941.7401535356, 6563209.5425065085],\n",
" [849896.4212796891, 6562719.844144765],\n",
" [849632.2745031306, 6561522.415193593],\n",
" [849891.0276243397, 6560738.406460746],\n",
" [848732.0257644501, 6559575.068823495],\n",
" [848585.9032087281, 6560169.582690463],\n",
" [847664.0345600601, 6560616.395794825],\n",
" [847793.2580021, 6562243.125831007],\n",
" [846774.7025280485, 6563840.655779875]]"
]
},
"execution_count": null,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"shapes[0].points"
]
},
{
"cell_type": "markdown",
Expand Down
Loading

0 comments on commit e48322d

Please sign in to comment.