<jupyter_start><jupyter_text>Visualization for GIS users 1. Smart mapping - lines - vary by symbol size 2. Smart mapping - polygons - vary by symbol color   - definition queries   - basic plots 3. Smart mapping - points - vary by density 4. Visualizing imagery layers - dynamic raster function  Smart mapping of line features<jupyter_code>from arcgis.gis import *
gis = GIS()
map1 = gis.map('USA',4)
map1<jupyter_output><empty_output><jupyter_text>Let us search for an item titled **USA Freeway System** by **Esri** and add that to the map<jupyter_code>search_result = gis.content.search('title:USA freeway system AND owner:esri', 
                                  item_type = 'Feature Layer')
search_result
freeway_item = search_result[0]
map1.add_layer(freeway_item)<jupyter_output><empty_output><jupyter_text>Display the fields<jupyter_code>freeway_item.layers
# Use the first layer available on the service.
freeway_feature_layer = freeway_item.layers[0]

# Print the layer's url and field names.
print(freeway_feature_layer.url)
for field in freeway_feature_layer.properties['fields']:
    print(field['name'])
map1.add_layer(freeway_feature_layer, {"renderer":"ClassedSizeRenderer", "field_name": "DIST_MILES"})
# Change map's extent to San Diego, CA
map1.center = [32.715, -117.1]
map1.zoom = 10<jupyter_output><empty_output><jupyter_text>Visualizing area features<jupyter_code>map2 = gis.map('California', 6)
map2
county_search = gis.content.search("title:USA counties & owner:esri_dm", "feature layer")
county_search
county_item = county_search[0]
county_item.layers
county_item
county_feature_layer = county_item.layers[0]
for field in county_feature_layer.properties.fields:
    print(field['name'])<jupyter_output>FID
NAME
STATE_NAME
POP2010
POP10_SQMI
POP2012
POP12_SQMI
WHITE
BLACK
AMERI_ES
ASIAN
HAWN_PI
HISPANIC
OTHER
MULT_RACE
MALES
FEMALES
AGE_UNDER5
AGE_5_9
AGE_10_14
AGE_15_19
AGE_20_24
AGE_25_34
AGE_35_44
AGE_45_54
AGE_55_64
AGE_65_74
AGE_75_84
AGE_85_UP
MED_AGE
MED_AGE_M
MED_AGE_F
HOUSEHOLDS
AVE_HH_SZ
HSEHLD_1_M
HSEHLD_1_F
MARHH_CHD
MARHH_NO_C
MHH_CHILD
FHH_CHILD
FAMILIES
AVE_FAM_SZ
HSE_UNITS
VACANT
OWNER_OCC
RENTER_OCC
NO_FARMS07
AVG_SIZE07
CROP_ACR07
AVG_SALE07
SQMI<jupyter_text>Use definition expression<jupyter_code>map2.add_layer(county_item, {'type':'FeatureLayer',
                             'definition_expression':"STATE_NAME='California'"})<jupyter_output><empty_output><jupyter_text>Plot CA population by county<jupyter_code>county_fset = county_feature_layer.query("STATE_NAME='California'")
county_df = county_fset.df
county_df.head(5)
county_df.shape
import matplotlib.pyplot
%matplotlib inline
county_df.set_index('NAME', inplace=True)
county_df.POP2012.plot(kind='bar', x='NAME', figsize=(15,5))<jupyter_output><empty_output><jupyter_text>Smart mapping - symbolize by colors<jupyter_code>map3 = gis.map('California')
map3
map3.add_layer(county_item, {"type":"FeatureLayer",
                             "definition_expression" : "STATE_NAME='California'",
                             "renderer":"ClassedColorRenderer",
                             "field_name":"POP2012","opacity":0.7
              })<jupyter_output><empty_output><jupyter_text>More plotting - how are the columns correlated<jupyter_code>import seaborn as sns
sns.jointplot(county_df['POP2012'], county_df['SQMI'])
sns.pairplot(county_df[['POP2012','MALES','RENTER_OCC','HOUSEHOLDS', 'MED_AGE']])<jupyter_output><empty_output><jupyter_text>Visualizing location data<jupyter_code>map3 = gis.map('Los Angeles', 8)
map3
gis2 = GIS("https://python.playground.esri.com/portal","arcgis_python","amazing_arcgis_123")
eq_list = gis2.content.search('title:earthquakes_2', 'feature layer')
eq_list
map3.add_layer(eq_list[0], {"type":"FeatureLayer",
                "renderer":"HeatmapRenderer",
                "opacity":0.8})<jupyter_output><empty_output><jupyter_text>Visualizing imagery layers<jupyter_code>landsat_items = gis.content.search("Landsat 8 Views", item_type="Imagery Layer", max_items=2)
landsat_items
l8_views = landsat_items[0]
l8_views
l8_lyr = l8_views.layers[0]
l8_lyr.url<jupyter_output><empty_output><jupyter_text>Quick viz of imagery layers<jupyter_code>l8_lyr
for fn in l8_lyr.properties.rasterFunctionInfos:
    print(fn['name'])
marsh_map = gis.map("Pallikaranai", zoomlevel=13)
marsh_map
import time
from arcgis.raster.functions import apply

for fn in l8_lyr.properties.rasterFunctionInfos:
    print(fn['name'])
    marsh_map.remove_layers()
    marsh_map.add_layer(apply(l8_lyr, fn['name']))
    time.sleep(2)<jupyter_output>Agriculture with DRA
Bathymetric with DRA
Color Infrared with DRA
Natural Color with DRA
Short-wave Infrared with DRA
Geology with DRA
Agriculture
Bathymetric
Color Infrared
Geology
Natural Color
Short-wave Infrared
NDVI Colorized
Normalized Difference Moisture Index Colorized
NDVI Raw
NBR Raw
None<jupyter_text>Computation using raster functionsSAVI - The Soil-Adjusted Vegetation Index (SAVI) is a vegetation index that attempts to minimize soil brightness influences using a soil-brightness correction factor. This is often used in arid regions where vegetative cover is low. SAVI is computed as below, where L is the vegetation correction factor and varies from 1 to 0. A value L = 1 is used for no vegetation cover and L=0 for high vegetation cover.    SAVI = ((NIR - Red) / (NIR + Red + L)) x (1 + L)<jupyter_code>savi_map = gis.map("Cairo", zoomlevel=6)
savi_map
from arcgis.raster.functions import savi
savi_map.add_layer(l8_lyr)
savi_map.add_layer(savi(l8_lyr, band_indexes="5 4 0.3"))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09881847475832438, 'fraction_numerical': 0.028464017185821696, 'mean_word_length': 5.889025893958077, 'pattern_counts': {'":': 9, '<': 47, '<?xml version=': 0, '>': 47, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '12', 'dir': 'jupyter-structured-clean-dedup', 'id': '58678', 'license': 'Apache-2.0', 'n_tokens_mistral': 2154, 'n_tokens_neox': 2030, 'n_words': 433, 'path': 'talks/uc2017/Mapping, Visualization, and Analysis Using ArcGIS API for Python/visualization.ipynb', 'repo_name': 'nitz21/arcpy', 'size': '5586'}