Skip to content

Commit 6374fa7

Browse files
authored
Merge pull request #138 from jyaistMap/jy_devlabs_split_import
Solution notebooks for the download, import, and create data DevLabs
2 parents 245fccc + 42f1596 commit 6374fa7

File tree

3 files changed

+410
-301
lines changed

3 files changed

+410
-301
lines changed

labs/create_data.ipynb

Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# Create Data ArcGIS DevLab\n",
8+
"This is the completed solution for the [Create data](https://developers.arcgis.com/labs/data/python/create-data/) ArcGIS DevLab. [ArcGIS DevLabs](https://developers.arcgis.com/labs/) are short introductory tutorials to guide you through the three phases of building geospatial apps: Data, Design, Develop"
9+
]
10+
},
11+
{
12+
"cell_type": "code",
13+
"execution_count": null,
14+
"metadata": {},
15+
"outputs": [],
16+
"source": [
17+
"import getpass\n",
18+
"from arcgis.gis import *\n",
19+
"\n",
20+
"password = getpass.getpass(\"Please enter password: \")\n",
21+
"dev_gis = GIS('https://www.arcgis.com', 'username', password)\n",
22+
"print(\"Successfully logged in to {} as {}\".format(dev_gis.properties.urlKey + '.' + dev_gis.properties.customBaseUrl,\n",
23+
" dev_gis.users.me.username))"
24+
]
25+
},
26+
{
27+
"cell_type": "code",
28+
"execution_count": 2,
29+
"metadata": {},
30+
"outputs": [
31+
{
32+
"data": {
33+
"text/plain": [
34+
"[<Item title:\"Griffith Park Access2\" type:Feature Layer Collection owner:johnnyDev>]"
35+
]
36+
},
37+
"execution_count": 2,
38+
"metadata": {},
39+
"output_type": "execute_result"
40+
}
41+
],
42+
"source": [
43+
"feature_layer_srch_results = dev_gis.content.search(query='title: \"Griffith*\" AND type: \"Feature Service\"', \n",
44+
" max_items=10)\n",
45+
"feature_layer_srch_results"
46+
]
47+
},
48+
{
49+
"cell_type": "code",
50+
"execution_count": 3,
51+
"metadata": {},
52+
"outputs": [
53+
{
54+
"data": {
55+
"text/plain": [
56+
"'griffith_park_access2'"
57+
]
58+
},
59+
"execution_count": 3,
60+
"metadata": {},
61+
"output_type": "execute_result"
62+
}
63+
],
64+
"source": [
65+
"feature_layer_coll_item = feature_layer_srch_results[0]\n",
66+
"feature_layers = feature_layer_coll_item.layers\n",
67+
"feature_layer = feature_layers[0]\n",
68+
"feature_layer.properties.name"
69+
]
70+
},
71+
{
72+
"cell_type": "code",
73+
"execution_count": 4,
74+
"metadata": {},
75+
"outputs": [
76+
{
77+
"name": "stdout",
78+
"output_type": "stream",
79+
"text": [
80+
"OBJECTID\n",
81+
"name\n",
82+
"type\n",
83+
"surface\n"
84+
]
85+
}
86+
],
87+
"source": [
88+
"for field in feature_layer.properties['fields']:\n",
89+
" print(field['name'])"
90+
]
91+
},
92+
{
93+
"cell_type": "code",
94+
"execution_count": 5,
95+
"metadata": {
96+
"collapsed": true
97+
},
98+
"outputs": [],
99+
"source": [
100+
"from arcgis import geometry\n",
101+
"from arcgis import features\n",
102+
"\n",
103+
"def create_feature(map1, g):\n",
104+
" try:\n",
105+
" oid = 1\n",
106+
" pt = geometry.Point(g)\n",
107+
" feat = features.Feature(geometry=pt, attributes={'OBJECTID': 1,\n",
108+
" 'name': 'name',\n",
109+
" 'type': 'park',\n",
110+
" 'surface': 'dirt'})\n",
111+
" feature_layer.edit_features(adds=[feat])\n",
112+
" print(str(g))\n",
113+
" map1.draw(g)\n",
114+
" except:\n",
115+
" print(\"Couldn't create the feature. Try again, please...\")"
116+
]
117+
},
118+
{
119+
"cell_type": "code",
120+
"execution_count": 6,
121+
"metadata": {},
122+
"outputs": [
123+
{
124+
"data": {
125+
"application/vnd.jupyter.widget-view+json": {
126+
"model_id": "57be67419bbb49babb30726e9d29aa91"
127+
}
128+
},
129+
"metadata": {},
130+
"output_type": "display_data"
131+
},
132+
{
133+
"name": "stdout",
134+
"output_type": "stream",
135+
"text": [
136+
"{'y': 4031785.200371807, 'type': 'point', 'spatialReference': {'latestWkid': 3857, 'wkid': 102100}, 'x': -13174326.588164143}\n",
137+
"{'y': 4039276.029143757, 'type': 'point', 'spatialReference': {'latestWkid': 3857, 'wkid': 102100}, 'x': -13181205.920709811}\n",
138+
"{'y': 4024447.2456564275, 'type': 'point', 'spatialReference': {'latestWkid': 3857, 'wkid': 102100}, 'x': -13167447.255618475}\n"
139+
]
140+
}
141+
],
142+
"source": [
143+
"map1 = dev_gis.map('Los Angeles', 10)\n",
144+
"map1"
145+
]
146+
},
147+
{
148+
"cell_type": "code",
149+
"execution_count": 7,
150+
"metadata": {
151+
"collapsed": true
152+
},
153+
"outputs": [],
154+
"source": [
155+
"map1.on_click(create_feature)"
156+
]
157+
},
158+
{
159+
"cell_type": "code",
160+
"execution_count": 8,
161+
"metadata": {
162+
"collapsed": true
163+
},
164+
"outputs": [],
165+
"source": [
166+
"map1.clear_graphics()"
167+
]
168+
},
169+
{
170+
"cell_type": "code",
171+
"execution_count": 9,
172+
"metadata": {
173+
"collapsed": true
174+
},
175+
"outputs": [],
176+
"source": [
177+
"map1.add_layer(feature_layer)"
178+
]
179+
}
180+
],
181+
"metadata": {
182+
"anaconda-cloud": {},
183+
"kernelspec": {
184+
"display_name": "Python [default]",
185+
"language": "python",
186+
"name": "python3"
187+
},
188+
"language_info": {
189+
"codemirror_mode": {
190+
"name": "ipython",
191+
"version": 3
192+
},
193+
"file_extension": ".py",
194+
"mimetype": "text/x-python",
195+
"name": "python",
196+
"nbconvert_exporter": "python",
197+
"pygments_lexer": "ipython3",
198+
"version": "3.5.3"
199+
}
200+
},
201+
"nbformat": 4,
202+
"nbformat_minor": 2
203+
}

labs/download_data.ipynb

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# Download Data ArcGIS DevLab"
8+
]
9+
},
10+
{
11+
"cell_type": "markdown",
12+
"metadata": {},
13+
"source": [
14+
"This is the completed solution for the [Download data](https://developers.arcgis.com/labs/data/python/download-data/) ArcGIS DevLab. [ArcGIS DevLabs](https://developers.arcgis.com/labs/) are short introductory tutorials to guide you through the three phases of building geospatial apps: Data, Design, Develop"
15+
]
16+
},
17+
{
18+
"cell_type": "code",
19+
"execution_count": 1,
20+
"metadata": {
21+
"collapsed": true
22+
},
23+
"outputs": [],
24+
"source": [
25+
"from arcgis.gis import *\n",
26+
"import os\n",
27+
"from zipfile import ZipFile"
28+
]
29+
},
30+
{
31+
"cell_type": "code",
32+
"execution_count": 2,
33+
"metadata": {
34+
"collapsed": true
35+
},
36+
"outputs": [],
37+
"source": [
38+
"public_data_item_id = 'a04933c045714492bda6886f355416f2'"
39+
]
40+
},
41+
{
42+
"cell_type": "code",
43+
"execution_count": 3,
44+
"metadata": {
45+
"collapsed": true
46+
},
47+
"outputs": [],
48+
"source": [
49+
"anon_gis = GIS()"
50+
]
51+
},
52+
{
53+
"cell_type": "code",
54+
"execution_count": 4,
55+
"metadata": {},
56+
"outputs": [
57+
{
58+
"data": {
59+
"text/html": [
60+
"<div class=\"item_container\" style=\"height: auto; overflow: hidden; border: 1px solid #cfcfcf; border-radius: 2px; background: #f6fafa; line-height: 1.21429em; padding: 10px;\">\n",
61+
" <div class=\"item_left\" style=\"width: 210px; float: left;\">\n",
62+
" <a href='http://www.arcgis.com/home/item.html?id=a04933c045714492bda6886f355416f2' target='_blank'>\n",
63+
" <img src='http://www.arcgis.com/sharing/rest//content/items/a04933c045714492bda6886f355416f2/info/thumbnail/la_hub_data_thumb.png' class=\"itemThumbnail\">\n",
64+
" </a>\n",
65+
" </div>\n",
66+
"\n",
67+
" <div class=\"item_right\" style=\"float: none; width: auto; overflow: hidden;\">\n",
68+
" <a href='http://www.arcgis.com/home/item.html?id=a04933c045714492bda6886f355416f2' target='_blank'><b>LA_Hub_Datasets</b>\n",
69+
" </a>\n",
70+
" <br/>Datasets for ArcGIS DevLabs<img src='http://www.arcgis.com/home/js/jsapi/esri/css/images/item_type_icons/layers16.png' style=\"vertical-align:middle;\">Code Sample by esri_devlabs\n",
71+
" <br/>Last Modified: June 22, 2017\n",
72+
" <br/>0 comments, 1,540 views\n",
73+
" </div>\n",
74+
" </div>\n",
75+
" "
76+
],
77+
"text/plain": [
78+
"<Item title:\"LA_Hub_Datasets\" type:Code Sample owner:esri_devlabs>"
79+
]
80+
},
81+
"execution_count": 4,
82+
"metadata": {},
83+
"output_type": "execute_result"
84+
}
85+
],
86+
"source": [
87+
"data_item = anon_gis.content.get(public_data_item_id)\n",
88+
"data_item"
89+
]
90+
},
91+
{
92+
"cell_type": "code",
93+
"execution_count": 5,
94+
"metadata": {},
95+
"outputs": [
96+
{
97+
"data": {
98+
"text/plain": [
99+
"'./LA_Hub_Datasets.zip'"
100+
]
101+
},
102+
"execution_count": 5,
103+
"metadata": {},
104+
"output_type": "execute_result"
105+
}
106+
],
107+
"source": [
108+
"data_item.download(save_path = r'./')"
109+
]
110+
},
111+
{
112+
"cell_type": "code",
113+
"execution_count": 6,
114+
"metadata": {
115+
"collapsed": true
116+
},
117+
"outputs": [],
118+
"source": [
119+
"zf = ZipFile(r'./LA_Hub_Datasets.zip')\n",
120+
"zf.extractall(path=r'./LA_Hub_datasets')"
121+
]
122+
},
123+
{
124+
"cell_type": "code",
125+
"execution_count": 7,
126+
"metadata": {},
127+
"outputs": [
128+
{
129+
"data": {
130+
"text/plain": [
131+
"['__MACOSX', 'Parks and Open Space.zip', 'Trailheads.csv', 'Trails.geojson']"
132+
]
133+
},
134+
"execution_count": 7,
135+
"metadata": {},
136+
"output_type": "execute_result"
137+
}
138+
],
139+
"source": [
140+
"file_list = os.listdir(r'./LA_Hub_datasets/')\n",
141+
"file_list"
142+
]
143+
}
144+
],
145+
"metadata": {
146+
"anaconda-cloud": {},
147+
"kernelspec": {
148+
"display_name": "Python [default]",
149+
"language": "python",
150+
"name": "python3"
151+
},
152+
"language_info": {
153+
"codemirror_mode": {
154+
"name": "ipython",
155+
"version": 3
156+
},
157+
"file_extension": ".py",
158+
"mimetype": "text/x-python",
159+
"name": "python",
160+
"nbconvert_exporter": "python",
161+
"pygments_lexer": "ipython3",
162+
"version": "3.5.3"
163+
}
164+
},
165+
"nbformat": 4,
166+
"nbformat_minor": 2
167+
}

0 commit comments

Comments
 (0)