ArcGIS Developer

ArcGIS API for Python

Download the samples Try it live

How much green is Delhi as on 15 Oct 2017?


The India State of Forests Report (ISFR) 2017, showed that the green cover of Delhi has increased from 20.08% in 2015 to 20.22% in 2017, as observed from satellite imageries of Delhi for the month of October and November [1]. This was a welcome news for the city struggling with severe pollution and rising population, which makes it necessary to monitor the city's green cover and keep the city liveable.

This sample shows the capabilities of spectral indices such as Normalized Difference Vegetation index (NDVI) for the calculation of green cover in Delhi, India on 15 October 2017 using Landsat 8 imagery.

Necessary Imports

In [1]:
%matplotlib inline

import pandas as pd
from datetime import datetime
from IPython.display import Image
from IPython.display import HTML
import matplotlib.pyplot as plt

import arcgis
from arcgis.gis import GIS
from arcgis.raster.functions import apply, clip, remap, colormap
from arcgis.geocoding import geocode

Connect to your GIS

In [2]:
gis = GIS('', 'arcgis_python', 'amazing_arcgis_123')

Get the data for analysis

Here we're getting the multispectral landsat imagery item in ArcGIS Online.

In [3]:
landsat_item = gis.content.get('d9b466d6a9e647ce8d1dd5fe12eb434b')
landsat = landsat_item.layers[0]
Multispectral Landsat
Landsat multispectral and multitemporal imagery with on-the-fly renderings and indices for visualization and analysis. The Landsat 8 imagery in this layer is updated daily and is directly sourced from the Landsat on AWS collection.Imagery Layer by esri_livingatlas
Last Modified: May 13, 2020
0 comments, 1 views

Search for India State Boundaries 2018 layer in ArcGIS Online. This layer has all the state boundaries for India. The boundary of Delhi can be filtered from the layer, as this notebook focuses on the city's green cover.

In [6]:
boundaries = gis.content.get('c10550159eef410299ed373ca15a354b')
state_boundaries = boundaries.layers[1]

Extracting Landsat imagery for New Delhi Region

In [8]:
area = geocode("New Delhi, India",[0]
landsat.extent = area['extent']

In State Boundary layer, OBJECTID for Delhi is 7 which is used below. Also, it is important to add extent to the geometry of selected boundary.

In [9]:
delhi = state_boundaries.query(where='OBJECTID=7')
delhi_geom = delhi.features[0].geometry
delhi_geom['spatialReference'] = {'wkid':4326}
delhi.features[0].extent = area['extent']

Filter imageries based on cloud cover and Acquisition Date

In order to have good result, it is important to select cloud free imagery from the image collection for a specified time duration. In this example we have selected all the imageries captured between 1 October, 2017 to 31 December, 2017 with cloud cover less than or equal to 5% for Delhi.

In [10]:
from datetime import datetime

selected = landsat.filter_by(where="(Category = 1) AND (cloudcover <=0.05)",
                             time=[datetime(2017, 10, 1), datetime(2017, 12, 31)],

df = selected.query(out_fields="AcquisitionDate, GroupName, CloudCover, DayOfYear", 
df['AcquisitionDate'] = pd.to_datetime(df['AcquisitionDate'], unit='ms')
OBJECTID AcquisitionDate GroupName CloudCover DayOfYear Shape_Length Shape_Area SHAPE
0 2096408 2017-10-06 05:25:18 LC81470402017279LGN00_MTL 0.0000 279 852147.705738 4.534369e+10 {"rings": [[[8625624.2331, 3442812.7971], [857...
1 2095521 2017-10-15 05:19:09 LC81460402017288LGN00_MTL 0.0011 288 852002.482986 4.532785e+10 {"rings": [[[8796766.063900001, 3442853.641099...
2 2203649 2017-11-23 05:25:14 LC81470402017327LGN00_MTL 0.0333 327 852242.226027 4.535328e+10 {"rings": [[[8627133.4597, 3442780.260499999],...
3 2206118 2017-12-02 05:19:00 LC81460402017336LGN00_MTL 0.0015 336 851555.400431 4.528033e+10 {"rings": [[[8800038.6758, 3442628.6884000003]...
4 2211732 2017-12-09 05:25:11 LC81470402017343LGN00_MTL 0.0099 343 852179.154208 4.532813e+10 {"rings": [[[8626952.113400001, 3442914.852600...

Selecting imagery dated 15 October, 2017 from the collection using its OBJECTID.

In [8]:
delhi_image = landsat.filter_by('OBJECTID=2095521') # 2017-10-15 

Applying Natural color to verify the quality of image

In [9]:
apply(delhi_image, 'Natural Color with DRA')