Skip to main content

Hello,


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.

    Example:

#my bounding box  (of the buffer): I generated it using the bounding box function over the polygon I have created with the buffer
bbox_coords_wgs84=w101.59549511684716,
21.452549959193306,
101.59551308315284,
21.452566680806214]


evalscript = """
//VERSION=3

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

function evaluatePixel(sample) {
return esample.DEM]
}
"""

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

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

df_entry_"interval_from"] = parse_time(single_datae"interval"]r"from"]).date()
df_entry_"interval_to"] = parse_time(single_datae"interval"]r"to"]).date()

for output_name, output_data in single_datae"outputs"].items():
for band_name, band_values in output_datat"bands"].items():
band_stats = band_valuesv"stats"]
if band_stats_"sampleCount"] == band_stats_"noDataCount"]:
is_valid_entry = False
break

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
else:
df_entry_col_name] = value

if is_valid_entry:
df_data.append(df_entry)

return pd.DataFrame(df_data)




elev_request = SentinelHubStatistical(
aggregation=SentinelHubStatistical.aggregation(
evalscript=evalscript,
time_interval=("2020-01-01", "2020-01-31"),
aggregation_interval="P1D",
size=(bbox_size),
),
input_data=_SentinelHubStatistical.input_data(DataCollection.DEM_COPERNICUS_30)],
bbox=bbox,
config=config,
)

result_stats =elev_request.get_data()d0]


DownloadFailedException: Failed to download from:
https://services.sentinel-hub.com/api/v1/statistics

with HTTPError:

400 Client Error: Bad Request for url: https://services.sentinel-hub.com/api/v1/statistics

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).

Hi,

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,
 


Thank you 
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.


Reply