Skip to content

Commit 283139e

Browse files
authored
Merge pull request #295 from mpayson/mp-devlab-findplaces-devsite
find places devlab notebook. Thanks @mpayson
2 parents d97e9d1 + 6bfefcb commit 283139e

File tree

1 file changed

+222
-0
lines changed

1 file changed

+222
-0
lines changed

labs/find_places.ipynb

Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# Find Places ArcGIS DevLab\n",
8+
"This is a completed solution for the [Find Places](https://developers.arcgis.com/labs/python/find-places/) ArcGIS DevLab. [ArcGIS DevLabs](https://developers.arcgis.com/labs/) are short, introductory tutorials to developing with the [ArcGIS platform](https://developers.arcgis.com/labs/what-is-arcgis/)."
9+
]
10+
},
11+
{
12+
"cell_type": "markdown",
13+
"metadata": {},
14+
"source": [
15+
"**1.** Model a GIS portal and import the geocode function from the ArcGIS API for Python"
16+
]
17+
},
18+
{
19+
"cell_type": "code",
20+
"execution_count": 1,
21+
"metadata": {},
22+
"outputs": [],
23+
"source": [
24+
"from arcgis.gis import GIS\n",
25+
"from arcgis.geocoding import geocode"
26+
]
27+
},
28+
{
29+
"cell_type": "markdown",
30+
"metadata": {},
31+
"source": [
32+
"**2.** Create an anonymous connection to ArcGIS Online. Since the results are not stored, you do not need credentials to call the geocoding service"
33+
]
34+
},
35+
{
36+
"cell_type": "code",
37+
"execution_count": 2,
38+
"metadata": {},
39+
"outputs": [],
40+
"source": [
41+
"gis = GIS()"
42+
]
43+
},
44+
{
45+
"cell_type": "markdown",
46+
"metadata": {},
47+
"source": [
48+
"**3.** Pass the relevant parameters into the geocode function and get the results"
49+
]
50+
},
51+
{
52+
"cell_type": "code",
53+
"execution_count": 3,
54+
"metadata": {},
55+
"outputs": [],
56+
"source": [
57+
"geocode_fs = geocode(address=None,\n",
58+
" location=[-118.71511, 34.09042],\n",
59+
" category=\"Coffee shop\",\n",
60+
" out_fields=\"Place_addr, PlaceName\",\n",
61+
" max_locations=25,\n",
62+
" as_featureset=True)"
63+
]
64+
},
65+
{
66+
"cell_type": "markdown",
67+
"metadata": {},
68+
"source": [
69+
"**4.** Convert the results to a dataframe and show the first two locations"
70+
]
71+
},
72+
{
73+
"cell_type": "code",
74+
"execution_count": 4,
75+
"metadata": {},
76+
"outputs": [
77+
{
78+
"data": {
79+
"text/html": [
80+
"<div>\n",
81+
"<style scoped>\n",
82+
" .dataframe tbody tr th:only-of-type {\n",
83+
" vertical-align: middle;\n",
84+
" }\n",
85+
"\n",
86+
" .dataframe tbody tr th {\n",
87+
" vertical-align: top;\n",
88+
" }\n",
89+
"\n",
90+
" .dataframe thead th {\n",
91+
" text-align: right;\n",
92+
" }\n",
93+
"</style>\n",
94+
"<table border=\"1\" class=\"dataframe\">\n",
95+
" <thead>\n",
96+
" <tr style=\"text-align: right;\">\n",
97+
" <th></th>\n",
98+
" <th>OBJECTID</th>\n",
99+
" <th>PlaceName</th>\n",
100+
" <th>Place_addr</th>\n",
101+
" <th>SHAPE</th>\n",
102+
" </tr>\n",
103+
" </thead>\n",
104+
" <tbody>\n",
105+
" <tr>\n",
106+
" <th>0</th>\n",
107+
" <td>1</td>\n",
108+
" <td>Starbucks</td>\n",
109+
" <td>26531 Agoura Rd, Calabasas, California, 91302</td>\n",
110+
" <td>{'x': -118.70030999999994, 'y': 34.14383000000...</td>\n",
111+
" </tr>\n",
112+
" <tr>\n",
113+
" <th>1</th>\n",
114+
" <td>2</td>\n",
115+
" <td>Starbucks</td>\n",
116+
" <td>26521 Agoura Rd, Calabasas, California, 91302</td>\n",
117+
" <td>{'x': -118.70023995051699, 'y': 34.14425002668...</td>\n",
118+
" </tr>\n",
119+
" </tbody>\n",
120+
"</table>\n",
121+
"</div>"
122+
],
123+
"text/plain": [
124+
" OBJECTID PlaceName Place_addr \\\n",
125+
"0 1 Starbucks 26531 Agoura Rd, Calabasas, California, 91302 \n",
126+
"1 2 Starbucks 26521 Agoura Rd, Calabasas, California, 91302 \n",
127+
"\n",
128+
" SHAPE \n",
129+
"0 {'x': -118.70030999999994, 'y': 34.14383000000... \n",
130+
"1 {'x': -118.70023995051699, 'y': 34.14425002668... "
131+
]
132+
},
133+
"execution_count": 4,
134+
"metadata": {},
135+
"output_type": "execute_result"
136+
}
137+
],
138+
"source": [
139+
"g_df = geocode_fs.df\n",
140+
"g_df.head(2)"
141+
]
142+
},
143+
{
144+
"cell_type": "markdown",
145+
"metadata": {},
146+
"source": [
147+
"**5.** Create a map to display the results"
148+
]
149+
},
150+
{
151+
"cell_type": "code",
152+
"execution_count": 8,
153+
"metadata": {
154+
"scrolled": true
155+
},
156+
"outputs": [
157+
{
158+
"data": {
159+
"application/vnd.jupyter.widget-view+json": {
160+
"model_id": "35aa51740ad646aca0cba4233d028205",
161+
"version_major": 2,
162+
"version_minor": 0
163+
},
164+
"text/plain": [
165+
"MapView(basemaps=['dark-gray', 'dark-gray-vector', 'gray', 'gray-vector', 'hybrid', 'national-geographic', 'oc…"
166+
]
167+
},
168+
"metadata": {},
169+
"output_type": "display_data"
170+
}
171+
],
172+
"source": [
173+
"g_map = gis.map([34.09042, -118.71511], zoomlevel=11)\n",
174+
"g_map"
175+
]
176+
},
177+
{
178+
"cell_type": "markdown",
179+
"metadata": {},
180+
"source": [
181+
"**6.** Once the map has loaded, draw the results"
182+
]
183+
},
184+
{
185+
"cell_type": "code",
186+
"execution_count": 9,
187+
"metadata": {},
188+
"outputs": [],
189+
"source": [
190+
"g_map.draw(geocode_fs)"
191+
]
192+
},
193+
{
194+
"cell_type": "code",
195+
"execution_count": null,
196+
"metadata": {},
197+
"outputs": [],
198+
"source": []
199+
}
200+
],
201+
"metadata": {
202+
"kernelspec": {
203+
"display_name": "Python 3",
204+
"language": "python",
205+
"name": "python3"
206+
},
207+
"language_info": {
208+
"codemirror_mode": {
209+
"name": "ipython",
210+
"version": 3
211+
},
212+
"file_extension": ".py",
213+
"mimetype": "text/x-python",
214+
"name": "python",
215+
"nbconvert_exporter": "python",
216+
"pygments_lexer": "ipython3",
217+
"version": "3.6.5"
218+
}
219+
},
220+
"nbformat": 4,
221+
"nbformat_minor": 2
222+
}

0 commit comments

Comments
 (0)