Access DEM data using statistical API


I’m trying to access elevation data per points using the statistical API.
I have used geopandas to generate small polygons (reproject them to crs 3857 and then build buffer , reproject back to 4326, and set geometry to the new buffer column), and then sent it as a statistical request.
However, this fails . Here are some questions/explanation about the failure:

  1. size of polygons - seems like the polygons should be small but not that much. If I buffer for 1meters, the bounding box size is 0,0 ,and then it fails.
  2. I get same error also when I put larger buffer size (2 meters). Then I get bbox size of 2,2 , so bbox “exists” but still same error.
#my bounding box  (of the buffer): I generated it using the bounding box function over the polygon I have created with the buffer

evalscript = """

function setup() {
  return {
    input: ["DEM"],
        id: "default",
        bands: 1,
        sampleType: SampleType.FLOAT32

function evaluatePixel(sample) {
  return [sample.DEM]

def stats_to_df(stats_data):
    """Transform Statistical API response into a pandas.DataFrame"""
    df_data = []

    for single_data in stats_data["data"]:
        df_entry = {}
        is_valid_entry = True

        df_entry["interval_from"] = parse_time(single_data["interval"]["from"]).date()
        df_entry["interval_to"] = parse_time(single_data["interval"]["to"]).date()

        for output_name, output_data in single_data["outputs"].items():
            for band_name, band_values in output_data["bands"].items():
                band_stats = band_values["stats"]
                if band_stats["sampleCount"] == band_stats["noDataCount"]:
                    is_valid_entry = False

                for stat_name, value in band_stats.items():
                    col_name = f"{output_name}_{band_name}_{stat_name}"
                    if stat_name == "percentiles":
                        for perc, perc_val in value.items():
                            perc_col_name = f"{col_name}_{perc}"
                            df_entry[perc_col_name] = perc_val
                        df_entry[col_name] = value

        if is_valid_entry:

    return pd.DataFrame(df_data)

    elev_request = SentinelHubStatistical(
            time_interval=("2020-01-01", "2020-01-31"),
    result_stats =elev_request.get_data()[0]

DownloadFailedException: Failed to download from:
with HTTPError:
400 Client Error: Bad Request for url:
Server response: “{“error”:{“status”:400,“reason”:“Bad Request”,“message”:“Processing error.”,“code”:“COMMON_EXCEPTION”}}”

  1. When I try to get the elevation I have to put the time range and aggregation parameters. Is there any way to exclude it?

So my goal here is to be able to retrieve elevation values for given points (after converting them to polygons).

Dear Reut,

You’re probably getting an error because DEM isn’t supported in statistical API. I don’t think polygon size is the problem, as I managed to get results with just 1 meter. Time parameters are crucial to statistical API, and are required, and as DEM has no time dimension, it’s not even supported.

What you can do is download a raw full resolution FLOAT32 DEM raster band, then inspect pixel values in QGIS by hand (if not too many) or input it into Python, then do analysis there.

All best,

1 Like

Thank you Monja.
I hope one day it ll be supported.
For now I used workaround based on this answer on gis stack-exchange, so I take very small image and get the value from the points.

1 Like