├── 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 | [](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 | "
"
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 | " departamento | \n",
326 | " provincia | \n",
327 | " distrito | \n",
328 | " direccion | \n",
329 | " nogeo | \n",
330 | " latitude | \n",
331 | " longitude | \n",
332 | "
\n",
333 | " \n",
334 | " \n",
335 | " \n",
336 | " 0 | \n",
337 | " Lima | \n",
338 | " Lima | \n",
339 | " Santa Anita | \n",
340 | " Carretera Central 167, Santa Anita 15008 | \n",
341 | " Carretera Central 167, Santa Anita 15008, Sant... | \n",
342 | " -12.045751 | \n",
343 | " -76.942885 | \n",
344 | "
\n",
345 | " \n",
346 | " 1 | \n",
347 | " Lima | \n",
348 | " Lima | \n",
349 | " Santa Anita | \n",
350 | " Jiron los Eucaliptos 996, La Molina 15023 | \n",
351 | " Jiron los Eucaliptos 996, La Molina 15023, San... | \n",
352 | " NaN | \n",
353 | " NaN | \n",
354 | "
\n",
355 | " \n",
356 | " 2 | \n",
357 | " Lima | \n",
358 | " Lima | \n",
359 | " Santa Anita | \n",
360 | " Avenida Metropolitana Mz M Lot 4, Ate 15026 | \n",
361 | " Avenida Metropolitana Mz M Lot 4, Ate 15026, S... | \n",
362 | " NaN | \n",
363 | " NaN | \n",
364 | "
\n",
365 | " \n",
366 | " 3 | \n",
367 | " Lima | \n",
368 | " Lima | \n",
369 | " Lurigancho | \n",
370 | " Los Robles, Lima 15457 | \n",
371 | " Los Robles, Lima 15457, Lurigancho, Lima, Lima... | \n",
372 | " -12.010709 | \n",
373 | " -76.909938 | \n",
374 | "
\n",
375 | " \n",
376 | " 4 | \n",
377 | " Lima | \n",
378 | " Lima | \n",
379 | " Lurigancho | \n",
380 | " Avenida las Torres 276, Lima, Ate 15498 | \n",
381 | " Avenida las Torres 276, Lima, Ate 15498, Lurig... | \n",
382 | " -12.014345 | \n",
383 | " -76.900770 | \n",
384 | "
\n",
385 | " \n",
386 | " 5 | \n",
387 | " Lima | \n",
388 | " Lima | \n",
389 | " Lurigancho | \n",
390 | " Avenida Nicolás Ayllón 7208, Ate 15487 | \n",
391 | " Avenida Nicolás Ayllón 7208, Ate 15487, Luriga... | \n",
392 | " NaN | \n",
393 | " NaN | \n",
394 | "
\n",
395 | " \n",
396 | " 6 | \n",
397 | " Lima | \n",
398 | " Lima | \n",
399 | " Lurigancho | \n",
400 | " La Capitana 190, Lurigancho-Chosica 15461 | \n",
401 | " La Capitana 190, Lurigancho-Chosica 15461, Lur... | \n",
402 | " NaN | \n",
403 | " NaN | \n",
404 | "
\n",
405 | " \n",
406 | " 7 | \n",
407 | " Lima | \n",
408 | " Lima | \n",
409 | " Surquillo | \n",
410 | " Avenida Angamos Este 1807-1803, Surquillo 15036 | \n",
411 | " Avenida Angamos Este 1807-1803, Surquillo 1503... | \n",
412 | " NaN | \n",
413 | " NaN | \n",
414 | "
\n",
415 | " \n",
416 | " 8 | \n",
417 | " Lima | \n",
418 | " Lima | \n",
419 | " Surquillo | \n",
420 | " Avenida República de Panamá 4295, Surquillo 15048 | \n",
421 | " Avenida República de Panamá 4295, Surquillo 15... | \n",
422 | " -12.116153 | \n",
423 | " -77.018354 | \n",
424 | "
\n",
425 | " \n",
426 | " 9 | \n",
427 | " Lima | \n",
428 | " Lima | \n",
429 | " Surquillo | \n",
430 | " Gonzáles Prada, Surquillo 15047 | \n",
431 | " Gonzáles Prada, Surquillo 15047, Surquillo, Li... | \n",
432 | " -12.116403 | \n",
433 | " -77.021011 | \n",
434 | "
\n",
435 | " \n",
436 | " 10 | \n",
437 | " Lima | \n",
438 | " Lima | \n",
439 | " Miraflores | \n",
440 | " Calle Bellavista 207, Miraflores 15074 | \n",
441 | " Calle Bellavista 207, Miraflores 15074, Mirafl... | \n",
442 | " -12.122818 | \n",
443 | " -77.032740 | \n",
444 | "
\n",
445 | " \n",
446 | " 11 | \n",
447 | " Lima | \n",
448 | " Lima | \n",
449 | " Miraflores | \n",
450 | " Avenida Grau 299, Miraflores 15074 | \n",
451 | " Avenida Grau 299, Miraflores 15074, Miraflores... | \n",
452 | " -12.120170 | \n",
453 | " -77.034772 | \n",
454 | "
\n",
455 | " \n",
456 | " 12 | \n",
457 | " Lima | \n",
458 | " Lima | \n",
459 | " Miraflores | \n",
460 | " Alfredo Leon 114, Miraflores 15074 | \n",
461 | " Alfredo Leon 114, Miraflores 15074, Miraflores... | \n",
462 | " -12.121135 | \n",
463 | " -77.037995 | \n",
464 | "
\n",
465 | " \n",
466 | " 13 | \n",
467 | " Lima | \n",
468 | " Lima | \n",
469 | " Miraflores | \n",
470 | " Calle Berlín 1273, Miraflores 15074 | \n",
471 | " Calle Berlín 1273, Miraflores 15074, Miraflore... | \n",
472 | " -12.120104 | \n",
473 | " -77.040088 | \n",
474 | "
\n",
475 | " \n",
476 | " 14 | \n",
477 | " Lima | \n",
478 | " Lima | \n",
479 | " Puente Piedra | \n",
480 | " Pasaje Las Vegas, Puente Piedra 15118 | \n",
481 | " Pasaje Las Vegas, Puente Piedra 15118, Puente ... | \n",
482 | " NaN | \n",
483 | " NaN | \n",
484 | "
\n",
485 | " \n",
486 | " 15 | \n",
487 | " Lima | \n",
488 | " Lima | \n",
489 | " Puente Piedra | \n",
490 | " Calle 9 de Junio 100, Puente Piedra 15115 | \n",
491 | " Calle 9 de Junio 100, Puente Piedra 15115, Pue... | \n",
492 | " NaN | \n",
493 | " NaN | \n",
494 | "
\n",
495 | " \n",
496 | " 16 | \n",
497 | " Lima | \n",
498 | " Lima | \n",
499 | " Puente Piedra | \n",
500 | " Avenida sanez numero 300 urbaizacion cercado d... | \n",
501 | " Avenida sanez numero 300 urbaizacion cercado d... | \n",
502 | " NaN | \n",
503 | " NaN | \n",
504 | "
\n",
505 | " \n",
506 | " 17 | \n",
507 | " Lima | \n",
508 | " Lima | \n",
509 | " Puente Piedra | \n",
510 | " Calle 8 6-130, Puente Piedra 15117 | \n",
511 | " Calle 8 6-130, Puente Piedra 15117, Puente Pie... | \n",
512 | " -11.884888 | \n",
513 | " -77.070530 | \n",
514 | "
\n",
515 | " \n",
516 | " 18 | \n",
517 | " Lima | \n",
518 | " Lima | \n",
519 | " Puente Piedra | \n",
520 | " Calle 8 132-356, Puente Piedra 15117 | \n",
521 | " Calle 8 132-356, Puente Piedra 15117, Puente P... | \n",
522 | " NaN | \n",
523 | " NaN | \n",
524 | "
\n",
525 | " \n",
526 | "
\n",
527 | "
\n",
528 | "
\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 | " departamento | \n",
1076 | " provincia | \n",
1077 | " distrito | \n",
1078 | " direccion | \n",
1079 | " nogeo | \n",
1080 | " latitude | \n",
1081 | " longitude | \n",
1082 | "
\n",
1083 | " \n",
1084 | " \n",
1085 | " \n",
1086 | " 0 | \n",
1087 | " Lima | \n",
1088 | " Lima | \n",
1089 | " Santa Anita | \n",
1090 | " Carretera Central 167, Santa Anita 15008 | \n",
1091 | " Carretera Central 167, Santa Anita 15008, Sant... | \n",
1092 | " -12.048364 | \n",
1093 | " -76.971911 | \n",
1094 | "
\n",
1095 | " \n",
1096 | " 1 | \n",
1097 | " Lima | \n",
1098 | " Lima | \n",
1099 | " Santa Anita | \n",
1100 | " Jiron los Eucaliptos 996, La Molina 15023 | \n",
1101 | " Jiron los Eucaliptos 996, La Molina 15023, San... | \n",
1102 | " -12.089682 | \n",
1103 | " -76.957556 | \n",
1104 | "
\n",
1105 | " \n",
1106 | " 2 | \n",
1107 | " Lima | \n",
1108 | " Lima | \n",
1109 | " Santa Anita | \n",
1110 | " Avenida Metropolitana Mz M Lot 4, Ate 15026 | \n",
1111 | " Avenida Metropolitana Mz M Lot 4, Ate 15026, S... | \n",
1112 | " -12.042531 | \n",
1113 | " -76.962451 | \n",
1114 | "
\n",
1115 | " \n",
1116 | " 3 | \n",
1117 | " Lima | \n",
1118 | " Lima | \n",
1119 | " Lurigancho | \n",
1120 | " Los Robles, Lima 15457 | \n",
1121 | " Los Robles, Lima 15457, Lurigancho, Lima, Lima... | \n",
1122 | " -12.010709 | \n",
1123 | " -76.909938 | \n",
1124 | "
\n",
1125 | " \n",
1126 | " 4 | \n",
1127 | " Lima | \n",
1128 | " Lima | \n",
1129 | " Lurigancho | \n",
1130 | " Avenida las Torres 276, Lima, Ate 15498 | \n",
1131 | " Avenida las Torres 276, Lima, Ate 15498, Lurig... | \n",
1132 | " -12.001441 | \n",
1133 | " -76.921296 | \n",
1134 | "
\n",
1135 | " \n",
1136 | " 5 | \n",
1137 | " Lima | \n",
1138 | " Lima | \n",
1139 | " Lurigancho | \n",
1140 | " Avenida Nicolás Ayllón 7208, Ate 15487 | \n",
1141 | " Avenida Nicolás Ayllón 7208, Ate 15487, Luriga... | \n",
1142 | " -11.957943 | \n",
1143 | " -76.728594 | \n",
1144 | "
\n",
1145 | " \n",
1146 | " 6 | \n",
1147 | " Lima | \n",
1148 | " Lima | \n",
1149 | " Lurigancho | \n",
1150 | " La Capitana 190, Lurigancho-Chosica 15461 | \n",
1151 | " La Capitana 190, Lurigancho-Chosica 15461, Lur... | \n",
1152 | " -11.972625 | \n",
1153 | " -76.931578 | \n",
1154 | "
\n",
1155 | " \n",
1156 | " 7 | \n",
1157 | " Lima | \n",
1158 | " Lima | \n",
1159 | " Surquillo | \n",
1160 | " Avenida Angamos Este 1807-1803, Surquillo 15036 | \n",
1161 | " Avenida Angamos Este 1807-1803, Surquillo 1503... | \n",
1162 | " -12.109998 | \n",
1163 | " -76.979985 | \n",
1164 | "
\n",
1165 | " \n",
1166 | " 8 | \n",
1167 | " Lima | \n",
1168 | " Lima | \n",
1169 | " Surquillo | \n",
1170 | " Avenida República de Panamá 4295, Surquillo 15048 | \n",
1171 | " Avenida República de Panamá 4295, Surquillo 15... | \n",
1172 | " -12.110501 | \n",
1173 | " -77.018335 | \n",
1174 | "
\n",
1175 | " \n",
1176 | " 9 | \n",
1177 | " Lima | \n",
1178 | " Lima | \n",
1179 | " Surquillo | \n",
1180 | " Gonzáles Prada, Surquillo 15047 | \n",
1181 | " Gonzáles Prada, Surquillo 15047, Surquillo, Li... | \n",
1182 | " -12.116907 | \n",
1183 | " -77.019599 | \n",
1184 | "
\n",
1185 | " \n",
1186 | " 10 | \n",
1187 | " Lima | \n",
1188 | " Lima | \n",
1189 | " Miraflores | \n",
1190 | " Calle Bellavista 207, Miraflores 15074 | \n",
1191 | " Calle Bellavista 207, Miraflores 15074, Mirafl... | \n",
1192 | " -12.120831 | \n",
1193 | " -77.031994 | \n",
1194 | "
\n",
1195 | " \n",
1196 | " 11 | \n",
1197 | " Lima | \n",
1198 | " Lima | \n",
1199 | " Miraflores | \n",
1200 | " Avenida Grau 299, Miraflores 15074 | \n",
1201 | " Avenida Grau 299, Miraflores 15074, Miraflores... | \n",
1202 | " -12.121223 | \n",
1203 | " -77.034818 | \n",
1204 | "
\n",
1205 | " \n",
1206 | " 12 | \n",
1207 | " Lima | \n",
1208 | " Lima | \n",
1209 | " Miraflores | \n",
1210 | " Alfredo Leon 114, Miraflores 15074 | \n",
1211 | " Alfredo Leon 114, Miraflores 15074, Miraflores... | \n",
1212 | " -12.119349 | \n",
1213 | " -77.039751 | \n",
1214 | "
\n",
1215 | " \n",
1216 | " 13 | \n",
1217 | " Lima | \n",
1218 | " Lima | \n",
1219 | " Miraflores | \n",
1220 | " Calle Berlín 1273, Miraflores 15074 | \n",
1221 | " Calle Berlín 1273, Miraflores 15074, Miraflore... | \n",
1222 | " -12.120072 | \n",
1223 | " -77.042339 | \n",
1224 | "
\n",
1225 | " \n",
1226 | " 14 | \n",
1227 | " Lima | \n",
1228 | " Lima | \n",
1229 | " Puente Piedra | \n",
1230 | " Pasaje Las Vegas, Puente Piedra 15118 | \n",
1231 | " Pasaje Las Vegas, Puente Piedra 15118, Puente ... | \n",
1232 | " -11.873307 | \n",
1233 | " -77.057781 | \n",
1234 | "
\n",
1235 | " \n",
1236 | " 15 | \n",
1237 | " Lima | \n",
1238 | " Lima | \n",
1239 | " Puente Piedra | \n",
1240 | " Calle 9 de Junio 100, Puente Piedra 15115 | \n",
1241 | " Calle 9 de Junio 100, Puente Piedra 15115, Pue... | \n",
1242 | " -11.876333 | \n",
1243 | " -77.074534 | \n",
1244 | "
\n",
1245 | " \n",
1246 | " 16 | \n",
1247 | " Lima | \n",
1248 | " Lima | \n",
1249 | " Puente Piedra | \n",
1250 | " Avenida sanez numero 300 urbaizacion cercado d... | \n",
1251 | " Avenida sanez numero 300 urbaizacion cercado d... | \n",
1252 | " -11.876333 | \n",
1253 | " -77.074534 | \n",
1254 | "
\n",
1255 | " \n",
1256 | " 17 | \n",
1257 | " Lima | \n",
1258 | " Lima | \n",
1259 | " Puente Piedra | \n",
1260 | " Calle 8 6-130, Puente Piedra 15117 | \n",
1261 | " Calle 8 6-130, Puente Piedra 15117, Puente Pie... | \n",
1262 | " -11.950650 | \n",
1263 | " -76.993833 | \n",
1264 | "
\n",
1265 | " \n",
1266 | " 18 | \n",
1267 | " Lima | \n",
1268 | " Lima | \n",
1269 | " Puente Piedra | \n",
1270 | " Calle 8 132-356, Puente Piedra 15117 | \n",
1271 | " Calle 8 132-356, Puente Piedra 15117, Puente P... | \n",
1272 | " -11.950650 | \n",
1273 | " -76.993833 | \n",
1274 | "
\n",
1275 | " \n",
1276 | "
\n",
1277 | "
\n",
1278 | "
\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 | " departamento | \n",
1701 | " provincia | \n",
1702 | " distrito | \n",
1703 | " direccion | \n",
1704 | " nogeo | \n",
1705 | " latitude | \n",
1706 | " longitude | \n",
1707 | "
\n",
1708 | " \n",
1709 | " \n",
1710 | " \n",
1711 | " 0 | \n",
1712 | " Lima | \n",
1713 | " Lima | \n",
1714 | " Santa Anita | \n",
1715 | " Carretera Central 167, Santa Anita 15008 | \n",
1716 | " Carretera Central 167, Santa Anita 15008, Sant... | \n",
1717 | " -12.056697 | \n",
1718 | " -76.969772 | \n",
1719 | "
\n",
1720 | " \n",
1721 | " 1 | \n",
1722 | " Lima | \n",
1723 | " Lima | \n",
1724 | " Santa Anita | \n",
1725 | " Jiron los Eucaliptos 996, La Molina 15023 | \n",
1726 | " Jiron los Eucaliptos 996, La Molina 15023, San... | \n",
1727 | " -12.065913 | \n",
1728 | " -76.967481 | \n",
1729 | "
\n",
1730 | " \n",
1731 | " 2 | \n",
1732 | " Lima | \n",
1733 | " Lima | \n",
1734 | " Santa Anita | \n",
1735 | " Avenida Metropolitana Mz M Lot 4, Ate 15026 | \n",
1736 | " Avenida Metropolitana Mz M Lot 4, Ate 15026, S... | \n",
1737 | " -12.033272 | \n",
1738 | " -76.940326 | \n",
1739 | "
\n",
1740 | " \n",
1741 | " 3 | \n",
1742 | " Lima | \n",
1743 | " Lima | \n",
1744 | " Lurigancho | \n",
1745 | " Los Robles, Lima 15457 | \n",
1746 | " Los Robles, Lima 15457, Lurigancho, Lima, Lima... | \n",
1747 | " -12.010731 | \n",
1748 | " -76.909908 | \n",
1749 | "
\n",
1750 | " \n",
1751 | " 4 | \n",
1752 | " Lima | \n",
1753 | " Lima | \n",
1754 | " Lurigancho | \n",
1755 | " Avenida las Torres 276, Lima, Ate 15498 | \n",
1756 | " Avenida las Torres 276, Lima, Ate 15498, Lurig... | \n",
1757 | " -12.009716 | \n",
1758 | " -76.905490 | \n",
1759 | "
\n",
1760 | " \n",
1761 | " 5 | \n",
1762 | " Lima | \n",
1763 | " Lima | \n",
1764 | " Lurigancho | \n",
1765 | " Avenida Nicolás Ayllón 7208, Ate 15487 | \n",
1766 | " Avenida Nicolás Ayllón 7208, Ate 15487, Luriga... | \n",
1767 | " -12.015194 | \n",
1768 | " -76.886799 | \n",
1769 | "
\n",
1770 | " \n",
1771 | " 6 | \n",
1772 | " Lima | \n",
1773 | " Lima | \n",
1774 | " Lurigancho | \n",
1775 | " La Capitana 190, Lurigancho-Chosica 15461 | \n",
1776 | " La Capitana 190, Lurigancho-Chosica 15461, Lur... | \n",
1777 | " -12.009340 | \n",
1778 | " -76.905460 | \n",
1779 | "
\n",
1780 | " \n",
1781 | " 7 | \n",
1782 | " Lima | \n",
1783 | " Lima | \n",
1784 | " Surquillo | \n",
1785 | " Avenida Angamos Este 1807-1803, Surquillo 15036 | \n",
1786 | " Avenida Angamos Este 1807-1803, Surquillo 1503... | \n",
1787 | " -12.112210 | \n",
1788 | " -77.010670 | \n",
1789 | "
\n",
1790 | " \n",
1791 | " 8 | \n",
1792 | " Lima | \n",
1793 | " Lima | \n",
1794 | " Surquillo | \n",
1795 | " Avenida República de Panamá 4295, Surquillo 15048 | \n",
1796 | " Avenida República de Panamá 4295, Surquillo 15... | \n",
1797 | " -12.107650 | \n",
1798 | " -77.018440 | \n",
1799 | "
\n",
1800 | " \n",
1801 | " 9 | \n",
1802 | " Lima | \n",
1803 | " Lima | \n",
1804 | " Surquillo | \n",
1805 | " Gonzáles Prada, Surquillo 15047 | \n",
1806 | " Gonzáles Prada, Surquillo 15047, Surquillo, Li... | \n",
1807 | " -12.116500 | \n",
1808 | " -77.022113 | \n",
1809 | "
\n",
1810 | " \n",
1811 | " 10 | \n",
1812 | " Lima | \n",
1813 | " Lima | \n",
1814 | " Miraflores | \n",
1815 | " Calle Bellavista 207, Miraflores 15074 | \n",
1816 | " Calle Bellavista 207, Miraflores 15074, Mirafl... | \n",
1817 | " -12.120800 | \n",
1818 | " -77.031960 | \n",
1819 | "
\n",
1820 | " \n",
1821 | " 11 | \n",
1822 | " Lima | \n",
1823 | " Lima | \n",
1824 | " Miraflores | \n",
1825 | " Avenida Grau 299, Miraflores 15074 | \n",
1826 | " Avenida Grau 299, Miraflores 15074, Miraflores... | \n",
1827 | " -12.121150 | \n",
1828 | " -77.034760 | \n",
1829 | "
\n",
1830 | " \n",
1831 | " 12 | \n",
1832 | " Lima | \n",
1833 | " Lima | \n",
1834 | " Miraflores | \n",
1835 | " Alfredo Leon 114, Miraflores 15074 | \n",
1836 | " Alfredo Leon 114, Miraflores 15074, Miraflores... | \n",
1837 | " -12.119380 | \n",
1838 | " -77.039810 | \n",
1839 | "
\n",
1840 | " \n",
1841 | " 13 | \n",
1842 | " Lima | \n",
1843 | " Lima | \n",
1844 | " Miraflores | \n",
1845 | " Calle Berlín 1273, Miraflores 15074 | \n",
1846 | " Calle Berlín 1273, Miraflores 15074, Miraflore... | \n",
1847 | " -12.120110 | \n",
1848 | " -77.042210 | \n",
1849 | "
\n",
1850 | " \n",
1851 | " 14 | \n",
1852 | " Lima | \n",
1853 | " Lima | \n",
1854 | " Puente Piedra | \n",
1855 | " Pasaje Las Vegas, Puente Piedra 15118 | \n",
1856 | " Pasaje Las Vegas, Puente Piedra 15118, Puente ... | \n",
1857 | " -11.867809 | \n",
1858 | " -77.076653 | \n",
1859 | "
\n",
1860 | " \n",
1861 | " 15 | \n",
1862 | " Lima | \n",
1863 | " Lima | \n",
1864 | " Puente Piedra | \n",
1865 | " Calle 9 de Junio 100, Puente Piedra 15115 | \n",
1866 | " Calle 9 de Junio 100, Puente Piedra 15115, Pue... | \n",
1867 | " -11.867419 | \n",
1868 | " -77.078053 | \n",
1869 | "
\n",
1870 | " \n",
1871 | " 16 | \n",
1872 | " Lima | \n",
1873 | " Lima | \n",
1874 | " Puente Piedra | \n",
1875 | " Avenida sanez numero 300 urbaizacion cercado d... | \n",
1876 | " Avenida sanez numero 300 urbaizacion cercado d... | \n",
1877 | " -11.838300 | \n",
1878 | " -77.098630 | \n",
1879 | "
\n",
1880 | " \n",
1881 | " 17 | \n",
1882 | " Lima | \n",
1883 | " Lima | \n",
1884 | " Puente Piedra | \n",
1885 | " Calle 8 6-130, Puente Piedra 15117 | \n",
1886 | " Calle 8 6-130, Puente Piedra 15117, Puente Pie... | \n",
1887 | " -11.866935 | \n",
1888 | " -77.073642 | \n",
1889 | "
\n",
1890 | " \n",
1891 | " 18 | \n",
1892 | " Lima | \n",
1893 | " Lima | \n",
1894 | " Puente Piedra | \n",
1895 | " Calle 8 132-356, Puente Piedra 15117 | \n",
1896 | " Calle 8 132-356, Puente Piedra 15117, Puente P... | \n",
1897 | " -11.866935 | \n",
1898 | " -77.073642 | \n",
1899 | "
\n",
1900 | " \n",
1901 | "
\n",
1902 | "
\n",
1903 | "
\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
--------------------------------------------------------------------------------