Extracting Shoreline Polygons and Polylines from Sentinel-2 Imagery

From CUOSGwiki
Jump to navigationJump to search

Introduction

The delineation of shoreline polygons can have a variety of practical applications, from shipping and navigation to change detection and mapping coastal erosion. Often shoreline shapefiles are created using a semi-automated method combining automated boundary extraction and manual interpretation. This tutorial will focus on delineating shoreline polygons and polylines from Sentinel-2 satellite data. The Naturalized Difference Water Index [NDWI] will be used to define the boundary between water and land. This boundary will then be extracted and manually corrected to produce a final shoreline polygon and polyline file.

The purpose of this tutorial is to show the user how to extract shoreline polygons from satellite data in the Qgis software package. For this tutorial the Copernicus Open Access Hub will be used to access the required satellite imagery. The report will explore how to use this data portal to browse and download the available Sentinel-2 imagery. The satellite imagery will then be imported to Qgis where polygons and polylines of the shoreline will be created.

Both Qgis and the Copernicus Open Access Hub are free to use, however the Copernicus Open Access Hub does require the user to create an account to download the data. The latest version of Qgis can be downloaded from the following link: (https://www.qgis.org/en/site/ )


Note: QGIS version 3.8.1 was used to create this tutorial. A newer version of the software may be available.

Data

This report will use Sentinel-2 satellite data collected by the European Space Agency. The Copernicus Sentinel-2 satellite mission is a constellation of two multispectral polar orbiting satellites [1]. The satellites offer data in the form of Level-1C and Level-2A data products. The Level-C1 products are multispectral satellite images that include the top of atmosphere reflectance. This means they do not have any atmospheric correction applied [2]. Level-2A data products are derived from Level-1C data and offer bottom of atmosphere reflectance. In this case atmospheric corrections have been applied to the image to remove some effects of the atmosphere on the image’s reflectance [3]. It is worth noting that Level-2A data may not be offered for many regions outside of Europe [4]. For this reason, the study will use Level-1C data.

Both the Level-1C and Level-2A data products have differing spatial resolutions depending on the multispectral bands being viewed. This study will use the Red, Green, Blue and Near Infrared [NIR] bands. All four of these bands have a spatial resolution of 10m with a swath width of 290m. In addition, when the data is downloaded it is projected in the relevant UTM zone using the WGS 83 datum [5].

Tutorial Methods and Instructions

Step 1. Using the Copernicus Open Access Hub

Click on the following link to access the Copernicus Open Access Hub: https://scihub.copernicus.eu/dhus/#/home

  • Click on the Login Step1 Copernicus Login Icon.png icon at the top right of the screen, create an account if you currently do not have an account or login to an existing account (Note: you cannot browse or download the data without creating an account)
  • After logging in you can now browse all of the data offered on the Copernicus Open Access Hub
  • To pan the field of view you can click and drag the underlying map, you can also zoom in and out using your scroll wheel
  • You can change the basemap of the data portal by clicking on the Map Layers button on the top right of the screen
Step1 Copernicus MapLayers.png
  • To browse satellite images over a specific area you can click and drag the mouse to draw a rectangle
  • When you do this a yellow box should appear over the area you selected (Note: if you click and drag the scroll wheel again you will draw a new area of interest and the previous one will be lost)
  • This will allow you to search for images over the area you have drawn the rectangle
  • Zoom in to the city of Corner Brook, on the west coast of the island of Newfoundland, Canada
  • Draw an area of interest around Cox’s Cove, the bay above Corner Brook as seen in the image below.
Step1 Copernicus AOI.png

Step 2. Browsing the Copernicus Open Access Hub

  • Click on the List Step2 Copernicus List Icon.png button on the left of the data search bar
  • You should now see an Advanced Search drop-down menu appear below the search bar, as seen below
Step2 Copernicus SearchMenu.png
  • This menu allows you to filter and search for images with specific criteria and date ranges
  • Under the Sort By header change the option to Sensing Date, this will show you all specified data products in order of when each image was taken
  • Under the Sensing Period header select the starting date October 1st 2019 on the left and the end date October 10th 2019 on the right (this will filter the search results to images that were taken between these two dates)
  • Note: if you use the Ingestion Period option you will filter images based on the date they were added to the Copernicus Open Access Hub archive not when the images were taken
  • Check the box beside the Mission: Sentinel-2 header to restrict all images to only the Sentinel-2 constellation of satellites
  • Under the Product Type header in the Mission: Sentinel-2 option select the S2MSI1C option, this will restrict all images to the Level-C1 product type
  • Note: using the Satellite Platform option will restrict the search to include one of the two Sentinel-2 sensors in the Sentiunel-2 constellation, depending on what sensor is selected
  • Note: using the Cloud Cover % option allows the user to specify what proportion of the image will be taken up by could cover, this can be useful to quickly filter out cloudy images from your search
  • Your search menu should look like the following
Step2 Copernicus SearchMenu Filled.png
  • After inputting these search options click the Search Step2 Copernicus Search Icon.png button

Step 3. Browsing the Copernicus Open Access Hub

  • You should now see a list of different images that fit your search criteria from above
  • Notice on the basemap the outline of each image footprint can be seen as a green outline
Step3 Results.png
  • When you hover your mouse over the images on the left of the screen the corresponding footprint will darken
  • Notice how the track of the satellite is broken down into multiple images, very often you will need to download multiple images to get the full coverage needed in a study site
  • Examine the different images available, you can click on the View Product Details Step3 ViewProduct Icon.png button to get a better look at the image you have selected
  • When you click the View Product Details Step3 ViewProduct Icon.png button you will be able to see additional information about the image, including the image footprint, time of acquisition and a variety of metadata
  • Notice each image has an associated name that quickly describes the image and some key pieces of information, here is a breakdown of the most important parts of the naming convention for Sentinel-2 data
For example, you have the image…
S2B_MSIL1C_20191010T145729_N0208_R082_T21UVQ_20191010T164326
S2B: This is the mission ID and satellite that acquired the image (Seninel-2 using the Seninel-2B satellite)
MSIL1C: This is the product level (Level-C1)
20191010T145729: This is the date and start time of acquisition (October 10th, 2019 at 14:57:29pm)
In addition to this each name acts as a unique identifier for the image
  • Find the two following images in the list of search results and click the Download Step3 Download Icon.png icon to download a zipfile of both images
S2B_MSIL1C_20191010T145729_N0208_R082_T21UVQ_20191010T164326
S2B_MSIL1C_20191010T145729_N0208_R082_T21UUQ_20191010T164326

Note: if you are having trouble finding these two images, clear your selections in the search window then cut and paste the image name into the search bar to find each of the images one by one


Step 4. Installing Plugins for Qgis

  • Go to the folder where you downloaded the two images and extract both zip files to a new working folder
  • Open the Qgis application
  • On the top of your screen click on the Plugin tab
  • A window of all the available plugins for Qgis should now appear
  • Plugins are different tools created by the Qgis community that add additional functionality to the base Qgis software
  • Search for and download the Value Tool plugin and the Virtual Raster Builder plugin
Step4 InstallPlugin.png
  • After the plugins are installed make sure they are enabled by clicking the checked box next to the tools name


Step 5. Opening Sentinel 2 Data in Qgis

  • You can now import the Sentinel-2 imagery into Qgis
  • Click on the Open Data Source Manager Step5 OpenDataSourceManager Icon.png button at the top left of your screen
  • The data source manager window should now pop up, navigate to your folder where the extracted Sentinel-2 images have been stored
  • In the file folder for the first image navigate to the GRANULE > L1C_T21UUQ_A013550_20191010T145730 > IMG_DATA folder
  • You should now see a series of .jp2 images that correspond to the bands of the satellite image
  • In a Sentinel-2 image Band 2 is the Red band, Band 3 is the Green band, Band 4 is the Blue band and Band 8 is the NIR band
  • The band number is indicated by the last three numbers in the name (Example: B02 is the band number 2 corresponding to the Red band)
  • Select bands 2,3,4,8 and the TCI image from this folder by holding the CTRL key and clicking each file (Note: select the raster image and not the polygon file with the same name, see the image below)
Step5 SelectBands.png
  • Right click one of the selected bands and select the Add Selected Layers to Project option
  • The selected bands should now be added to your project under the Layers table of contents
  • Click through the five bands and look at each (Note: you can change the order of what image is on top by clicking and dragging a raster image under the Layers table of contents)
  • Bands 2,3,4 and 8 should all be individual greyscale images
  • The TCI image is the true colour image and has the RGB bands mapped to 2,3,4 respectively this is why it is the only colour image out of the five
Step5 TCI.png


Step 6. Combining and Exporting Seninel-2 Data to GeoTIFF Format

  • The five bands that you imported in step 5 can be opened by Qgis however, most cannot be used with other raster tools in the software
  • This is why the Create Virtual Raster plugin has been installed, it gives Qgis some extra functionality so that we may create colour composites out of these individual raster images
  • Frist, right click on the TCI band and select Export > Save As…
  • Make sure the output format is GeoTIFF and save the file to your working file folder where the two Sentinel-2 images are stored, give it a name like "TCI_1.tif"
  • Keep all the default parameters and click OK
  • The GeoTIFF version of the TCI image should now be added to your Layers table of contents
  • Second, we will create a colour composite image from the four individual bands you previously imported
  • Navigate to the Build Virtual Raster tool by clicking on Raster > Miscellanies > Build Virtual Raster… under the main toolbar
  • The Build Virtual Raster tool window should now pop up
  • Under the Input Layers header click the … button and add bands 2, 3, 4, 8 in this order
  • Keep all default options and click Run
Step6 BuildVirtualRaster.png
  • After the tool has completed you should now have a temporary virtual raster added to your Layers table of contents
  • The image may look slightly orange like in the example below (This is due to the way the image is symbolized, don’t worry we will change this later)
  • Note that the bands have been renamed in the virtual raster from 2,3,4, 8 to 1,2,3, and 4 respectively (They should still be in the order in which you added them to the Build Virtual Raster tool)
  • Right click the virtual layer and select Export > Save As…
  • Make sure the output format is GeoTIFF and save the file to your working folder, give it a name like "ColourComp_1.tif"
  • Keep all the default parameters and click OK
  • You should now have a GeoTiff version of the TCI image and a Colour Composite image
Step6 ColourComp.png
  • Under the Layers table of contents select the five bands previously imported and the temporary virtual raster by holding the CTRL key and clicking each image
  • Right click one of the selected rasters and select Remove Layer to remove them from your project

Step 7. Merging Raster Images

  • Repeat steps 5 to 6 using the second Sentinel-2 image giving the output GeoTIFFs different names like "TCI_2" and "ColourComp_2"
  • You should now have two colour composite images and two true colour images, one for each half of the full Senienl-2 Scene
Step7 Scene.png
  • We can now merge the two halves of both the true colour and colour composite scenes using the Merge raster tool
  • Navigate to Raster > Miscellaneous > Merge the merge raster tool window should now appear
  • Select the two TCI rasters then click run
Step7 Merge.png
  • This will produce another temporary raster so you will need to export and save the merged file to a new GeoTIFF file using Export > Save As…
  • Repeat the merge process with the two halves of the colour composite image
  • You should now have two complete rasters of the full Sentinel-2 scene, one a true colour image and one a colour composite image
  • Right click the unmerged rasters and remove them from the project using the Remove Layer option

Step 8. Symbolizing Raster Layers in Qgis

  • In Qgis you are able to change the way raster layers are symbolized
  • To change a raster’s symbolization right click the layer and select Properties
  • Under the various headers there are options for changing the image’s saturation, contrast, brightness, minimum value, maximum value and bands that are mapped to the image's RGB channels
  • We will now create a false colour image from the colour composite merge layer
  • Right click the colour composite merge raster and select Properties
  • Under the band rendering window, you should be able to see what bands have been assigned to the Red, Green and Blue channels(Note: the band numbers have changed in this image after creating the first colour composite image back in step 6 Band 1 in this image is the Red band from the Sentinel 2 data, Band 2 is the Green band and Band 3 is the Blue band, Band 4 is NIR)
  • We can change the bands that are mapped to the image's RGB channels to create an image that accentuates specific features in our environment
  • A common false colour image combination used to view vegetation and water uses NIR mapped as (red) , Green mapped as (blue) and Red mapped as (green)
  • This combination highlights vegetation in red because vegetation reflects large amount of the NIR wavelength
  • Change the assigned bands under the Band Rendering header so that Red channel is assigned to band 4, Green channel is assigned to band 3 and the Blue channel is assigned to band 2, then click OK
  • The image should now appear as a false colour image, as seen below
Step8 FalseColour.png
  • You can adjust the brightness on both the false colour and true colour image to your liking using the brightness slider in the Layer Properties window


Step 9. Creating a NDWI Image

  • The Naturalized Difference Water Index is spectral ratio that is used to accentuate the presence of water in a satellite image, it is calculated by the following formula
(Green – NIR) / (Green + NIR) [6].
  • This formula is applied to each pixel of an image and uses the reflective properties of water in the NIR and Green bands derive a value from -1 to 1 that represents the water content of that pixel
  • NDWI is very useful for determining the boundary between land and water in an image
  • To create a raster of the NDWI navigate to the Raster > Raster Calculator tool
  • The raster calculator window should now appear, under the Bands header you should see all the available bands of each raster image loaded into your project (Note: the number after the @ symbol corresponds to the band number)
  • In the text box under the Raster Calculator Expression header type the following expression:
("ColourComp_M@2"-"ColourComp_M@4") / ("ColourComp_M@2"+"ColourComp_M@4")
Step9 RasterCalc.png
  • Give the output layer a save location and name it "NDWI.tif" then press OK
  • You should now have a greyscale raster of the NDWI as seen below (Note: brighter pixels indicate water, darker pixels indicate land)
Step9 NDWI.png

Step 10. Finding the Water Land Boundary

  • Now that we have an image of the NDWI it is possible to find the boundary between water pixels and land pixels in the image
  • First click on the Identify Features Step10 IdentifyFeatures.png button then click on the Value Tool Step10 ValueTool.png button to activate the plugin tool that we installed(Note: to turn off the tool click the identify feature button again)
  • Zoom in to the image and find an area the water meets the land, click around the image to see the corresponding pixel value at each location in the popup window on the right of your screen (Note: light pixels are water, dark pixels are land)
  • Look at the different values between the water pixels and land pixels to see if you can find a general value that separates the two (Note: this value will change between different satellite images and even within the same satellite image)
Step10 BoundaryValue.png
  • In the example above the value separating land and water appears to be around -0.169 so this will be the value where we draw the line between water and land
  • To generate a raster of the land and water boundary navigate to the raster calculator tool under Raster > Raster Calculator
  • Enter the following expression for the tool and specify the save location (Note: NDWI@1 is the name of the NDWI raster that was created, this name may change depending on what you named it)
(("NDWI@1">= -0.16)=1) AND (("NDWI@1"<=-0.16)=0)
  • The resulting raster should be a black and white raster showing black as land and white as water
Step10 BoundaryRaster.png


Step 11. Creating an AOI

  • The next few steps would be very labour intensive and take a long time to run on the full Sentinel-2 image so we will create a smaller subset of our image to work with going forward
  • To extract an area of interest or AOI from the scene we first need to create a polygon around the area we are interested in
  • To create an empty shapefile layer, navigate to Layers > Create Layer > New Shapefile Layer
  • Give the new shapefile a name like AOI and specify a save location then change the geometry type to Polygon and press OK
  • You should now see an empty polygon layer under the table of contents called AOI
  • To draw your AOI right click the new polygon layer and select Toggle Editing
  • Click on the Add Polygon Feature Step11 AddPolygonFeature.png button
  • You can now click and draw the four corners of your AOI rectangle, when you have finished the fourth corner right click press OK (Note: if you click cancel you can delete the currently drawn polygon and start again)
  • You should now have a rectangle over the are you drew the polygon, you may choose a different location then the tutorial if you wish
Step11 AOI.png
  • Right click the AOI polygon layer under the table of contents and select Save Layer Edits then right click the layer again and select Toggle Editing to stop editing
  • Navigate to Raster > Extract > Clip Raster by Mask Layer…
  • The Clip Raster by Mask Layer tool window should now be open
  • Under the Input Layer specify your black and white land water boundary raster, under the Mask Layer specify your AOI polygon
  • Specify a save location for the Clipped (Mask) and give it a save location then press Run
  • You should now have a black and white land water boundary raster clipped to your AOI extent
Step11 AOI Finished.jpg


Step 12. Creating Land/Water Polygons

  • To create a polygon layer from the clipped black and white raster navigate to the Raster -> Conversion > Polygonize (Raster to Vector)… tool
  • Make sure the input is your black and white raster (Note: the output will be a temporary file so you do not need to specify a save location just yet)
  • The output will be a polygon version of the raster clipped black and white raster (Note: each polygon still has its associated pixel value in its attributes under the polygon's attribute table)
Step12 Polygons.jpg
  • To select the polygons that only correspond to land first click the "Vectorized" polygon layer to highlight it in blue, then click on the Select Feature by Value Step12 SelectFeaturesByValue.png button
  • A window should now pop up, under the DN heading type 0 then press the select features button
  • The land should now be highlighted in yellow, you can now click Close to close the window
Step12 SelectedLand.jpg
  • You can now export the land to a new permanent shapefile by right clicking the "Vectorized" layer under the table of contents and selecting Export > Save Selected Features As…
  • Make sure the output format is ESRI Shapefile then specify a save location and name for the output file
  • You should now have land only polygon layer
Step12 LandPoly.jpg


Step 13. Correcting the Land Polygon

  • Turn off all rasters except for the false colour image and bring the land polygon to the top of the table of contents
  • Zoom in and pan around the image, you will notice many areas were the shoreline is incorrectly drawn
  • This is the result of many different errors like shadow, cloud, shallow water and even selecting the wrong value for the NDWI boundary in step 10
  • This is why manual correction is always needed before finalizing shorelines and it highlights one of the many downfalls to extracting shoreline from satellite imagery
  • You can manually correct the shoreline by right clicking the polygon layer in the table of contents and selecting Toggle Editing
  • In the image below we can see that the shoreline has incorrectly isolated some small pixels classifying them as land, in addition some areas have been incorrectly identified as water
  • You can compare the false colour and true colour images by turning them off and on under the Table of Contents to identify where the water land boundary is
Step13 IncorrectShoreline.png
  • The easiest approach to correct this section of the image is to first delete all of the isolated pixels then go back and redraw the shoreline manually
  • To delete polygons from the layer use the Select Features by Area or Single Click Step13 SelectFeatureClick.pngbutton then click on the polygon you want to delete (Note: you can click and drag to draw a rectangle over an area to select multiple polygons at once)
  • The selected polygon should now be highlighted in yellow and you can press the delete key to delete it
  • To undo any previous actions, use the hot key CTRL + Y
  • To redraw the shoreline, navigate to the Edit > Reshape Features tool
  • Your cursor should now be a crosshair icon
  • To redraw the polygon first click inside the polygon then trace the outline of the shore, clicking along the way to add nodes (you should see a red line showing you where you have drawn)
  • Once you have redrawn the shoreline click inside the polygon once more to add a node inside the polygon’s boundary, then right click to finish redrawing the polygon
  • To add a new polygon over an island or area that has been missed click the Add Polygon Feature Step11 AddPolygonFeature.png button and draw a new polygon, right click and press OK to finish drawing the new polygon
  • To delete incorrect holes in the shoreline polygon, navigate to the Edit > Delete Ring tool
  • Then click the hole to remove it from the polygon
  • You can then pan around the image and correct different areas where the shoreline has been incorrectly drawn
  • Remember to save your edits and toggle off Toggle Editing before moving on
  • Manually correcting an AOI can take hours to days, even weeks depending on the size of the area being mapped
Step13 CorrectShoreline.png


Step 14. Simplifying the Shoreline

  • By using the NDWI boundary to create a shoreline the resulting polygon is very pixilated and can have rough edges
  • To remove these rough edges and smooth the shoreline we can simplify the shoreline’s geometry
  • Navigate to the Vector > Geometry Tools > Simplify tool
  • The tool window should now open
  • Select the land polygon shapefile for the input layer
  • You can then change the Tolerance value and its units to control the amount you smooth the layer
  • For the purpose of this tutorial use a smoothing tolerance of 30 meters
  • Under the Simplified header give the output layer a save location and name like “SmoothShore” then make sure the output is in .shp format
  • You can now see how the shoreline has been smoothed
Step14 SmoothShore.png
  • Sometimes smoothing the shoreline can incorrectly change its shape, so a second manual revision is then made to fix any of these problem areas


Step 15. Creating a Shoreline Polyline

  • Sometimes shoreline data needs to be in the form of a polyline instead of a polygon
  • You can easily change a polygon to a polyline by using the Polygons to Lines tool
  • Before running the tool it is helpful to make sure all of the shapefile’s geometry is correct
  • Often times shapefiles created from raster boundaries can have different overlapping nodes in a single shapefile, this can prevent the Polygons to Lines tool from working correctly and polygons with this error will be excluded from the tool
  • To fix this issue first click on the smoothed shoreline polygon to highlight it, then type fix geometries into the search bar at the bottom of your screen
  • You should see Edit Selected Features at the top of the search results, under this heading click the Fix Geometries option to run the tool (Note: this will take a long time)
  • You can then continue and use the Polygons to Lines tool
  • Navigate to Vector > Geometry Tools > Polygons to Lines to open the tool window
  • Select the simplified shoreline polygon as the input to the tool and give the output layer a name and save location
  • You should now have a polyline version of the shoreline shapefile
  • Notice that the bottom boundary of our AOI was also converted to a line that cuts across the land, we can quickly fix this
Step15 PolylineAOIBoundary.jpg
  • To get rid of these lines right click the polyline layer and Toggle Editing on
  • Navigate to the Edit > Split Features tool, the cursor should now become a crosshair
  • Zoom in to the area where you want to cut the line
  • Draw a line across the boundary by clicking on either side of the line you want to cut then right click to finish
  • The line should now be cut along the line that you drew, repeat the split again at the other end of the line where you want it cut
  • Next select the cut line that you want to get rid of by using the Select Features by Area or Single Click Step13 SelectFeatureClick.png button
  • When the line is selected hit the Delete key to delete it
  • Save your edits and toggle editing off to finish
  • You should now have a finished polygon and polyline file of your shoreline
Step15 PolylineFinal.jpg

References

[7]

[8]

[9]

[10]

  1. [1],Retrieved: 2019-11-05
  2. [2],Retrieved: 2019-11-05
  3. [3],Retrieved: 2019-11-05
  4. [4],Retrieved: 2019-11-05
  5. [5],Retrieved: 2019-11-05
  6. [6],Retrieved: 2019-12-10
  7. 1 The European Space Agency,"Sentinel-2", Retrieved: 2019-11-05
  8. 2 The European Space Agency,"Data Products", Retrieved: 2019-11-05
  9. 3 The European Space Agency,"Resolution and Swath", Retrieved: 2019-11-05
  10. 4 Stuart K. McFeeters,"Using the Normalized Difference Water Index (NDWI) within a Geographic Information System to Detect Swimming Pools for Mosquito Abatement: A Practical Approach", Retrieved: 2019-12-10