This notebook presents a Sentinel2 collection that is filtered using 3 criteria:
1) geographic location: filterOnGeoName(...) that filters all images that intersect a given geoname;
2) acquisition date: filterOnDate(2015,1,1, 2016,12,31) that means all the images acquired in 2015 or 2016;
3) images metadata: filterOn("cloudcover", "<=", 5) filters only images with no more than 5% of cloud cover.
The images that satisfy all the filtering criteria are then sorted in ascending mode based on cloudcover attribute, so the more cloudy images will be displayed first, the more cloud free last and they will therefore stay "over".
coll.limit(4) is used to reduce to only the first 4 less cloudy images the collection.
The collection object can give information on images satisfying the selection criteria. The function call coll.printImages("fullpath") will show the full path of the images in the collection.
coll.printAttributes() prints the list of all available metadata attributes for a Sentinel 2 images collection
coll = inter.ImageCollection("S2")
cityName="Munchen"
enlargeByDegree= 0
countryCode="DE"
coll = coll.filterOnGeoName(cityName, enlargeByDegree, countryCode)
coll = coll.filterOnDate(2015,1,1, 2016,12,31)
coll = coll.filterOn("cloudcover", "<=", 5)
coll = coll.filterOn("jrc_filepath", "<>", "")
coll.limit(4)
coll.sort("cloudcover",True)
coll.printImages("fullpath")
#coll.printAttributes()
We now open an interactive map:
map = Map(basemap=1)
map
From the collection a "process" object is created (p1 = coll.process()...) that calculates an RGB composition
in "true color" from bands B04, B03 and B02 and adds it as a new layer to the map (map.addLayer(p1.toLayer()))
p1 = coll.process().bands("B04","B03","B02",2)
p1.optimizeStats(True)
map.clear()
map.zoomToImageExtent(p1)
tlayer1 = map.addLayer(p1.toLayer())
Visibility of a layer can be changed using:
tlayer1.visible = False
An example of simple arithmetic operation: making the average of band B03 and B04, masking out all values less than 600 and displaying the result applying a color palette and 50% transparency (p1.opacity(128))
p1 = coll.process().band("B04")
p2 = coll.process().band("B03")
p1 = p1.math("+",p2).math("*",0.5).maskLT(600)
p1.scale(600,1500)
colors = ["Green", "Yellow", "Red"]
p1.colorCustom(colors)
p1.opacity(255)
map.clear()
tlayer1 = map.addLayer(p1.toLayer())