Issue with Scene Classification Algorithm

Hello everyone,

I’ve been trying to apply the Scene Classification algorithm in Sentinel Hub to classify land use within specific vector polygons in QGIS. However, I’m encountering difficulties and I suspect it might be due to a Coordinate Reference System (CRS) mismatch between the vector layer and the Sentinel Hub satellite image.

I’m attempting to generate a zonal histogram by using the Sentinel Hub satellite image as a raster layer and overlaying it with a vector layer. Unfortunately, when I initiate the process in QGIS, it seems to run indefinitely without completion. This situation exhausts my Processing Units on Sentinel Hub, preventing the process from finishing.

Could the discrepancy in CRS values between the vector layer and the Sentinel Hub satellite image be causing this issue? If so, how can I address it to ensure proper execution of the Scene Classification algorithm and successful generation of the zonal histogram?

I appreciate any insights or guidance you can provide regarding this problem. Thank you in advance for your help!

Best regards,
Ciro

Hi @cirotccmbauspesalq2 ,

Could you please describe your processing steps in details? Did you first download satellite imagery using Processing API and then did the post-processing (scene classification) in QGIS?

Hello @chung.horng,

Thank you for your response. I appreciate your willingness to help.

To clarify, I set up a layer within the Sentinel Hub dashboard and added it as a WMS layer on QGIS. Subsequently, I attempted to generate the zonal histogram using the native QGIS toolbox. I added the WMS layer as a raster and overlaid it with a vector layer in the QGIS zonal histogram tool. However, the QGIS tool fails to complete the request, and unfortunately, this process exhausts my Processing Units on the platform without achieving a successful result.

I hope this description provides more insight into my workflow. Any suggestions or guidance on resolving this issue would be greatly appreciated.

Thank you @cirotccmbauspesalq2 , this clarifies the issue.

To further pin down the issue, I need some more information:

  • I think you’re using Sentinel Hub QGIS plugin. What is the WMS layer you select in the plugin? Could you share the Evalscript of this layer? You can find out the Evalscript by visiting your Configuration on the dashboard → Click the configuration you select in the plugin → Click the layer you add as WMS → Check the script next to the Data Processing.
  • What error message did you get from running the zonal histogram tool?

Hi, @chung.horng. Thank you again.

Thank you for your continued assistance and interest in resolving this issue.

Actually, I’m not using the Sentinel Hub plugin in QGIS. My workflow involves configuring a WMS layer directly within the EO Browser Dashboard on the Sentinel Hub website. Subsequently, I add this layer from the Dashboard as a WMS layer in QGIS. My goal is to generate a zonal histogram using this configuration.

Regarding your inquiry about error messages, the zonal histogram tool doesn’t generate any error messages. The issue I’m encountering is that the tool doesn’t complete the process; it keeps running indefinitely without producing any output.

This is a print from my QGIS environment

Hi @cirotccmbauspesalq2 ,

I can confirm the issue of non-stopping processing of zonal histogram tool with a wms layer as input.

For now, the easiest workaround is to mast a request to download Scene Classification band data using Processing API and use TIFF as the input layer of zonal histogram tool.

I will further investigate how to use a wms layer as input for the zonal histogram tool and keep you up to date. If you have a working wms layer that can be used in the zonal histogram tool, please let me know as this can facilitate the investigation.

Hello @chong.horng,

Thank you for your prompt response and for providing a potential workaround for the zonal histogram tool issue.

I greatly appreciate your efforts in investigating the usage of a WMS layer as input for the zonal histogram tool. I understand that you’ll keep me updated on any developments in this regard.

In the meantime, I’m interested in exploring the solution you mentioned about using the Processing API to download Scene Classification band data and using TIFF as the input layer for the zonal histogram tool. Could you please guide me on how to proceed with this approach? I’m eager to learn more about using the Processing API for this purpose.

Thank you once again for your assistance and insights.

Hi @cirotccmbauspesalq2 ,

Here’s a step-by-step guide to implement the suggested workaround:

  1. Make a Processing API request to get a tiff containing scene classification data. This can be done via Requests Builder. For example, you can copy and paste the curl request below to the Request Preview window can click the parse button. Then you should be able to download the scene classification band as a tiff over the selected area.
curl -X POST https://services.sentinel-hub.com/api/v1/process \
 -H 'Content-Type: application/json' \
 -H 'Authorization: Bearer ' \
 -d '{
  "input": {
    "bounds": {
      "bbox": [
        12.44693,
        41.870072,
        12.541001,
        41.917096
      ]
    },
    "data": [
      {
        "dataFilter": {
          "timeRange": {
            "from": "2023-08-08T00:00:00Z",
            "to": "2023-08-08T23:59:59Z"
          }
        },
        "type": "sentinel-2-l2a"
      }
    ]
  },
  "output": {
    "width": 512,
    "height": 343.697,
    "responses": [
      {
        "identifier": "default",
        "format": {
          "type": "image/tiff"
        }
      }
    ]
  },
  "evalscript": "//VERSION=3\n\nfunction setup() {\n  return {\n    input: [\"SCL\"],\n    output: { bands: 1, sampleType: \"UINT8\" }\n  };\n}\n\nfunction evaluatePixel(sample) {\n  return [sample.SCL];\n}"
}'
  1. Import the tiff to qgis.
  2. Add a vector layer for zonal histogram calculation. For example, create a GeoJSON file with the following content and import it to qgis.
{
  "type": "Polygon",
  "coordinates": [
    [
      [
        12.44693,
        41.870072
      ],
      [
        12.541001,
        41.870072
      ],
      [
        12.541001,
        41.917096
      ],
      [
        12.44693,
        41.917096
      ],
      [
        12.44693,
        41.870072
      ]
    ]
  ]
}
  1. Run the zonal histogram tool using the two layers above as input and you should get the result.

For more information about the Processing API, please refer to the documentation. There’s also a Processing API webinar which should give you a thorough introduction to the API.

Hi, @chung.horng.

I’ll try out your solution and will keep you updated

Regards

Hello @chong.horng,

I want to express my sincere gratitude for the detailed instructions you provided. Following your guidance, I was able to successfully use the Processing API to download Scene Classification band data and utilize TIFF as the input layer for the zonal histogram tool. Your assistance has been invaluable in overcoming this challenge.

However, despite this progress, I’m still facing difficulties in achieving the automated land classification provided by the Scene Classification algorithm. Could you kindly help me with generating this automatic classification? Is it necessary to generate de zonal histogram? Any further insights or guidance you can provide would be greatly appreciated.

Thank you once again for your support and expertise.

Hi @cirotccmbauspesalq2 ,

In your case I would recommend using the Statistical API to automatically obtain zonal histogram.

Below is an example request to get zonal statistics and histogram of all acquisitions available from 2023-07-07 to 2023-08-17. For more details please have a look at the Statistical API documentation and, to get a better idea, go through the webinar on Statistical API which gives a step-by-step guide to the API.

curl -X POST https://services.sentinel-hub.com/api/v1/statistics \
 -H 'Authorization: Bearer ' \
 -H 'Accept: application/json' \
 -H 'Content-Type: application/json' \
 -d '{
  "input": {
    "bounds": {
      "bbox": [
        4524858.253997,
        2088521.994524,
        4532692.194797,
        2093982.407454
      ],
      "properties": {
        "crs": "http://www.opengis.net/def/crs/EPSG/0/3035"
      }
    },
    "data": [
      {
        "dataFilter": {},
        "type": "sentinel-2-l2a"
      }
    ]
  },
  "aggregation": {
    "timeRange": {
      "from": "2023-07-17T00:00:00Z",
      "to": "2023-08-17T23:59:59Z"
    },
    "aggregationInterval": {
      "of": "P1D"
    },
    "resx": "10",
    "resy": "10",
    "evalscript": "//VERSION=3\nfunction setup() {\n  return {\n    input: [{\n      bands: [\n        \"SCL\",\n        \"dataMask\"\n      ]\n    }],\n    output: [\n      {\n        id: \"scl\",\n        sampleType: \"INT8\",\n        bands: 1\n      },\n      {\n        id: \"dataMask\",\n        bands: 1,\n        sampleType: \"INT8\"\n      }]\n  };\n}\n\nfunction evaluatePixel(samples) {\n    return {\n        dataMask: [samples.dataMask],\n        scl: [samples.SCL]\n    };\n}\n"
  },
  "calculations": {
    "scl": {
      "histograms": {
        "default": {
          "binWidth": "1",
          "lowEdge": "0",
          "highEdge": "12"
        }
      }
    }
  }
}'

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.