if not geojson_str or not start_date or not end_date:
return JsonResponse(status=400)
try:
geojson = json.loads(geojson_str)
except json.JSONDecodeError:
return JsonResponse({'error': 'geosonerror'}, status=400)
if 'features' not in geojson or not geojson['features']:
return JsonResponse({'error': 'GeoJSONerror'}, status=400)
area_of_interest = geojson['features'][0]['geometry']
catalog = pystac_client.Client.open(
"https://planetarycomputer.microsoft.com/api/stac/v1",
modifier=planetary_computer.sign_inplace,
)
search = catalog.search(
collections=["sentinel-2-l2a"],
intersects=area_of_interest,
datetime=time_of_interest,
query={"eo:cloud_cover": {"lt": cloud_cover}},
)
items = list(search.get_items())
if not items:
return JsonResponse({'message': 'no image'}, status=200)
item_details = []
for item in items:
item_link = item.assets["visual"].href
parsed_url = urlparse(item_link)
filename = parsed_url.path.split('/')[-1]
filename_without_ext = filename.split('.')[0]
cloud_cover = item.properties['eo:cloud_cover']
item_details.append({
'Image ID':item.id,
'Product parameters': filename_without_ext,
'Shooting date': str(item.datetime.date()),
'Cloud cover': cloud_cover,
})
return JsonResponse({'message': 'successful', 'Data information': item_details})
return JsonResponse({'error': 'POST'}, status=405)
I also encountered the same problem when I integrated the functionality into Django
Wrong content:pystac_client.exceptions.apierror: the request exceeded the maximum allowed time, please try again. if the issue persists, please contact [email protected].
Originally posted by @Mrjoecen in #240