├── LICENSE ├── README.md ├── geocoding.ipynb ├── img └── banner.png └── rawdata └── rawdata.xlsx /LICENSE: -------------------------------------------------------------------------------- 1 | Creative Commons Legal Code 2 | 3 | CC0 1.0 Universal 4 | 5 | CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE 6 | LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN 7 | ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS 8 | INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES 9 | REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS 10 | PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM 11 | THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED 12 | HEREUNDER. 13 | 14 | Statement of Purpose 15 | 16 | The laws of most jurisdictions throughout the world automatically confer 17 | exclusive Copyright and Related Rights (defined below) upon the creator 18 | and subsequent owner(s) (each and all, an "owner") of an original work of 19 | authorship and/or a database (each, a "Work"). 20 | 21 | Certain owners wish to permanently relinquish those rights to a Work for 22 | the purpose of contributing to a commons of creative, cultural and 23 | scientific works ("Commons") that the public can reliably and without fear 24 | of later claims of infringement build upon, modify, incorporate in other 25 | works, reuse and redistribute as freely as possible in any form whatsoever 26 | and for any purposes, including without limitation commercial purposes. 27 | These owners may contribute to the Commons to promote the ideal of a free 28 | culture and the further production of creative, cultural and scientific 29 | works, or to gain reputation or greater distribution for their Work in 30 | part through the use and efforts of others. 31 | 32 | For these and/or other purposes and motivations, and without any 33 | expectation of additional consideration or compensation, the person 34 | associating CC0 with a Work (the "Affirmer"), to the extent that he or she 35 | is an owner of Copyright and Related Rights in the Work, voluntarily 36 | elects to apply CC0 to the Work and publicly distribute the Work under its 37 | terms, with knowledge of his or her Copyright and Related Rights in the 38 | Work and the meaning and intended legal effect of CC0 on those rights. 39 | 40 | 1. Copyright and Related Rights. A Work made available under CC0 may be 41 | protected by copyright and related or neighboring rights ("Copyright and 42 | Related Rights"). Copyright and Related Rights include, but are not 43 | limited to, the following: 44 | 45 | i. the right to reproduce, adapt, distribute, perform, display, 46 | communicate, and translate a Work; 47 | ii. moral rights retained by the original author(s) and/or performer(s); 48 | iii. publicity and privacy rights pertaining to a person's image or 49 | likeness depicted in a Work; 50 | iv. rights protecting against unfair competition in regards to a Work, 51 | subject to the limitations in paragraph 4(a), below; 52 | v. rights protecting the extraction, dissemination, use and reuse of data 53 | in a Work; 54 | vi. database rights (such as those arising under Directive 96/9/EC of the 55 | European Parliament and of the Council of 11 March 1996 on the legal 56 | protection of databases, and under any national implementation 57 | thereof, including any amended or successor version of such 58 | directive); and 59 | vii. other similar, equivalent or corresponding rights throughout the 60 | world based on applicable law or treaty, and any national 61 | implementations thereof. 62 | 63 | 2. Waiver. To the greatest extent permitted by, but not in contravention 64 | of, applicable law, Affirmer hereby overtly, fully, permanently, 65 | irrevocably and unconditionally waives, abandons, and surrenders all of 66 | Affirmer's Copyright and Related Rights and associated claims and causes 67 | of action, whether now known or unknown (including existing as well as 68 | future claims and causes of action), in the Work (i) in all territories 69 | worldwide, (ii) for the maximum duration provided by applicable law or 70 | treaty (including future time extensions), (iii) in any current or future 71 | medium and for any number of copies, and (iv) for any purpose whatsoever, 72 | including without limitation commercial, advertising or promotional 73 | purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each 74 | member of the public at large and to the detriment of Affirmer's heirs and 75 | successors, fully intending that such Waiver shall not be subject to 76 | revocation, rescission, cancellation, termination, or any other legal or 77 | equitable action to disrupt the quiet enjoyment of the Work by the public 78 | as contemplated by Affirmer's express Statement of Purpose. 79 | 80 | 3. Public License Fallback. Should any part of the Waiver for any reason 81 | be judged legally invalid or ineffective under applicable law, then the 82 | Waiver shall be preserved to the maximum extent permitted taking into 83 | account Affirmer's express Statement of Purpose. In addition, to the 84 | extent the Waiver is so judged Affirmer hereby grants to each affected 85 | person a royalty-free, non transferable, non sublicensable, non exclusive, 86 | irrevocable and unconditional license to exercise Affirmer's Copyright and 87 | Related Rights in the Work (i) in all territories worldwide, (ii) for the 88 | maximum duration provided by applicable law or treaty (including future 89 | time extensions), (iii) in any current or future medium and for any number 90 | of copies, and (iv) for any purpose whatsoever, including without 91 | limitation commercial, advertising or promotional purposes (the 92 | "License"). The License shall be deemed effective as of the date CC0 was 93 | applied by Affirmer to the Work. Should any part of the License for any 94 | reason be judged legally invalid or ineffective under applicable law, such 95 | partial invalidity or ineffectiveness shall not invalidate the remainder 96 | of the License, and in such case Affirmer hereby affirms that he or she 97 | will not (i) exercise any of his or her remaining Copyright and Related 98 | Rights in the Work or (ii) assert any associated claims and causes of 99 | action with respect to the Work, in either case contrary to Affirmer's 100 | express Statement of Purpose. 101 | 102 | 4. Limitations and Disclaimers. 103 | 104 | a. No trademark or patent rights held by Affirmer are waived, abandoned, 105 | surrendered, licensed or otherwise affected by this document. 106 | b. Affirmer offers the Work as-is and makes no representations or 107 | warranties of any kind concerning the Work, express, implied, 108 | statutory or otherwise, including without limitation warranties of 109 | title, merchantability, fitness for a particular purpose, non 110 | infringement, or the absence of latent or other defects, accuracy, or 111 | the present or absence of errors, whether or not discoverable, all to 112 | the greatest extent permissible under applicable law. 113 | c. Affirmer disclaims responsibility for clearing rights of other persons 114 | that may apply to the Work or any use thereof, including without 115 | limitation any person's Copyright and Related Rights in the Work. 116 | Further, Affirmer disclaims responsibility for obtaining any necessary 117 | consents, permissions or other rights required for any use of the 118 | Work. 119 | d. Affirmer understands and acknowledges that Creative Commons is not a 120 | party to this document and has no duty or obligation with respect to 121 | this CC0 or use of the Work. 122 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | Este repositorio 🗂️ contiene un script📜 desarrollado en que te permitirá realizar el proceso de geocodificación directa o inverso a través de un cuaderno de jupyter. 4 | 5 | *"📍 La geocodificación es un geoproceso que convierte direcciones o información de ubicaciones en datos espaciales, permitiendo su visualización a través de puntos en un mapa 🗺️."* 6 | 7 | Para este video usaremos las siguientes librerias: 8 | - **geopy**: Librería que permite realizar el proceso de geocodificación a través de diferentes servicios. 9 | - pandas: Librería que permite crear, manipular y guardar dataframes 10 | - geopandas: Librería que permite manipular datos espaciales de tipo vector 11 | - mapclassify: Librería que permite clasificar de forma discreta a los datos espaciales para faciliar su visualización. 12 | 13 | Todo el proceso desarrollado esta explicado paso a paso en el siguiente video de Youtube 🎥. 14 | [![Watch the video](https://img.youtube.com/vi/aM93Jn1uD-I/0.jpg)](https://youtu.be/aM93Jn1uD-I?si=tnOLDjmW-TkOb3U9) 15 | 16 | ¡Enteráte más y aprender conmigo! 🔍💡 Suscríbete, activa las notificaciones 🔔 y únete a la comunidad que ama el software libre de código abierto. 🌟🌍 👇 17 | - https://www.youtube.com/@geografope 18 | 19 | - https://www.tiktok.com/@geografope 20 | ## 🟡 Referencias: 21 | - *https://support.esri.com/en-us/gis-dictionary/geocoding* 22 | - *https://github.com/osm-search/Nominatim* 23 | -------------------------------------------------------------------------------- /geocoding.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "id": "view-in-github", 7 | "colab_type": "text" 8 | }, 9 | "source": [ 10 | "\"Open" 11 | ] 12 | }, 13 | { 14 | "cell_type": "markdown", 15 | "metadata": { 16 | "id": "JlV6huXsEQ0E" 17 | }, 18 | "source": [ 19 | "" 20 | ] 21 | }, 22 | { 23 | "cell_type": "markdown", 24 | "source": [ 25 | "Este tutorial fue elaboradro por **Geografo.PE**\n", 26 | "\n", 27 | "Redes sociales:\n", 28 | "- Youtube: www.youtube.com/@ambarja\n", 29 | "- Tiktok: https://www.tiktok.com/@geografo.pe\n", 30 | "- Linkdin: https://www.linkedin.com/in/antonybarja/\n", 31 | "- GitHub: https://github.com/geografope\n", 32 | "\n", 33 | "Para más información, puedes visitar mi pagina personal:*https://geografo.pe*" 34 | ], 35 | "metadata": { 36 | "id": "G_8NqYyOKOPl" 37 | } 38 | }, 39 | { 40 | "cell_type": "markdown", 41 | "source": [ 42 | "### **1.Instalación de librerias a utilizar**\n" 43 | ], 44 | "metadata": { 45 | "id": "wnmMnL1QXqRa" 46 | } 47 | }, 48 | { 49 | "cell_type": "code", 50 | "execution_count": null, 51 | "metadata": { 52 | "id": "8Y3pAmhjEKfc" 53 | }, 54 | "outputs": [], 55 | "source": [ 56 | "!pip install geopy\n", 57 | "!pip install pandas\n", 58 | "!pip install geopandas\n", 59 | "!pip install mapclassify" 60 | ] 61 | }, 62 | { 63 | "cell_type": "markdown", 64 | "source": [ 65 | "### **2.Llamado o activación de librerias**" 66 | ], 67 | "metadata": { 68 | "id": "7l44pRVyYk7X" 69 | } 70 | }, 71 | { 72 | "cell_type": "code", 73 | "execution_count": null, 74 | "metadata": { 75 | "id": "YCm5aUYJfWjt" 76 | }, 77 | "outputs": [], 78 | "source": [ 79 | "from geopy.geocoders import Nominatim, ArcGIS, MapBox\n", 80 | "import pandas as pd\n", 81 | "import geopandas as gpd\n", 82 | "from functools import partial" 83 | ] 84 | }, 85 | { 86 | "cell_type": "markdown", 87 | "source": [ 88 | "### **3.Lectura de los datos crudos en formato excel**" 89 | ], 90 | "metadata": { 91 | "id": "y4cj52EVY8lo" 92 | } 93 | }, 94 | { 95 | "cell_type": "code", 96 | "execution_count": null, 97 | "metadata": { 98 | "id": "RGrUk6O_eEDY" 99 | }, 100 | "outputs": [], 101 | "source": [ 102 | "url = 'https://github.com/geografope/geocodificacion-con-python/raw/main/rawdata/rawdata.xlsx'\n", 103 | "rawdata = pd.read_excel(url)" 104 | ] 105 | }, 106 | { 107 | "cell_type": "code", 108 | "source": [ 109 | "rawdata.shape" 110 | ], 111 | "metadata": { 112 | "id": "xJRT32c8ets-", 113 | "outputId": "43c02bf2-b9a6-49a9-c7a9-22c8f04cf885", 114 | "colab": { 115 | "base_uri": "https://localhost:8080/" 116 | } 117 | }, 118 | "execution_count": null, 119 | "outputs": [ 120 | { 121 | "output_type": "execute_result", 122 | "data": { 123 | "text/plain": [ 124 | "(19, 4)" 125 | ] 126 | }, 127 | "metadata": {}, 128 | "execution_count": 107 129 | } 130 | ] 131 | }, 132 | { 133 | "cell_type": "markdown", 134 | "source": [ 135 | "### **4.Función para estandarizar extructura de texto para geocodificar**" 136 | ], 137 | "metadata": { 138 | "id": "UTDT9kD89PSM" 139 | } 140 | }, 141 | { 142 | "cell_type": "code", 143 | "source": [ 144 | "# Forma estandar de la estructura del texto para geodificar con Nominatim:\n", 145 | "# direccion,distrito,provincia,departamento,pais\n", 146 | "# Ejemplo: \"Calle Los Angeles 123, Carabayllo, Lima, Lima, Perú\"\n", 147 | "def concatenar_campos(row):\n", 148 | " return f\"{row['direccion']}, {row['distrito']}, {row['provincia']}, {row['departamento']}, Perú\"" 149 | ], 150 | "metadata": { 151 | "id": "bm12Yjs6YFUP" 152 | }, 153 | "execution_count": null, 154 | "outputs": [] 155 | }, 156 | { 157 | "cell_type": "code", 158 | "execution_count": null, 159 | "metadata": { 160 | "id": "UUabd8NViDWh" 161 | }, 162 | "outputs": [], 163 | "source": [ 164 | "rawdata['nogeo'] = rawdata.apply(concatenar_campos, axis= 1)\n", 165 | "rawdata.head()" 166 | ] 167 | }, 168 | { 169 | "cell_type": "code", 170 | "source": [ 171 | "rawdata_for_osm = rawdata.copy()\n", 172 | "rawdata_for_mapbox = rawdata.copy()\n", 173 | "rawdata_for_arcgis = rawdata.copy()" 174 | ], 175 | "metadata": { 176 | "id": "QdWRYjT8LNFm" 177 | }, 178 | "execution_count": null, 179 | "outputs": [] 180 | }, 181 | { 182 | "cell_type": "markdown", 183 | "source": [ 184 | "### **5.Gecodificación directa con la API de OSM**\n", 185 | "- Nominatim: Es una herramienta open source que sirve para realizar proceso de geocodificación a través de OpenSteetMap.\n", 186 | "Referencia: *https://github.com/osm-search/Nominatim*" 187 | ], 188 | "metadata": { 189 | "id": "28uNbQrk9dOY" 190 | } 191 | }, 192 | { 193 | "cell_type": "code", 194 | "execution_count": null, 195 | "metadata": { 196 | "id": "cQpZU3pPhXWw" 197 | }, 198 | "outputs": [], 199 | "source": [ 200 | "# Gecodificación directa\n", 201 | "geolocator = Nominatim(user_agent=\"geografo_pe\",timeout = 5)\n", 202 | "geocode = partial(geolocator.geocode, language=\"es\")\n", 203 | "def tidygeocode(row):\n", 204 | " location = geolocator.geocode(row['nogeo'])\n", 205 | " if location:\n", 206 | " return pd.Series({'latitude': location.latitude, 'longitude': location.longitude})\n", 207 | " else:\n", 208 | " return pd.Series({'latitude': None, 'longitude': None})" 209 | ] 210 | }, 211 | { 212 | "cell_type": "code", 213 | "source": [ 214 | "rawdata_for_osm[['latitude', 'longitude']] = rawdata_for_osm.apply(tidygeocode, axis=1)" 215 | ], 216 | "metadata": { 217 | "id": "k2wcaOnUZzW5" 218 | }, 219 | "execution_count": null, 220 | "outputs": [] 221 | }, 222 | { 223 | "cell_type": "code", 224 | "source": [ 225 | "rawdata_for_osm" 226 | ], 227 | "metadata": { 228 | "id": "A5Jn0BMPgGLe", 229 | "outputId": "8ae8c01a-a61b-4888-ecb3-889319f2ae0c", 230 | "colab": { 231 | "base_uri": "https://localhost:8080/", 232 | "height": 645 233 | } 234 | }, 235 | "execution_count": null, 236 | "outputs": [ 237 | { 238 | "output_type": "execute_result", 239 | "data": { 240 | "text/plain": [ 241 | " departamento provincia distrito \\\n", 242 | "0 Lima Lima Santa Anita \n", 243 | "1 Lima Lima Santa Anita \n", 244 | "2 Lima Lima Santa Anita \n", 245 | "3 Lima Lima Lurigancho \n", 246 | "4 Lima Lima Lurigancho \n", 247 | "5 Lima Lima Lurigancho \n", 248 | "6 Lima Lima Lurigancho \n", 249 | "7 Lima Lima Surquillo \n", 250 | "8 Lima Lima Surquillo \n", 251 | "9 Lima Lima Surquillo \n", 252 | "10 Lima Lima Miraflores \n", 253 | "11 Lima Lima Miraflores \n", 254 | "12 Lima Lima Miraflores \n", 255 | "13 Lima Lima Miraflores \n", 256 | "14 Lima Lima Puente Piedra \n", 257 | "15 Lima Lima Puente Piedra \n", 258 | "16 Lima Lima Puente Piedra \n", 259 | "17 Lima Lima Puente Piedra \n", 260 | "18 Lima Lima Puente Piedra \n", 261 | "\n", 262 | " direccion \\\n", 263 | "0 Carretera Central 167, Santa Anita 15008 \n", 264 | "1 Jiron los Eucaliptos 996, La Molina 15023 \n", 265 | "2 Avenida Metropolitana Mz M Lot 4, Ate 15026 \n", 266 | "3 Los Robles, Lima 15457 \n", 267 | "4 Avenida las Torres 276, Lima, Ate 15498 \n", 268 | "5 Avenida Nicolás Ayllón 7208, Ate 15487 \n", 269 | "6 La Capitana 190, Lurigancho-Chosica 15461 \n", 270 | "7 Avenida Angamos Este 1807-1803, Surquillo 15036 \n", 271 | "8 Avenida República de Panamá 4295, Surquillo 15048 \n", 272 | "9 Gonzáles Prada, Surquillo 15047 \n", 273 | "10 Calle Bellavista 207, Miraflores 15074 \n", 274 | "11 Avenida Grau 299, Miraflores 15074 \n", 275 | "12 Alfredo Leon 114, Miraflores 15074 \n", 276 | "13 Calle Berlín 1273, Miraflores 15074 \n", 277 | "14 Pasaje Las Vegas, Puente Piedra 15118 \n", 278 | "15 Calle 9 de Junio 100, Puente Piedra 15115 \n", 279 | "16 Avenida sanez numero 300 urbaizacion cercado d... \n", 280 | "17 Calle 8 6-130, Puente Piedra 15117 \n", 281 | "18 Calle 8 132-356, Puente Piedra 15117 \n", 282 | "\n", 283 | " nogeo latitude longitude \n", 284 | "0 Carretera Central 167, Santa Anita 15008, Sant... -12.045751 -76.942885 \n", 285 | "1 Jiron los Eucaliptos 996, La Molina 15023, San... NaN NaN \n", 286 | "2 Avenida Metropolitana Mz M Lot 4, Ate 15026, S... NaN NaN \n", 287 | "3 Los Robles, Lima 15457, Lurigancho, Lima, Lima... -12.010709 -76.909938 \n", 288 | "4 Avenida las Torres 276, Lima, Ate 15498, Lurig... -12.014345 -76.900770 \n", 289 | "5 Avenida Nicolás Ayllón 7208, Ate 15487, Luriga... NaN NaN \n", 290 | "6 La Capitana 190, Lurigancho-Chosica 15461, Lur... NaN NaN \n", 291 | "7 Avenida Angamos Este 1807-1803, Surquillo 1503... NaN NaN \n", 292 | "8 Avenida República de Panamá 4295, Surquillo 15... -12.116153 -77.018354 \n", 293 | "9 Gonzáles Prada, Surquillo 15047, Surquillo, Li... -12.116403 -77.021011 \n", 294 | "10 Calle Bellavista 207, Miraflores 15074, Mirafl... -12.122818 -77.032740 \n", 295 | "11 Avenida Grau 299, Miraflores 15074, Miraflores... -12.120170 -77.034772 \n", 296 | "12 Alfredo Leon 114, Miraflores 15074, Miraflores... -12.121135 -77.037995 \n", 297 | "13 Calle Berlín 1273, Miraflores 15074, Miraflore... -12.120104 -77.040088 \n", 298 | "14 Pasaje Las Vegas, Puente Piedra 15118, Puente ... NaN NaN \n", 299 | "15 Calle 9 de Junio 100, Puente Piedra 15115, Pue... NaN NaN \n", 300 | "16 Avenida sanez numero 300 urbaizacion cercado d... NaN NaN \n", 301 | "17 Calle 8 6-130, Puente Piedra 15117, Puente Pie... -11.884888 -77.070530 \n", 302 | "18 Calle 8 132-356, Puente Piedra 15117, Puente P... NaN NaN " 303 | ], 304 | "text/html": [ 305 | "\n", 306 | "
\n", 307 | "
\n", 308 | "\n", 321 | "\n", 322 | " \n", 323 | " \n", 324 | " \n", 325 | " \n", 326 | " \n", 327 | " \n", 328 | " \n", 329 | " \n", 330 | " \n", 331 | " \n", 332 | " \n", 333 | " \n", 334 | " \n", 335 | " \n", 336 | " \n", 337 | " \n", 338 | " \n", 339 | " \n", 340 | " \n", 341 | " \n", 342 | " \n", 343 | " \n", 344 | " \n", 345 | " \n", 346 | " \n", 347 | " \n", 348 | " \n", 349 | " \n", 350 | " \n", 351 | " \n", 352 | " \n", 353 | " \n", 354 | " \n", 355 | " \n", 356 | " \n", 357 | " \n", 358 | " \n", 359 | " \n", 360 | " \n", 361 | " \n", 362 | " \n", 363 | " \n", 364 | " \n", 365 | " \n", 366 | " \n", 367 | " \n", 368 | " \n", 369 | " \n", 370 | " \n", 371 | " \n", 372 | " \n", 373 | " \n", 374 | " \n", 375 | " \n", 376 | " \n", 377 | " \n", 378 | " \n", 379 | " \n", 380 | " \n", 381 | " \n", 382 | " \n", 383 | " \n", 384 | " \n", 385 | " \n", 386 | " \n", 387 | " \n", 388 | " \n", 389 | " \n", 390 | " \n", 391 | " \n", 392 | " \n", 393 | " \n", 394 | " \n", 395 | " \n", 396 | " \n", 397 | " \n", 398 | " \n", 399 | " \n", 400 | " \n", 401 | " \n", 402 | " \n", 403 | " \n", 404 | " \n", 405 | " \n", 406 | " \n", 407 | " \n", 408 | " \n", 409 | " \n", 410 | " \n", 411 | " \n", 412 | " \n", 413 | " \n", 414 | " \n", 415 | " \n", 416 | " \n", 417 | " \n", 418 | " \n", 419 | " \n", 420 | " \n", 421 | " \n", 422 | " \n", 423 | " \n", 424 | " \n", 425 | " \n", 426 | " \n", 427 | " \n", 428 | " \n", 429 | " \n", 430 | " \n", 431 | " \n", 432 | " \n", 433 | " \n", 434 | " \n", 435 | " \n", 436 | " \n", 437 | " \n", 438 | " \n", 439 | " \n", 440 | " \n", 441 | " \n", 442 | " \n", 443 | " \n", 444 | " \n", 445 | " \n", 446 | " \n", 447 | " \n", 448 | " \n", 449 | " \n", 450 | " \n", 451 | " \n", 452 | " \n", 453 | " \n", 454 | " \n", 455 | " \n", 456 | " \n", 457 | " \n", 458 | " \n", 459 | " \n", 460 | " \n", 461 | " \n", 462 | " \n", 463 | " \n", 464 | " \n", 465 | " \n", 466 | " \n", 467 | " \n", 468 | " \n", 469 | " \n", 470 | " \n", 471 | " \n", 472 | " \n", 473 | " \n", 474 | " \n", 475 | " \n", 476 | " \n", 477 | " \n", 478 | " \n", 479 | " \n", 480 | " \n", 481 | " \n", 482 | " \n", 483 | " \n", 484 | " \n", 485 | " \n", 486 | " \n", 487 | " \n", 488 | " \n", 489 | " \n", 490 | " \n", 491 | " \n", 492 | " \n", 493 | " \n", 494 | " \n", 495 | " \n", 496 | " \n", 497 | " \n", 498 | " \n", 499 | " \n", 500 | " \n", 501 | " \n", 502 | " \n", 503 | " \n", 504 | " \n", 505 | " \n", 506 | " \n", 507 | " \n", 508 | " \n", 509 | " \n", 510 | " \n", 511 | " \n", 512 | " \n", 513 | " \n", 514 | " \n", 515 | " \n", 516 | " \n", 517 | " \n", 518 | " \n", 519 | " \n", 520 | " \n", 521 | " \n", 522 | " \n", 523 | " \n", 524 | " \n", 525 | " \n", 526 | "
departamentoprovinciadistritodireccionnogeolatitudelongitude
0LimaLimaSanta AnitaCarretera Central 167, Santa Anita 15008Carretera Central 167, Santa Anita 15008, Sant...-12.045751-76.942885
1LimaLimaSanta AnitaJiron los Eucaliptos 996, La Molina 15023Jiron los Eucaliptos 996, La Molina 15023, San...NaNNaN
2LimaLimaSanta AnitaAvenida Metropolitana Mz M Lot 4, Ate 15026Avenida Metropolitana Mz M Lot 4, Ate 15026, S...NaNNaN
3LimaLimaLuriganchoLos Robles, Lima 15457Los Robles, Lima 15457, Lurigancho, Lima, Lima...-12.010709-76.909938
4LimaLimaLuriganchoAvenida las Torres 276, Lima, Ate 15498Avenida las Torres 276, Lima, Ate 15498, Lurig...-12.014345-76.900770
5LimaLimaLuriganchoAvenida Nicolás Ayllón 7208, Ate 15487Avenida Nicolás Ayllón 7208, Ate 15487, Luriga...NaNNaN
6LimaLimaLuriganchoLa Capitana 190, Lurigancho-Chosica 15461La Capitana 190, Lurigancho-Chosica 15461, Lur...NaNNaN
7LimaLimaSurquilloAvenida Angamos Este 1807-1803, Surquillo 15036Avenida Angamos Este 1807-1803, Surquillo 1503...NaNNaN
8LimaLimaSurquilloAvenida República de Panamá 4295, Surquillo 15048Avenida República de Panamá 4295, Surquillo 15...-12.116153-77.018354
9LimaLimaSurquilloGonzáles Prada, Surquillo 15047Gonzáles Prada, Surquillo 15047, Surquillo, Li...-12.116403-77.021011
10LimaLimaMirafloresCalle Bellavista 207, Miraflores 15074Calle Bellavista 207, Miraflores 15074, Mirafl...-12.122818-77.032740
11LimaLimaMirafloresAvenida Grau 299, Miraflores 15074Avenida Grau 299, Miraflores 15074, Miraflores...-12.120170-77.034772
12LimaLimaMirafloresAlfredo Leon 114, Miraflores 15074Alfredo Leon 114, Miraflores 15074, Miraflores...-12.121135-77.037995
13LimaLimaMirafloresCalle Berlín 1273, Miraflores 15074Calle Berlín 1273, Miraflores 15074, Miraflore...-12.120104-77.040088
14LimaLimaPuente PiedraPasaje Las Vegas, Puente Piedra 15118Pasaje Las Vegas, Puente Piedra 15118, Puente ...NaNNaN
15LimaLimaPuente PiedraCalle 9 de Junio 100, Puente Piedra 15115Calle 9 de Junio 100, Puente Piedra 15115, Pue...NaNNaN
16LimaLimaPuente PiedraAvenida sanez numero 300 urbaizacion cercado d...Avenida sanez numero 300 urbaizacion cercado d...NaNNaN
17LimaLimaPuente PiedraCalle 8 6-130, Puente Piedra 15117Calle 8 6-130, Puente Piedra 15117, Puente Pie...-11.884888-77.070530
18LimaLimaPuente PiedraCalle 8 132-356, Puente Piedra 15117Calle 8 132-356, Puente Piedra 15117, Puente P...NaNNaN
\n", 527 | "
\n", 528 | "
\n", 529 | "\n", 530 | "
\n", 531 | " \n", 539 | "\n", 540 | " \n", 580 | "\n", 581 | " \n", 605 | "
\n", 606 | "\n", 607 | "\n", 608 | "
\n", 609 | " \n", 620 | "\n", 621 | "\n", 710 | "\n", 711 | " \n", 733 | "
\n", 734 | "\n", 735 | "
\n", 736 | " \n", 767 | " \n", 776 | " \n", 788 | "
\n", 789 | "\n", 790 | "
\n", 791 | "
\n" 792 | ], 793 | "application/vnd.google.colaboratory.intrinsic+json": { 794 | "type": "dataframe", 795 | "variable_name": "rawdata_for_osm", 796 | "summary": "{\n \"name\": \"rawdata_for_osm\",\n \"rows\": 19,\n \"fields\": [\n {\n \"column\": \"departamento\",\n \"properties\": {\n \"dtype\": \"category\",\n \"num_unique_values\": 1,\n \"samples\": [\n \"Lima\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"provincia\",\n \"properties\": {\n \"dtype\": \"category\",\n \"num_unique_values\": 1,\n \"samples\": [\n \"Lima\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"distrito\",\n \"properties\": {\n \"dtype\": \"category\",\n \"num_unique_values\": 5,\n \"samples\": [\n \"Lurigancho\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"direccion\",\n \"properties\": {\n \"dtype\": \"string\",\n \"num_unique_values\": 19,\n \"samples\": [\n \"Carretera Central 167, Santa Anita 15008\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"nogeo\",\n \"properties\": {\n \"dtype\": \"string\",\n \"num_unique_values\": 19,\n \"samples\": [\n \"Carretera Central 167, Santa Anita 15008, Santa Anita, Lima, Lima, Per\\u00fa\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"latitude\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 0.07895635756708763,\n \"min\": -12.1228184,\n \"max\": -11.8848884,\n \"num_unique_values\": 10,\n \"samples\": [\n -12.1201043\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"longitude\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 0.0599036593100993,\n \"min\": -77.0705296,\n \"max\": -76.9007696,\n \"num_unique_values\": 10,\n \"samples\": [\n -77.0400876\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n }\n ]\n}" 797 | } 798 | }, 799 | "metadata": {}, 800 | "execution_count": 113 801 | } 802 | ] 803 | }, 804 | { 805 | "cell_type": "markdown", 806 | "source": [ 807 | "### **6.Visualización de datos espaciales**" 808 | ], 809 | "metadata": { 810 | "id": "lgomjYoj9lqW" 811 | } 812 | }, 813 | { 814 | "cell_type": "code", 815 | "execution_count": null, 816 | "metadata": { 817 | "id": "y2NcB8nNhbvh" 818 | }, 819 | "outputs": [], 820 | "source": [ 821 | "# Eliminar datos vacios\n", 822 | "geo_rawdata = rawdata_for_osm.dropna()\n", 823 | "# Dataframe a gepandas\n", 824 | "geo_rawdata = gpd.GeoDataFrame(data = geo_rawdata, geometry=gpd.points_from_xy(geo_rawdata.longitude, geo_rawdata.latitude),crs = 4326)" 825 | ] 826 | }, 827 | { 828 | "cell_type": "code", 829 | "source": [ 830 | "# Visualización interactiva\n", 831 | "geo_rawdata.explore(tiles = \"Esri.WorldImagery\",marker_kwds={'radius': 10} )" 832 | ], 833 | "metadata": { 834 | "id": "cL5iBx2qjgxY" 835 | }, 836 | "execution_count": null, 837 | "outputs": [] 838 | }, 839 | { 840 | "cell_type": "markdown", 841 | "source": [ 842 | "### **7.Geocodificación inversa**" 843 | ], 844 | "metadata": { 845 | "id": "2ikE-iWF96kv" 846 | } 847 | }, 848 | { 849 | "cell_type": "code", 850 | "execution_count": null, 851 | "metadata": { 852 | "id": "b4c2Sv8RhfDO" 853 | }, 854 | "outputs": [], 855 | "source": [ 856 | "# Geocodificación indirecta\n", 857 | "def tidygeocode_inv(row):\n", 858 | " adress = geolocator.reverse([row['latitude'],row['longitude']])\n", 859 | " return(str(adress))" 860 | ] 861 | }, 862 | { 863 | "cell_type": "code", 864 | "source": [ 865 | "geocode_inv = geo_rawdata.copy()" 866 | ], 867 | "metadata": { 868 | "id": "tZ9CIuE_hRSk" 869 | }, 870 | "execution_count": null, 871 | "outputs": [] 872 | }, 873 | { 874 | "cell_type": "code", 875 | "source": [ 876 | "geocode_inv['direccion_geo_inv'] = geocode_inv.apply(tidygeocode_inv, axis = 1)" 877 | ], 878 | "metadata": { 879 | "id": "L_aMTzqNWKXr" 880 | }, 881 | "execution_count": null, 882 | "outputs": [] 883 | }, 884 | { 885 | "cell_type": "code", 886 | "source": [ 887 | "geocode_inv = geocode_inv.drop(columns=['geometry'])\n", 888 | "geocode_inv = gpd.GeoDataFrame(data = geocode_inv, geometry=gpd.points_from_xy(geo_rawdata.longitude, geo_rawdata.latitude),crs = 4326)" 889 | ], 890 | "metadata": { 891 | "id": "B9-pxGawWrwH" 892 | }, 893 | "execution_count": null, 894 | "outputs": [] 895 | }, 896 | { 897 | "cell_type": "code", 898 | "source": [ 899 | "geocode_inv" 900 | ], 901 | "metadata": { 902 | "id": "SVai9lVVii97" 903 | }, 904 | "execution_count": null, 905 | "outputs": [] 906 | }, 907 | { 908 | "cell_type": "markdown", 909 | "source": [ 910 | "### **8.Exportar datos espaciales**" 911 | ], 912 | "metadata": { 913 | "id": "xwJZ-2wk9_U1" 914 | } 915 | }, 916 | { 917 | "cell_type": "code", 918 | "execution_count": null, 919 | "metadata": { 920 | "id": "jRPqMFYohiLH" 921 | }, 922 | "outputs": [], 923 | "source": [ 924 | "# Exportar datos en formato gpkg\n", 925 | "geo_rawdata.to_file('geocoding_directo.gpkg')\n", 926 | "geocode_inv.to_file('geocoding_inverso.gpkg')" 927 | ] 928 | }, 929 | { 930 | "cell_type": "markdown", 931 | "source": [ 932 | "### **9.Gecodificación usando la API de MapBox**\n", 933 | "Para poder optener nuestra API de MapBox tenemos que registrarnos en el siguiente enlace:\n", 934 | " - Registro: *https://account.mapbox.com/auth/signup/*\n", 935 | " - Activar API: *https://account.mapbox.com/access-tokens/create*\n", 936 | "\n", 937 | "#### *Geocodificación gratis: 100 000 al mes*" 938 | ], 939 | "metadata": { 940 | "id": "3ggsxWNc-MDq" 941 | } 942 | }, 943 | { 944 | "cell_type": "code", 945 | "source": [ 946 | "api_mapbox = 'PON_TU_API_KEY_AQUI'\n", 947 | "geolocator = MapBox(api_key = api_mapbox)\n", 948 | "def tidygeocode(row):\n", 949 | " location = geolocator.geocode(row['nogeo'])\n", 950 | " if location:\n", 951 | " return pd.Series({'latitude': location.latitude, 'longitude': location.longitude})\n", 952 | " else:\n", 953 | " return pd.Series({'latitude': None, 'longitude': None})" 954 | ], 955 | "metadata": { 956 | "id": "UX43Gv_i-gYY" 957 | }, 958 | "execution_count": null, 959 | "outputs": [] 960 | }, 961 | { 962 | "cell_type": "code", 963 | "source": [ 964 | "rawdata_for_mapbox[['latitude', 'longitude']] = rawdata_for_mapbox.apply(tidygeocode, axis=1)" 965 | ], 966 | "metadata": { 967 | "id": "Ej-p07RwCW5m" 968 | }, 969 | "execution_count": null, 970 | "outputs": [] 971 | }, 972 | { 973 | "cell_type": "code", 974 | "source": [ 975 | "rawdata_for_mapbox" 976 | ], 977 | "metadata": { 978 | "id": "fjUkNAF-oNR1", 979 | "outputId": "732bec28-217e-4351-ca8d-d03d994f0aba", 980 | "colab": { 981 | "base_uri": "https://localhost:8080/", 982 | "height": 645 983 | } 984 | }, 985 | "execution_count": null, 986 | "outputs": [ 987 | { 988 | "output_type": "execute_result", 989 | "data": { 990 | "text/plain": [ 991 | " departamento provincia distrito \\\n", 992 | "0 Lima Lima Santa Anita \n", 993 | "1 Lima Lima Santa Anita \n", 994 | "2 Lima Lima Santa Anita \n", 995 | "3 Lima Lima Lurigancho \n", 996 | "4 Lima Lima Lurigancho \n", 997 | "5 Lima Lima Lurigancho \n", 998 | "6 Lima Lima Lurigancho \n", 999 | "7 Lima Lima Surquillo \n", 1000 | "8 Lima Lima Surquillo \n", 1001 | "9 Lima Lima Surquillo \n", 1002 | "10 Lima Lima Miraflores \n", 1003 | "11 Lima Lima Miraflores \n", 1004 | "12 Lima Lima Miraflores \n", 1005 | "13 Lima Lima Miraflores \n", 1006 | "14 Lima Lima Puente Piedra \n", 1007 | "15 Lima Lima Puente Piedra \n", 1008 | "16 Lima Lima Puente Piedra \n", 1009 | "17 Lima Lima Puente Piedra \n", 1010 | "18 Lima Lima Puente Piedra \n", 1011 | "\n", 1012 | " direccion \\\n", 1013 | "0 Carretera Central 167, Santa Anita 15008 \n", 1014 | "1 Jiron los Eucaliptos 996, La Molina 15023 \n", 1015 | "2 Avenida Metropolitana Mz M Lot 4, Ate 15026 \n", 1016 | "3 Los Robles, Lima 15457 \n", 1017 | "4 Avenida las Torres 276, Lima, Ate 15498 \n", 1018 | "5 Avenida Nicolás Ayllón 7208, Ate 15487 \n", 1019 | "6 La Capitana 190, Lurigancho-Chosica 15461 \n", 1020 | "7 Avenida Angamos Este 1807-1803, Surquillo 15036 \n", 1021 | "8 Avenida República de Panamá 4295, Surquillo 15048 \n", 1022 | "9 Gonzáles Prada, Surquillo 15047 \n", 1023 | "10 Calle Bellavista 207, Miraflores 15074 \n", 1024 | "11 Avenida Grau 299, Miraflores 15074 \n", 1025 | "12 Alfredo Leon 114, Miraflores 15074 \n", 1026 | "13 Calle Berlín 1273, Miraflores 15074 \n", 1027 | "14 Pasaje Las Vegas, Puente Piedra 15118 \n", 1028 | "15 Calle 9 de Junio 100, Puente Piedra 15115 \n", 1029 | "16 Avenida sanez numero 300 urbaizacion cercado d... \n", 1030 | "17 Calle 8 6-130, Puente Piedra 15117 \n", 1031 | "18 Calle 8 132-356, Puente Piedra 15117 \n", 1032 | "\n", 1033 | " nogeo latitude longitude \n", 1034 | "0 Carretera Central 167, Santa Anita 15008, Sant... -12.048364 -76.971911 \n", 1035 | "1 Jiron los Eucaliptos 996, La Molina 15023, San... -12.089682 -76.957556 \n", 1036 | "2 Avenida Metropolitana Mz M Lot 4, Ate 15026, S... -12.042531 -76.962451 \n", 1037 | "3 Los Robles, Lima 15457, Lurigancho, Lima, Lima... -12.010709 -76.909938 \n", 1038 | "4 Avenida las Torres 276, Lima, Ate 15498, Lurig... -12.001441 -76.921296 \n", 1039 | "5 Avenida Nicolás Ayllón 7208, Ate 15487, Luriga... -11.957943 -76.728594 \n", 1040 | "6 La Capitana 190, Lurigancho-Chosica 15461, Lur... -11.972625 -76.931578 \n", 1041 | "7 Avenida Angamos Este 1807-1803, Surquillo 1503... -12.109998 -76.979985 \n", 1042 | "8 Avenida República de Panamá 4295, Surquillo 15... -12.110501 -77.018335 \n", 1043 | "9 Gonzáles Prada, Surquillo 15047, Surquillo, Li... -12.116907 -77.019599 \n", 1044 | "10 Calle Bellavista 207, Miraflores 15074, Mirafl... -12.120831 -77.031994 \n", 1045 | "11 Avenida Grau 299, Miraflores 15074, Miraflores... -12.121223 -77.034818 \n", 1046 | "12 Alfredo Leon 114, Miraflores 15074, Miraflores... -12.119349 -77.039751 \n", 1047 | "13 Calle Berlín 1273, Miraflores 15074, Miraflore... -12.120072 -77.042339 \n", 1048 | "14 Pasaje Las Vegas, Puente Piedra 15118, Puente ... -11.873307 -77.057781 \n", 1049 | "15 Calle 9 de Junio 100, Puente Piedra 15115, Pue... -11.876333 -77.074534 \n", 1050 | "16 Avenida sanez numero 300 urbaizacion cercado d... -11.876333 -77.074534 \n", 1051 | "17 Calle 8 6-130, Puente Piedra 15117, Puente Pie... -11.950650 -76.993833 \n", 1052 | "18 Calle 8 132-356, Puente Piedra 15117, Puente P... -11.950650 -76.993833 " 1053 | ], 1054 | "text/html": [ 1055 | "\n", 1056 | "
\n", 1057 | "
\n", 1058 | "\n", 1071 | "\n", 1072 | " \n", 1073 | " \n", 1074 | " \n", 1075 | " \n", 1076 | " \n", 1077 | " \n", 1078 | " \n", 1079 | " \n", 1080 | " \n", 1081 | " \n", 1082 | " \n", 1083 | " \n", 1084 | " \n", 1085 | " \n", 1086 | " \n", 1087 | " \n", 1088 | " \n", 1089 | " \n", 1090 | " \n", 1091 | " \n", 1092 | " \n", 1093 | " \n", 1094 | " \n", 1095 | " \n", 1096 | " \n", 1097 | " \n", 1098 | " \n", 1099 | " \n", 1100 | " \n", 1101 | " \n", 1102 | " \n", 1103 | " \n", 1104 | " \n", 1105 | " \n", 1106 | " \n", 1107 | " \n", 1108 | " \n", 1109 | " \n", 1110 | " \n", 1111 | " \n", 1112 | " \n", 1113 | " \n", 1114 | " \n", 1115 | " \n", 1116 | " \n", 1117 | " \n", 1118 | " \n", 1119 | " \n", 1120 | " \n", 1121 | " \n", 1122 | " \n", 1123 | " \n", 1124 | " \n", 1125 | " \n", 1126 | " \n", 1127 | " \n", 1128 | " \n", 1129 | " \n", 1130 | " \n", 1131 | " \n", 1132 | " \n", 1133 | " \n", 1134 | " \n", 1135 | " \n", 1136 | " \n", 1137 | " \n", 1138 | " \n", 1139 | " \n", 1140 | " \n", 1141 | " \n", 1142 | " \n", 1143 | " \n", 1144 | " \n", 1145 | " \n", 1146 | " \n", 1147 | " \n", 1148 | " \n", 1149 | " \n", 1150 | " \n", 1151 | " \n", 1152 | " \n", 1153 | " \n", 1154 | " \n", 1155 | " \n", 1156 | " \n", 1157 | " \n", 1158 | " \n", 1159 | " \n", 1160 | " \n", 1161 | " \n", 1162 | " \n", 1163 | " \n", 1164 | " \n", 1165 | " \n", 1166 | " \n", 1167 | " \n", 1168 | " \n", 1169 | " \n", 1170 | " \n", 1171 | " \n", 1172 | " \n", 1173 | " \n", 1174 | " \n", 1175 | " \n", 1176 | " \n", 1177 | " \n", 1178 | " \n", 1179 | " \n", 1180 | " \n", 1181 | " \n", 1182 | " \n", 1183 | " \n", 1184 | " \n", 1185 | " \n", 1186 | " \n", 1187 | " \n", 1188 | " \n", 1189 | " \n", 1190 | " \n", 1191 | " \n", 1192 | " \n", 1193 | " \n", 1194 | " \n", 1195 | " \n", 1196 | " \n", 1197 | " \n", 1198 | " \n", 1199 | " \n", 1200 | " \n", 1201 | " \n", 1202 | " \n", 1203 | " \n", 1204 | " \n", 1205 | " \n", 1206 | " \n", 1207 | " \n", 1208 | " \n", 1209 | " \n", 1210 | " \n", 1211 | " \n", 1212 | " \n", 1213 | " \n", 1214 | " \n", 1215 | " \n", 1216 | " \n", 1217 | " \n", 1218 | " \n", 1219 | " \n", 1220 | " \n", 1221 | " \n", 1222 | " \n", 1223 | " \n", 1224 | " \n", 1225 | " \n", 1226 | " \n", 1227 | " \n", 1228 | " \n", 1229 | " \n", 1230 | " \n", 1231 | " \n", 1232 | " \n", 1233 | " \n", 1234 | " \n", 1235 | " \n", 1236 | " \n", 1237 | " \n", 1238 | " \n", 1239 | " \n", 1240 | " \n", 1241 | " \n", 1242 | " \n", 1243 | " \n", 1244 | " \n", 1245 | " \n", 1246 | " \n", 1247 | " \n", 1248 | " \n", 1249 | " \n", 1250 | " \n", 1251 | " \n", 1252 | " \n", 1253 | " \n", 1254 | " \n", 1255 | " \n", 1256 | " \n", 1257 | " \n", 1258 | " \n", 1259 | " \n", 1260 | " \n", 1261 | " \n", 1262 | " \n", 1263 | " \n", 1264 | " \n", 1265 | " \n", 1266 | " \n", 1267 | " \n", 1268 | " \n", 1269 | " \n", 1270 | " \n", 1271 | " \n", 1272 | " \n", 1273 | " \n", 1274 | " \n", 1275 | " \n", 1276 | "
departamentoprovinciadistritodireccionnogeolatitudelongitude
0LimaLimaSanta AnitaCarretera Central 167, Santa Anita 15008Carretera Central 167, Santa Anita 15008, Sant...-12.048364-76.971911
1LimaLimaSanta AnitaJiron los Eucaliptos 996, La Molina 15023Jiron los Eucaliptos 996, La Molina 15023, San...-12.089682-76.957556
2LimaLimaSanta AnitaAvenida Metropolitana Mz M Lot 4, Ate 15026Avenida Metropolitana Mz M Lot 4, Ate 15026, S...-12.042531-76.962451
3LimaLimaLuriganchoLos Robles, Lima 15457Los Robles, Lima 15457, Lurigancho, Lima, Lima...-12.010709-76.909938
4LimaLimaLuriganchoAvenida las Torres 276, Lima, Ate 15498Avenida las Torres 276, Lima, Ate 15498, Lurig...-12.001441-76.921296
5LimaLimaLuriganchoAvenida Nicolás Ayllón 7208, Ate 15487Avenida Nicolás Ayllón 7208, Ate 15487, Luriga...-11.957943-76.728594
6LimaLimaLuriganchoLa Capitana 190, Lurigancho-Chosica 15461La Capitana 190, Lurigancho-Chosica 15461, Lur...-11.972625-76.931578
7LimaLimaSurquilloAvenida Angamos Este 1807-1803, Surquillo 15036Avenida Angamos Este 1807-1803, Surquillo 1503...-12.109998-76.979985
8LimaLimaSurquilloAvenida República de Panamá 4295, Surquillo 15048Avenida República de Panamá 4295, Surquillo 15...-12.110501-77.018335
9LimaLimaSurquilloGonzáles Prada, Surquillo 15047Gonzáles Prada, Surquillo 15047, Surquillo, Li...-12.116907-77.019599
10LimaLimaMirafloresCalle Bellavista 207, Miraflores 15074Calle Bellavista 207, Miraflores 15074, Mirafl...-12.120831-77.031994
11LimaLimaMirafloresAvenida Grau 299, Miraflores 15074Avenida Grau 299, Miraflores 15074, Miraflores...-12.121223-77.034818
12LimaLimaMirafloresAlfredo Leon 114, Miraflores 15074Alfredo Leon 114, Miraflores 15074, Miraflores...-12.119349-77.039751
13LimaLimaMirafloresCalle Berlín 1273, Miraflores 15074Calle Berlín 1273, Miraflores 15074, Miraflore...-12.120072-77.042339
14LimaLimaPuente PiedraPasaje Las Vegas, Puente Piedra 15118Pasaje Las Vegas, Puente Piedra 15118, Puente ...-11.873307-77.057781
15LimaLimaPuente PiedraCalle 9 de Junio 100, Puente Piedra 15115Calle 9 de Junio 100, Puente Piedra 15115, Pue...-11.876333-77.074534
16LimaLimaPuente PiedraAvenida sanez numero 300 urbaizacion cercado d...Avenida sanez numero 300 urbaizacion cercado d...-11.876333-77.074534
17LimaLimaPuente PiedraCalle 8 6-130, Puente Piedra 15117Calle 8 6-130, Puente Piedra 15117, Puente Pie...-11.950650-76.993833
18LimaLimaPuente PiedraCalle 8 132-356, Puente Piedra 15117Calle 8 132-356, Puente Piedra 15117, Puente P...-11.950650-76.993833
\n", 1277 | "
\n", 1278 | "
\n", 1279 | "\n", 1280 | "
\n", 1281 | " \n", 1289 | "\n", 1290 | " \n", 1330 | "\n", 1331 | " \n", 1355 | "
\n", 1356 | "\n", 1357 | "\n", 1358 | "
\n", 1359 | " \n", 1370 | "\n", 1371 | "\n", 1460 | "\n", 1461 | " \n", 1483 | "
\n", 1484 | "\n", 1485 | "
\n", 1486 | " \n", 1517 | " \n", 1526 | " \n", 1538 | "
\n", 1539 | "\n", 1540 | "
\n", 1541 | "
\n" 1542 | ], 1543 | "application/vnd.google.colaboratory.intrinsic+json": { 1544 | "type": "dataframe", 1545 | "variable_name": "rawdata_for_mapbox", 1546 | "summary": "{\n \"name\": \"rawdata_for_mapbox\",\n \"rows\": 19,\n \"fields\": [\n {\n \"column\": \"departamento\",\n \"properties\": {\n \"dtype\": \"category\",\n \"num_unique_values\": 1,\n \"samples\": [\n \"Lima\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"provincia\",\n \"properties\": {\n \"dtype\": \"category\",\n \"num_unique_values\": 1,\n \"samples\": [\n \"Lima\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"distrito\",\n \"properties\": {\n \"dtype\": \"category\",\n \"num_unique_values\": 5,\n \"samples\": [\n \"Lurigancho\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"direccion\",\n \"properties\": {\n \"dtype\": \"string\",\n \"num_unique_values\": 19,\n \"samples\": [\n \"Carretera Central 167, Santa Anita 15008\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"nogeo\",\n \"properties\": {\n \"dtype\": \"string\",\n \"num_unique_values\": 19,\n \"samples\": [\n \"Carretera Central 167, Santa Anita 15008, Santa Anita, Lima, Lima, Per\\u00fa\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"latitude\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 0.09149062137404783,\n \"min\": -12.121223,\n \"max\": -11.8733067,\n \"num_unique_values\": 17,\n \"samples\": [\n -12.048364\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"longitude\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 0.07974673381636406,\n \"min\": -77.074534,\n \"max\": -76.7285945,\n \"num_unique_values\": 17,\n \"samples\": [\n -76.971911\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n }\n ]\n}" 1547 | } 1548 | }, 1549 | "metadata": {}, 1550 | "execution_count": 124 1551 | } 1552 | ] 1553 | }, 1554 | { 1555 | "cell_type": "markdown", 1556 | "source": [ 1557 | "### **10.Gecodificación usando la API de ArcGIS**\n", 1558 | "Para poder optener nuestra API de ArcGIS tenemos que registrarnos en el siguiente enlace:\n", 1559 | " * Registro: *https://developers.arcgis.com/sign-up/*\n", 1560 | " * Activar API: *https://developers.arcgis.com/dashboard/#*\n", 1561 | "\n", 1562 | "#### *Geocodificación gratis: 20 000 gratis*" 1563 | ], 1564 | "metadata": { 1565 | "id": "PVudz9Xi-Vq9" 1566 | } 1567 | }, 1568 | { 1569 | "cell_type": "code", 1570 | "source": [ 1571 | "api_arcgis = 'PON_TU_API_KEY_AQUI'\n", 1572 | "geolocator = ArcGIS(auth_domain = api_arcgis)\n", 1573 | "def tidygeocode(row):\n", 1574 | " location = geolocator.geocode(row['nogeo'])\n", 1575 | " if location:\n", 1576 | " return pd.Series({'latitude': location.latitude, 'longitude': location.longitude})\n", 1577 | " else:\n", 1578 | " return pd.Series({'latitude': None, 'longitude': None})" 1579 | ], 1580 | "metadata": { 1581 | "id": "e5sIsifs-gxx" 1582 | }, 1583 | "execution_count": null, 1584 | "outputs": [] 1585 | }, 1586 | { 1587 | "cell_type": "code", 1588 | "source": [ 1589 | "rawdata_for_arcgis[['latitude', 'longitude']] = rawdata_for_arcgis.apply(tidygeocode, axis=1)" 1590 | ], 1591 | "metadata": { 1592 | "id": "SoGySMI3DADB" 1593 | }, 1594 | "execution_count": null, 1595 | "outputs": [] 1596 | }, 1597 | { 1598 | "cell_type": "code", 1599 | "source": [ 1600 | "rawdata_for_arcgis" 1601 | ], 1602 | "metadata": { 1603 | "id": "UdjlBNjKobnv", 1604 | "outputId": "565b55e0-66aa-47bb-fc2c-174f7c241762", 1605 | "colab": { 1606 | "base_uri": "https://localhost:8080/", 1607 | "height": 645 1608 | } 1609 | }, 1610 | "execution_count": null, 1611 | "outputs": [ 1612 | { 1613 | "output_type": "execute_result", 1614 | "data": { 1615 | "text/plain": [ 1616 | " departamento provincia distrito \\\n", 1617 | "0 Lima Lima Santa Anita \n", 1618 | "1 Lima Lima Santa Anita \n", 1619 | "2 Lima Lima Santa Anita \n", 1620 | "3 Lima Lima Lurigancho \n", 1621 | "4 Lima Lima Lurigancho \n", 1622 | "5 Lima Lima Lurigancho \n", 1623 | "6 Lima Lima Lurigancho \n", 1624 | "7 Lima Lima Surquillo \n", 1625 | "8 Lima Lima Surquillo \n", 1626 | "9 Lima Lima Surquillo \n", 1627 | "10 Lima Lima Miraflores \n", 1628 | "11 Lima Lima Miraflores \n", 1629 | "12 Lima Lima Miraflores \n", 1630 | "13 Lima Lima Miraflores \n", 1631 | "14 Lima Lima Puente Piedra \n", 1632 | "15 Lima Lima Puente Piedra \n", 1633 | "16 Lima Lima Puente Piedra \n", 1634 | "17 Lima Lima Puente Piedra \n", 1635 | "18 Lima Lima Puente Piedra \n", 1636 | "\n", 1637 | " direccion \\\n", 1638 | "0 Carretera Central 167, Santa Anita 15008 \n", 1639 | "1 Jiron los Eucaliptos 996, La Molina 15023 \n", 1640 | "2 Avenida Metropolitana Mz M Lot 4, Ate 15026 \n", 1641 | "3 Los Robles, Lima 15457 \n", 1642 | "4 Avenida las Torres 276, Lima, Ate 15498 \n", 1643 | "5 Avenida Nicolás Ayllón 7208, Ate 15487 \n", 1644 | "6 La Capitana 190, Lurigancho-Chosica 15461 \n", 1645 | "7 Avenida Angamos Este 1807-1803, Surquillo 15036 \n", 1646 | "8 Avenida República de Panamá 4295, Surquillo 15048 \n", 1647 | "9 Gonzáles Prada, Surquillo 15047 \n", 1648 | "10 Calle Bellavista 207, Miraflores 15074 \n", 1649 | "11 Avenida Grau 299, Miraflores 15074 \n", 1650 | "12 Alfredo Leon 114, Miraflores 15074 \n", 1651 | "13 Calle Berlín 1273, Miraflores 15074 \n", 1652 | "14 Pasaje Las Vegas, Puente Piedra 15118 \n", 1653 | "15 Calle 9 de Junio 100, Puente Piedra 15115 \n", 1654 | "16 Avenida sanez numero 300 urbaizacion cercado d... \n", 1655 | "17 Calle 8 6-130, Puente Piedra 15117 \n", 1656 | "18 Calle 8 132-356, Puente Piedra 15117 \n", 1657 | "\n", 1658 | " nogeo latitude longitude \n", 1659 | "0 Carretera Central 167, Santa Anita 15008, Sant... -12.056697 -76.969772 \n", 1660 | "1 Jiron los Eucaliptos 996, La Molina 15023, San... -12.065913 -76.967481 \n", 1661 | "2 Avenida Metropolitana Mz M Lot 4, Ate 15026, S... -12.033272 -76.940326 \n", 1662 | "3 Los Robles, Lima 15457, Lurigancho, Lima, Lima... -12.010731 -76.909908 \n", 1663 | "4 Avenida las Torres 276, Lima, Ate 15498, Lurig... -12.009716 -76.905490 \n", 1664 | "5 Avenida Nicolás Ayllón 7208, Ate 15487, Luriga... -12.015194 -76.886799 \n", 1665 | "6 La Capitana 190, Lurigancho-Chosica 15461, Lur... -12.009340 -76.905460 \n", 1666 | "7 Avenida Angamos Este 1807-1803, Surquillo 1503... -12.112210 -77.010670 \n", 1667 | "8 Avenida República de Panamá 4295, Surquillo 15... -12.107650 -77.018440 \n", 1668 | "9 Gonzáles Prada, Surquillo 15047, Surquillo, Li... -12.116500 -77.022113 \n", 1669 | "10 Calle Bellavista 207, Miraflores 15074, Mirafl... -12.120800 -77.031960 \n", 1670 | "11 Avenida Grau 299, Miraflores 15074, Miraflores... -12.121150 -77.034760 \n", 1671 | "12 Alfredo Leon 114, Miraflores 15074, Miraflores... -12.119380 -77.039810 \n", 1672 | "13 Calle Berlín 1273, Miraflores 15074, Miraflore... -12.120110 -77.042210 \n", 1673 | "14 Pasaje Las Vegas, Puente Piedra 15118, Puente ... -11.867809 -77.076653 \n", 1674 | "15 Calle 9 de Junio 100, Puente Piedra 15115, Pue... -11.867419 -77.078053 \n", 1675 | "16 Avenida sanez numero 300 urbaizacion cercado d... -11.838300 -77.098630 \n", 1676 | "17 Calle 8 6-130, Puente Piedra 15117, Puente Pie... -11.866935 -77.073642 \n", 1677 | "18 Calle 8 132-356, Puente Piedra 15117, Puente P... -11.866935 -77.073642 " 1678 | ], 1679 | "text/html": [ 1680 | "\n", 1681 | "
\n", 1682 | "
\n", 1683 | "\n", 1696 | "\n", 1697 | " \n", 1698 | " \n", 1699 | " \n", 1700 | " \n", 1701 | " \n", 1702 | " \n", 1703 | " \n", 1704 | " \n", 1705 | " \n", 1706 | " \n", 1707 | " \n", 1708 | " \n", 1709 | " \n", 1710 | " \n", 1711 | " \n", 1712 | " \n", 1713 | " \n", 1714 | " \n", 1715 | " \n", 1716 | " \n", 1717 | " \n", 1718 | " \n", 1719 | " \n", 1720 | " \n", 1721 | " \n", 1722 | " \n", 1723 | " \n", 1724 | " \n", 1725 | " \n", 1726 | " \n", 1727 | " \n", 1728 | " \n", 1729 | " \n", 1730 | " \n", 1731 | " \n", 1732 | " \n", 1733 | " \n", 1734 | " \n", 1735 | " \n", 1736 | " \n", 1737 | " \n", 1738 | " \n", 1739 | " \n", 1740 | " \n", 1741 | " \n", 1742 | " \n", 1743 | " \n", 1744 | " \n", 1745 | " \n", 1746 | " \n", 1747 | " \n", 1748 | " \n", 1749 | " \n", 1750 | " \n", 1751 | " \n", 1752 | " \n", 1753 | " \n", 1754 | " \n", 1755 | " \n", 1756 | " \n", 1757 | " \n", 1758 | " \n", 1759 | " \n", 1760 | " \n", 1761 | " \n", 1762 | " \n", 1763 | " \n", 1764 | " \n", 1765 | " \n", 1766 | " \n", 1767 | " \n", 1768 | " \n", 1769 | " \n", 1770 | " \n", 1771 | " \n", 1772 | " \n", 1773 | " \n", 1774 | " \n", 1775 | " \n", 1776 | " \n", 1777 | " \n", 1778 | " \n", 1779 | " \n", 1780 | " \n", 1781 | " \n", 1782 | " \n", 1783 | " \n", 1784 | " \n", 1785 | " \n", 1786 | " \n", 1787 | " \n", 1788 | " \n", 1789 | " \n", 1790 | " \n", 1791 | " \n", 1792 | " \n", 1793 | " \n", 1794 | " \n", 1795 | " \n", 1796 | " \n", 1797 | " \n", 1798 | " \n", 1799 | " \n", 1800 | " \n", 1801 | " \n", 1802 | " \n", 1803 | " \n", 1804 | " \n", 1805 | " \n", 1806 | " \n", 1807 | " \n", 1808 | " \n", 1809 | " \n", 1810 | " \n", 1811 | " \n", 1812 | " \n", 1813 | " \n", 1814 | " \n", 1815 | " \n", 1816 | " \n", 1817 | " \n", 1818 | " \n", 1819 | " \n", 1820 | " \n", 1821 | " \n", 1822 | " \n", 1823 | " \n", 1824 | " \n", 1825 | " \n", 1826 | " \n", 1827 | " \n", 1828 | " \n", 1829 | " \n", 1830 | " \n", 1831 | " \n", 1832 | " \n", 1833 | " \n", 1834 | " \n", 1835 | " \n", 1836 | " \n", 1837 | " \n", 1838 | " \n", 1839 | " \n", 1840 | " \n", 1841 | " \n", 1842 | " \n", 1843 | " \n", 1844 | " \n", 1845 | " \n", 1846 | " \n", 1847 | " \n", 1848 | " \n", 1849 | " \n", 1850 | " \n", 1851 | " \n", 1852 | " \n", 1853 | " \n", 1854 | " \n", 1855 | " \n", 1856 | " \n", 1857 | " \n", 1858 | " \n", 1859 | " \n", 1860 | " \n", 1861 | " \n", 1862 | " \n", 1863 | " \n", 1864 | " \n", 1865 | " \n", 1866 | " \n", 1867 | " \n", 1868 | " \n", 1869 | " \n", 1870 | " \n", 1871 | " \n", 1872 | " \n", 1873 | " \n", 1874 | " \n", 1875 | " \n", 1876 | " \n", 1877 | " \n", 1878 | " \n", 1879 | " \n", 1880 | " \n", 1881 | " \n", 1882 | " \n", 1883 | " \n", 1884 | " \n", 1885 | " \n", 1886 | " \n", 1887 | " \n", 1888 | " \n", 1889 | " \n", 1890 | " \n", 1891 | " \n", 1892 | " \n", 1893 | " \n", 1894 | " \n", 1895 | " \n", 1896 | " \n", 1897 | " \n", 1898 | " \n", 1899 | " \n", 1900 | " \n", 1901 | "
departamentoprovinciadistritodireccionnogeolatitudelongitude
0LimaLimaSanta AnitaCarretera Central 167, Santa Anita 15008Carretera Central 167, Santa Anita 15008, Sant...-12.056697-76.969772
1LimaLimaSanta AnitaJiron los Eucaliptos 996, La Molina 15023Jiron los Eucaliptos 996, La Molina 15023, San...-12.065913-76.967481
2LimaLimaSanta AnitaAvenida Metropolitana Mz M Lot 4, Ate 15026Avenida Metropolitana Mz M Lot 4, Ate 15026, S...-12.033272-76.940326
3LimaLimaLuriganchoLos Robles, Lima 15457Los Robles, Lima 15457, Lurigancho, Lima, Lima...-12.010731-76.909908
4LimaLimaLuriganchoAvenida las Torres 276, Lima, Ate 15498Avenida las Torres 276, Lima, Ate 15498, Lurig...-12.009716-76.905490
5LimaLimaLuriganchoAvenida Nicolás Ayllón 7208, Ate 15487Avenida Nicolás Ayllón 7208, Ate 15487, Luriga...-12.015194-76.886799
6LimaLimaLuriganchoLa Capitana 190, Lurigancho-Chosica 15461La Capitana 190, Lurigancho-Chosica 15461, Lur...-12.009340-76.905460
7LimaLimaSurquilloAvenida Angamos Este 1807-1803, Surquillo 15036Avenida Angamos Este 1807-1803, Surquillo 1503...-12.112210-77.010670
8LimaLimaSurquilloAvenida República de Panamá 4295, Surquillo 15048Avenida República de Panamá 4295, Surquillo 15...-12.107650-77.018440
9LimaLimaSurquilloGonzáles Prada, Surquillo 15047Gonzáles Prada, Surquillo 15047, Surquillo, Li...-12.116500-77.022113
10LimaLimaMirafloresCalle Bellavista 207, Miraflores 15074Calle Bellavista 207, Miraflores 15074, Mirafl...-12.120800-77.031960
11LimaLimaMirafloresAvenida Grau 299, Miraflores 15074Avenida Grau 299, Miraflores 15074, Miraflores...-12.121150-77.034760
12LimaLimaMirafloresAlfredo Leon 114, Miraflores 15074Alfredo Leon 114, Miraflores 15074, Miraflores...-12.119380-77.039810
13LimaLimaMirafloresCalle Berlín 1273, Miraflores 15074Calle Berlín 1273, Miraflores 15074, Miraflore...-12.120110-77.042210
14LimaLimaPuente PiedraPasaje Las Vegas, Puente Piedra 15118Pasaje Las Vegas, Puente Piedra 15118, Puente ...-11.867809-77.076653
15LimaLimaPuente PiedraCalle 9 de Junio 100, Puente Piedra 15115Calle 9 de Junio 100, Puente Piedra 15115, Pue...-11.867419-77.078053
16LimaLimaPuente PiedraAvenida sanez numero 300 urbaizacion cercado d...Avenida sanez numero 300 urbaizacion cercado d...-11.838300-77.098630
17LimaLimaPuente PiedraCalle 8 6-130, Puente Piedra 15117Calle 8 6-130, Puente Piedra 15117, Puente Pie...-11.866935-77.073642
18LimaLimaPuente PiedraCalle 8 132-356, Puente Piedra 15117Calle 8 132-356, Puente Piedra 15117, Puente P...-11.866935-77.073642
\n", 1902 | "
\n", 1903 | "
\n", 1904 | "\n", 1905 | "
\n", 1906 | " \n", 1914 | "\n", 1915 | " \n", 1955 | "\n", 1956 | " \n", 1980 | "
\n", 1981 | "\n", 1982 | "\n", 1983 | "
\n", 1984 | " \n", 1995 | "\n", 1996 | "\n", 2085 | "\n", 2086 | " \n", 2108 | "
\n", 2109 | "\n", 2110 | "
\n", 2111 | " \n", 2142 | " \n", 2151 | " \n", 2163 | "
\n", 2164 | "\n", 2165 | "
\n", 2166 | "
\n" 2167 | ], 2168 | "application/vnd.google.colaboratory.intrinsic+json": { 2169 | "type": "dataframe", 2170 | "variable_name": "rawdata_for_arcgis", 2171 | "summary": "{\n \"name\": \"rawdata_for_arcgis\",\n \"rows\": 19,\n \"fields\": [\n {\n \"column\": \"departamento\",\n \"properties\": {\n \"dtype\": \"category\",\n \"num_unique_values\": 1,\n \"samples\": [\n \"Lima\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"provincia\",\n \"properties\": {\n \"dtype\": \"category\",\n \"num_unique_values\": 1,\n \"samples\": [\n \"Lima\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"distrito\",\n \"properties\": {\n \"dtype\": \"category\",\n \"num_unique_values\": 5,\n \"samples\": [\n \"Lurigancho\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"direccion\",\n \"properties\": {\n \"dtype\": \"string\",\n \"num_unique_values\": 19,\n \"samples\": [\n \"Carretera Central 167, Santa Anita 15008\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"nogeo\",\n \"properties\": {\n \"dtype\": \"string\",\n \"num_unique_values\": 19,\n \"samples\": [\n \"Carretera Central 167, Santa Anita 15008, Santa Anita, Lima, Lima, Per\\u00fa\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"latitude\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 0.10432579391195491,\n \"min\": -12.121150019635,\n \"max\": -11.8383,\n \"num_unique_values\": 18,\n \"samples\": [\n -12.056696969231\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"longitude\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 0.06791612421471181,\n \"min\": -77.09863,\n \"max\": -76.886798593187,\n \"num_unique_values\": 18,\n \"samples\": [\n -76.969772234329\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n }\n ]\n}" 2172 | } 2173 | }, 2174 | "metadata": {}, 2175 | "execution_count": 127 2176 | } 2177 | ] 2178 | } 2179 | ], 2180 | "metadata": { 2181 | "colab": { 2182 | "provenance": [], 2183 | "include_colab_link": true 2184 | }, 2185 | "kernelspec": { 2186 | "display_name": "Python 3", 2187 | "name": "python3" 2188 | }, 2189 | "language_info": { 2190 | "name": "python" 2191 | } 2192 | }, 2193 | "nbformat": 4, 2194 | "nbformat_minor": 0 2195 | } -------------------------------------------------------------------------------- /img/banner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/geografope/geocodificacion-con-python/dee3c7165cc8417a2cfaaa5b05afa23381bb3802/img/banner.png -------------------------------------------------------------------------------- /rawdata/rawdata.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/geografope/geocodificacion-con-python/dee3c7165cc8417a2cfaaa5b05afa23381bb3802/rawdata/rawdata.xlsx --------------------------------------------------------------------------------