Tuesday, February 7, 2023

Using Python Interpret Landsat File Naming Convention

 If you have ever worked with Landsat images, you would have noticed that the image files usually have a long name made-up of letters and numbers that probably looks like this: LC08_L2SP_188054_20221120_20221129_02_T1.

In this article, we will use python to extract the meaning of the file name.

After downloading a Landsat file from the USGS Earth Explorer, there’s surprisingly a lot of information you can get from just the file name. The following web pages provide detailed information on the file naming convention:-

  • https://www.usgs.gov/faqs/what-naming-convention-landsat-collections-level-1-scenes
  • https://gisgeography.com/landsat-file-naming-convention/

The Landsat satellite series is a long-running satellite program that provides high-resolution imagery of the Earth's surface. The images taken by the Landsat satellites are named using a standardized naming convention that includes information about the satellite, the path and row of the image, the date the image was taken, and the band of the image.

Here is an example of a Landsat image file name: LC08_L1TP_012030_20170604_20170615_01_T1

This file name can be interpreted as follows:

LC08: The satellite that took the image (Landsat 8)

L1TP: The processing level of the image (Level 1 Terrain Corrected)

012030: The path and row of the image (path 01, row 20)

20170604: The date the image was taken (June 4, 2017)

20170615: The date the image was processed (June 15, 2017)

01: The band of the image (band 1)

T1: The product type of the image (Type 1)

You can use Python to parse and interpret Landsat image file names by splitting the file name string using the split() method and extracting the relevant pieces of information using string slicing and indexing. For example:

filename = 'LC08_L1TP_012030_20170604_20170615_01_T1'

satellite = filename[:4]  # 'LC8'
processing_level = filename[5:9]  # 'L1TP'
path_row = filename[10:16]  # '012030'
date_taken = filename[17:25]  # '20170604'
date_processed = filename[26:34]  # '20170615'
band = filename[35:37]  # '01'
product_type = filename[38:]  # 'T1'

      The satellite name is: {satellite}, 
      The processing level of the image is: {processing_level}, 
      The path and row of the image is: {path_row}, 
      The date the image was taken on: {date_taken}, 
      The date the image was processed is: {date_processed}, 
      The band of the image is: {band}, 
      The product type of the image is: {product_type}

The code use string slicing to get the required information from the file names.

Saturday, February 4, 2023

SVG remove polygon using JS

 In this post, you will find a code snippet that will remove a state polygon on mouse click. The tech stack used are: HTML, CSS, JS and SVG.

The result will look like below image.

First step is to setup a basic HTML page and use the 'object' tag to embed the SVG file into the HTML body like this:-

<object id="svg-object" data="svg_map_filename.svg" type="image/svg+xml"></object>

Then we will update the SVG file with CSS and JS code as follow. In the '.svg' document, we need to put the styles declaration inside cdata, as follows;-

<style type="text/css" media="screen"> <![CDATA[

/*Add CSS code here...*/

  ]]> </style>

The CSS style is added at the top of the svg file just after the opening <svg ...> tag.

Lastly we will add JS code at the end of the  svg file just after the closing <svg ...> tag. The script code must be wrapped inside cdata, as follows;-

<script> <![CDATA[

    // Add JS code here...

  ]]> </script>

Wrapping the CSS or JS codes in the cdata is important so that characters like > don't conflict with XML parsers. Using cdata is highly recommended for embedding style or script in SVG, even if the conflicting character is not given in the style sheet or script file.

That is it!