planetlabs / planet-client-python

Python client for Planet APIs
https://planet-sdk-for-python-v2.readthedocs.io/en/latest/
Apache License 2.0
276 stars 92 forks source link

Geometry filter that worked in 2.6 does not work in 2.7 #1038

Closed s6hebern closed 6 months ago

s6hebern commented 6 months ago

Expected behavior In version 2.6, the attached search filter worked fine. Attaching the original geojson as well (had to rename it to "json" to be able to upload). bunthaus.json planet_search_filter.json

Actual behavior (describe the problem) In version 2.7, that same search filter returns the following error: planet_error.txt

Minimum, Complete, Viable Code Sample Tried my best to extract the relevant functions from a much larger script.

import datetime
import asyncio
import geopandas as gpd
from planet import Auth, data_filter, Session

def prepare_aoi(aoi):
    gdf = gpd.read_file(aoi)
    # make MultiPolygon
    if gdf.geometry.count() > 1:
        log.warn('Found multiple features! Morphing them into one multipart feature ...')
        multipart = gpd.tools.collect(gdf.geometry)
        crs = gdf.crs
        gdf = gpd.GeoDataFrame({'id': [0], 'geometry': [multipart]}, crs=crs)
        gdf.to_crs(epsg=4326, inplace=True)
    return json.loads(gdf.to_json())

async def search_scenes(geojson, start, end, api_key):
    search_filter = data_filter.and_filter([
        data_filter.permission_filter(),
        data_filter.string_in_filter('instrument', ['PSB.SD', ]),
        data_filter.date_range_filter('acquired', gte=start),
        data_filter.date_range_filter('acquired', lte=end),
        data_filter.geometry_filter(geojson),
    ])
    async with Session(auth=Auth.from_key(api_key)) as session:
        client = session.client('data')
        return {item.get('id'): item.get('properties').get('cloud_cover') * 100 async for item in
                client.search(['PSScene'], search_filter, limit=0)}

if __name__ == '__main__':
    # "MY_GEOJSON" needs to be the real file
    geojson = prepare_aoi(MY_GEOJSON)
    start = datetime.datetime(2023, 9, 25)
    end = datetime.datetime(2023, 9, 30)
    # provide working API key here
    await search_scenes(geojson, start, end, API_KEY)

Workaround Downgrade to version 2.6

Environment Information

Installation Method pip

bauer-eo commented 6 months ago

confirmed, also see this in my routines

stephenhillier commented 6 months ago

Thanks for creating an issue and for providing a code sample. @angaither was able to reproduce the error and released a fix (2.7.1). Can you confirm if that fixes the issue?

s6hebern commented 6 months ago

Thanks for creating an issue and for providing a code sample. @angaither was able to reproduce the error and released a fix (2.7.1). Can you confirm if that fixes the issue?

Confirmed! Thanks for the quick solution!