|
1 | 1 | { |
2 | 2 | "cells": [ |
3 | | - { |
4 | | - "cell_type": "markdown", |
5 | | - "metadata": {}, |
6 | | - "source": [ |
7 | | - "## Overview\n", |
8 | | - "\n", |
9 | | - "**You will learn:** a fast and easy way to use your Developer Subscription content manager and the [ArcGIS API for Python](https://developers.arcgis.com/python/guide/) to create a data schema in the cloud and populate features for use in your apps.\n", |
10 | | - "\n", |
11 | | - "With your [ArcGIS Developer Subscription](https://developers.arcgis.com/pricing/), you can use the [**Create Layer Dev Lab**](https://developers.arcgis.com/labs/data/create-a-new-dataset/) to learn how to create a new empty layer in your account. You can then use the [ArcGIS API for Python](https://developers.arcgis.com/python/) to easily populate the layer with actual features and attributes. \n", |
12 | | - "\n", |
13 | | - "The **Create Layer** tool lets you interactively define the name, feature type (points, lines or polygons), and attribute fields for a layer, and then save it to the cloud (ArcGIS Online). This process is called [publishing a hosted feature layer](https://doc.arcgis.com/en/arcgis-online/share-maps/publish-features.htm). Behind every feature layer is a [REST feature service](https://resources.arcgis.com/en/help/arcgis-rest-api/#/Feature_Service/02r3000000z2000000/), and the ArcGIS Platform provides many tools to populate this layer with data. The [features module](http://esri.github.io/arcgis-python-api/apidoc/html/arcgis.features.toc.html) and [geometry module](http://esri.github.io/arcgis-python-api/apidoc/html/arcgis.geometry.html) in the ArcGIS API for Python can be used with the [map widget](http://esri.github.io/arcgis-python-api/apidoc/html/arcgis.widgets.html) to interactively edit a feature layer by adding new features. Once created and populated, your apps can access this service to query, draw or edit the data.\n", |
14 | | - "\n", |
15 | | - "In this lab you will create a new point dataset (feature layer) with the Create Layer tool and store it in your own developer [ArcGIS Online](https://doc.arcgis.com/en/arcgis-online/share-maps/hosted-web-layers.htm) account. You'll then use the ArcGIS API for Python to add features into the new layer. The lab will create points near Los Angeles, CA.\n", |
16 | | - "\n", |
17 | | - "You will run this lab in a [Jupyter Notebook](/python/guide/using-the-jupyter-notebook-environment/) IDE that is hosted by Esri. Notebooks created here are temporary, hence you must download them if you want to preserve them for later. However, you can [install the ArcGIS API for Python](/python/guide/install-and-set-up/) locally on your computer and run this lab from it, in which case, the notebooks are stored locally on your machine." |
18 | | - ] |
19 | | - }, |
20 | | - { |
21 | | - "cell_type": "markdown", |
22 | | - "metadata": {}, |
23 | | - "source": [ |
24 | | - "## Steps\n", |
25 | | - "#### Create a connection to your Developer Subscription account\n", |
26 | | - "\n", |
27 | | - "Log into ArcGIS Online by making a GIS connection to ArcGIS Online using your developer account. Replace `username` and `password` with the credentials to your ArcGIS Developer account. \n", |
28 | | - " \n", |
29 | | - "It is not good security practice to leave account credentials in source code shared by others, but it is beyond the scope of this lab to go over security best practices. The [getpass module](https://pymotw.com/2/getpass/) for Python provides an easy way to hide passwords in shared code.\n", |
30 | | - "\n", |
31 | | - "You can use a print statement with some gis properties to verify sign-in." |
32 | | - ] |
33 | | - }, |
34 | 3 | { |
35 | 4 | "cell_type": "code", |
36 | 5 | "execution_count": null, |
|
48 | 17 | " dev_gis.users.me.username))" |
49 | 18 | ] |
50 | 19 | }, |
51 | | - { |
52 | | - "cell_type": "markdown", |
53 | | - "metadata": {}, |
54 | | - "source": [ |
55 | | - "#### Search for the empty feature layer\n", |
56 | | - "\n", |
57 | | - "You can use the ArcGIS API for Python [Helper Objects](https://developers.arcgis.com/python/guide/using-the-GIS/#Helper-objects) to manage GIS resources. One such helper object is the [Content Manager](http://esri.github.io/arcgis-python-api/apidoc/html/arcgis.gis.toc.html#contentmanager). You use its [search method](https://developers.arcgis.com/python/guide/accessing-and-creating-your-content/#Searching-for-content) to retrieve items from your GIS. The ArcGIS API for Python Guide also documents the process of [searching your gis for feature layers](https://developers.arcgis.com/python/guide/working-with-feature-layers-and-features/#Searching-the-GIS-for-feature-layers).\n", |
58 | | - "\n", |
59 | | - "The ArcGIS API for Python is a front end to the [ArcGIS REST API](https://developers.arcgis.com/documentation/core-concepts/rest-api/). The full [search reference](http://resources.arcgis.com/en/help/arcgis-rest-api/#/Search_reference/02r3000000mn000000/) documentation details how to search for items, including proper use of wildcards for characters and phrases. You'll use a wildcard to search for the empty feature layer created in the first portion of this lab (Steps 1-8).\n", |
60 | | - "\n", |
61 | | - "The `search()` method returns a list of `Item` objects that match the search criteria. " |
62 | | - ] |
63 | | - }, |
64 | 20 | { |
65 | 21 | "cell_type": "code", |
66 | 22 | "execution_count": null, |
|
75 | 31 | "flyr_search_results" |
76 | 32 | ] |
77 | 33 | }, |
78 | | - { |
79 | | - "cell_type": "markdown", |
80 | | - "metadata": {}, |
81 | | - "source": [ |
82 | | - "#### Retrieve the feature layer object from the search results\n", |
83 | | - "\n", |
84 | | - "Since the search returns a list, you'll use Python [indexing](https://docs.python.org/3/tutorial/introduction.html#lists) to retrieve the object you want. In this case, the item returned is a feature layer collection item, so you'll need to obtain the list of layers in the collection and use indexing to access the layer you want." |
85 | | - ] |
86 | | - }, |
87 | 34 | { |
88 | 35 | "cell_type": "code", |
89 | 36 | "execution_count": null, |
|
98 | 45 | "flayer.properties.name" |
99 | 46 | ] |
100 | 47 | }, |
101 | | - { |
102 | | - "cell_type": "markdown", |
103 | | - "metadata": {}, |
104 | | - "source": [ |
105 | | - "#### Define a function to serve as the event listener for the map widget on_click event\n", |
106 | | - "\n", |
107 | | - "You'll use a Python function to add fetures to the feature layer for locations you click on the map. Further illustrations of concepts and operations are available at [using the geometry service and geometry functions](https://developers.arcgis.com/python/sample-notebooks/using-geometry-functions/) in the [ArcGIS API for Python Guide](https://developers.arcgis.com/python/guide/). The API Reference documents the map widget [draw method](http://esri.github.io/arcgis-python-api/apidoc/html/arcgis.widgets.html#arcgis.widgets.MapView.draw) that you'll use to initially place graphic markers at the locations where you'll add features to the layer.\n", |
108 | | - "\n", |
109 | | - "The function creates a feature from the location clicked on the map. The **`OBJECTID`** attribute **MUST** be included in the attributes dictionary parameter to create a valid feature. You can also add additional attributes from the layer schema if desired." |
110 | | - ] |
111 | | - }, |
112 | 48 | { |
113 | 49 | "cell_type": "code", |
114 | 50 | "execution_count": null, |
|
133 | 69 | " print(\"Couldn't create the feature. Try again, please...\")" |
134 | 70 | ] |
135 | 71 | }, |
136 | | - { |
137 | | - "cell_type": "markdown", |
138 | | - "metadata": {}, |
139 | | - "source": [ |
140 | | - "#### Assign a map object to a variable. Center the map in Los Angeles with a zoom level of your choice." |
141 | | - ] |
142 | | - }, |
143 | 72 | { |
144 | 73 | "cell_type": "code", |
145 | 74 | "execution_count": null, |
|
152 | 81 | "map1" |
153 | 82 | ] |
154 | 83 | }, |
155 | | - { |
156 | | - "cell_type": "markdown", |
157 | | - "metadata": {}, |
158 | | - "source": [ |
159 | | - "#### Execute the on_click event to begin adding locations to the map\n", |
160 | | - "\n", |
161 | | - "Use the function you defined above as the callback parameter for the map widget [on_click](http://esri.github.io/arcgis-python-api/apidoc/html/arcgis.widgets.html#arcgis.widgets.MapView.on_click) event. Click on the map to draw a graphic marker for each feature you want to add to the layer. The callback also outputs a string representation of the geometry." |
162 | | - ] |
163 | | - }, |
164 | 84 | { |
165 | 85 | "cell_type": "code", |
166 | 86 | "execution_count": null, |
|
172 | 92 | "map1.on_click(create_feature)" |
173 | 93 | ] |
174 | 94 | }, |
175 | | - { |
176 | | - "cell_type": "markdown", |
177 | | - "metadata": {}, |
178 | | - "source": [ |
179 | | - "#### Clear the graphic markers from the map\n", |
180 | | - "\n", |
181 | | - "You'll clear the graphics so you can subsequently add the layer to the map to verify features have been added." |
182 | | - ] |
183 | | - }, |
184 | 95 | { |
185 | 96 | "cell_type": "code", |
186 | 97 | "execution_count": null, |
|
192 | 103 | "map1.clear_graphics()" |
193 | 104 | ] |
194 | 105 | }, |
195 | | - { |
196 | | - "cell_type": "markdown", |
197 | | - "metadata": {}, |
198 | | - "source": [ |
199 | | - "#### Use the map widget `add_layer` method to add the feature layer to the map\n", |
200 | | - "\n", |
201 | | - "You should see the locations you clicked in the previous steps now visualized as features in the feature layer, with symbology defined by the Create Layer tool." |
202 | | - ] |
203 | | - }, |
204 | 106 | { |
205 | 107 | "cell_type": "code", |
206 | 108 | "execution_count": null, |
|
216 | 118 | "metadata": { |
217 | 119 | "anaconda-cloud": {}, |
218 | 120 | "kernelspec": { |
219 | | - "display_name": "Python 3", |
| 121 | + "display_name": "Python [default]", |
220 | 122 | "language": "python", |
221 | 123 | "name": "python3" |
222 | 124 | }, |
|
230 | 132 | "name": "python", |
231 | 133 | "nbconvert_exporter": "python", |
232 | 134 | "pygments_lexer": "ipython3", |
233 | | - "version": "3.5.2" |
| 135 | + "version": "3.5.3" |
234 | 136 | } |
235 | 137 | }, |
236 | 138 | "nbformat": 4, |
|
0 commit comments