|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "metadata": {}, |
| 6 | + "source": [ |
| 7 | + "# Search and Geocode ArcGIS DevLab\n", |
| 8 | + "This is the completed solution for the [Search and geocode](https://developers.arcgis.com/labs/develop/python/search-and-geocode/) 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": 55, |
| 14 | + "metadata": { |
| 15 | + "collapsed": true |
| 16 | + }, |
| 17 | + "outputs": [], |
| 18 | + "source": [ |
| 19 | + "from arcgis.gis import *\n", |
| 20 | + "from arcgis.geocoding import geocode, reverse_geocode\n", |
| 21 | + "from arcgis.geometry import Point" |
| 22 | + ] |
| 23 | + }, |
| 24 | + { |
| 25 | + "cell_type": "code", |
| 26 | + "execution_count": 56, |
| 27 | + "metadata": {}, |
| 28 | + "outputs": [ |
| 29 | + { |
| 30 | + "data": { |
| 31 | + "text/html": [ |
| 32 | + "GIS @ <a href=\"http://www.arcgis.com\">http://www.arcgis.com</a>" |
| 33 | + ], |
| 34 | + "text/plain": [ |
| 35 | + "<arcgis.gis.GIS at 0x10e4fe2e8>" |
| 36 | + ] |
| 37 | + }, |
| 38 | + "execution_count": 56, |
| 39 | + "metadata": {}, |
| 40 | + "output_type": "execute_result" |
| 41 | + } |
| 42 | + ], |
| 43 | + "source": [ |
| 44 | + "dev_gis = GIS()\n", |
| 45 | + "dev_gis" |
| 46 | + ] |
| 47 | + }, |
| 48 | + { |
| 49 | + "cell_type": "markdown", |
| 50 | + "metadata": {}, |
| 51 | + "source": [ |
| 52 | + "## Geocode place names" |
| 53 | + ] |
| 54 | + }, |
| 55 | + { |
| 56 | + "cell_type": "code", |
| 57 | + "execution_count": 6, |
| 58 | + "metadata": {}, |
| 59 | + "outputs": [ |
| 60 | + { |
| 61 | + "data": { |
| 62 | + "text/plain": [ |
| 63 | + "2" |
| 64 | + ] |
| 65 | + }, |
| 66 | + "execution_count": 6, |
| 67 | + "metadata": {}, |
| 68 | + "output_type": "execute_result" |
| 69 | + } |
| 70 | + ], |
| 71 | + "source": [ |
| 72 | + "geocode_result = geocode(address=\"Hollywood sign\", as_featureset=True)\n", |
| 73 | + "len(geocode_result.features)" |
| 74 | + ] |
| 75 | + }, |
| 76 | + { |
| 77 | + "cell_type": "code", |
| 78 | + "execution_count": 17, |
| 79 | + "metadata": {}, |
| 80 | + "outputs": [ |
| 81 | + { |
| 82 | + "data": { |
| 83 | + "application/vnd.jupyter.widget-view+json": { |
| 84 | + "model_id": "ae2904ea086c48ca996f957fb5834e52" |
| 85 | + } |
| 86 | + }, |
| 87 | + "metadata": {}, |
| 88 | + "output_type": "display_data" |
| 89 | + } |
| 90 | + ], |
| 91 | + "source": [ |
| 92 | + "map1 = dev_gis.map(\"Los Angeles, CA\", zoomlevel=11)\n", |
| 93 | + "map1" |
| 94 | + ] |
| 95 | + }, |
| 96 | + { |
| 97 | + "cell_type": "code", |
| 98 | + "execution_count": 18, |
| 99 | + "metadata": {}, |
| 100 | + "outputs": [], |
| 101 | + "source": [ |
| 102 | + "map1.draw(geocode_result)" |
| 103 | + ] |
| 104 | + }, |
| 105 | + { |
| 106 | + "cell_type": "code", |
| 107 | + "execution_count": 19, |
| 108 | + "metadata": { |
| 109 | + "collapsed": true |
| 110 | + }, |
| 111 | + "outputs": [], |
| 112 | + "source": [ |
| 113 | + "map1.clear_graphics()" |
| 114 | + ] |
| 115 | + }, |
| 116 | + { |
| 117 | + "cell_type": "markdown", |
| 118 | + "metadata": {}, |
| 119 | + "source": [ |
| 120 | + "## Reverse geocode a coordinate" |
| 121 | + ] |
| 122 | + }, |
| 123 | + { |
| 124 | + "cell_type": "code", |
| 125 | + "execution_count": 36, |
| 126 | + "metadata": {}, |
| 127 | + "outputs": [], |
| 128 | + "source": [ |
| 129 | + "location = {'Y':34.13419,\n", |
| 130 | + " 'X':-118.29636,\n", |
| 131 | + " 'spatialReference':{\n", |
| 132 | + " 'wkid':4326}\n", |
| 133 | + " }\n", |
| 134 | + "unknown_pt = Point(location)" |
| 135 | + ] |
| 136 | + }, |
| 137 | + { |
| 138 | + "cell_type": "code", |
| 139 | + "execution_count": 37, |
| 140 | + "metadata": {}, |
| 141 | + "outputs": [ |
| 142 | + { |
| 143 | + "data": { |
| 144 | + "text/plain": [ |
| 145 | + "{'address': {'AddNum': '',\n", |
| 146 | + " 'Addr_type': 'StreetName',\n", |
| 147 | + " 'Address': 'Vista del Valle Dr',\n", |
| 148 | + " 'Block': '',\n", |
| 149 | + " 'City': 'Los Angeles',\n", |
| 150 | + " 'CountryCode': 'USA',\n", |
| 151 | + " 'District': '',\n", |
| 152 | + " 'LongLabel': 'Vista del Valle Dr, Los Angeles, CA, 90027, USA',\n", |
| 153 | + " 'Match_addr': 'Vista del Valle Dr, Los Angeles, California, 90027',\n", |
| 154 | + " 'MetroArea': 'Los Angeles Metro Area',\n", |
| 155 | + " 'Neighborhood': 'Los Feliz',\n", |
| 156 | + " 'PlaceName': '',\n", |
| 157 | + " 'Postal': '90027',\n", |
| 158 | + " 'PostalExt': '',\n", |
| 159 | + " 'Region': 'California',\n", |
| 160 | + " 'Sector': '',\n", |
| 161 | + " 'ShortLabel': 'Vista del Valle Dr',\n", |
| 162 | + " 'Subregion': 'Los Angeles',\n", |
| 163 | + " 'Territory': '',\n", |
| 164 | + " 'Type': ''},\n", |
| 165 | + " 'location': {'spatialReference': {'latestWkid': 4326, 'wkid': 4326},\n", |
| 166 | + " 'x': -118.29641724469197,\n", |
| 167 | + " 'y': 34.13381075391577}}" |
| 168 | + ] |
| 169 | + }, |
| 170 | + "execution_count": 37, |
| 171 | + "metadata": {}, |
| 172 | + "output_type": "execute_result" |
| 173 | + } |
| 174 | + ], |
| 175 | + "source": [ |
| 176 | + "address = reverse_geocode(unknown_pt)\n", |
| 177 | + "address" |
| 178 | + ] |
| 179 | + } |
| 180 | + ], |
| 181 | + "metadata": { |
| 182 | + "kernelspec": { |
| 183 | + "display_name": "Python 3", |
| 184 | + "language": "python", |
| 185 | + "name": "python3" |
| 186 | + }, |
| 187 | + "language_info": { |
| 188 | + "codemirror_mode": { |
| 189 | + "name": "ipython", |
| 190 | + "version": 3 |
| 191 | + }, |
| 192 | + "file_extension": ".py", |
| 193 | + "mimetype": "text/x-python", |
| 194 | + "name": "python", |
| 195 | + "nbconvert_exporter": "python", |
| 196 | + "pygments_lexer": "ipython3", |
| 197 | + "version": "3.6.1" |
| 198 | + } |
| 199 | + }, |
| 200 | + "nbformat": 4, |
| 201 | + "nbformat_minor": 2 |
| 202 | +} |
0 commit comments