How much green is Delhi as on 15 Oct 2017?¶
Table of Contents
Introduction¶
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¶
%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¶
gis = GIS('https://pythonapi.playground.esri.com/portal', 'arcgis_python', 'amazing_arcgis_123')
Get the data for analysis¶
Here we're getting the multispectral landsat imagery item in ArcGIS Online.
landsat_item = gis.content.get('d9b466d6a9e647ce8d1dd5fe12eb434b')
landsat = landsat_item.layers[0]
landsat_item
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.
boundaries = gis.content.get('c10550159eef410299ed373ca15a354b')
state_boundaries = boundaries.layers[1]
Extracting Landsat imagery for New Delhi Region
area = geocode("New Delhi, India", out_sr=landsat.properties.spatialReference)[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.
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.
from datetime import datetime
selected = landsat.filter_by(where="(Category = 1) AND (cloudcover <=0.05)",
time=[datetime(2017, 10, 1), datetime(2017, 12, 31)],
geometry=arcgis.geometry.filters.intersects(delhi_geom))
df = selected.query(out_fields="AcquisitionDate, GroupName, CloudCover, DayOfYear",
order_by_fields="AcquisitionDate").sdf
df['AcquisitionDate'] = pd.to_datetime(df['AcquisitionDate'], unit='ms')
df
Selecting imagery dated 15 October, 2017 from the collection using its OBJECTID.
delhi_image = landsat.filter_by('OBJECTID=2095521') # 2017-10-15
Applying Natural color to verify the quality of image
apply(delhi_image, 'Natural Color with DRA')