Coastline Extraction using Sentinel-2 data

Hi all!

I’m new to SNAP and I’m working on a project to examine coastal erosion using sentinel 2 data. My aim is to extract a coastline using vegetation indices to distinguish water from land because the location I’m looking at has very long shallow beaches which are often waterlogged, making coastline extraction unreliable, particularly when looking at coastal erosion. I cannot figure out how to do it at all. I can use the land/water masks, I can use filters like NDVI or NDWI to distinguish water from land, but how do you extract a line between the two of them without digitising everything by hand? I’m trying to do a comparison over time and I can’t do that unless I can compare coastlines. I have searched far and wide for methodologies for how to do this, and while I have found some articles (and very few tutorials), their methodologies are not easily replicable and don’t use SNAP to do it. I’ve tried edge detection methods, but that did not draw a coastline (it was just a grey mess), I used a high pass filter for it too. Even if I just used the land and sea masks, I cannot compare different vegetation indices or change over time without either a line between the land and the water or overlaying one image over the other (which I don’t know how to do either, just side by side tabs).

This seems like a relatively easy task, but I’ve been trying to figure this out for months and it’s just not going anywhere. Do I need to use different software? Should I be using SAR instead?

Any help is appreciated,

You are close to the solution.
My suggestion is to use a mean filter (Raster / Filtered Band) on your created land/water mask.
Maybe 3x3 or 5x5.
Everything which is clear land will 255 and everything what is clearly water will be 0. Or the other way around.
Now you can define a thresholds (one for the upper and for the lower) for which values shall be considered as coastline. This can be done with the Band Maths.
The result might not always be good. It depends on your mask.
The following image is the result of one test I once made:

The red line is the coastline. But as you see, the blueish area is not considered. This wasn’t included in may land/water mask. The resulting coastline depends on your input.
A radiometric test is also problematic, because of clouds. Where you have clouds you won’t have a coastline. So, a good high resolution land/water mask would be beneficial.
As an idea. You could use the 30m Copernicus DEM and derive from this the land/water mask.


I would go a bit further from Marco’s suggestion and use SAR. For a better separation of water and land I’d do the following:

  1. Extract the backscatter from either a Sentinel-1 GRD product (less operations) or a Sentinel-1 SLC one (more operations). Optimally, a Speckle filter (or even a multi-temporal one) would reduce the noise.
  2. Compute the NDVI from a Sentinel-2 product and apply an Arithmetic Mean 3x3 to smooth it a bit.
  3. Subset the backscatter to the Sentinel-2 extent and reproject it in the Sentinel-2 projection.
  4. Create a binary mask by applying a Band Maths on the subset backscatter and the mean NDVI (altogether). For example, where ndvi<0.1 and bck<0.1 then the value is 0 else 255.
    The DEM may also help, but it may have been created using a landscape that is already changed. Here’s an example of the above:
  • Top-left: the true color Sentinel-2 image
  • Top-right: the Sentinel-1 backscatter
  • Bottom-left: the DEM (Copernicus Global 30m in this case)
  • Bottom-right: the binary Band Math
    The acquisitions are from this month over the S2 tile 35TPK. Above is the Sacalin Island (Sacalin Island - Wikipedia) which changes its shape (it’s an aluvional island near the Romanian Black Sea shore). In the DEM it has another shape than it currently has.

Thank you @marpet and @kraftek for your suggestions! I will have to experiment with your methodologies and try to figure things out. I don’t quite understand Band Maths yet, but I have to learn at some stage!

@marpet I’m curious how you would use the DEM and derive from the land/water mask, I’m not sure exactly what you mean there. Is it like you blend the mask and the DEM together?

@kraftek When you’re creating a binary mask, are you blending the back scatter extraction onto the NDVI? I’m not sure how you are thinking of using the DEM in this context. Is it similar to Marpet’s suggestion?

Thanks for your time and patience,

It depends on the DEM how you can use it. But for example you could create a binary mask by using the Band Maths with the expression dem_band >= 0. This assumes that l land is grater or equal to zero and water is less then 0.
On this you could then run the mean filter.

Then DEM can be integrated in you data by using ‘Add elevation band’ from the context menu of the product in the product explorer.

Hi @marpet and @kraftek,

I have taken your advice and experimented a little. I used the GNDVI on this subset, made a land/sea mask (masking the land). I then applied a median 7 filtered band, followed by an arithmetic mean of 5x5. Then I used the following band maths to create the outputs pictured below:

gndvi_median7_am5 <= 0.1 and
gndvi_median7_am5 >= -0.1 and
gndvi_median7_am5 != 0.0

I think this is the best I’m going to get, but if you have any advice on how to extract only the lines along the vegetation and not the entire beach outline I’d greatly appreciate it! My biggest issue is that I cannot seem to extract this line as a shapefile, even after I export the band as a TIFF, I cannot convert it into a shapefile that can be used for DSAS in ArcMap. @marpet how did you overlay your extracted coastline onto another image? How did you extract the line to be used elsewhere?


You can create a Mask from your data.
Got to the Mask Manager and create a new one.
Please have a look at the help.
You can create the mask by expression and you can give it a colour.

coastline_band == 1
You can toggle the visibility.
Afterwards, you can use the Layer Manager to configure the layer even more.

Another option is to set a no-data value to the coastline band. Open the context-menu of the band and select Properties.
There, you can set 0 (already is probably) as no-data value and set the check mark for ‘use no-data value’. Then all the black area gets transparent. The Colour Manipulation window can be used to colourise the image.
Now, the Layer Manager can be used to add a new layer. Select ‘Image of Band’ in the wizard and then select the coastline band.

SNAP does not have the feature to turn raster data into vector data. But with QGIS it should be possible. But I don’t know how. I never did it.


A post was split to a new topic: How to access chl and turbidity after C2RCC processing?

Hello, I’m working on coastline extraction, polarimetric correlation. Could you please share the steps you used to manage here in the SNAP tool for S2?
Thank you!

Sentinel-2 is an optical sensor and polarimetric refers to radar data. Are you sure you aim at the right approach?

Yes, S2 is optical data. I guess it works with the same approach as the polrimetric one.
We need a threshold to distinguish land and water.
I.e., the above-mentioned mean filter, 3*3, is best for S2 (smoothing regularization).
Then a threshold is required to discriminate between land and water as binary data.
Later, edge detection can be deployed to obtain a coastline map.
This works for both S1 and S2.