kapadia / usgs

Client library for interfacing with USGS datasets
http://kapadia.github.io/usgs/
ISC License
109 stars 38 forks source link

usgs uses minimum bounding rectangle now for spatial filter #47

Open rbavery opened 4 years ago

rbavery commented 4 years ago

https://earthexplorer.usgs.gov/inventory/documentation/test?version=1.3.0 used ll and ur coordinates but the later api versions use the MBR. I think this might be what is causing my Remote Disconnected errors.

This payload would need to be updated in the search function, I'll see if I can fix this and submit a PR if PRs are being accepted.

kapadia commented 4 years ago

Yep, PRs welcome. There was some effort to update some calls to the v1.4 API, such as during login, but not everything was updated.

Feel free to drop your usage here, and I'll can try to confirm the issue if you're not entirely sure.

rbavery commented 4 years ago

Awesome thanks! Here is my call

from usgs import api results = api.search("ARD_TILE", "EE", start_date="2002-06-01" , ll={"longitude":-103.962375,"latitude":40.132703}, ur={"longitude": -95.192605,"latitude": 42.950893}, api_key=token)

kapadia commented 4 years ago

Try this in your shell. Make sure you're logged in as well

usgs search --node EE ARD_TILE --start-date 2002-06-01 --end-date 2002-06-07 --lower-left -103.962375 40.132703 --upper-right -95.192605 42.950893 --geojson

Your query doesn't set an end date, which, in my experience tends to cause the USGS servers to hang. If you're trying to search from 2002 to current, you'll want to chunk the queries along the date range. Try one month intervals to start. If that's successful in a reasonable amount of time, expand the time range. If that falls over, try reducing to one or two week intervals.

rbavery commented 4 years ago

I get the following error running that line, not sure what's going on.

# rave at rave-thinkpad in ~ [14:37:33]
→ usgs search --node EE ARD_TILE --start-date 2002-06-01 --end-date 2002-06-07 --lower-left -103.962375 40.132703 --upper-right -95.192605 42.950893 --geojson
Traceback (most recent call last):
  File "/home/rave/miniconda3/bin/usgs", line 10, in <module>
    sys.exit(usgs())
  File "/home/rave/miniconda3/lib/python3.7/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/home/rave/miniconda3/lib/python3.7/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/home/rave/miniconda3/lib/python3.7/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/rave/miniconda3/lib/python3.7/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/rave/miniconda3/lib/python3.7/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/home/rave/miniconda3/lib/python3.7/site-packages/usgs/scripts/cli.py", line 211, in search
    print(json.dumps(result))
  File "/home/rave/miniconda3/lib/python3.7/json/__init__.py", line 231, in dumps
    return _default_encoder.encode(obj)
  File "/home/rave/miniconda3/lib/python3.7/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/home/rave/miniconda3/lib/python3.7/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "/home/rave/miniconda3/lib/python3.7/json/encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type map is not JSON serializable

It looks like the result is received but can't be printed with json.dumps so maybe it is a python version issue, I'll try this in a different env

rbavery commented 4 years ago

The error also occurs on python 3.6.7

rbavery commented 4 years ago

I'm not sure what the issue is with the cli, but I've made a PR that adds geojson filtering for the python api. My PR doesn't seem to fix or change the above error for the cli.

kapadia commented 4 years ago

Likely a version issue. I'll take a look tomorrow.

arbab-vassar-labs commented 1 year ago

@kapadia I've made an effort to implement GeoJSON filtering, but unfortunately, it doesn't appear to be functioning as intended. Would you be so kind as to inform me if this issue has already been addressed? Your assistance would be greatly appreciated.