{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Search and Geocode ArcGIS DevLab\n", "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" ] }, { "cell_type": "code", "execution_count": 55, "metadata": { "collapsed": true }, "outputs": [], "source": [ "from arcgis.gis import *\n", "from arcgis.geocoding import geocode, reverse_geocode\n", "from arcgis.geometry import Point" ] }, { "cell_type": "code", "execution_count": 56, "metadata": {}, "outputs": [ { "data": { "text/html": [ "GIS @ http://www.arcgis.com" ], "text/plain": [ "" ] }, "execution_count": 56, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dev_gis = GIS()\n", "dev_gis" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Geocode place names" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "2" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "geocode_result = geocode(address=\"Hollywood sign\", as_featureset=True)\n", "len(geocode_result.features)" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "ae2904ea086c48ca996f957fb5834e52" } }, "metadata": {}, "output_type": "display_data" } ], "source": [ "map1 = dev_gis.map(\"Los Angeles, CA\", zoomlevel=11)\n", "map1" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [], "source": [ "map1.draw(geocode_result)" ] }, { "cell_type": "code", "execution_count": 19, "metadata": { "collapsed": true }, "outputs": [], "source": [ "map1.clear_graphics()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Reverse geocode a coordinate" ] }, { "cell_type": "code", "execution_count": 36, "metadata": {}, "outputs": [], "source": [ "location = {'Y':34.13419,\n", " 'X':-118.29636,\n", " 'spatialReference':{\n", " 'wkid':4326}\n", " }\n", "unknown_pt = Point(location)" ] }, { "cell_type": "code", "execution_count": 37, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'address': {'AddNum': '',\n", " 'Addr_type': 'StreetName',\n", " 'Address': 'Vista del Valle Dr',\n", " 'Block': '',\n", " 'City': 'Los Angeles',\n", " 'CountryCode': 'USA',\n", " 'District': '',\n", " 'LongLabel': 'Vista del Valle Dr, Los Angeles, CA, 90027, USA',\n", " 'Match_addr': 'Vista del Valle Dr, Los Angeles, California, 90027',\n", " 'MetroArea': 'Los Angeles Metro Area',\n", " 'Neighborhood': 'Los Feliz',\n", " 'PlaceName': '',\n", " 'Postal': '90027',\n", " 'PostalExt': '',\n", " 'Region': 'California',\n", " 'Sector': '',\n", " 'ShortLabel': 'Vista del Valle Dr',\n", " 'Subregion': 'Los Angeles',\n", " 'Territory': '',\n", " 'Type': ''},\n", " 'location': {'spatialReference': {'latestWkid': 4326, 'wkid': 4326},\n", " 'x': -118.29641724469197,\n", " 'y': 34.13381075391577}}" ] }, "execution_count": 37, "metadata": {}, "output_type": "execute_result" } ], "source": [ "address = reverse_geocode(unknown_pt)\n", "address" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.1" } }, "nbformat": 4, "nbformat_minor": 2 }