{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# ArcGIS API for Python\n", "\n", "## How to install ArcGIS API for Python\n", "\n", "* ArcGIS API for Python only for Python 3\n", "* https://developers.arcgis.com/python/guide/install-and-set-up/#Using-the-API\n", "* Create a Python virtual environment using Anaconda: `conda create -n py36 python=3.6`\n", "* Activate the Python environment: `activate py36`\n", "* Install arcgis to the Python environment: `conda install -c esri arcgis`" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from arcgis.gis import GIS" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "a84dd4592bd1429b82a590af91e8de57", "version_major": 2, "version_minor": 0 }, "text/plain": [ "MapView(layout=Layout(height='400px', width='100%'))" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "my_gis = GIS()\n", "my_gis.map()" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[,\n", " ,\n", " ,\n", " ,\n", " ]" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from arcgis.gis import GIS\n", "gis = GIS()\n", "public_content = gis.content.search(\"Fire\", item_type=\"Feature Layer\", max_items=5)\n", "public_content" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "
\n", " \n", " \n", " \n", "
\n", "\n", "
\n", " מיפוי שריפה חדש\n", " \n", "
שכבה פוליגונלית של היקף שריפה חיה איתה עובדים באופן שוטף ומעדכנים בקולקטורFeature Layer Collection by kkl_arcgis_10\n", "
Last Modified: November 15, 2018\n", "
0 comments, 21,729 views\n", "
\n", "
\n", " " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
\n", "
\n", " \n", " \n", " \n", "
\n", "\n", "
\n", " Intact Forest Landscapes (2000)\n", " \n", "
Identifies the world’s last remaining unfragmented forest landscapes, large enough to retain all native biodiversity and showing no signs of human alteration as of the year 2013. This layer also shows the reduction in the extent of Intact Forest Landscapes from 2000 to 2013.Feature Layer Collection by GlobalForestWatch\n", "
Last Modified: October 29, 2018\n", "
0 comments, 2,863 views\n", "
\n", "
\n", " " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
\n", "
\n", " \n", " \n", " \n", "
\n", "\n", "
\n", " WRI_BeforeAndAfterPhotos\n", " \n", "
WRI Projects with Before and After PhotosFeature Layer Collection by FireFFSL\n", "
Last Modified: January 24, 2018\n", "
0 comments, 9,409 views\n", "
\n", "
\n", " " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
\n", "
\n", " \n", " \n", " \n", "
\n", "\n", "
\n", " Social Vulnerability 2010\n", " \n", "
This map shows a simple summary of social vulnerability of populations in the United States.Feature Layer Collection by AtlasPublisher\n", "
Last Modified: July 19, 2018\n", "
0 comments, 195,382 views\n", "
\n", "
\n", " " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
\n", "
\n", " \n", " \n", " \n", "
\n", "\n", "
\n", " GIS_Export\n", " \n", "
Feature Layer Collection by baszlera\n", "
Last Modified: April 26, 2018\n", "
0 comments, 518 views\n", "
\n", "
\n", " " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "from IPython.display import display\n", "for item in public_content:\n", " display(item)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "c559b3634c3c4d9d87d064d72cef9a96", "version_major": 2, "version_minor": 0 }, "text/plain": [ "MapView(layout=Layout(height='400px', width='100%'))" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "map1 = gis.map('Collier County, FL')\n", "map1" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "#get the first item\n", "fire = public_content[0]\n", "\n", "#add to map\n", "map1.add_layer(fire)" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "
\n", " \n", " \n", " \n", "
\n", "\n", "
\n", " Landsat_Multispectral\n", " \n", "
Imagery Layer by Craig_ESRIAU\n", "
Last Modified: November 24, 2016\n", "
0 comments, 90 views\n", "
\n", "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from arcgis.gis import GIS\n", "from arcgis.raster.functions import *\n", "gis = GIS()\n", "landsat_item = gis.content.search('\"Landsat Multispectral\"', 'Imagery Layer')[0]\n", "landsat_item" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "landsat = landsat_item.layers[0]" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "def extract_stretch(bandids):\n", " return stretch(extract_band(landsat, bandids),\n", " stretch_type='PercentClip',\n", " min_percent=2, \n", " max_percent=2,\n", " dra=True, \n", " gamma=[0.8,0.8,0.8])" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "from arcgis.geocoding import geocode\n", "area = geocode('Cambridge Gulf')[0]" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "7e3f856cf0d94d7aa7b8acbc5377219d", "version_major": 2, "version_minor": 0 }, "text/plain": [ "MapView(layout=Layout(height='400px', width='100%'), zoom=10.0)" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "m = gis.map(area, 10)\n", "m" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [], "source": [ "m.add_layer(extract_stretch([5, 4, 1]))" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "675b879bce9e4a46b93833f05e7f216e", "version_major": 2, "version_minor": 0 }, "text/plain": [ "MapView(layout=Layout(height='400px', width='100%'), zoom=11.0)" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "m2 = gis.map(\"Guelb Er Richat\", 11)\n", "m2" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [], "source": [ "m2.add_layer(extract_stretch([6, 3, 1]))" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "6b4c1a055a304a0287f398fbf6742271", "version_major": 2, "version_minor": 0 }, "text/plain": [ "MapView(layout=Layout(height='400px', width='100%'), zoom=10.0)" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "m3 = gis.map(\"Gosses Bluff\", 10)\n", "m3" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [], "source": [ "m3.add_layer(extract_stretch([6, 3, 0]))" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "d3bc43e9664b45d6b7ff4b35b8ec4811", "version_major": 2, "version_minor": 0 }, "text/plain": [ "MapView(layout=Layout(height='400px', width='100%'), zoom=11.0)" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "m4 = gis.map(\"Great Exumas, Bahamas\", 11)\n", "m4" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [], "source": [ "m4.add_layer(extract_stretch([5, 3, 0]))" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "54eee94768d04a51be26ec57e64b0d24", "version_major": 2, "version_minor": 0 }, "text/plain": [ "MapView(layout=Layout(height='400px', width='100%'), zoom=10.0)" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "m5 = gis.map(\"Mexico City\", 10)\n", "m5" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [], "source": [ "m5.add_layer(extract_stretch([6, 5, 3]))" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "b4a07def91fc431b9556da364d1954c1", "version_major": 2, "version_minor": 0 }, "text/plain": [ "MapView(layout=Layout(height='400px', width='100%'), zoom=12.0)" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "m6 = gis.map(\"Ash Simasiyah, Saudi Arabia\", 12)\n", "m6" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [], "source": [ "m6.add_layer(extract_stretch([5, 4, 1]))" ] } ], "metadata": { "kernelspec": { "display_name": "pygeo", "language": "python", "name": "pygeo" }, "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.6" } }, "nbformat": 4, "nbformat_minor": 2 }