bird-house / finch

A Web Processing Service for Climate Indicators
https://finch.readthedocs.io/en/latest/
Apache License 2.0
13 stars 5 forks source link

Wrong geojson mimetype #153

Closed aulemahal closed 3 years ago

aulemahal commented 3 years ago

Description

While trying average_shape I stumbled into this error. It seems the geojson is not recognized to the appropriate mime type string?

Environment

Steps to Reproduce

from owslib.wfs import WebFeatureService
from birdy import WPSClient

wps = WPSClient('http://localhost:5000')  # default finch at master

tasmin = "https://pavics.ouranos.ca/twitcher/ows/proxy/thredds/dodsC/birdhouse/testdata/flyingpigeon/cmip3/tasmin.sresa2.miub_echo_g.run1.atm.da.nc"

wfs_url = 'http://pavics.ouranos.ca/geoserver/wfs'
# Connect to GeoServer WFS service.
wfs = WebFeatureService(wfs_url, version='2.0.0')

layer_id = 'public:canada_admin_boundaries'
meta = wfs.contents[layer_id]

# Get the actual data
data = wfs.getfeature(typename='public:canada_admin_boundaries', bbox=(-74.5, 45.2, -73, 46), outputFormat='JSON')
with open('output.geojson', 'wb') as f:
    f.write(data.read())

sub = wps.subset_polygon(tasmin,'output.geojson', variable=['tasmin'])

Fails with:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-61-1cd045d567fe> in <module>
     18     f.write(data.read())
     19 
---> 20 sub = wps.subset_polygon(tasmin,'output.geojson', variable=['tasmin'])

</home/phobos/.conda/envs/finch/lib/python3.8/site-packages/birdy/client/base.py-1533> in subset_polygon(self, resource, shape, start_date, end_date, variable)

~/.conda/envs/finch/lib/python3.8/site-packages/birdy/client/base.py in _execute(self, pid, **kwargs)
    281     def _execute(self, pid, **kwargs):
    282         """Execute the process."""
--> 283         wps_inputs = self._build_inputs(pid, **kwargs)
    284         wps_outputs = [
    285             (o.identifier, "ComplexData" in o.dataType)

~/.conda/envs/finch/lib/python3.8/site-packages/birdy/client/base.py in _build_inputs(self, pid, **kwargs)
    251 
    252                     # Guess the mimetype of the input value
--> 253                     mimetype, encoding = guess_type(value, supported_mimetypes)
    254 
    255                     if encoding is None:

~/.conda/envs/finch/lib/python3.8/site-packages/birdy/utils.py in guess_type(url, supported)
    167     else:
    168         if mime not in supported:
--> 169             raise ValueError(f"mimetype {mime} not in supported mimetypes {supported}.")
    170 
    171     return mime, enc

ValueError: mimetype application/geo+json not in supported mimetypes ['application/vnd.geo+json', 'application/x-zipped-shp'].

Are there 2 versions of the geojson mimetype, or am I mistaken in how this works?

Zeitsperre commented 3 years ago

I was working on a few PRs related to this (revision and testing) but got sidetracked: https://github.com/bird-house/birdy/pull/189/files https://github.com/bird-house/emu/pull/108/files

Essentially, application/vnd.geo+json is obsolete. It needs to be updated to application/geo+json in a some component libraries and verified in emu and birdy. If you'd like, I can bring you up to speed on this next week sometime.

aulemahal commented 3 years ago

Oh I understand! It's not really a need for me right now, just that testing with a geojson was slightly more straightforward than zipping a shapefile. Good to know it is getting solved!

Zeitsperre commented 3 years ago

@aulemahal With the changes in Birdy and PyWPS, is this still an issue?

aulemahal commented 3 years ago

Yes! PyWPS 4.4.0 and birdy@master make this work. I haven't tested with the latest birdy release. Should I?

Zeitsperre commented 3 years ago

"Yes!" as in "Yes! It works!" or "Yes!" as in "Yes! Why isn't there a fix yet?" ;)

Feel free to check with the newest Birdy release. The fix should be in the latest release. If so, feel free to close.

aulemahal commented 3 years ago

haha sorry. The bug is gone when using PyWPS 4.4 and birdy 0.7.0 (or master). Thanks!