Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Download with geometry parameter #81

Closed
nmtarr opened this issue Apr 22, 2021 · 10 comments · Fixed by #84
Closed

Download with geometry parameter #81

nmtarr opened this issue Apr 22, 2021 · 10 comments · Fixed by #84
Milestone

Comments

@nmtarr
Copy link

nmtarr commented Apr 22, 2021

Hello,

I can't seem to figure out how to run occurrences.download() with a geometry parameter successfully. I've tried enough tweaks to get to the point of wondering if there's a bug. Anyone got any advice?

I'm using Python 3.7.10 and pygbif 0.5.0. Here is my code; it works without the geometry parameter:

------------------------------------------------

from pygbif import occurrences

username = 'xxxxxx'
password = 'xxxxxx'
email = 'xxxxxx'

download_filters = ["taxonKey = 2496287",
"geometry within 'POLYGON ((-82.7 36.9, -85.0 35.6, -81.0 33.5, -79.4 36.3, -79.4 36.3, -82.7 36.9))'"]

download = occurrences.download(download_filters,
pred_type='and',
user = username,
pwd = password,
email = email)
#-------------------------------------------------

And here is the error message:

Exception: error: JSON parse error: Cannot construct instance of org.gbif.api.model.occurrence.predicate.WithinPredicate, problem: may not be null; nested exception is com.fasterxml.jackson.databind.exc.ValueInstantiationException: Cannot construct instance of org.gbif.api.model.occurrence.predicate.WithinPredicate, problem: may not be null
at [Source: UNKNOWN; line: -1, column: -1] (through reference chain: org.gbif.api.model.occurrence.predicate.ConjunctionPredicate["predicates"]->java.util.ArrayList[1]), with error status code 400check your number of active downloads.

Regards,

Nathan

@sckott
Copy link
Collaborator

sckott commented Apr 22, 2021

thanks, on leave until may 3, will have a look then

@sckott
Copy link
Collaborator

sckott commented May 6, 2021

Wasn't quite sure, had to look this one up, see https://github.com/sckott/pygbif/blob/master/test/test-occurrences-download_request.py#L83

Seems a little bit different from other queries, have to use GbifDownload to construct a class first, then add_geometry

e.g.,

req = GbifDownload("name", "email")
req.add_geometry(
    "POLYGON((-14.06 42.55, 9.84 38.27, -7.03 26.43, -14.06 42.55))"
)
req.post_download()

@nmtarr
Copy link
Author

nmtarr commented May 10, 2021 via email

@sckott
Copy link
Collaborator

sckott commented May 18, 2021

@nmtarr Yes, download dev version from github pip install git+git://github.com/sckott/pygbif.git#egg=pygbif

@nmtarr
Copy link
Author

nmtarr commented Jun 24, 2021

@sckott I downloaded the dev version, but I'm still getting the error as described above. Can someone please confirm that my geometry parameter should indeed be formatted like this:

"geometry within 'POLYGON ((-82.7 36.9, -85.0 35.6, -81.0 33.5, -79.4 36.3, -79.4 36.3, -82.7 36.9))'"

I'm not confident that I've got it right.

Thanks for the help.

@sckott
Copy link
Collaborator

sckott commented Jun 28, 2021

The string you supply to add_geometry should just be the WKT itself, without the geometry within part - the geometry within gets added internally. Does that make sense?

@nmtarr
Copy link
Author

nmtarr commented Jun 29, 2021

@sckott Thanks. That makes sense for use of add_geometry. I would really like to be able to include a geometry parameter with occurrences.download. The documentation for that function states that geometry can be included. Is that not actually the case?

sckott added a commit that referenced this issue Jun 29, 2021
- bump package version
- add a test for adding geometry via a string rather than via add_geometry
- (unrelated: also remove response header content-type check in gbif_GET_write because ctype has changed)
@sckott
Copy link
Collaborator

sckott commented Jun 29, 2021

Got it now, thanks for clarifying.

Okay, just pushed a change on branch geometry-predicate. The download predicate logic was splitting strings on spaces, which doesn't work for geometry predicate since you can't remove spaces from a WKT string. Should work now after reinstalling from github. Let me know if works.

@nmtarr
Copy link
Author

nmtarr commented Jun 30, 2021

It is working for me now. Thanks for addressing the issue!

@sckott
Copy link
Collaborator

sckott commented Jun 30, 2021

Awesome, glad it works now.

i'll PR the change to the main branch and seek a bit of feedback first from other contribs

@sckott sckott added this to the v0.6 milestone Jun 30, 2021
sckott added a commit that referenced this issue Jun 30, 2021
- bump package version
- add a test for adding geometry via a string rather than via add_geometry
- (unrelated: also remove response header content-type check in gbif_GET_write because ctype has changed)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants